Skip to content

Commit

Permalink
Remove ASCII case-insensitivity exception
Browse files Browse the repository at this point in the history
Ref. #15.
  • Loading branch information
mathiasbynens committed Jan 23, 2018
1 parent 71a3f90 commit 81f0a93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ For `Number` values, there is [`parseInt(string, radix = 10)`](https://tc39.gith

## Proposed solution

We propose extending both `BigInt` and `Number` with a new static `fromString(string, radix = 10)` method which acts as the inverse of `{BigInt,Number}.prototype.toString(radix = 10)`. It accepts only ASCII-case-insensitive strings that can be produced by `{BigInt,Number}.prototype.toString(radix = 10)`, and throws an exception for any other input.
We propose extending both `BigInt` and `Number` with a new static `fromString(string, radix = 10)` method which acts as the inverse of `{BigInt,Number}.prototype.toString(radix = 10)`. It accepts only strings that can be produced by `{BigInt,Number}.prototype.toString(radix = 10)`, and throws an exception for any other input.

## High-level API

Expand All @@ -46,22 +46,22 @@ The following examples use `Number.fromString`. The semantics for `BigInt.fromSt
Unlike `parseInt`, `fromString` intentionally lacks special handling for integer literal prefixes.

```js
Number.parseInt('0xC0FFEE');
Number.parseInt('0xc0ffee');
// → 12648430
Number.parseInt('0o755');
// → 0
Number.parseInt('0b00101010');
// → 0

Number.fromString('0xC0FFEE');
Number.fromString('0xc0ffee');
// → SyntaxError
Number.fromString('0o755');
// → SyntaxError
Number.fromString('0b00101010');
// → SyntaxError

Number.fromString('C0FFEE', 16);
//12648430 === 0xC0FFEE
//SyntaxError (toString produces lowercase digits)
Number.fromString('c0ffee', 16);
// → 12648430 === 0xc0ffee
Number.fromString('755', 8);
Expand Down
4 changes: 2 additions & 2 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1>BigInt.fromString ( _string_, _radix_ )</h1>
1. Else if _radix_ is *undefined*, let _R_ be 10.
1. Else, let _R_ be ? ToInteger(_radix_).
1. If _R_ &lt; 2 or _R_ &gt; 36, throw a *RangeError* exception.
1. If _string_ represents a mathematical integer value in radix-_R_ notation, using the characters <b>0</b>-<b>9</b> for digits with values 0 to 9, and the letters <b>A</b>-<b>Z</b> and <b>a</b>-<b>z</b> for digits with values 10 through 35, then
1. If _string_ represents a mathematical integer value in radix-_R_ notation, using the characters <b>0</b>-<b>9</b> for digits with values 0 to 9, and the letters <b>a</b>-<b>z</b> for digits with values 10 through 35, then
1. Let _mathInt_ be that mathematical integer value.
1. Else, throw a *SyntaxError* exception.
1. Let _number_ be _sign_ &times; _mathInt_.
Expand All @@ -58,7 +58,7 @@ <h1>Number.fromString ( _string_, _radix_ )</h1>
1. Else if _radix_ is *undefined*, let _R_ be 10.
1. Else, let _R_ be ? ToInteger(_radix_).
1. If _R_ &lt; 2 or _R_ &gt; 36, throw a *RangeError* exception.
1. If _string_ represents a mathematical number value in radix-_R_ notation, using the characters <b>0</b>-<b>9</b> for digits with values 0 to 9, and the letters <b>A</b>-<b>Z</b> and <b>a</b>-<b>z</b> for digits with values 10 through 35, then
1. If _string_ represents a mathematical number value in radix-_R_ notation, using the characters <b>0</b>-<b>9</b> for digits with values 0 to 9, and the letters <b>a</b>-<b>z</b> for digits with values 10 through 35, then
1. Let _mathNum_ be that mathematical number value.
1. Else, throw a *SyntaxError* exception.
1. Let _number_ be _sign_ &times; _mathNum_.
Expand Down

0 comments on commit 81f0a93

Please sign in to comment.