Sha256: 20a508f36b9dd28ee3989e66cb92e4a24f292c019c19de9e8da144cf9ee04b79

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

'use strict';
var $ = require('../internals/export');
var toInteger = require('../internals/to-integer');
var parseInt = require('../internals/parse-int');

var INVALID_NUMBER_REPRESENTATION = 'Invalid number representation';
var INVALID_RADIX = 'Invalid radix';
var valid = /^[\da-z]+$/;

// `Number.fromString` method
// https://github.com/tc39/proposal-number-fromstring
$({ target: 'Number', stat: true }, {
  fromString: function fromString(string, radix) {
    var sign = 1;
    var R, mathNum;
    if (typeof string != 'string') throw TypeError(INVALID_NUMBER_REPRESENTATION);
    if (!string.length) throw SyntaxError(INVALID_NUMBER_REPRESENTATION);
    if (string.charAt(0) == '-') {
      sign = -1;
      string = string.slice(1);
      if (!string.length) throw SyntaxError(INVALID_NUMBER_REPRESENTATION);
    }
    R = radix === undefined ? 10 : toInteger(radix);
    if (R < 2 || R > 36) throw RangeError(INVALID_RADIX);
    if (!valid.test(string) || (mathNum = parseInt(string, R)).toString(R) !== string) {
      throw SyntaxError(INVALID_NUMBER_REPRESENTATION);
    }
    return sign * mathNum;
  }
});

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/core-js/modules/esnext.number.from-string.js
disco_app-0.18.2 test/dummy/node_modules/core-js/modules/esnext.number.from-string.js
condenser-0.0.8 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js
jester-data-8.0.0 node_modules/core-js/modules/esnext.number.from-string.js
ezii-os-5.2.1 node_modules/core-js/modules/esnext.number.from-string.js
ezii-os-2.0.1 node_modules/core-js/modules/esnext.number.from-string.js
ezii-os-1.1.0 node_modules/core-js/modules/esnext.number.from-string.js
ezii-os-1.0.0 node_modules/core-js/modules/esnext.number.from-string.js
condenser-0.0.7 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js
ezii-os-0.0.0.1.0 node_modules/core-js/modules/esnext.number.from-string.js
ezii-os-0.0.0.0.1 node_modules/core-js/modules/esnext.number.from-string.js
condenser-0.0.5 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js