commonly-used-utils
Advanced tools
Comparing version 1.0.0-beat15 to 1.0.0-beat16
@@ -1,1 +0,1 @@ | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(self,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{NotRepeatedArray:()=>E,addItem:()=>w,deleteRecursively:()=>h,deleteRecursivelyReverse:()=>p,findArrayAttr:()=>g,isArray:()=>l,isFunction:()=>c,isNil:()=>u,isNumber:()=>a,isObject:()=>i,oneDimensional:()=>v,removeItem:()=>O,setTreeAttr:()=>d,setTreeAttr_copy:()=>b,sleep:()=>A,treeFindParents:()=>s});var r,n=new Map([["[object Boolean]","boolean"],["[object Number]","number"],["[object String]","string"],["[object Function]","function"],["[object Array]","array"],["[object Date]","date"],["[object RegExp]","regExp"],["[object Object]","object"],["[object Error]","error"]]),o=function(t){return null==t?t+"":"object"==typeof t||"function"==typeof t?n.get(Object.prototype.toString.call(t))||"object":typeof t},i=function(t){return"object"===o(t)},c=function(t){return"function"===o(t)},l=function(t){return"array"===o(t)},u=function(t){return null==t},a=function(t){return null!==t&&""!==t&&void 0!==t&&!isNaN(Number(t))},f=function(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))},v=function(t,e){return void 0===t&&(t=[]),void 0===e&&(e="children"),t&&t.length?t.reduce((function(t,r){var n;return t.concat(r,(null===(n=null==r?void 0:r[e])||void 0===n?void 0:n.length)?v(r[e],e):[])}),[]):[]},s=function(t,e,r,n,o,c,l){var u;if(void 0===t&&(t=[]),void 0===r&&(r="id"),void 0===n&&(n="children"),void 0===o&&(o=!0),void 0===c&&(c=!0),void 0===l&&(l=!0),!t.length)return[];for(var a=0,f=t.length;a<f;a++){var v=t[a];if(v[r]===e)return c?[v]:l?[]:v;var d=(null===(u=null==v?void 0:v[n])||void 0===u?void 0:u.length)&&s(v[n],e,r,n,o,c,!1);if(i(d))return[v];if(null==d?void 0:d.length)return o?[v].concat(d):d.concat(v)}},d=function(t,e,r,n){var o;void 0===t&&(t=[]),void 0===r&&(r="children"),void 0===n&&(n=[]);for(var i=0,c=t.length;i<c;i++){var l=t[i];e(l,n),(null===(o=null==l?void 0:l[r])||void 0===o?void 0:o.length)&&d(l[r],e,r,f(f([],n,!0),[l],!1))}},h=function(t,e,r){var n;void 0===t&&(t=[]),void 0===r&&(r="children");for(var i=0,c=t.length;i<c;i++){var l=t[i],u=e(l);if("boolean"!==o(u)){new Error("callback返回值:".concat(u,"(返回值只能是布尔值)"));break}u?(null===(n=null==l?void 0:l[r])||void 0===n?void 0:n.length)&&h(l[r],e,r):(t.splice(i,1),c--,i--)}},p=function(t,e,r){var n;void 0===t&&(t=[]),void 0===r&&(r="children");for(var i=t.length-1;i>=0;i--){var c=t[i],l=e(c);if("boolean"!==o(l)){new Error("callback返回值:".concat(l,"(返回值只能是布尔值)"));break}l?(null===(n=null==c?void 0:c[r])||void 0===n?void 0:n.length)&&h(c[r],e,r):t.splice(i,1)}},b=function(t,e,r,n){return void 0===r&&(r="children"),void 0===n&&(n=[]),t.length?t.reduce((function(t,o){var c=e(o,n);if(!i(c))throw new Error("函数返回值必须为对象");return c[r]&&(c[r]=b(c[r],e,r,f(f([],n,!0),[o],!1))),0===Object.keys(c).length?t:t.concat(c)}),[]):[]},y=(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),g=function(t,e,r,n,o){if(void 0===o&&(o=!1),!l(t)||!r||u(e)||o&&!t.length)throw new Error("请检查参数");var c=t.find((function(t){return!!i(t)&&(o?t[r]===e:""+t[r]==""+e)}));if("{}"===n||"string"==typeof n&&"object"===n.toLowerCase()||i(n)){if(o&&!i(c))throw new Error("严格模式(对象)未找到, value: ".concat(e,", attr:").concat(r,", url: ").concat(location.href));return c}if(o&&(!i(c)||!(n in c)||u(c[n])))throw new Error("严格模式(属性)未找到, value: ".concat(e,", attr:").concat(r,", url: ").concat(location.href));return null==c?void 0:c[n]};function j(t){if("number"!==o(t)&&"string"!==o(t))throw new Error("只支持string、number类型的数据");!l(this)||this.includes(t)?this instanceof Set&&this.add(t):this.push(t)}function m(t){if("number"!==o(t)&&"string"!==o(t))throw new Error("只支持string、number类型的数据");if(l(this)){var e=this.indexOf(t);-1!==e&&this.splice(e,1)}else this instanceof Set&&this.delete(t)}var w=function(){for(var t=this,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];for(var n in e){var o=e[n];l(o)?o.forEach((function(e){j.call(t,e)})):j.call(this,o)}return this},O=function(){for(var t=this,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];for(var n in e){var o=e[n];l(o)?o.forEach((function(e){m.call(t,e)})):m.call(this,o)}return this},E=function(t){function e(e){return(null==e?void 0:e.length)?t.apply(this,e)||this:t.call(this)||this}return y(e,t),e.prototype.addItem=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return w.call(this,t),this},e.prototype.removeItem=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return O.call(this,t),this},e}(Array),A=function(t){return new Promise((function(e){return setTimeout(e,t)}))};return e})())); | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(self,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{NotRepeatedArray:()=>E,addItem:()=>w,deleteRecursively:()=>h,deleteRecursivelyReverse:()=>p,findArrayAttr:()=>g,isArray:()=>l,isFunction:()=>c,isNil:()=>u,isNumber:()=>a,isObject:()=>i,oneDimensional:()=>v,removeItem:()=>O,setTreeAttr:()=>d,setTreeAttr_copy:()=>b,sleep:()=>A,treeFindParents:()=>s});var r,n=new Map([["[object Boolean]","boolean"],["[object Number]","number"],["[object String]","string"],["[object Function]","function"],["[object Array]","array"],["[object Date]","date"],["[object RegExp]","regExp"],["[object Object]","object"],["[object Error]","error"]]),o=function(t){return null==t?t+"":"object"==typeof t||"function"==typeof t?n.get(Object.prototype.toString.call(t))||"object":typeof t},i=function(t){return"object"===o(t)},c=function(t){return"function"===o(t)},l=function(t){return"array"===o(t)},u=function(t){return null==t},a=function(t){return null!==t&&""!==t&&void 0!==t&&!isNaN(Number(t))},f=function(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))},v=function(t,e){return void 0===t&&(t=[]),void 0===e&&(e="children"),t&&t.length?t.reduce((function(t,r){var n;return t.concat(r,(null===(n=null==r?void 0:r[e])||void 0===n?void 0:n.length)?v(r[e],e):[])}),[]):[]},s=function(t,e,r,n,o,c,l){var u;if(void 0===t&&(t=[]),void 0===r&&(r="id"),void 0===n&&(n="children"),void 0===o&&(o=!0),void 0===c&&(c=!0),void 0===l&&(l=!0),!t.length)return[];for(var a=0,f=t.length;a<f;a++){var v=t[a];if(v[r]===e)return c?[v]:l?[]:v;var d=(null===(u=null==v?void 0:v[n])||void 0===u?void 0:u.length)&&s(v[n],e,r,n,o,c,!1);if(i(d))return[v];if(null==d?void 0:d.length)return o?[v].concat(d):d.concat(v)}},d=function(t,e,r,n){var o;void 0===t&&(t=[]),void 0===r&&(r="children"),void 0===n&&(n=[]);for(var i=0,c=t.length;i<c;i++){var l=t[i];e(l,n,i,t),(null===(o=null==l?void 0:l[r])||void 0===o?void 0:o.length)&&d(l[r],e,r,f(f([],n,!0),[l],!1))}},h=function(t,e,r){var n;void 0===t&&(t=[]),void 0===r&&(r="children");for(var i=0,c=t.length;i<c;i++){var l=t[i],u=e(l);if("boolean"!==o(u)){new Error("callback返回值:".concat(u,"(返回值只能是布尔值)"));break}u?(null===(n=null==l?void 0:l[r])||void 0===n?void 0:n.length)&&h(l[r],e,r):(t.splice(i,1),c--,i--)}},p=function(t,e,r){var n;void 0===t&&(t=[]),void 0===r&&(r="children");for(var i=t.length-1;i>=0;i--){var c=t[i],l=e(c);if("boolean"!==o(l)){new Error("callback返回值:".concat(l,"(返回值只能是布尔值)"));break}l?(null===(n=null==c?void 0:c[r])||void 0===n?void 0:n.length)&&h(c[r],e,r):t.splice(i,1)}},b=function(t,e,r,n){return void 0===r&&(r="children"),void 0===n&&(n=[]),t.length?t.reduce((function(t,o){var c=e(o,n);if(!i(c))throw new Error("函数返回值必须为对象");return c[r]&&(c[r]=b(c[r],e,r,f(f([],n,!0),[o],!1))),0===Object.keys(c).length?t:t.concat(c)}),[]):[]},y=(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),g=function(t,e,r,n,o){if(void 0===o&&(o=!1),!l(t)||!r||u(e)||o&&!t.length||"boolean"!=typeof o)throw new Error("请检查参数");var c=t.find((function(t){return!!i(t)&&(o?t[r]===e:""+t[r]==""+e)}));if("{}"===n||"string"==typeof n&&"object"===n.toLowerCase()||i(n)){if(o&&!i(c))throw new Error("严格模式(对象)未找到, value: ".concat(e,", attr:").concat(r,", url: ").concat(location.href));return c}if(o&&(!i(c)||!(n in c)||u(c[n])))throw new Error("严格模式(属性)未找到, value: ".concat(e,", attr:").concat(r,", url: ").concat(location.href));return null==c?void 0:c[n]};function j(t){if("number"!==o(t)&&"string"!==o(t))throw new Error("只支持string、number类型的数据");!l(this)||this.includes(t)?this instanceof Set&&this.add(t):this.push(t)}function m(t){if("number"!==o(t)&&"string"!==o(t))throw new Error("只支持string、number类型的数据");if(l(this)){var e=this.indexOf(t);-1!==e&&this.splice(e,1)}else this instanceof Set&&this.delete(t)}var w=function(){for(var t=this,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];for(var n in e){var o=e[n];l(o)?o.forEach((function(e){j.call(t,e)})):j.call(this,o)}return this},O=function(){for(var t=this,e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];for(var n in e){var o=e[n];l(o)?o.forEach((function(e){m.call(t,e)})):m.call(this,o)}return this},E=function(t){function e(e){return(null==e?void 0:e.length)?t.apply(this,e)||this:t.call(this)||this}return y(e,t),e.prototype.addItem=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return w.call(this,t),this},e.prototype.removeItem=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return O.call(this,t),this},e}(Array),A=function(t){return new Promise((function(e){return setTimeout(e,t)}))};return e})())); |
{ | ||
"name": "commonly-used-utils", | ||
"version": "1.0.0-beat15", | ||
"version": "1.0.0-beat16", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,2 +11,7 @@ ### 1.0.0-beat11 | ||
#### 2023/7/19 | ||
1. 新增 isNumber | ||
1. 新增 isNumber | ||
### 1.0.0-beat16 | ||
#### 2023/9/15 | ||
1. setTreeAttr TS 声明调整 | ||
2. setTreeAttr 增加回调函数第四参数(当前循环的数组) |
@@ -17,3 +17,3 @@ import { isArray, isNil, isObject, type } from './utils/basics' | ||
array: any[], | ||
value: string, | ||
value: string | number | undefined, | ||
attr: 'id' | string | number, | ||
@@ -27,3 +27,4 @@ returnData: string | number | object | '{}' | 'object', | ||
isNil(value) || | ||
(isStrict && !array.length) | ||
(isStrict && !array.length) || | ||
typeof isStrict !== 'boolean' | ||
) { | ||
@@ -30,0 +31,0 @@ throw new Error('请检查参数') |
@@ -67,2 +67,6 @@ import { isObject, type } from './utils/basics' | ||
* @param callback 每个节点执行的方法 | ||
* <object>item 当前节点 | ||
* <(string | number)[]>parents 所有父节点 | ||
* <number>index 当前循环下标 | ||
* <object[]>array 当前循环的数组 | ||
* @param children 数组子类字段(默认值'children') | ||
@@ -74,5 +78,8 @@ * @param parents | ||
* treeData, | ||
* (item, parents) => { | ||
* (item, parents, index, array) => { | ||
* item['parentId'] = parents[parents.length - 1]?.['id'] // 父节点 | ||
* item['parentIds'] = parents.map((i) => i?.['id']) || [] // 所有父级链id | ||
* item['level'] = item.parentIds.length // 层级(0开始) | ||
* item[children] = item?.['children']?.['length'] ? item['children'] : [] // 建议无 children 节点赋值为空数组([]) | ||
* Object.is(item, array[index]) // true | ||
* ... | ||
@@ -91,3 +98,3 @@ * }, | ||
let item = array[i] | ||
callback(item, parents) | ||
callback(item, parents, i, array) | ||
item?.[children]?.length && setTreeAttr(item[children], callback, children, [...parents, item]) | ||
@@ -94,0 +101,0 @@ } |
@@ -108,2 +108,6 @@ // 是否为对象 | ||
* @param callback 每个节点执行的方法 | ||
* <object>item 当前节点 | ||
* <(string | number)[]>parents 所有父节点 | ||
* <number>index 当前循环下标 | ||
* <object[]>array 当前循环的数组 | ||
* @param children 数组子类字段(默认值'children') | ||
@@ -114,5 +118,8 @@ * @return void | ||
* treeData, | ||
* (item, parents) => { | ||
* (item, parents, index, array) => { | ||
* item['parentId'] = parents[parents.length - 1]?.['id'] // 父节点 | ||
* item['parentIds'] = parents.map((i) => i?.['id']) || [] // 所有父级链id | ||
* item['level'] = item.parentIds.length // 层级(0开始) | ||
* item[children] = item?.['children']?.['length'] ? item['children'] : [] // 建议无 children 节点赋值为空数组([]) | ||
* Object.is(item, array[index]) // true | ||
* ... | ||
@@ -119,0 +126,0 @@ * }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25034
16
15
620