commonly-used-utils
Advanced tools
Comparing version 1.0.0-beat4 to 1.0.0-beat5
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(self,(()=>(()=>{"use strict";var e={605:(e,t,r)=>{t.__esModule=!0,t.removeItem=t.addItem=t.findArrayAttr=void 0;var n=r(208);function i(e){if("number"!==(0,n.type)(e)&&"string"!==(0,n.type)(e))throw new Error("只支持string、number类型的数据");!(0,n.isArray)(this)||this.includes(e)?this instanceof Set&&this.add(e):this.push(e)}function o(e){if("number"!==(0,n.type)(e)&&"string"!==(0,n.type)(e))throw new Error("只支持string、number类型的数据");if((0,n.isArray)(this)){var t=this.indexOf(e);-1!==t&&this.splice(t,1)}else this instanceof Set&&this.remove(e)}t.findArrayAttr=function(e,t,r,i,o){if(void 0===o&&(o=!1),!(0,n.isArray)(e)||!r||(0,n.isNil)(t)||o&&!e.length)throw new Error("请检查参数");var c=e.find((function(e){return!!(0,n.isObject)(e)&&(o?e[r]===t:""+e[r]==""+t)}));if("{}"===i||"string"==typeof i&&"object"===i.toLowerCase()||(0,n.isObject)(i)){if(o&&!(0,n.isObject)(c))throw new Error("严格模式(对象)未找到, value: ".concat(t,", attr:").concat(r,", url: ").concat(location.href));return c}if(o&&(!(0,n.isObject)(c)||!(i in c)||(0,n.isNil)(c[i])))throw new Error("严格模式(属性)未找到, value: ".concat(t,", attr:").concat(r,", url: ").concat(location.href));return null==c?void 0:c[i]},t.addItem=function(){var e=this;for(var t in arguments){var r=arguments[t];(0,n.isArray)(r)?r.forEach((function(t){i.call(e,t)})):i.call(this,r)}},t.removeItem=function(){var e=this;for(var t in arguments){var r=arguments[t];(0,n.isArray)(r)?r.forEach((function(t){o.call(e,t)})):o.call(this,r)}}},441:(e,t)=>{t.__esModule=!0,t.sleep=void 0,t.sleep=function(e){return new Promise((function(t){return setTimeout(t,e)}))}},607:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]});t.__esModule=!0,t.sleep=t.removeItem=t.addItem=t.findArrayAttr=t.deleteRecursivelyReverse=t.deleteRecursively=t.setTreeAttr=t.treeFindParents=t.oneDimensional=t.isObject=t.isFunction=t.isArray=t.isNil=void 0;var i=r(208);n(t,i,"isNil"),n(t,i,"isArray"),n(t,i,"isFunction"),n(t,i,"isObject");var o=r(788);n(t,o,"oneDimensional"),n(t,o,"treeFindParents"),n(t,o,"setTreeAttr"),n(t,o,"deleteRecursively"),n(t,o,"deleteRecursivelyReverse");var c=r(605);n(t,c,"findArrayAttr"),n(t,c,"addItem"),n(t,c,"removeItem"),n(t,r(441),"sleep")},788:function(e,t,r){var n=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))};t.__esModule=!0,t.deleteRecursivelyReverse=t.deleteRecursively=t.setTreeAttr=t.treeFindParents=t.oneDimensional=void 0;var i=r(208);t.oneDimensional=function(e,r){return void 0===e&&(e=[]),void 0===r&&(r="children"),e&&e.length?e.reduce((function(e,n){var i;return e.concat(n,(null===(i=null==n?void 0:n[r])||void 0===i?void 0:i.length)?(0,t.oneDimensional)(n[r],r):[])}),[]):[]},t.treeFindParents=function(e,r,n,o,c,l,a){var s;if(void 0===e&&(e=[]),void 0===n&&(n="id"),void 0===o&&(o="children"),void 0===c&&(c=!0),void 0===l&&(l=!0),void 0===a&&(a=!0),!e.length)return[];for(var u=0,v=e.length;u<v;u++){var d=e[u];if(d[n]===r)return l?[d]:a?[]:d;var f=(null===(s=null==d?void 0:d[o])||void 0===s?void 0:s.length)&&(0,t.treeFindParents)(d[o],r,n,o,c,l,!1);if((0,i.isObject)(f))return[d];if(null==f?void 0:f.length)return c?[d].concat(f):f.concat(d)}},t.setTreeAttr=function(e,r,i,o){var c;void 0===e&&(e=[]),void 0===i&&(i="children"),void 0===o&&(o=[]);for(var l=0,a=e.length;l<a;l++){var s=e[l];r(s,o),(null===(c=null==s?void 0:s[i])||void 0===c?void 0:c.length)&&(0,t.setTreeAttr)(s[i],r,i,n(n([],o,!0),[s],!1))}},t.deleteRecursively=function(e,r,n){var o;void 0===e&&(e=[]),void 0===n&&(n="children");for(var c=0,l=e.length;c<l;c++){var a=e[c],s=r(a);if("boolean"!==(0,i.type)(s)){new Error("callback返回值:".concat(s,"(返回值只能是布尔值)"));break}s?(null===(o=null==a?void 0:a[n])||void 0===o?void 0:o.length)&&(0,t.deleteRecursively)(a[n],r,n):(e.splice(c,1),l--,c--)}},t.deleteRecursivelyReverse=function(e,r,n){var o;void 0===e&&(e=[]),void 0===n&&(n="children");for(var c=e.length-1;c>=0;c--){var l=e[c],a=r(l);if("boolean"!==(0,i.type)(a)){new Error("callback返回值:".concat(a,"(返回值只能是布尔值)"));break}a?(null===(o=null==l?void 0:l[n])||void 0===o?void 0:o.length)&&(0,t.deleteRecursively)(l[n],r,n):e.splice(c,1)}}},208:(e,t)=>{t.__esModule=!0,t.isNil=t.isArray=t.isFunction=t.isObject=t.type=void 0;var r=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"]]);t.type=function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?r.get(Object.prototype.toString.call(e))||"object":typeof e},t.isObject=function(e){return"object"===(0,t.type)(e)},t.isFunction=function(e){return"function"===(0,t.type)(e)},t.isArray=function(e){return"array"===(0,t.type)(e)},t.isNil=function(e){return null==e}}},t={};return function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}(607)})())); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(self,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{NotRepeatedArray:()=>j,addItem:()=>g,deleteRecursively:()=>u,deleteRecursivelyReverse:()=>h,findArrayAttr:()=>b,isArray:()=>l,isFunction:()=>i,isNil:()=>c,isObject:()=>o,oneDimensional:()=>s,removeItem:()=>y,setTreeAttr:()=>f,sleep:()=>m,treeFindParents:()=>a});const r=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?r.get(Object.prototype.toString.call(e))||"object":typeof e,o=e=>"object"===n(e),i=e=>"function"===n(e),l=e=>"array"===n(e),c=e=>null==e,s=(e=[],t="children")=>e&&e.length?e.reduce(((e,r)=>e.concat(r,r?.[t]?.length?s(r[t],t):[])),[]):[],a=(e=[],t,r="id",n="children",i=!0,l=!0,c=!0)=>{if(!e.length)return[];for(let s=0,f=e.length;s<f;s++){const f=e[s];if(f[r]===t)return l?[f]:c?[]:f;const u=f?.[n]?.length&&a(f[n],t,r,n,i,l,!1);if(o(u))return[f];if(u?.length)return i?[f].concat(u):u.concat(f)}},f=(e=[],t,r="children",n=[])=>{for(let o=0,i=e.length;o<i;o++){let i=e[o];t(i,n),i?.[r]?.length&&f(i[r],t,r,[...n,i])}},u=(e=[],t,r="children")=>{for(let o=0,i=e.length;o<i;o++){let l=e[o],c=t(l);if("boolean"!==n(c)){new Error(`callback返回值:${c}(返回值只能是布尔值)`);break}c?l?.[r]?.length&&u(l[r],t,r):(e.splice(o,1),i--,o--)}},h=(e=[],t,r="children")=>{for(let o=e.length-1;o>=0;o--){let i=e[o],l=t(i);if("boolean"!==n(l)){new Error(`callback返回值:${l}(返回值只能是布尔值)`);break}l?i?.[r]?.length&&u(i[r],t,r):e.splice(o,1)}},b=(e,t,r,n,i=!1)=>{if(!l(e)||!r||c(t)||i&&!e.length)throw new Error("请检查参数");const s=e.find((e=>!!o(e)&&(i?e[r]===t:""+e[r]==""+t)));if("{}"===n||"string"==typeof n&&"object"===n.toLowerCase()||o(n)){if(i&&!o(s))throw new Error(`严格模式(对象)未找到, value: ${t}, attr:${r}, url: ${location.href}`);return s}if(i&&(!o(s)||!(n in s)||c(s[n])))throw new Error(`严格模式(属性)未找到, value: ${t}, attr:${r}, url: ${location.href}`);return s?.[n]};function d(e){if("number"!==n(e)&&"string"!==n(e))throw new Error("只支持string、number类型的数据");!l(this)||this.includes(e)?this instanceof Set&&this.add(e):this.push(e)}function p(e){if("number"!==n(e)&&"string"!==n(e))throw new Error("只支持string、number类型的数据");if(l(this)){const t=this.indexOf(e);-1!==t&&this.splice(t,1)}else this instanceof Set&&this.delete(e)}const g=function(...e){for(let t in e){const r=e[t];l(r)?r.forEach((e=>{d.call(this,e)})):d.call(this,r)}return this},y=function(...e){for(let t in e){const r=e[t];l(r)?r.forEach((e=>{p.call(this,e)})):p.call(this,r)}return this};class j extends Array{constructor(e){e?.length?super(...e):super()}addItem(...e){return g.call(this,e),this}removeItem(...e){return y.call(this,e),this}}const m=e=>new Promise((t=>setTimeout(t,e)));return t})())); |
{ | ||
"name": "commonly-used-utils", | ||
"version": "1.0.0-beat4", | ||
"version": "1.0.0-beat5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -82,3 +82,3 @@ import { isArray, isNil, isObject, type } from './utils/basics' | ||
if (this instanceof Set) { | ||
this.remove(value) | ||
this.delete(value) | ||
return | ||
@@ -88,14 +88,31 @@ } | ||
export const addItem = function () { | ||
for (let i in arguments) { | ||
const item = arguments[i] | ||
export const addItem = function (...args) { | ||
for (let i in args) { | ||
const item = args[i] | ||
isArray(item) ? item.forEach((_i) => { add.call(this, _i) }) : add.call(this, item) | ||
} | ||
return this | ||
} | ||
export const removeItem = function () { | ||
for (let i in arguments) { | ||
const item = arguments[i] | ||
export const removeItem = function (...args) { | ||
for (let i in args) { | ||
const item = args[i] | ||
isArray(item) ? item.forEach((_i) => { remove.call(this, _i) }) : remove.call(this, item) | ||
} | ||
return this | ||
} | ||
export class NotRepeatedArray extends Array { | ||
constructor(args?) { | ||
args?.length ? super(...args) : super() | ||
} | ||
addItem(...args) { | ||
addItem.call(this, args) | ||
return this | ||
} | ||
removeItem(...args) { | ||
removeItem.call(this, args) | ||
return this | ||
} | ||
} |
@@ -14,4 +14,9 @@ // 常用工具 | ||
// 数组 | ||
export { findArrayAttr, addItem, removeItem } from './array' | ||
export { | ||
findArrayAttr, | ||
NotRepeatedArray, | ||
addItem, | ||
removeItem | ||
} from './array' | ||
export { sleep } from './function' |
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "esnext", | ||
"lib": [ | ||
"esnext", | ||
"es2021", | ||
"dom" | ||
] | ||
], | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": [ | ||
"src/*" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"types" | ||
"types/**/*.ts", | ||
"types/**/*.tsx" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
@@ -28,3 +28,9 @@ | ||
export function addItem() | ||
export function removeItem() | ||
export function addItem(...param) | ||
export function removeItem(...param) | ||
export class NotRepeatedArray { | ||
constructor(param) | ||
addItem(...param) | ||
removeItem(...param) | ||
} |
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
328
13915