| /** | ||
| * @file copy 和 extend 方法相互引用,所以放在一个文件里。 | ||
| */ | ||
| const hasOwn = Object.prototype.hasOwnProperty | ||
| /** | ||
| * 深复制 JSON 对象的函数——除了对象和数组,其它类型的值都只会简单的赋值。 | ||
| * @param dest | ||
| * @param objects | ||
| * @return {*} | ||
| */ | ||
| export function extend (dest, ...objects) { | ||
| if (dest == null) return dest | ||
| objects.forEach(obj => { | ||
| if (obj == null) return | ||
| mixin(dest, obj) | ||
| }) | ||
| return dest | ||
| } | ||
| /** | ||
| * 复制一个值的方法。除了对象和和数组会使用新的以外,其它类型的值都是直接返回。 | ||
| * @param val | ||
| * @return {*} | ||
| */ | ||
| export function copy (val) { | ||
| if (Array.isArray(val)) { | ||
| const newArray = [] | ||
| val.forEach((item, index) => { | ||
| newArray[index] = copy(item) | ||
| }) | ||
| return newArray | ||
| } else if (typeof val === 'object' && val) { | ||
| return mixin({}, val) | ||
| } else { | ||
| return val | ||
| } | ||
| } | ||
| function mixin (to, from) { | ||
| for (let key in from) { | ||
| if (!hasOwn.call(from, key)) continue | ||
| to[key] = copy(from[key]) | ||
| } | ||
| return to | ||
| } |
+22
| /** | ||
| * 获取对象上一个属性的值 | ||
| * @param {*} obj | ||
| * @param {Array} pathArray | ||
| * @param {*} [defaultValue] | ||
| * @return {*} | ||
| */ | ||
| export default function (obj, pathArray, defaultValue) { | ||
| if (obj == null) return defaultValue | ||
| let value = obj | ||
| for (let i = 0; i < pathArray.length; i += 1) { | ||
| const key = pathArray[i] | ||
| value = value[key] | ||
| if (value == null) { | ||
| return defaultValue | ||
| } | ||
| } | ||
| return value | ||
| } |
| import isNumber from './isNumber' | ||
| /** | ||
| * 将一个小数转换为百分比 | ||
| * @param {number|string} number | ||
| * @param {number} [fixed=2] | ||
| * @return {string} | ||
| */ | ||
| export default function (number, fixed = 2) { | ||
| number = Number(number) | ||
| if (!isNumber(number)) return '' | ||
| return (number * 100).toFixed(fixed) + '%' | ||
| } |
+91
-8
| /*! | ||
| * nosh.js v0.0.4 | ||
| * nosh.js v0.1.0 | ||
| * https://github.com/lmk123/noshjs | ||
@@ -10,9 +10,23 @@ * Released under the MIT License. | ||
| var copy = function (obj) { | ||
| if (obj == null) { return obj } | ||
| return JSON.parse(JSON.stringify(obj)) | ||
| }; | ||
| /** | ||
| * 获取对象上一个属性的值 | ||
| * @param {*} obj | ||
| * @param {Array} pathArray | ||
| * @param {*} [defaultValue] | ||
| * @return {*} | ||
| */ | ||
| var get = function (obj, pathArray, defaultValue) { | ||
| if (obj == null) { return defaultValue } | ||
| var filterBy = function (array, prop, value) { | ||
| return array.filter(function (item) { return item[prop] === value; }) | ||
| var value = obj; | ||
| for (var i = 0; i < pathArray.length; i += 1) { | ||
| var key = pathArray[i]; | ||
| value = value[key]; | ||
| if (value == null) { | ||
| return defaultValue | ||
| } | ||
| } | ||
| return value | ||
| }; | ||
@@ -128,4 +142,72 @@ | ||
| /** | ||
| * @file copy 和 extend 方法相互引用,所以放在一个文件里。 | ||
| */ | ||
| var hasOwn = Object.prototype.hasOwnProperty; | ||
| /** | ||
| * 深复制 JSON 对象的函数——除了对象和数组,其它类型的值都只会简单的赋值。 | ||
| * @param dest | ||
| * @param objects | ||
| * @return {*} | ||
| */ | ||
| function extend (dest) { | ||
| var objects = [], len = arguments.length - 1; | ||
| while ( len-- > 0 ) objects[ len ] = arguments[ len + 1 ]; | ||
| if (dest == null) { return dest } | ||
| objects.forEach(function (obj) { | ||
| if (obj == null) { return } | ||
| mixin(dest, obj); | ||
| }); | ||
| return dest | ||
| } | ||
| /** | ||
| * 复制一个值的方法。除了对象和和数组会使用新的以外,其它类型的值都是直接返回。 | ||
| * @param val | ||
| * @return {*} | ||
| */ | ||
| function copy (val) { | ||
| if (Array.isArray(val)) { | ||
| var newArray = []; | ||
| val.forEach(function (item, index) { | ||
| newArray[index] = copy(item); | ||
| }); | ||
| return newArray | ||
| } else if (typeof val === 'object' && val) { | ||
| return mixin({}, val) | ||
| } else { | ||
| return val | ||
| } | ||
| } | ||
| function mixin (to, from) { | ||
| for (var key in from) { | ||
| if (!hasOwn.call(from, key)) { continue } | ||
| to[key] = copy(from[key]); | ||
| } | ||
| return to | ||
| } | ||
| /** | ||
| * 将一个小数转换为百分比 | ||
| * @param {number|string} number | ||
| * @param {number} [fixed=2] | ||
| * @return {string} | ||
| */ | ||
| var percentage = function (number, fixed) { | ||
| if ( fixed === void 0 ) fixed = 2; | ||
| number = Number(number); | ||
| if (!isNumber(number)) { return '' } | ||
| return (number * 100).toFixed(fixed) + '%' | ||
| }; | ||
| exports.extend = extend; | ||
| exports.copy = copy; | ||
| exports.filterBy = filterBy; | ||
| exports.get = get; | ||
| exports.isNumber = isNumber; | ||
@@ -136,1 +218,2 @@ exports.kmbt = kmbt; | ||
| exports.remove = remove; | ||
| exports.percentage = percentage; |
+89
-8
| /*! | ||
| * nosh.js v0.0.4 | ||
| * nosh.js v0.1.0 | ||
| * https://github.com/lmk123/noshjs | ||
| * Released under the MIT License. | ||
| */ | ||
| var copy = function (obj) { | ||
| if (obj == null) { return obj } | ||
| return JSON.parse(JSON.stringify(obj)) | ||
| }; | ||
| /** | ||
| * 获取对象上一个属性的值 | ||
| * @param {*} obj | ||
| * @param {Array} pathArray | ||
| * @param {*} [defaultValue] | ||
| * @return {*} | ||
| */ | ||
| var get = function (obj, pathArray, defaultValue) { | ||
| if (obj == null) { return defaultValue } | ||
| var filterBy = function (array, prop, value) { | ||
| return array.filter(function (item) { return item[prop] === value; }) | ||
| var value = obj; | ||
| for (var i = 0; i < pathArray.length; i += 1) { | ||
| var key = pathArray[i]; | ||
| value = value[key]; | ||
| if (value == null) { | ||
| return defaultValue | ||
| } | ||
| } | ||
| return value | ||
| }; | ||
@@ -123,2 +137,69 @@ | ||
| export { copy, filterBy, isNumber, kmbt, thousands, obj2qs, remove }; | ||
| /** | ||
| * @file copy 和 extend 方法相互引用,所以放在一个文件里。 | ||
| */ | ||
| var hasOwn = Object.prototype.hasOwnProperty; | ||
| /** | ||
| * 深复制 JSON 对象的函数——除了对象和数组,其它类型的值都只会简单的赋值。 | ||
| * @param dest | ||
| * @param objects | ||
| * @return {*} | ||
| */ | ||
| function extend (dest) { | ||
| var objects = [], len = arguments.length - 1; | ||
| while ( len-- > 0 ) objects[ len ] = arguments[ len + 1 ]; | ||
| if (dest == null) { return dest } | ||
| objects.forEach(function (obj) { | ||
| if (obj == null) { return } | ||
| mixin(dest, obj); | ||
| }); | ||
| return dest | ||
| } | ||
| /** | ||
| * 复制一个值的方法。除了对象和和数组会使用新的以外,其它类型的值都是直接返回。 | ||
| * @param val | ||
| * @return {*} | ||
| */ | ||
| function copy (val) { | ||
| if (Array.isArray(val)) { | ||
| var newArray = []; | ||
| val.forEach(function (item, index) { | ||
| newArray[index] = copy(item); | ||
| }); | ||
| return newArray | ||
| } else if (typeof val === 'object' && val) { | ||
| return mixin({}, val) | ||
| } else { | ||
| return val | ||
| } | ||
| } | ||
| function mixin (to, from) { | ||
| for (var key in from) { | ||
| if (!hasOwn.call(from, key)) { continue } | ||
| to[key] = copy(from[key]); | ||
| } | ||
| return to | ||
| } | ||
| /** | ||
| * 将一个小数转换为百分比 | ||
| * @param {number|string} number | ||
| * @param {number} [fixed=2] | ||
| * @return {string} | ||
| */ | ||
| var percentage = function (number, fixed) { | ||
| if ( fixed === void 0 ) fixed = 2; | ||
| number = Number(number); | ||
| if (!isNumber(number)) { return '' } | ||
| return (number * 100).toFixed(fixed) + '%' | ||
| }; | ||
| export { extend, copy, get, isNumber, kmbt, thousands, obj2qs, remove, percentage }; |
+91
-8
| /*! | ||
| * nosh.js v0.0.4 | ||
| * nosh.js v0.1.0 | ||
| * https://github.com/lmk123/noshjs | ||
@@ -12,9 +12,23 @@ * Released under the MIT License. | ||
| var copy = function (obj) { | ||
| if (obj == null) { return obj } | ||
| return JSON.parse(JSON.stringify(obj)) | ||
| }; | ||
| /** | ||
| * 获取对象上一个属性的值 | ||
| * @param {*} obj | ||
| * @param {Array} pathArray | ||
| * @param {*} [defaultValue] | ||
| * @return {*} | ||
| */ | ||
| var get = function (obj, pathArray, defaultValue) { | ||
| if (obj == null) { return defaultValue } | ||
| var filterBy = function (array, prop, value) { | ||
| return array.filter(function (item) { return item[prop] === value; }) | ||
| var value = obj; | ||
| for (var i = 0; i < pathArray.length; i += 1) { | ||
| var key = pathArray[i]; | ||
| value = value[key]; | ||
| if (value == null) { | ||
| return defaultValue | ||
| } | ||
| } | ||
| return value | ||
| }; | ||
@@ -130,4 +144,72 @@ | ||
| /** | ||
| * @file copy 和 extend 方法相互引用,所以放在一个文件里。 | ||
| */ | ||
| var hasOwn = Object.prototype.hasOwnProperty; | ||
| /** | ||
| * 深复制 JSON 对象的函数——除了对象和数组,其它类型的值都只会简单的赋值。 | ||
| * @param dest | ||
| * @param objects | ||
| * @return {*} | ||
| */ | ||
| function extend (dest) { | ||
| var objects = [], len = arguments.length - 1; | ||
| while ( len-- > 0 ) objects[ len ] = arguments[ len + 1 ]; | ||
| if (dest == null) { return dest } | ||
| objects.forEach(function (obj) { | ||
| if (obj == null) { return } | ||
| mixin(dest, obj); | ||
| }); | ||
| return dest | ||
| } | ||
| /** | ||
| * 复制一个值的方法。除了对象和和数组会使用新的以外,其它类型的值都是直接返回。 | ||
| * @param val | ||
| * @return {*} | ||
| */ | ||
| function copy (val) { | ||
| if (Array.isArray(val)) { | ||
| var newArray = []; | ||
| val.forEach(function (item, index) { | ||
| newArray[index] = copy(item); | ||
| }); | ||
| return newArray | ||
| } else if (typeof val === 'object' && val) { | ||
| return mixin({}, val) | ||
| } else { | ||
| return val | ||
| } | ||
| } | ||
| function mixin (to, from) { | ||
| for (var key in from) { | ||
| if (!hasOwn.call(from, key)) { continue } | ||
| to[key] = copy(from[key]); | ||
| } | ||
| return to | ||
| } | ||
| /** | ||
| * 将一个小数转换为百分比 | ||
| * @param {number|string} number | ||
| * @param {number} [fixed=2] | ||
| * @return {string} | ||
| */ | ||
| var percentage = function (number, fixed) { | ||
| if ( fixed === void 0 ) fixed = 2; | ||
| number = Number(number); | ||
| if (!isNumber(number)) { return '' } | ||
| return (number * 100).toFixed(fixed) + '%' | ||
| }; | ||
| exports.extend = extend; | ||
| exports.copy = copy; | ||
| exports.filterBy = filterBy; | ||
| exports.get = get; | ||
| exports.isNumber = isNumber; | ||
@@ -138,2 +220,3 @@ exports.kmbt = kmbt; | ||
| exports.remove = remove; | ||
| exports.percentage = percentage; | ||
@@ -140,0 +223,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
+6
-1
@@ -1,1 +0,6 @@ | ||
| undefined | ||
| /*! | ||
| * nosh.js v0.1.0 | ||
| * https://github.com/lmk123/noshjs | ||
| * Released under the MIT License. | ||
| */ | ||
| !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.nosh=e.nosh||{})}(this,function(e){"use strict";function n(e){if(Array.isArray(e)){var t=[];return e.forEach(function(e,r){t[r]=n(e)}),t}return"object"==typeof e&&e?r({},e):e}function r(e,r){for(var t in r)a.call(r,t)&&(e[t]=n(r[t]));return e}var t=function(e){return"number"==typeof e&&!isNaN(e)},i=function(e){if(e=Number(e),!t(e))return null;var n=!1,r=String(e);"-"===r[0]&&(n=!0,r=r.slice(1));var i=r.indexOf(".");return{minus:n,integer:i>0?r.slice(0,i):r,decimal:i>0?r.slice(i):""}},o=["","K","M","B","T","P","E"],u=o.length,f=Math.pow(10,3),c=Object.prototype.hasOwnProperty,a=Object.prototype.hasOwnProperty;e.extend=function(e){for(var n=[],t=arguments.length-1;t-- >0;)n[t]=arguments[t+1];return null==e?e:(n.forEach(function(n){null!=n&&r(e,n)}),e)},e.copy=n,e.get=function(e,n,r){if(null==e)return r;for(var t=e,i=0;i<n.length;i+=1)if(null==(t=t[n[i]]))return r;return t},e.isNumber=t,e.kmbt=function(e,n){void 0===n&&(n=2);var r=i(e);if(!r)return"";var t=Math.min(Math.ceil(r.integer.length/3),u)-1;return Number((e/Math.pow(f,t)).toFixed(n))+o[t]},e.thousands=function(e){var n=i(e);if(!n)return"";for(var r=n.minus,t=n.integer,o=n.decimal,u=t.length,f=Math.ceil(u/3),c=[],a=0;a<f;a++)c.unshift(t.slice(-3*(a+1),u-3*a));return(r?"-":"")+c.join(",")+o},e.obj2qs=function(e){var n=[];for(var r in e)c.call(e,r)&&n.push(r+"="+encodeURIComponent(e[r]));return n.join("&")},e.remove=function(e,n){var r=e.indexOf(n);return r>=0&&e.splice(r,1),r},e.percentage=function(e,n){return void 0===n&&(n=2),e=Number(e),t(e)?(100*e).toFixed(n)+"%":""},Object.defineProperty(e,"__esModule",{value:!0})}); |
+7
-4
@@ -1,3 +0,2 @@ | ||
| import copy from './copy' | ||
| import filterBy from './filterBy' | ||
| import get from './get' | ||
| import isNumber from './isNumber' | ||
@@ -8,6 +7,9 @@ import kmbt from './kmbt' | ||
| import remove from './remove' | ||
| import { extend, copy } from './extend' | ||
| import percentage from './percentage' | ||
| export { | ||
| extend, | ||
| copy, | ||
| filterBy, | ||
| get, | ||
| isNumber, | ||
@@ -17,3 +19,4 @@ kmbt, | ||
| obj2qs, | ||
| remove | ||
| remove, | ||
| percentage | ||
| } |
+4
-4
| { | ||
| "name": "noshjs", | ||
| "version": "0.0.4", | ||
| "version": "0.1.0", | ||
| "main": "dist/nosh.common.js", | ||
@@ -21,6 +21,6 @@ "module": "dist/nosh.esm.js", | ||
| "coveralls": "^2.13.1", | ||
| "eslint": "^3.17.0", | ||
| "eslint": "^4.1.1", | ||
| "eslint-config-standard": "^10.2.1", | ||
| "eslint-plugin-import": "^2.2.0", | ||
| "eslint-plugin-node": "^4.2.2", | ||
| "eslint-plugin-node": "^5.1.0", | ||
| "eslint-plugin-promise": "^3.5.0", | ||
@@ -31,3 +31,3 @@ "eslint-plugin-standard": "^3.0.1", | ||
| "jasmine": "^2.5.3", | ||
| "rollup": "^0.41.6", | ||
| "rollup": "^0.43.0", | ||
| "rollup-plugin-buble": "^0.15.0", | ||
@@ -34,0 +34,0 @@ "uglify-js": "^3.0.5" |
| export default function (obj) { | ||
| if (obj == null) return obj | ||
| return JSON.parse(JSON.stringify(obj)) | ||
| } |
| export default function (array, prop, value) { | ||
| return array.filter(item => item[prop] === value) | ||
| } |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
23692
58.07%16
6.67%756
60.85%3
50%