source: imaps-frontend/node_modules/es-abstract/5/ToNumber.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 929 bytes
Line 
1'use strict';
2
3var ToPrimitive = require('./ToPrimitive');
4
5var callBound = require('call-bound');
6
7var $replace = callBound('String.prototype.replace');
8
9var safeRegexTester = require('safe-regex-test');
10
11var isNonDecimal = safeRegexTester(/^0[ob]|^[+-]0x/);
12
13var $Number = Number;
14
15// http://262.ecma-international.org/5.1/#sec-9.3
16
17module.exports = function ToNumber(value) {
18 var prim = ToPrimitive(value, $Number);
19 if (typeof prim !== 'string') {
20 return $Number(prim);
21 }
22
23 var trimmed = $replace(
24 prim,
25 // eslint-disable-next-line no-control-regex
26 /^[ \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u0085]+|[ \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u0085]+$/g,
27 ''
28 );
29 if (isNonDecimal(trimmed)) {
30 return NaN;
31 }
32
33 return +trimmed;
34};
Note: See TracBrowser for help on using the repository browser.