diff --git a/History.md b/History.md index dc39684..9378c5e 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +1.1.0 / 2018-06-29 +================== + * add Number.parse + + 1.0.1 / 2018-05-25 ================== * delete global extends diff --git a/Readme.md b/Readme.md index d850b1f..72aba59 100644 --- a/Readme.md +++ b/Readme.md @@ -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() diff --git a/index.js b/index.js index 824980e..0d90b89 100644 --- a/index.js +++ b/index.js @@ -10,5 +10,6 @@ require('./lib/object') require('./lib/array') require('./lib/string') +require('./lib/number') require('./lib/date') require('./lib/promise') diff --git a/lib/number.js b/lib/number.js new file mode 100644 index 0000000..a51bad1 --- /dev/null +++ b/lib/number.js @@ -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 + }) +} diff --git a/package.json b/package.json index cd68934..c418c31 100644 --- a/package.json +++ b/package.json @@ -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",