tc39 / tc39/proposal-amount

JSON support

Open
#53 4 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

Should Amount have a toJSON method? If so, perhaps the method could return something like

{ 
  "value": "123.456"
  "unit": "kilogram"
}

The value in unit could be undefined if the Amount doesn't have a unit.

Do we want to include the significant digits and/or fraction digits properties, too?

This issue touches on #35. If we round on the way in, then the string contained in the value property is precisely the value, so including significant digits and fraction digits is arguably unnecessary. However, if we round only on the way out (only), conversion to JSON might be like toNumber, toString in that toJSON would not just emit a JSON object, but also do rounding beforehand. Altneratively, one could include significant digits and fraction digits in the JSON:

let a = new Amount(123.456);
a.with({ fractionDigits: 2 }.toJSON();
// { "value": "123.46", "unit": undefined }

// or:

// { "value": "123.456", "fractionDigits": 2, "unit": undefined }

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

No files or tests are named. Start by reviewing the JSON examples and the relationship to issue #35, then resolve whether toJSON should round values and include precision properties, and define the behavior for amounts without units.

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
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.