commonly-used-utils
Advanced tools
Comparing version 1.0.0-beat11 to 1.0.0-beat12
{ | ||
"name": "commonly-used-utils", | ||
"version": "1.0.0-beat11", | ||
"version": "1.0.0-beat12", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
/** | ||
* 睡眠(由于 Event Loop 机制,无法保证睡眠结束后代码立即执行) | ||
* @param time | ||
* @param time 间隔时间 | ||
* @return void | ||
*/ | ||
export const sleep = (time: 0) => new Promise(resolve => setTimeout(resolve, time)) |
@@ -114,3 +114,3 @@ import { isObject, type } from './utils/basics' | ||
* 'children' | ||
* ) | ||
* ) | ||
*/ | ||
@@ -117,0 +117,0 @@ export const deleteRecursively = ( |
@@ -0,7 +1,21 @@ | ||
// 是否为对象 | ||
export function isObject (param: any): param is boolean | ||
export function isObject (param: any): param is boolean | ||
// 是否为数组 | ||
export function isArray (param: any): param is boolean | ||
// 是否为方法 | ||
export function isFunction (param: any): param is boolean | ||
// 是否为 NULL | ||
export function isNil (param: any): param is boolean | ||
/** | ||
* 多维嵌套数组转一维数组 | ||
* @param array treeData | ||
* @param children 数组子类字段(默认值'children') | ||
* @returns array|[] | ||
* @example | ||
* oneDimensional(treeData, 'children') | ||
*/ | ||
export function oneDimensional ( | ||
@@ -11,3 +25,16 @@ array: object[], | ||
): any[] | ||
export function TreeFindParents ( | ||
/** | ||
* 通过 ID 查找祖父节点 | ||
* @param array treeData | ||
* @param value value | ||
* @param attr 属性值(默认值'id') | ||
* @param children 数组子类字段(默认值'children') | ||
* @param descend 返回数组是否为正序 | ||
* @param self 返回数组是否包含自身 | ||
* @return array|[] | ||
* @example | ||
* treeFindParents(treeData, value, 'id', 'children', true, true) | ||
*/ | ||
export function treeFindParents ( | ||
array: any[], | ||
@@ -20,2 +47,15 @@ value: string | number | undefined, | ||
): any[] | void | ||
/** | ||
* 查找数组符合属性的数据 | ||
* @param array 数组 | ||
* @param value value | ||
* @param attr 属性值(默认值'id') | ||
* @param returnData 返回数据(对象或value) | ||
* @param isStrict 严格模式(== 与 === 的区别) | ||
* @example | ||
* const array = [{ value: '小明', id: 1 }, { value: '小红', id: 2}] | ||
* findArrayAttr(array, 1, 'id', {}) // { value: '小明', id: 1 } | ||
* findArrayAttr(array, 2, 'id', 'value') // value: '小红' | ||
*/ | ||
export function findArrayAttr ( | ||
@@ -29,4 +69,27 @@ array: any[], | ||
export function addItem(...param) | ||
export function removeItem(...param) | ||
/** | ||
* 添加不重复数据(多参数) | ||
* @param args | ||
* @return this | ||
* @example | ||
* const array = [] | ||
* addItem.call(array, 1, 1, 2, 3) // [1, 2, 3] | ||
*/ | ||
export function addItem(...args) | ||
/** | ||
* 删除数组数据(多参数) | ||
* @param args | ||
* @return this | ||
* @example | ||
* const array = [1, 2] | ||
* removeItem.call(array, 1, 2, 3) // [] | ||
*/ | ||
export function removeItem(...args) | ||
/** | ||
* 睡眠(由于 Event Loop 机制,无法保证睡眠结束后代码立即执行) | ||
* @param time 间隔时间 | ||
* @return void | ||
*/ | ||
export function sleep(time?: number): void | ||
@@ -40,3 +103,43 @@ | ||
/** | ||
* 递归树每个对象 | ||
* @param array treeData | ||
* @param callback 每个节点执行的方法 | ||
* @param children 数组子类字段(默认值'children') | ||
* @return void | ||
* @example | ||
* setTreeAttr( | ||
* treeData, | ||
* (item, parents) => { | ||
* item['parentId'] = parents[parents.length - 1]?.['id'] // 父节点 | ||
* item['parentIds'] = parents.map((i) => i?.['id']) || [] // 所有父级链id | ||
* ... | ||
* }, | ||
* 'children' | ||
* ) | ||
*/ | ||
export function setTreeAttr(array, callback, children?: 'children' | string) | ||
/** | ||
* 删除不符合条件的某个节点 | ||
* @param array treeData | ||
* @param callback 每个对象执行的方法 | ||
* @param children 数组子类字段(默认值'children') | ||
* @example | ||
* deleteRecursively( | ||
* treeData, | ||
* (item) => { | ||
* if (item['disable']) { | ||
* return false | ||
* } | ||
* | ||
* // 添加数据等 | ||
* // item['disableStatus'] = 1 | ||
* // ... | ||
* | ||
* return true | ||
* }, | ||
* 'children' | ||
* ) | ||
*/ | ||
export function deleteRecursively(array, callback, children?: 'children' | string) |
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
23546
590