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
1
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.0.0-beat17 to 1.0.0-beat18

2

dist/index.js

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

!function(t,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var e=r();for(var n in e)("object"==typeof exports?exports:t)[n]=e[n]}}(self,(()=>(()=>{"use strict";var t={d:(r,e)=>{for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},o:(t,r)=>Object.prototype.hasOwnProperty.call(t,r),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},r={};t.r(r),t.d(r,{NotRepeatedArray:()=>A,addItem:()=>O,deleteRecursively:()=>h,deleteRecursivelyReverse:()=>p,findArrayAttr:()=>j,isArray:()=>l,isFunction:()=>c,isNil:()=>u,isNumber:()=>a,isObject:()=>i,oneDimensional:()=>v,removeItem:()=>E,setTreeAttr:()=>s,setTreeAttr_copy:()=>b,sleep:()=>_,treeFind:()=>y,treeFindParents:()=>d});var e,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,r,e){if(e||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return t.concat(n||Array.prototype.slice.call(r))},v=function(t,r){return void 0===t&&(t=[]),void 0===r&&(r="children"),t&&t.length?t.reduce((function(t,e){var n;return t.concat(e,(null===(n=null==e?void 0:e[r])||void 0===n?void 0:n.length)?v(e[r],r):[])}),[]):[]},d=function(t,r,e,n,o,c,l){var u;if(void 0===t&&(t=[]),void 0===e&&(e="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[e]===r)return c?[v]:l?[]:v;var s=(null===(u=null==v?void 0:v[n])||void 0===u?void 0:u.length)&&d(v[n],r,e,n,o,c,!1);if(i(s))return[v];if(null==s?void 0:s.length)return o?[v].concat(s):s.concat(v)}},s=function(t,r,e,n){var o;void 0===t&&(t=[]),void 0===e&&(e="children"),void 0===n&&(n=[]);for(var i=0,c=t.length;i<c;i++){var l=t[i];r(l,n,i,t),(null===(o=null==l?void 0:l[e])||void 0===o?void 0:o.length)&&s(l[e],r,e,f(f([],n,!0),[l],!1))}},h=function(t,r,e){var n;void 0===t&&(t=[]),void 0===e&&(e="children");for(var i=0,c=t.length;i<c;i++){var l=t[i],u=r(l);if("boolean"!==o(u)){new Error("callback返回值:".concat(u,"(返回值只能是布尔值)"));break}u?(null===(n=null==l?void 0:l[e])||void 0===n?void 0:n.length)&&h(l[e],r,e):(t.splice(i,1),c--,i--)}},p=function(t,r,e){var n;void 0===t&&(t=[]),void 0===e&&(e="children");for(var i=t.length-1;i>=0;i--){var c=t[i],l=r(c);if("boolean"!==o(l)){new Error("callback返回值:".concat(l,"(返回值只能是布尔值)"));break}l?(null===(n=null==c?void 0:c[e])||void 0===n?void 0:n.length)&&h(c[e],r,e):t.splice(i,1)}},b=function(t,r,e,n){return void 0===e&&(e="children"),void 0===n&&(n=[]),t.length?t.reduce((function(t,o){var c=r(o,n);if(!i(c))throw new Error("函数返回值必须为对象");return c[e]&&(c[e]=b(c[e],r,e,f(f([],n,!0),[o],!1))),0===Object.keys(c).length?t:t.concat(c)}),[]):[]},y=function(t,r,e,n){void 0===e&&(e="{}"),void 0===n&&(n="children");for(var o=0,c=t.length;o<c;o++){var l=t[o];if(r(l))return"{}"===e||"Object"===e||i(e)?l:l[e];var u=l[n]&&y(l[n],r,e,n);if(u)return u}},g=(e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},e(t,r)},function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}),j=function(t,r,e,n,o){if(void 0===o&&(o=!1),!l(t)||!e||u(r)||o&&!t.length||"boolean"!=typeof o)throw new Error("请检查参数");var c=t.find((function(t){return!!i(t)&&(o?t[e]===r:""+t[e]==""+r)}));if("{}"===n||"string"==typeof n&&"object"===n.toLowerCase()||i(n)){if(o&&!i(c))throw new Error("严格模式(对象)未找到, value: ".concat(r,", attr:").concat(e,", url: ").concat(location.href));return c}if(o&&(!i(c)||!(n in c)||u(c[n])))throw new Error("严格模式(属性)未找到, value: ".concat(r,", attr:").concat(e,", url: ").concat(location.href));return null==c?void 0:c[n]};function m(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 w(t){if("number"!==o(t)&&"string"!==o(t))throw new Error("只支持string、number类型的数据");if(l(this)){var r=this.indexOf(t);-1!==r&&this.splice(r,1)}else this instanceof Set&&this.delete(t)}var O=function(){for(var t=this,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];for(var n in r){var o=r[n];l(o)?o.forEach((function(r){m.call(t,r)})):m.call(this,o)}return this},E=function(){for(var t=this,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];for(var n in r){var o=r[n];l(o)?o.forEach((function(r){w.call(t,r)})):w.call(this,o)}return this},A=function(t){function r(r){return(null==r?void 0:r.length)?t.apply(this,r)||this:t.call(this)||this}return g(r,t),r.prototype.addItem=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return O.call(this,t),this},r.prototype.removeItem=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return E.call(this,t),this},r}(Array),_=function(t){return new Promise((function(r){return setTimeout(r,t)}))};return r})()));
!function(t,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var e=r();for(var n in e)("object"==typeof exports?exports:t)[n]=e[n]}}(self,(()=>(()=>{"use strict";var t={d:(r,e)=>{for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},o:(t,r)=>Object.prototype.hasOwnProperty.call(t,r),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},r={};t.r(r),t.d(r,{NotRepeatedArray:()=>A,addItem:()=>O,deleteRecursively:()=>h,deleteRecursivelyReverse:()=>p,findArrayAttr:()=>j,isArray:()=>l,isFunction:()=>c,isNil:()=>u,isNumber:()=>a,isObject:()=>i,oneDimensional:()=>v,removeItem:()=>E,setTreeAttr:()=>s,setTreeAttr_copy:()=>b,sleep:()=>_,treeFind:()=>y,treeFindParents:()=>d});var e,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,r,e){if(e||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return t.concat(n||Array.prototype.slice.call(r))},v=function(t,r){return void 0===t&&(t=[]),void 0===r&&(r="children"),t&&t.length?t.reduce((function(t,e){var n;return t.concat(e,(null===(n=null==e?void 0:e[r])||void 0===n?void 0:n.length)?v(e[r],r):[])}),[]):[]},d=function(t,r,e,n,o,c,l){var u;if(void 0===t&&(t=[]),void 0===e&&(e="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[e]===r)return c?[v]:l?[]:v;var s=(null===(u=null==v?void 0:v[n])||void 0===u?void 0:u.length)&&d(v[n],r,e,n,o,c,!1);if(i(s))return[v];if(null==s?void 0:s.length)return o?[v].concat(s):s.concat(v)}},s=function(t,r,e,n){var o;void 0===t&&(t=[]),void 0===e&&(e="children"),void 0===n&&(n=[]);for(var i=0,c=t.length;i<c;i++){var l=t[i];r(l,n,i,t),(null===(o=null==l?void 0:l[e])||void 0===o?void 0:o.length)&&s(l[e],r,e,f(f([],n,!0),[l],!1))}},h=function(t,r,e,n){var i;void 0===t&&(t=[]),void 0===e&&(e="children"),void 0===n&&(n=[]);for(var c=0,l=t.length;c<l;c++){var u=t[c],a=r(u,n,c,t);if("boolean"!==o(a)){new Error("callback返回值:".concat(a,"(返回值只能是布尔值)"));break}a?(null===(i=null==u?void 0:u[e])||void 0===i?void 0:i.length)&&h(u[e],r,e,f(f([],n,!0),[u],!1)):(t.splice(c,1),l--,c--)}},p=function(t,r,e,n){var i;void 0===t&&(t=[]),void 0===e&&(e="children"),void 0===n&&(n=[]);for(var c=t.length-1;c>=0;c--){var l=t[c],u=r(l,n,c,t);if("boolean"!==o(u)){new Error("callback返回值:".concat(u,"(返回值只能是布尔值)"));break}u?(null===(i=null==l?void 0:l[e])||void 0===i?void 0:i.length)&&h(l[e],r,e,f(f([],n,!0),[l],!1)):t.splice(c,1)}},b=function(t,r,e,n){return void 0===e&&(e="children"),void 0===n&&(n=[]),t.length?t.reduce((function(t,o,c,l){var u=r(o,n,c,l);if(!i(u))throw new Error("函数返回值必须为对象");return u[e]&&(u[e]=b(u[e],r,e,f(f([],n,!0),[o],!1))),0===Object.keys(u).length?t:t.concat(u)}),[]):[]},y=function(t,r,e,n,o){void 0===e&&(e="{}"),void 0===n&&(n="children"),void 0===o&&(o=[]);for(var c=0,l=t.length;c<l;c++){var u=t[c];if(r(u,o,c,t))return"{}"===e||"Object"===e||i(e)?u:u[e];var a=u[n]&&y(u[n],r,e,n,f(f([],o,!0),[u],!1));if(a)return a}},g=(e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},e(t,r)},function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}),j=function(t,r,e,n,o){if(void 0===o&&(o=!1),!l(t)||!e||u(r)||o&&!t.length||"boolean"!=typeof o)throw new Error("请检查参数");var c=t.find((function(t){return!!i(t)&&(o?t[e]===r:""+t[e]==""+r)}));if("{}"===n||"string"==typeof n&&"object"===n.toLowerCase()||i(n)){if(o&&!i(c))throw new Error("严格模式(对象)未找到, value: ".concat(r,", attr:").concat(e,", url: ").concat(location.href));return c}if(o&&(!i(c)||!(n in c)||u(c[n])))throw new Error("严格模式(属性)未找到, value: ".concat(r,", attr:").concat(e,", url: ").concat(location.href));return null==c?void 0:c[n]};function m(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 w(t){if("number"!==o(t)&&"string"!==o(t))throw new Error("只支持string、number类型的数据");if(l(this)){var r=this.indexOf(t);-1!==r&&this.splice(r,1)}else this instanceof Set&&this.delete(t)}var O=function(){for(var t=this,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];for(var n in r){var o=r[n];l(o)?o.forEach((function(r){m.call(t,r)})):m.call(this,o)}return this},E=function(){for(var t=this,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];for(var n in r){var o=r[n];l(o)?o.forEach((function(r){w.call(t,r)})):w.call(this,o)}return this},A=function(t){function r(r){return(null==r?void 0:r.length)?t.apply(this,r)||this:t.call(this)||this}return g(r,t),r.prototype.addItem=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return O.call(this,t),this},r.prototype.removeItem=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return E.call(this,t),this},r}(Array),_=function(t){return new Promise((function(r){return setTimeout(r,t)}))};return r})()));
{
"name": "commonly-used-utils",
"version": "1.0.0-beat17",
"version": "1.0.0-beat18",
"description": "",

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

@@ -20,2 +20,6 @@ ### 1.0.0-beat11

#### 2023/10/13
1. 新增 treeFind 方法
1. 新增 treeFind 方法
### 1.0.0-beat18
#### 2023/10/17
1. deleteRecursively、deleteRecursivelyReverse、setTreeAttr_copy、treeFind回调函数扩展属性

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

* @param array treeData
* @param children 数组子类字段(默认值'children')
* @param children 数组子类字段(默认值children')
* @returns array|[]

@@ -28,3 +28,3 @@ * @example

* @param attr 属性值(默认值'id')
* @param children 数组子类字段(默认值'children')
* @param children 数组子类字段(默认值children')
* @param descend 返回数组是否为正序

@@ -39,3 +39,3 @@ * @param self 返回数组是否包含自身

array = [],
value,
value: number | string | undefined,
attr = 'id',

@@ -74,3 +74,3 @@ children = 'children',

* <object[]>array 当前循环的数组
* @param children 数组子类字段(默认值'children')
* @param children 数组子类字段(默认值children)
* @param parents

@@ -88,3 +88,3 @@ * @return void

* ...
* },
* }
* 'children'

@@ -95,3 +95,3 @@ * )

array = [],
callback,
callback: (item: any, parents: any[], i: number, array: any[]) => void,
children = 'children',

@@ -111,3 +111,4 @@ parents = []

* @param callback 每个对象执行的方法
* @param children 数组子类字段(默认值'children')
* @param children 数组子类字段(默认值children')
* @param parents
* @example

@@ -132,8 +133,9 @@ * deleteRecursively(

array = [],
callback,
children = 'children'
callback: (item: any, parents: any[], i: number, array: any[]) => boolean,
children = 'children',
parents = []
) => {
for (let i = 0, len = array.length; i < len; i++) {
let item = array[i]
let status = callback(item)
let status = callback(item, parents, i, array)
if (type(status) !== 'boolean') {

@@ -150,3 +152,3 @@ new Error(`callback返回值:${status}(返回值只能是布尔值)`)

}
item?.[children]?.length && deleteRecursively(item[children], callback, children)
item?.[children]?.length && deleteRecursively(item[children], callback, children, [...parents, item])
}

@@ -159,3 +161,4 @@ }

* @param callback 每个对象执行的方法
* @param children 数组子类字段(默认值'children')
* @param children 数组子类字段(默认值children')
* @param parents
* @example

@@ -180,8 +183,9 @@ * deleteRecursively(

array = [],
callback,
children = 'children'
callback: (item: any, parents: any[], i: number, array: any[]) => boolean,
children = 'children',
parents = []
) => {
for (let i = array.length - 1; i >= 0; i--) {
let item = array[i]
let status = callback(item)
let status = callback(item, parents, i, array)
if (type(status) !== 'boolean') {

@@ -196,3 +200,3 @@ new Error(`callback返回值:${status}(返回值只能是布尔值)`)

item?.[children]?.length && deleteRecursively(item[children], callback, children)
item?.[children]?.length && deleteRecursively(item[children], callback, children, [...parents, item])
}

@@ -206,8 +210,8 @@ }

* @param callback 回调
* @param children 数组子类字段(默认值'children')
* @param children 数组子类字段(默认值children')
* @param parents
*/
export const setTreeAttr_copy = (
array,
callback: (item, parents) => object,
array: any[],
callback: (item: any, parents: any[], index: number, array: any[]) => object,
children = 'children',

@@ -218,4 +222,4 @@ parents = []

return array.reduce((total, item) => {
const result = callback(item, parents)
return array.reduce((total, item, index, _array) => {
const result = callback(item, parents, index, _array)
if (!isObject(result)) { throw new Error('函数返回值必须为对象') }

@@ -234,3 +238,4 @@

* @param returnType 返回类型 (对象或对象的某个属性)
* @param children 数组子类字段(默认值'children')
* @param children 数组子类字段(默认值children')
* @param parents
* @example

@@ -242,21 +247,22 @@ * treeFind(

* },
* {}
* 'children',
* {}
* )
*/
export const treeFind = (
array,
callback: (item: any) => boolean,
array: any[],
callback: (item: any, parents: any[], i: number, array: any[]) => boolean,
returnType = '{}',
children = 'children',
parents = []
) => {
for (let i = 0, len = array.length; i < len; i++) {
const item = array[i]
if (callback(item)) {
if (callback(item, parents, i, array)) {
return returnType === '{}' || returnType === 'Object' || isObject(returnType) ? item : item[returnType]
}
const result = item[children] && treeFind(item[children], callback, returnType, children)
const result = item[children] && treeFind(item[children], callback, returnType, children, [...parents, item])
if (result) { return result }
}
}
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