CanonicalNumericIndexString.js 572 B

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