rattail 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +43 -0
- package/lib/index.d.cts +14 -1
- package/lib/index.d.ts +14 -1
- package/lib/index.global.js +41 -0
- package/lib/index.js +43 -0
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -64,6 +64,7 @@ __export(src_exports, {
|
|
|
64
64
|
cloneDeep: () => cloneDeep,
|
|
65
65
|
cloneDeepWith: () => cloneDeepWith,
|
|
66
66
|
copyText: () => copyText,
|
|
67
|
+
createCacheManager: () => createCacheManager,
|
|
67
68
|
createNamespaceFn: () => createNamespaceFn,
|
|
68
69
|
createStorage: () => createStorage,
|
|
69
70
|
debounce: () => debounce,
|
|
@@ -855,6 +856,7 @@ __export(util_exports, {
|
|
|
855
856
|
cancelAnimationFrame: () => cancelAnimationFrame,
|
|
856
857
|
classes: () => classes,
|
|
857
858
|
copyText: () => copyText,
|
|
859
|
+
createCacheManager: () => createCacheManager,
|
|
858
860
|
createNamespaceFn: () => createNamespaceFn,
|
|
859
861
|
createStorage: () => createStorage,
|
|
860
862
|
doubleRaf: () => doubleRaf,
|
|
@@ -1298,6 +1300,46 @@ function duration() {
|
|
|
1298
1300
|
return ctx;
|
|
1299
1301
|
}
|
|
1300
1302
|
|
|
1303
|
+
// src/util/createCacheManager.ts
|
|
1304
|
+
function createCacheManager(options = {}) {
|
|
1305
|
+
const cacheManager = /* @__PURE__ */ new Map();
|
|
1306
|
+
const { ttl: defaultTtl = Infinity } = options;
|
|
1307
|
+
function purgeStale() {
|
|
1308
|
+
cacheManager.forEach((value, key3) => {
|
|
1309
|
+
if (performance.now() > value.expiredAt) {
|
|
1310
|
+
remove(key3);
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
function has(key3) {
|
|
1315
|
+
purgeStale();
|
|
1316
|
+
return cacheManager.has(key3);
|
|
1317
|
+
}
|
|
1318
|
+
function get(key3) {
|
|
1319
|
+
var _a;
|
|
1320
|
+
purgeStale();
|
|
1321
|
+
return (_a = cacheManager.get(key3)) == null ? void 0 : _a.value;
|
|
1322
|
+
}
|
|
1323
|
+
function set2(key3, value, options2) {
|
|
1324
|
+
var _a;
|
|
1325
|
+
const ttl = (_a = options2 == null ? void 0 : options2.ttl) != null ? _a : defaultTtl;
|
|
1326
|
+
cacheManager.set(key3, { expiredAt: performance.now() + ttl, value });
|
|
1327
|
+
}
|
|
1328
|
+
function remove(key3) {
|
|
1329
|
+
return cacheManager.delete(key3);
|
|
1330
|
+
}
|
|
1331
|
+
function clear() {
|
|
1332
|
+
cacheManager.clear();
|
|
1333
|
+
}
|
|
1334
|
+
return {
|
|
1335
|
+
has,
|
|
1336
|
+
get,
|
|
1337
|
+
set: set2,
|
|
1338
|
+
remove,
|
|
1339
|
+
clear
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1301
1343
|
// src/util/index.ts
|
|
1302
1344
|
__reExport(util_exports, require("mitt"));
|
|
1303
1345
|
var import_mitt = __toESM(require("mitt"), 1);
|
|
@@ -1653,6 +1695,7 @@ function ceil(val, precision = 0) {
|
|
|
1653
1695
|
cloneDeep,
|
|
1654
1696
|
cloneDeepWith,
|
|
1655
1697
|
copyText,
|
|
1698
|
+
createCacheManager,
|
|
1656
1699
|
createNamespaceFn,
|
|
1657
1700
|
createStorage,
|
|
1658
1701
|
debounce,
|
package/lib/index.d.cts
CHANGED
|
@@ -155,6 +155,19 @@ interface DurationContext {
|
|
|
155
155
|
}
|
|
156
156
|
declare function duration(): DurationContext;
|
|
157
157
|
|
|
158
|
+
interface CreateCacheManagerOptions {
|
|
159
|
+
ttl?: number;
|
|
160
|
+
}
|
|
161
|
+
declare function createCacheManager<T = any>(options?: CreateCacheManagerOptions): {
|
|
162
|
+
has: (key: any) => boolean;
|
|
163
|
+
get: (key: any) => T | undefined;
|
|
164
|
+
set: (key: any, value: T, options?: {
|
|
165
|
+
ttl: number;
|
|
166
|
+
}) => void;
|
|
167
|
+
remove: (key: any) => boolean;
|
|
168
|
+
clear: () => void;
|
|
169
|
+
};
|
|
170
|
+
|
|
158
171
|
declare function call<P extends any[], R>(fn?: ((...arg: P) => R) | ((...arg: P) => R)[] | null, ...args: P): R | R[] | undefined;
|
|
159
172
|
|
|
160
173
|
declare function once<F extends (...args: any[]) => any>(fn: F): (this: unknown, ...args: Parameters<F>) => ReturnType<F>;
|
|
@@ -326,4 +339,4 @@ declare function floor(val: number, precision?: number): number;
|
|
|
326
339
|
|
|
327
340
|
declare function ceil(val: number, precision?: number): number;
|
|
328
341
|
|
|
329
|
-
export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, callOrReturn, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasDuplicates, hasDuplicatesBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
|
|
342
|
+
export { type BEM, type ClassName, type Classes, type CreateCacheManagerOptions, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, callOrReturn, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createCacheManager, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasDuplicates, hasDuplicatesBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
|
package/lib/index.d.ts
CHANGED
|
@@ -155,6 +155,19 @@ interface DurationContext {
|
|
|
155
155
|
}
|
|
156
156
|
declare function duration(): DurationContext;
|
|
157
157
|
|
|
158
|
+
interface CreateCacheManagerOptions {
|
|
159
|
+
ttl?: number;
|
|
160
|
+
}
|
|
161
|
+
declare function createCacheManager<T = any>(options?: CreateCacheManagerOptions): {
|
|
162
|
+
has: (key: any) => boolean;
|
|
163
|
+
get: (key: any) => T | undefined;
|
|
164
|
+
set: (key: any, value: T, options?: {
|
|
165
|
+
ttl: number;
|
|
166
|
+
}) => void;
|
|
167
|
+
remove: (key: any) => boolean;
|
|
168
|
+
clear: () => void;
|
|
169
|
+
};
|
|
170
|
+
|
|
158
171
|
declare function call<P extends any[], R>(fn?: ((...arg: P) => R) | ((...arg: P) => R)[] | null, ...args: P): R | R[] | undefined;
|
|
159
172
|
|
|
160
173
|
declare function once<F extends (...args: any[]) => any>(fn: F): (this: unknown, ...args: Parameters<F>) => ReturnType<F>;
|
|
@@ -326,4 +339,4 @@ declare function floor(val: number, precision?: number): number;
|
|
|
326
339
|
|
|
327
340
|
declare function ceil(val: number, precision?: number): number;
|
|
328
341
|
|
|
329
|
-
export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, callOrReturn, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasDuplicates, hasDuplicatesBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
|
|
342
|
+
export { type BEM, type ClassName, type Classes, type CreateCacheManagerOptions, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, callOrReturn, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createCacheManager, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasDuplicates, hasDuplicatesBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
|
package/lib/index.global.js
CHANGED
|
@@ -54,6 +54,7 @@ var Rattail = (() => {
|
|
|
54
54
|
cloneDeep: () => cloneDeep,
|
|
55
55
|
cloneDeepWith: () => cloneDeepWith,
|
|
56
56
|
copyText: () => copyText,
|
|
57
|
+
createCacheManager: () => createCacheManager,
|
|
57
58
|
createNamespaceFn: () => createNamespaceFn,
|
|
58
59
|
createStorage: () => createStorage,
|
|
59
60
|
debounce: () => debounce,
|
|
@@ -1258,6 +1259,46 @@ var Rattail = (() => {
|
|
|
1258
1259
|
return ctx;
|
|
1259
1260
|
}
|
|
1260
1261
|
|
|
1262
|
+
// src/util/createCacheManager.ts
|
|
1263
|
+
function createCacheManager(options = {}) {
|
|
1264
|
+
const cacheManager = /* @__PURE__ */ new Map();
|
|
1265
|
+
const { ttl: defaultTtl = Infinity } = options;
|
|
1266
|
+
function purgeStale() {
|
|
1267
|
+
cacheManager.forEach((value, key3) => {
|
|
1268
|
+
if (performance.now() > value.expiredAt) {
|
|
1269
|
+
remove(key3);
|
|
1270
|
+
}
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
function has(key3) {
|
|
1274
|
+
purgeStale();
|
|
1275
|
+
return cacheManager.has(key3);
|
|
1276
|
+
}
|
|
1277
|
+
function get(key3) {
|
|
1278
|
+
var _a;
|
|
1279
|
+
purgeStale();
|
|
1280
|
+
return (_a = cacheManager.get(key3)) == null ? void 0 : _a.value;
|
|
1281
|
+
}
|
|
1282
|
+
function set2(key3, value, options2) {
|
|
1283
|
+
var _a;
|
|
1284
|
+
const ttl = (_a = options2 == null ? void 0 : options2.ttl) != null ? _a : defaultTtl;
|
|
1285
|
+
cacheManager.set(key3, { expiredAt: performance.now() + ttl, value });
|
|
1286
|
+
}
|
|
1287
|
+
function remove(key3) {
|
|
1288
|
+
return cacheManager.delete(key3);
|
|
1289
|
+
}
|
|
1290
|
+
function clear() {
|
|
1291
|
+
cacheManager.clear();
|
|
1292
|
+
}
|
|
1293
|
+
return {
|
|
1294
|
+
has,
|
|
1295
|
+
get,
|
|
1296
|
+
set: set2,
|
|
1297
|
+
remove,
|
|
1298
|
+
clear
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1261
1302
|
// node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
|
|
1262
1303
|
function mitt_default(n) {
|
|
1263
1304
|
return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
|
package/lib/index.js
CHANGED
|
@@ -52,6 +52,7 @@ __export(src_exports, {
|
|
|
52
52
|
cloneDeep: () => cloneDeep,
|
|
53
53
|
cloneDeepWith: () => cloneDeepWith,
|
|
54
54
|
copyText: () => copyText,
|
|
55
|
+
createCacheManager: () => createCacheManager,
|
|
55
56
|
createNamespaceFn: () => createNamespaceFn,
|
|
56
57
|
createStorage: () => createStorage,
|
|
57
58
|
debounce: () => debounce,
|
|
@@ -842,6 +843,7 @@ __export(util_exports, {
|
|
|
842
843
|
cancelAnimationFrame: () => cancelAnimationFrame,
|
|
843
844
|
classes: () => classes,
|
|
844
845
|
copyText: () => copyText,
|
|
846
|
+
createCacheManager: () => createCacheManager,
|
|
845
847
|
createNamespaceFn: () => createNamespaceFn,
|
|
846
848
|
createStorage: () => createStorage,
|
|
847
849
|
doubleRaf: () => doubleRaf,
|
|
@@ -1285,6 +1287,46 @@ function duration() {
|
|
|
1285
1287
|
return ctx;
|
|
1286
1288
|
}
|
|
1287
1289
|
|
|
1290
|
+
// src/util/createCacheManager.ts
|
|
1291
|
+
function createCacheManager(options = {}) {
|
|
1292
|
+
const cacheManager = /* @__PURE__ */ new Map();
|
|
1293
|
+
const { ttl: defaultTtl = Infinity } = options;
|
|
1294
|
+
function purgeStale() {
|
|
1295
|
+
cacheManager.forEach((value, key3) => {
|
|
1296
|
+
if (performance.now() > value.expiredAt) {
|
|
1297
|
+
remove(key3);
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
function has(key3) {
|
|
1302
|
+
purgeStale();
|
|
1303
|
+
return cacheManager.has(key3);
|
|
1304
|
+
}
|
|
1305
|
+
function get(key3) {
|
|
1306
|
+
var _a;
|
|
1307
|
+
purgeStale();
|
|
1308
|
+
return (_a = cacheManager.get(key3)) == null ? void 0 : _a.value;
|
|
1309
|
+
}
|
|
1310
|
+
function set2(key3, value, options2) {
|
|
1311
|
+
var _a;
|
|
1312
|
+
const ttl = (_a = options2 == null ? void 0 : options2.ttl) != null ? _a : defaultTtl;
|
|
1313
|
+
cacheManager.set(key3, { expiredAt: performance.now() + ttl, value });
|
|
1314
|
+
}
|
|
1315
|
+
function remove(key3) {
|
|
1316
|
+
return cacheManager.delete(key3);
|
|
1317
|
+
}
|
|
1318
|
+
function clear() {
|
|
1319
|
+
cacheManager.clear();
|
|
1320
|
+
}
|
|
1321
|
+
return {
|
|
1322
|
+
has,
|
|
1323
|
+
get,
|
|
1324
|
+
set: set2,
|
|
1325
|
+
remove,
|
|
1326
|
+
clear
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1288
1330
|
// src/util/index.ts
|
|
1289
1331
|
__reExport(util_exports, mitt_star);
|
|
1290
1332
|
import * as mitt_star from "mitt";
|
|
@@ -1640,6 +1682,7 @@ export {
|
|
|
1640
1682
|
cloneDeep,
|
|
1641
1683
|
cloneDeepWith,
|
|
1642
1684
|
copyText,
|
|
1685
|
+
createCacheManager,
|
|
1643
1686
|
createNamespaceFn,
|
|
1644
1687
|
createStorage,
|
|
1645
1688
|
debounce,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rattail",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "A utilities library for front-end developers, lightweight and ts-friendly",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"utilities library",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@configurajs/eslint": "^0.0.14",
|
|
52
52
|
"@configurajs/prettier": "^0.1.1",
|
|
53
53
|
"@types/node": "^22.8.1",
|
|
54
|
-
"@varlet/release": "^0.
|
|
54
|
+
"@varlet/release": "^0.4.4",
|
|
55
55
|
"@vitest/coverage-istanbul": "^2.1.3",
|
|
56
56
|
"eslint": "9.17.0",
|
|
57
57
|
"jsdom": "^25.0.1",
|