New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

commonly-used-utils

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commonly-used-utils - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

2

dist/index.js

@@ -1,1 +0,1 @@

!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t=r();for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(self,(()=>(()=>{"use strict";var e={d:(r,t)=>{for(var n in t)e.o(t,n)&&!e.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:t[n]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{addItem:()=>$,areObjectArraysEqual:()=>u,deleteRecursively:()=>y,deleteRecursivelyReverse:()=>j,findArrayAttr:()=>E,findNestArrayAttr:()=>A,isArray:()=>s,isEmptyObject:()=>f,isFunction:()=>o,isNil:()=>c,isNumber:()=>a,isObject:()=>i,isObjectEqual:()=>d,isString:()=>l,listToTree:()=>v,listToTreeWithMeta:()=>m,mb:()=>h,oneDimensional:()=>b,removeItem:()=>N,setTreeAttr:()=>p,setTreeAttrCopy:()=>w,sleep:()=>x,treeFind:()=>O,treeFindParents:()=>g});const t=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"]]),n=e=>null==e?e+"":"object"==typeof e||"function"==typeof e?t.get(Object.prototype.toString.call(e))||"object":typeof e,i=e=>"object"===n(e),o=e=>"function"===n(e),s=e=>"array"===n(e),l=e=>"string"===n(e),c=e=>null==e,a=e=>null!==e&&""!==e&&void 0!==e&&!isNaN(Number(e)),f=e=>{if(!i(e))return!1;for(let r in e)if(e.hasOwnProperty(r))return!1;return!0},h=e=>r=>(e.map((e=>{r=(r||{})[e]})),r),d=(e,r)=>{const t=Object.keys(e),n=Object.keys(r);if(t.length!==n.length)return!1;for(const n of t)if(e[n]!==r[n])return!1;return!0},u=(e,r)=>{if(e.some((e=>s(e)))||r.some((e=>s(e))))throw new Error("暂不支持二维数组比对");if(e.length!==r.length)return!1;if(i(e[0])){const t=e.map((e=>Object.keys(e).sort().reduce(((r,t)=>Object.assign(Object.assign({},r),{[t]:e[t]})),{}))).sort(((e,r)=>JSON.stringify(e).localeCompare(JSON.stringify(r)))),n=r.map((e=>Object.keys(e).sort().reduce(((r,t)=>Object.assign(Object.assign({},r),{[t]:e[t]})),{}))).sort(((e,r)=>JSON.stringify(e).localeCompare(JSON.stringify(r))));for(let e=0;e<t.length;e++)if(!d(t[e],n[e]))return!1}else{const t=e.slice().sort(),n=r.slice().sort();for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1}return!0},b=(e=[],r="children")=>{const t=[],n=[...e];for(;n.length;){const e=n.shift();t.push(e);const i=e[r];Array.isArray(i)&&n.unshift(...e[r])}return t},g=(e=[],r,t="id",n="children",o=!0,s=!0,l=!0)=>{var c;if(!e.length)return[];for(let a=0,f=e.length;a<f;a++){const f=e[a];if(f[t]===r)return s?[f]:l?[]:f;const h=(null===(c=null==f?void 0:f[n])||void 0===c?void 0:c.length)&&g(f[n],r,t,n,o,s,!1);if(i(h))return[f];if(null==h?void 0:h.length)return o?[f].concat(h):h.concat(f)}},p=(e=[],r,t="children",n=[])=>{for(let i=0,o=e.length;i<o;i++){let o=e[i];r(o,n,i,e),o&&o[t]&&o[t].length&&p(o[t],r,t,[...n,o])}},y=(e=[],r,t="children",i=[])=>{var o;for(let s=0,l=e.length;s<l;s++){let c=e[s],a=r(c,i,s,e);if("boolean"!==n(a)){new Error(`callback返回值:${a}(返回值只能是布尔值)`);break}a?(null===(o=null==c?void 0:c[t])||void 0===o?void 0:o.length)&&y(c[t],r,t,[...i,c]):(e.splice(s,1),l--,s--)}},j=(e=[],r,t="children",i=[])=>{var o;for(let s=e.length-1;s>=0;s--){let l=e[s],c=r(l,i,s,e);if("boolean"!==n(c)){new Error(`callback返回值:${c}(返回值只能是布尔值)`);break}c?(null===(o=null==l?void 0:l[t])||void 0===o?void 0:o.length)&&j(l[t],r,t,[...i,l]):e.splice(s,1)}},w=(e,r,t="children",n=[])=>e.length?e.reduce(((e,o,s,l)=>{const c=r(o,n,s,l);if(!i(c))throw new Error("函数返回值必须为对象");return c[t]&&(c[t]=w(c[t],r,t,[...n,o])),0===Object.keys(c).length?e:e.concat(c)}),[]):[],O=(e,r,t="{}",n="children",o=[])=>{for(let s=0,l=e.length;s<l;s++){const l=e[s];if(r(l,o,s,e))return"{}"===t||"Object"===t||i(t)?l:l[t];const c=l[n]&&O(l[n],r,t,n,[...o,l]);if(c)return c}},v=(e=[],r="id",t="parentId",n="children")=>{const i=new Map,o=[];return e.forEach((e=>{const t=Object.assign(Object.assign({},e),{[n]:[]});i.set(e[r],t)})),e.forEach((e=>{const s=i.get(e[t]);s?s[n].push(i.get(e[r])):o.push(i.get(e[r]))})),o},m=(e=[],r,t="id",n="parentId")=>{const i=[],o=[],s=[];r&&e.forEach(((e,t,n)=>{r(e,t,n)}));const l=new Map(e.map((e=>[e[t],Object.assign(Object.assign({},e),{parentIds:[],children:[],childrenIds:[],childrenLastIds:[]})])));e.forEach((e=>{const r=l.get(e[n]);r?(r.childrenIds.push(e[t]),r.children.push(l.get(e[t]))):i.push(e[t])}));const c=(e,r=[])=>{let t={childrenIds:[],childrenLastIds:[]};for(let n=0,i=e.length;n<i;n++){const i=e[n],a=l.get(i);if(a)if(a.parentIds=r,a.level=r.length+1,s.push(a),a.childrenIds.length){const{childrenIds:e,childrenLastIds:n}=c(a.childrenIds,[...r,i]);t.childrenIds.push(i,...e),t.childrenLastIds.push(...n),a.childrenIds=e,a.childrenLastIds=n}else t.childrenIds.push(i),t.childrenLastIds.push(i),o.push(i)}return t};return c(i),{data:s,topNode:i,allLastChildNode:o}},E=(e,r,t,n,o=!1)=>{if(!Array.isArray(e)||!t||c(r)||"boolean"!=typeof o)throw new Error("请检查参数");if(o&&!e.length)throw new Error("严格模式下,数组不能为空");const s=e.find(((e,n)=>!!i(e)&&(o?e[t]===r:String(e[t])===String(r))));if("{}"===n||"object"===n||i(n)){if(o&&!i(s))throw new Error(`严格模式(对象)未找到, value: ${r}, attr:${t}`);return s}if(o&&!i(s))throw new Error(`严格模式下未找到匹配项, value: ${r}, attr:${t}`);if("$index"===n)return e.indexOf(s);if(s&&n in s)return s[n];if(o&&c(null==s?void 0:s[n]))throw new Error(`严格模式下,属性值为 null 或 undefined, value: ${r}, attr:${t}`)},A=(e,r,t,n,o=!1)=>{if(!Array.isArray(e)||!Array.isArray(t)||c(r)||"boolean"!=typeof o)throw new Error("请检查参数");if(o&&!e.length)throw new Error("严格模式下,数组不能为空");const s=e.find(((e,n)=>{const i=h(t)(e);return o?i===r:String(i)===String(r)}));if("{}"===n||"object"===n||i(n)){if(o&&!i(s))throw new Error(`严格模式(对象)未找到, value: ${r}, attr:${t}, url: ${location.href}`);return s}if(o&&!i(s))throw new Error(`严格模式下未找到匹配项, value: ${r}, attr:${t}`);if("$index"===n)return e.indexOf(s);if(s&&n in s)return s[n];if(o&&s&&n in s&&c(s[n]))throw new Error(`严格模式下,属性值为 null 或 undefined, value: ${r}, attr:${t}`)};function I(e){if("number"!==n(e)&&"string"!==n(e))throw new Error("只支持string、number类型的数据");!Array.isArray(this)||this.includes(e)?this instanceof Set&&this.add(e):this.push(e)}function S(e){if("number"!==n(e)&&"string"!==n(e))throw new Error("只支持string、number类型的数据");if(Array.isArray(this)){const r=this.indexOf(e);-1!==r&&this.splice(r,1)}else this instanceof Set&&this.delete(e)}const $=function(...e){for(let r in e){const t=e[r];s(t)?t.forEach((e=>{I.call(this,e)})):I.call(this,t)}return this},N=function(...e){for(let r in e){const t=e[r];s(t)?t.forEach((e=>{S.call(this,e)})):S.call(this,t)}return this},x=e=>new Promise((r=>setTimeout(r,e)));return r})()));
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t=r();for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(self,(()=>(()=>{"use strict";var e={d:(r,t)=>{for(var n in t)e.o(t,n)&&!e.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:t[n]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{addItem:()=>$,areObjectArraysEqual:()=>u,deleteRecursively:()=>y,deleteRecursivelyReverse:()=>j,findArrayAttr:()=>E,findNestArrayAttr:()=>A,isArray:()=>s,isEmptyObject:()=>f,isFunction:()=>o,isNil:()=>c,isNumber:()=>a,isObject:()=>i,isObjectEqual:()=>d,isString:()=>l,listToTree:()=>v,listToTreeWithMeta:()=>m,mb:()=>h,oneDimensional:()=>g,removeItem:()=>N,setTreeAttr:()=>p,setTreeAttrCopy:()=>w,sleep:()=>x,treeFind:()=>O,treeFindParents:()=>b});const t=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"]]),n=e=>null==e?e+"":"object"==typeof e||"function"==typeof e?t.get(Object.prototype.toString.call(e))||"object":typeof e,i=e=>"object"===n(e),o=e=>"function"===n(e),s=e=>"array"===n(e),l=e=>"string"===n(e),c=e=>null==e,a=e=>null!==e&&""!==e&&void 0!==e&&!isNaN(Number(e)),f=e=>{if(!i(e))return!1;for(let r in e)if(e.hasOwnProperty(r))return!1;return!0},h=e=>r=>(e.map((e=>{r=(r||{})[e]})),r),d=(e,r)=>{const t=Object.keys(e),n=Object.keys(r);if(t.length!==n.length)return!1;for(const n of t)if(e[n]!==r[n])return!1;return!0},u=(e,r)=>{if(e.some((e=>s(e)))||r.some((e=>s(e))))throw new Error("暂不支持二维数组比对");if(e.length!==r.length)return!1;if(i(e[0])){const t=e.map((e=>Object.keys(e).sort().reduce(((r,t)=>Object.assign(Object.assign({},r),{[t]:e[t]})),{}))).sort(((e,r)=>JSON.stringify(e).localeCompare(JSON.stringify(r)))),n=r.map((e=>Object.keys(e).sort().reduce(((r,t)=>Object.assign(Object.assign({},r),{[t]:e[t]})),{}))).sort(((e,r)=>JSON.stringify(e).localeCompare(JSON.stringify(r))));for(let e=0;e<t.length;e++)if(!d(t[e],n[e]))return!1}else{const t=e.slice().sort(),n=r.slice().sort();for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1}return!0},g=(e=[],r="children")=>{const t=[],n=Array.isArray(e)?[...e]:[];for(;n.length;){const e=n.shift();t.push(e);const i=e[r];Array.isArray(i)&&n.unshift(...e[r])}return t},b=(e=[],r,t="id",n="children",o=!0,s=!0,l=!0)=>{var c;if(!e.length)return[];for(let a=0,f=e.length;a<f;a++){const f=e[a];if(f[t]===r)return s?[f]:l?[]:f;const h=(null===(c=null==f?void 0:f[n])||void 0===c?void 0:c.length)&&b(f[n],r,t,n,o,s,!1);if(i(h))return[f];if(null==h?void 0:h.length)return o?[f].concat(h):h.concat(f)}},p=(e=[],r,t="children",n=[])=>{for(let i=0,o=e.length;i<o;i++){let o=e[i];r(o,n,i,e),o&&o[t]&&o[t].length&&p(o[t],r,t,[...n,o])}},y=(e=[],r,t="children",i=[])=>{var o;for(let s=0,l=e.length;s<l;s++){let c=e[s],a=r(c,i,s,e);if("boolean"!==n(a)){new Error(`callback返回值:${a}(返回值只能是布尔值)`);break}a?(null===(o=null==c?void 0:c[t])||void 0===o?void 0:o.length)&&y(c[t],r,t,[...i,c]):(e.splice(s,1),l--,s--)}},j=(e=[],r,t="children",i=[])=>{var o;for(let s=e.length-1;s>=0;s--){let l=e[s],c=r(l,i,s,e);if("boolean"!==n(c)){new Error(`callback返回值:${c}(返回值只能是布尔值)`);break}c?(null===(o=null==l?void 0:l[t])||void 0===o?void 0:o.length)&&j(l[t],r,t,[...i,l]):e.splice(s,1)}},w=(e,r,t="children",n=[])=>e.length?e.reduce(((e,o,s,l)=>{const c=r(o,n,s,l);if(!i(c))throw new Error("函数返回值必须为对象");return c[t]&&(c[t]=w(c[t],r,t,[...n,o])),0===Object.keys(c).length?e:e.concat(c)}),[]):[],O=(e,r,t="{}",n="children",o=[])=>{for(let s=0,l=e.length;s<l;s++){const l=e[s];if(r(l,o,s,e))return"{}"===t||"Object"===t||i(t)?l:l[t];const c=l[n]&&O(l[n],r,t,n,[...o,l]);if(c)return c}},v=(e=[],r="id",t="parentId",n="children")=>{const i=new Map,o=[];return e.forEach((e=>{const t=Object.assign(Object.assign({},e),{[n]:[]});i.set(e[r],t)})),e.forEach((e=>{const s=i.get(e[t]);s?s[n].push(i.get(e[r])):o.push(i.get(e[r]))})),o},m=(e=[],r,t="id",n="parentId")=>{const i=[],o=[],s=[];if(r)for(let t=0,n=e.length;t<n;t++)r(e[t],t,e);const l=new Map(e.map((e=>[e[t],Object.assign(Object.assign({},e),{parentIds:[],children:[],childrenIds:[],childrenLastIds:[]})])));for(let r=0,o=e.length;r<o;r++){const o=e[r],s=l.get(o[n]);s?(s.childrenIds.push(o[t]),s.children.push(l.get(o[t]))):i.push(o[t])}const c=(e,r=[])=>{let t={childrenIds:[],childrenLastIds:[]};for(let n=0,i=e.length;n<i;n++){const i=e[n],a=l.get(i);if(a)if(a.parentIds=r,a.level=r.length+1,s.push(a),a.childrenIds.length){const{childrenIds:e,childrenLastIds:n}=c(a.childrenIds,[...r,i]);t.childrenIds.push(i,...e),t.childrenLastIds.push(...n),a.childrenIds=e,a.childrenLastIds=n}else t.childrenIds.push(i),t.childrenLastIds.push(i),o.push(i)}return t};return c(i),{data:s,topNode:i,allLastChildNode:o}},E=(e,r,t,n,o=!1)=>{if(!Array.isArray(e)||!t||c(r)||"boolean"!=typeof o)throw new Error("请检查参数");if(o&&!e.length)throw new Error("严格模式下,数组不能为空");const s=e.find(((e,n)=>!!i(e)&&(o?e[t]===r:String(e[t])===String(r))));if("{}"===n||"object"===n||i(n)){if(o&&!i(s))throw new Error(`严格模式(对象)未找到, value: ${r}, attr:${t}`);return s}if(o&&!i(s))throw new Error(`严格模式下未找到匹配项, value: ${r}, attr:${t}`);if("$index"===n)return e.indexOf(s);if(s&&n in s)return s[n];if(o&&c(null==s?void 0:s[n]))throw new Error(`严格模式下,属性值为 null 或 undefined, value: ${r}, attr:${t}`)},A=(e,r,t,n,o=!1)=>{if(!Array.isArray(e)||!Array.isArray(t)||c(r)||"boolean"!=typeof o)throw new Error("请检查参数");if(o&&!e.length)throw new Error("严格模式下,数组不能为空");const s=e.find(((e,n)=>{const i=h(t)(e);return o?i===r:String(i)===String(r)}));if("{}"===n||"object"===n||i(n)){if(o&&!i(s))throw new Error(`严格模式(对象)未找到, value: ${r}, attr:${t}, url: ${location.href}`);return s}if(o&&!i(s))throw new Error(`严格模式下未找到匹配项, value: ${r}, attr:${t}`);if("$index"===n)return e.indexOf(s);if(s&&n in s)return s[n];if(o&&s&&n in s&&c(s[n]))throw new Error(`严格模式下,属性值为 null 或 undefined, value: ${r}, attr:${t}`)};function I(e){if("number"!==n(e)&&"string"!==n(e))throw new Error("只支持string、number类型的数据");!Array.isArray(this)||this.includes(e)?this instanceof Set&&this.add(e):this.push(e)}function S(e){if("number"!==n(e)&&"string"!==n(e))throw new Error("只支持string、number类型的数据");if(Array.isArray(this)){const r=this.indexOf(e);-1!==r&&this.splice(r,1)}else this instanceof Set&&this.delete(e)}const $=function(...e){for(let r in e){const t=e[r];s(t)?t.forEach((e=>{I.call(this,e)})):I.call(this,t)}return this},N=function(...e){for(let r in e){const t=e[r];s(t)?t.forEach((e=>{S.call(this,e)})):S.call(this,t)}return this},x=e=>new Promise((r=>setTimeout(r,e)));return r})()));
{
"name": "commonly-used-utils",
"version": "1.1.0",
"version": "1.1.1",
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"description": "",

@@ -5,0 +8,0 @@ "main": "dist/index.js",

@@ -38,3 +38,3 @@ import { isObject, type } from './utils/basics'

const result: T[] = []
const queue: T[] = [...array] // 使用栈存储待处理的节点
const queue: T[] = Array.isArray(array) ? [...array] : [] // 使用栈存储待处理的节点

@@ -338,7 +338,6 @@ while (queue.length) {

// 更新ID字段值(type === '1' 的节点特殊处理)
if (callback) {
list.forEach((item, index, array) => {
callback(item, index, array)
})
for (let i = 0, len = list.length; i < len; i++) {
callback(list[i], i, list)
}
}

@@ -352,3 +351,4 @@

// 构建父子关系
list.forEach((item) => {
for (let i = 0, len = list.length; i < len; i++) {
const item = list[i]
const parent = map.get(item[parentKey]) // 找到父节点

@@ -361,3 +361,3 @@ if (parent) {

}
})
}

@@ -364,0 +364,0 @@ // 递归构建树

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc