tc39 / tc39/proposal-amount

Amount toString serialization discussions

Open
#116 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
58
Forks
12
Avg merge
2h 35m
Merged PRs (30d)
2

Description

Diving straight in: there are a number of constraints around toString, which could carry different weight:

  • Should be consistently (always or never) parseable by existing parse functions like JSON.parse and Number.parseFloat
  • Should work seamlessly with sequence units
  • Should be parseable by a custom parser
  • Should be developer-readable
  • Should build on top of existing serialization formats if possible

Any other constraints? Please comment below.

With that in mind, here are some possible syntaxes for these inputs:

  • Unitless: { value: 1, unit: null }
  • Meter: { value: 5, unit: "meter" }
  • Sequence: { value: { pound: 7, ounce: 1 }, unit: "pound-and-ounce" }
Name Unitless Meter Sequence
Stage 2 [1e+0 ~] [5e+0 meter] [7e+0 pound, 1e+0 ounce]
With IXDTF annotations 1e+0[] 5e+0[meter] 7e+0,1e+0[pound-and-ounce]
At-sign IXDTF @1e+0 @5e+0[meter] @7,1e+0[pound-and-ounce]
Raw JSON {"value":1e+0,"unit":null} {"value":5e+0,"unit":"meter"} {"value":{"pound":7e+0,"ounce":1e+0},"unit":"pound-and-ounce"}
Nicer JS, A [{value:1e+0}] [{value:5e+0,unit:"meter"}] [{value:7e+0,unit:"pound"},{value:1e+0,unit:"ounce"}]
Nicer JS, B [1e+0] [{meter:5e+0}] [{pound:7e+0},{ounce:1e+0}]
Inspired by ISO 8601 P-string A1e+0 A5e+0meter A7e+0pound1e+0ounce
P-string with well-known abbreviations A1e+0 A5e+0M A7e+0L1e+0O
P-string with annotations A1e+0 A5e+0[meter] A7e+0[pound]1e+0[ounce]

Please feel free to offer more ideas.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the constraints and syntax comparison in the issue, then review the existing parse functions and serialization formats referenced there. The issue currently asks for more discussion and does not identify files, tests, an implementation entry point, or a settled definition of done.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.