main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
994 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var ToPrimitive = require('./ToPrimitive');
|
---|
4 |
|
---|
5 | var callBound = require('call-bind/callBound');
|
---|
6 |
|
---|
7 | var $replace = callBound('String.prototype.replace');
|
---|
8 |
|
---|
9 | var safeRegexTester = require('safe-regex-test');
|
---|
10 |
|
---|
11 | var isNonDecimal = safeRegexTester(/^0[ob]|^[+-]0x/);
|
---|
12 |
|
---|
13 | // http://262.ecma-international.org/5.1/#sec-9.3
|
---|
14 |
|
---|
15 | module.exports = function ToNumber(value) {
|
---|
16 | var prim = ToPrimitive(value, Number);
|
---|
17 | if (typeof prim !== 'string') {
|
---|
18 | return +prim; // eslint-disable-line no-implicit-coercion
|
---|
19 | }
|
---|
20 |
|
---|
21 | var trimmed = $replace(
|
---|
22 | prim,
|
---|
23 | // eslint-disable-next-line no-control-regex
|
---|
24 | /^[ \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,
|
---|
25 | ''
|
---|
26 | );
|
---|
27 | if (isNonDecimal(trimmed)) {
|
---|
28 | return NaN;
|
---|
29 | }
|
---|
30 |
|
---|
31 | return +trimmed; // eslint-disable-line no-implicit-coercion
|
---|
32 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.