CanonicalNumericIndexString.js 654 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var SameValue = require('./SameValue');
  5. var ToNumber = require('./ToNumber');
  6. var ToString = require('./ToString');
  7. var Type = require('./Type');
  8. // https://ecma-international.org/ecma-262/6.0/#sec-canonicalnumericindexstring
  9. module.exports = function CanonicalNumericIndexString(argument) {
  10. if (Type(argument) !== 'String') {
  11. throw new $TypeError('Assertion failed: `argument` must be a String');
  12. }
  13. if (argument === '-0') { return -0; }
  14. var n = ToNumber(argument);
  15. if (SameValue(ToString(n), argument)) { return n; }
  16. return void 0;
  17. };