增加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
==================
* delete global extends

View File

@ -6,38 +6,39 @@
+ Obejct
* empty()
* empty()
+ Obejct.prototype
* merge()
* merge()
+ Array.prototype
* includes()
* includes()
+ Date
* isDate()
* isDate()
+ Date.prototype
* getFullWeek()
* getWeek()
* format()
* getFullWeek()
* getWeek()
* format()
+ String.prototype
* splice()
* htmlspecialchars()
* tohtml()
* xss()
* escape()
* padStart()
* padEnd()
* splice()
* htmlspecialchars()
* tohtml()
* xss()
* escape()
* padStart()
* padEnd()
+ Number
* parse()

View File

@ -10,5 +10,6 @@
require('./lib/object')
require('./lib/array')
require('./lib/string')
require('./lib/number')
require('./lib/date')
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",
"version": "1.0.1",
"version": "1.1.0",
"description": "Some shim api that let you can use in all node.js environment",
"keyworks": [
"es5",