Sha256: 8eabbfb44bab74eca2d08de23e08028b93a4b5be4045e365561ed15718d0be24

Contents?: true

Size: 1.1 KB

Versions: 17

Compression:

Stored size: 1.1 KB

Contents

'use strict';
var $ = require('../internals/export');
var toInteger = require('../internals/to-integer');
var parseInt = require('../internals/number-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

17 entries across 16 versions & 6 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/core-js/modules/esnext.number.from-string.js
tang-0.2.1 spec/tang_app/node_modules/core-js/modules/esnext.number.from-string.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/core-js/modules/esnext.number.from-string.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/core-js/modules/esnext.number.from-string.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/core-js/modules/esnext.number.from-string.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/core-js/modules/esnext.number.from-string.js
tang-0.2.0 spec/tang_app/node_modules/core-js/modules/esnext.number.from-string.js
tang-0.1.0 spec/tang_app/node_modules/core-js/modules/esnext.number.from-string.js
tang-0.0.9 spec/tang_app/node_modules/core-js/modules/esnext.number.from-string.js
enju_library-0.3.8 spec/dummy/node_modules/core-js/modules/esnext.number.from-string.js
condenser-0.3 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js
condenser-0.2 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js
condenser-0.1 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js
condenser-0.0.12 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js
condenser-0.0.11 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js
condenser-0.0.10 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js
condenser-0.0.9 lib/condenser/processors/node_modules/core-js-pure/modules/esnext.number.from-string.js