Comparing version 1.4.0 to 1.4.1
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var smallQueue = require('small-queue'); | ||
@@ -1543,2 +1541,26 @@ | ||
}; | ||
const batchProcess = ({ ms, processor }) => { | ||
const queue = []; | ||
const flush = () => { | ||
setTimeout(() => { | ||
const ls = []; | ||
const fns = []; | ||
for (const { value, resolve } of queue) { | ||
ls.push(value); | ||
fns.push(resolve); | ||
} | ||
queue.length = 0; | ||
processor(ls); | ||
for (const fn of fns) { | ||
fn(); | ||
} | ||
}, ms || 0); | ||
}; | ||
return (value) => { | ||
const defer = defered(); | ||
if (queue.length === 0) flush(); | ||
queue.push({ value, resolve: defer.resolve }); | ||
return defer.promise; | ||
}; | ||
}; | ||
@@ -1548,2 +1570,3 @@ exports.Queue = smallQueue.Queue; | ||
exports.assert = assert; | ||
exports.batchProcess = batchProcess; | ||
exports.capitalize = capitalize; | ||
@@ -1550,0 +1573,0 @@ exports.clearUndef = clearUndef; |
@@ -1539,2 +1539,26 @@ export { Queue } from 'small-queue'; | ||
}; | ||
const batchProcess = ({ ms, processor }) => { | ||
const queue = []; | ||
const flush = () => { | ||
setTimeout(() => { | ||
const ls = []; | ||
const fns = []; | ||
for (const { value, resolve } of queue) { | ||
ls.push(value); | ||
fns.push(resolve); | ||
} | ||
queue.length = 0; | ||
processor(ls); | ||
for (const fn of fns) { | ||
fn(); | ||
} | ||
}, ms || 0); | ||
}; | ||
return (value) => { | ||
const defer = defered(); | ||
if (queue.length === 0) flush(); | ||
queue.push({ value, resolve: defer.resolve }); | ||
return defer.promise; | ||
}; | ||
}; | ||
@@ -1544,2 +1568,3 @@ export { | ||
assert, | ||
batchProcess, | ||
capitalize, | ||
@@ -1546,0 +1571,0 @@ clearUndef, |
@@ -1602,2 +1602,26 @@ (function (global, factory) { | ||
}; | ||
const batchProcess = ({ ms, processor }) => { | ||
const queue = []; | ||
const flush = () => { | ||
setTimeout(() => { | ||
const ls = []; | ||
const fns = []; | ||
for (const { value, resolve } of queue) { | ||
ls.push(value); | ||
fns.push(resolve); | ||
} | ||
queue.length = 0; | ||
processor(ls); | ||
for (const fn of fns) { | ||
fn(); | ||
} | ||
}, ms || 0); | ||
}; | ||
return (value) => { | ||
const defer = defered(); | ||
if (queue.length === 0) flush(); | ||
queue.push({ value, resolve: defer.resolve }); | ||
return defer.promise; | ||
}; | ||
}; | ||
@@ -1607,2 +1631,3 @@ exports.Queue = Queue; | ||
exports.assert = assert; | ||
exports.batchProcess = batchProcess; | ||
exports.capitalize = capitalize; | ||
@@ -1684,4 +1709,2 @@ exports.clearUndef = clearUndef; | ||
exports.uuid = uuid; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}); |
@@ -135,1 +135,8 @@ export { Queue } from 'small-queue'; | ||
}; | ||
export declare const batchProcess: <T = unknown>({ | ||
ms, | ||
processor, | ||
}: { | ||
ms?: number | undefined; | ||
processor: (queue: T[]) => void; | ||
}) => (value: T) => Promise<void>; |
{ | ||
"name": "aidly", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Tool library.", | ||
@@ -17,10 +17,5 @@ "sideEffects": false, | ||
}, | ||
"files": ["dist", "README.zh-CN.md"], | ||
"scripts": { | ||
"test": "jest", | ||
"prepare": "husky", | ||
"dev": "ts-node ./test.ts", | ||
"build": "rimraf ./dist && rollup --config && rimraf ./dist/__tests__", | ||
"format": "prettier --write --parser typescript \"(src|dist)/**/*.(js|ts?(x))\"" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"lint-staged": { | ||
@@ -52,18 +47,17 @@ "*.js": [ | ||
}, | ||
"packageManager": "pnpm@9.1.3", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
"@types/jest": "^27.4.0", | ||
"@rollup/plugin-commonjs": "^26.0.1", | ||
"@rollup/plugin-json": "^6.1.0", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.14.9", | ||
"husky": "^9.0.11", | ||
"lint-staged": "^15.2.5", | ||
"jest": "^29.0.0", | ||
"jest": "^29.7.0", | ||
"prettier": "^2.5.1", | ||
"rimraf": "^5.0.7", | ||
"rollup": "^2.67.2", | ||
"rollup": "^4.18.0", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
"rollup-plugin-typescript2": "^0.31.1", | ||
"ts-jest": "^29.1.5", | ||
"rollup-plugin-typescript2": "^0.36.0", | ||
"ts-jest": "^29.1.4", | ||
"ts-node": "^10.9.2", | ||
@@ -74,3 +68,9 @@ "typescript": "^4.5.5" | ||
"small-queue": "^1.0.1" | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"dev": "ts-node ./test.ts", | ||
"build": "rimraf ./dist && rollup --config && rimraf ./dist/__tests__", | ||
"format": "prettier --write --parser typescript \"(src|dist)/**/*.(js|ts?(x))\"" | ||
} | ||
} | ||
} |
@@ -117,2 +117,3 @@ <div align="center"> | ||
`root` | Alias for global objects, compatible with different environments. | ||
`batchProcess` | Used for transactional batch processing, for example: `const set = batchProcess({ ms: 50, processor(ls) { ... } });` | ||
`jsonStringify` | Format objects as json strings, able to handle reference relationships (including circular references). | ||
@@ -119,0 +120,0 @@ `jsonParse` | Parse the json string into an object, able to handle reference relationships (including circular references). |
@@ -117,2 +117,3 @@ <div align="center"> | ||
`root` | 为全局对象提供的别名,兼容不同环境。 | ||
`batchProcess` | 用于事务的批量处理,例如: `const set = batchProcess({ ms: 50, process(ls) { ... } });`。 | ||
`jsonParse` | 将 `json` 字符串解析为对象,能够处理引用关系(包括循环引用)。 | ||
@@ -119,0 +120,0 @@ `jsonStringify` | 将对象格式化为 `json` 字符串,能够处理引用关系(包括循环引用)。 |
Sorry, the diff of this file is not supported yet
180544
5475
121