增加Number.parse方法

master
宇天 2018-06-29 19:54:02 +08:00
parent 8abd6982ec
commit 32d0841e60
5 changed files with 55 additions and 16 deletions

View File

@ -1,3 +1,8 @@
1.1.0 / 2018-06-29
==================
* add Number.parse
1.0.1 / 2018-05-25 1.0.1 / 2018-05-25
================== ==================
* delete global extends * delete global extends

View File

@ -8,7 +8,6 @@
+ Obejct + Obejct
* empty() * empty()
+ Obejct.prototype + Obejct.prototype
* merge() * merge()
@ -38,6 +37,8 @@
* padEnd() * padEnd()
+ Number
* parse()

View File

@ -10,5 +10,6 @@
require('./lib/object') require('./lib/object')
require('./lib/array') require('./lib/array')
require('./lib/string') require('./lib/string')
require('./lib/number')
require('./lib/date') require('./lib/date')
require('./lib/promise') require('./lib/promise')

32
lib/number.js Normal file
View File

@ -0,0 +1,32 @@
/**
*
* @authors yutent (yutent@doui.cc)
* @date 2018-06-29 19:29:19
* @version $Id$
*/
'use strict'
// 简单的数字处理
// 将安全范围内的数字字符串转为数字类型
// 否则转为字符串类型
if (!Number.parse) {
Object.defineProperty(Number, 'parse', {
value: function(val) {
val += ''
if (val.startsWith(0) && !val.startsWith('0.')) {
return val
} else {
if (isFinite(val)) {
if (
val >= Number.MIN_SAFE_INTEGER &&
val <= Number.MAX_SAFE_INTEGER
) {
val = +val
}
}
return val
}
},
enumerable: false
})
}

View File

@ -1,6 +1,6 @@
{ {
"name": "es.shim", "name": "es.shim",
"version": "1.0.1", "version": "1.1.0",
"description": "Some shim api that let you can use in all node.js environment", "description": "Some shim api that let you can use in all node.js environment",
"keyworks": [ "keyworks": [
"es5", "es5",