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
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var ToPrimitive = require('./ToPrimitive');
|
---|
| 4 |
|
---|
[79a0317] | 5 | var callBound = require('call-bound');
|
---|
[d565449] | 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 |
|
---|
[79a0317] | 13 | var $Number = Number;
|
---|
| 14 |
|
---|
[d565449] | 15 | // http://262.ecma-international.org/5.1/#sec-9.3
|
---|
| 16 |
|
---|
| 17 | module.exports = function ToNumber(value) {
|
---|
[79a0317] | 18 | var prim = ToPrimitive(value, $Number);
|
---|
[d565449] | 19 | if (typeof prim !== 'string') {
|
---|
[79a0317] | 20 | return $Number(prim);
|
---|
[d565449] | 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 |
|
---|
[79a0317] | 33 | return +trimmed;
|
---|
[d565449] | 34 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.