@catbee/utils 2.0.0-next.1 → 2.0.1
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/LICENSE +1 -1
- package/README.md +55 -38
- package/array/index.cjs +37 -5
- package/array/index.d.ts +59 -8
- package/array/index.mjs +32 -4
- package/async/index.cjs +24 -3
- package/async/index.d.ts +18 -2
- package/async/index.mjs +24 -4
- package/cache/index.cjs +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.mjs +1 -1
- package/config/index.cjs +8 -8
- package/config/index.d.ts +1 -1
- package/config/index.mjs +4 -4
- package/context-store/index.cjs +2 -3
- package/context-store/index.d.ts +1 -1
- package/context-store/index.mjs +2 -3
- package/crypto/index.cjs +55 -5
- package/crypto/index.d.ts +63 -2
- package/crypto/index.mjs +52 -7
- package/date/index.cjs +630 -1
- package/date/index.d.ts +487 -2
- package/date/index.mjs +621 -2
- package/{decorators → decorator}/index.cjs +425 -304
- package/{decorators → decorator}/index.d.ts +3 -2
- package/{decorators → decorator}/index.mjs +425 -304
- package/{dir → directory}/index.cjs +1 -1
- package/{dir → directory}/index.d.ts +1 -1
- package/{dir → directory}/index.mjs +1 -1
- package/env/index.cjs +90 -42
- package/env/index.d.ts +12 -1
- package/env/index.mjs +90 -42
- package/exception/index.cjs +1 -1
- package/exception/index.d.ts +1 -1
- package/exception/index.mjs +1 -1
- package/fs/index.cjs +1 -1
- package/fs/index.d.ts +1 -1
- package/fs/index.mjs +1 -1
- package/http-status-codes/index.cjs +1 -1
- package/http-status-codes/index.d.ts +1 -1
- package/http-status-codes/index.mjs +1 -1
- package/id/index.cjs +1 -1
- package/id/index.d.ts +1 -1
- package/id/index.mjs +1 -1
- package/index.cjs +10 -10
- package/index.d.ts +4 -4
- package/index.mjs +4 -4
- package/logger/index.cjs +2 -4
- package/logger/index.d.ts +2 -2
- package/logger/index.mjs +2 -4
- package/middleware/index.cjs +1 -1
- package/middleware/index.d.ts +1 -1
- package/middleware/index.mjs +1 -1
- package/{obj → object}/index.cjs +182 -108
- package/{obj → object}/index.d.ts +38 -2
- package/{obj → object}/index.mjs +180 -109
- package/package.json +31 -13
- package/performance/index.cjs +2 -2
- package/performance/index.d.ts +1 -1
- package/performance/index.mjs +2 -2
- package/request/index.cjs +36 -24
- package/request/index.d.ts +1 -1
- package/request/index.mjs +36 -24
- package/response/index.cjs +1 -1
- package/response/index.d.ts +1 -1
- package/response/index.mjs +1 -1
- package/server/index.cjs +233 -131
- package/server/index.d.ts +81 -1
- package/server/index.mjs +229 -127
- package/stream/index.cjs +1 -1
- package/stream/index.d.ts +1 -1
- package/stream/index.mjs +1 -1
- package/string/index.cjs +34 -1
- package/string/index.d.ts +45 -2
- package/string/index.mjs +31 -2
- package/type/index.cjs +18 -1
- package/type/index.d.ts +38 -2
- package/type/index.mjs +16 -2
- package/types/index.cjs +1 -1
- package/types/index.d.ts +10 -3
- package/types/index.mjs +1 -1
- package/url/index.cjs +61 -1
- package/url/index.d.ts +59 -2
- package/url/index.mjs +57 -2
- package/validation/index.cjs +3 -3
- package/validation/index.d.ts +1 -1
- package/validation/index.mjs +3 -3
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
# @catbee/utils
|
|
2
2
|
|
|
3
|
-
<!-- <div style="width: 100%; display: flex; align-items: center; justify-content: space-between;">
|
|
4
|
-
<b style="font-size: 24px; text-decoration: none;">@catbee/utils</b>
|
|
5
|
-
<a href="https://sonarcloud.io/summary/new_code?id=catbee-technologies_catbee-utils">
|
|
6
|
-
<img src="https://sonarcloud.io/images/project_badges/sonarcloud-dark.svg" alt="SonarQube Cloud" width="200"/>
|
|
7
|
-
</a>
|
|
8
|
-
</div> -->
|
|
9
3
|
|
|
10
4
|
## 🧰 Utility Modules for Node.js
|
|
11
5
|
|
|
12
6
|
A modular, production-grade utility toolkit for Node.js and TypeScript, designed for robust, scalable applications. All utilities are tree-shakable and can be imported independently.
|
|
13
7
|
|
|
14
8
|
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0;">
|
|
15
|
-
<img src="https://
|
|
9
|
+
<img src="https://github.com/catbee-technologies/catbee-utils/actions/workflows/ci.yml/badge.svg?label=Build" alt="Build Status" />
|
|
16
10
|
<img src="https://codecov.io/gh/catbee-technologies/catbee-utils/graph/badge.svg?token=XAJHK6R1OQ" alt="Coverage" />
|
|
17
11
|
<img src="https://img.shields.io/node/v/@catbee/utils" alt="Node Version" />
|
|
18
12
|
<img src="https://img.shields.io/npm/v/@catbee/utils" alt="NPM Version" />
|
|
@@ -20,7 +14,7 @@ A modular, production-grade utility toolkit for Node.js and TypeScript, designed
|
|
|
20
14
|
<img src="https://img.shields.io/npm/v/@catbee/utils/next" alt="NPM Next Version" /> -->
|
|
21
15
|
<img src="https://img.shields.io/npm/dt/@catbee/utils" alt="NPM Downloads" />
|
|
22
16
|
<img src="https://img.shields.io/npm/types/@catbee/utils" alt="TypeScript Types" />
|
|
23
|
-
<img src="https://img.shields.io/maintenance/yes/
|
|
17
|
+
<img src="https://img.shields.io/maintenance/yes/2050" alt="Maintenance" />
|
|
24
18
|
<img src="https://snyk.io/test/github/catbee-technologies/catbee-utils/badge.svg" alt="Snyk Vulnerabilities" />
|
|
25
19
|
<img src="https://sonarcloud.io/api/project_badges/measure?project=catbee-technologies_catbee-utils&metric=alert_status&token=93da835f2d48d37b41fa628cc7fc764c873bd700" alt="Quality Gate Status" />
|
|
26
20
|
<img src="https://sonarcloud.io/api/project_badges/measure?project=catbee-technologies_catbee-utils&metric=ncloc&token=93da835f2d48d37b41fa628cc7fc764c873bd700" alt="Lines of Code" />
|
|
@@ -71,7 +65,10 @@ const config = new ServerConfigBuilder()
|
|
|
71
65
|
|
|
72
66
|
const server = new ExpressServer(config, {
|
|
73
67
|
beforeInit: srv => console.log('Initializing server...'),
|
|
68
|
+
beforeRoutes: app => console.log('Setting up routes...'),
|
|
69
|
+
afterRoutes: app => console.log('Routes initialized.'),
|
|
74
70
|
afterInit: srv => console.log('Server initialized'),
|
|
71
|
+
onServerCreated: srv => console.log('HTTP/HTTPS server instance created.'),
|
|
75
72
|
beforeStart: app => console.log('Starting server...'),
|
|
76
73
|
afterStart: srv => console.log('Server started!'),
|
|
77
74
|
beforeStop: srv => console.log('Stopping server...'),
|
|
@@ -111,44 +108,64 @@ server.enableGracefulShutdown();
|
|
|
111
108
|
|
|
112
109
|
## 📚 Modules Overview
|
|
113
110
|
|
|
114
|
-
| Module
|
|
115
|
-
|
|
|
116
|
-
| [Express Server](https://catbee.in/docs/@catbee/utils/
|
|
117
|
-
| [Array Utilities](https://catbee.in/docs/@catbee/utils/
|
|
118
|
-
| [Async Utilities](https://catbee.in/docs/@catbee/utils/
|
|
119
|
-
| [Cache Utilities](https://catbee.in/docs/@catbee/utils/
|
|
120
|
-
| [Context Store](https://catbee.in/docs/@catbee/utils/
|
|
121
|
-
| [Crypto Utilities](https://catbee.in/docs/@catbee/utils/
|
|
122
|
-
| [Date Utilities](https://catbee.in/docs/@catbee/utils/
|
|
123
|
-
| [Decorators Utilities](https://catbee.in/docs/@catbee/utils/
|
|
124
|
-
| [Directory Utilities](https://catbee.in/docs/@catbee/utils/
|
|
125
|
-
| [Environment Utilities](https://catbee.in/docs/@catbee/utils/
|
|
126
|
-
| [Exception Utilities](https://catbee.in/docs/@catbee/utils/
|
|
127
|
-
| [File System Utilities](https://catbee.in/docs/@catbee/utils/
|
|
128
|
-
| [HTTP Status Codes](https://catbee.in/docs/@catbee/utils/
|
|
129
|
-
| [ID Utilities](https://catbee.in/docs/@catbee/utils/
|
|
130
|
-
| [Logger Utilities](https://catbee.in/docs/@catbee/utils/
|
|
131
|
-
| [Middleware Utilities](https://catbee.in/docs/@catbee/utils/
|
|
132
|
-
| [Object Utilities](https://catbee.in/docs/@catbee/utils/
|
|
133
|
-
| [Performance Utilities](https://catbee.in/docs/@catbee/utils/
|
|
134
|
-
| [Request Utilities](https://catbee.in/docs/@catbee/utils/
|
|
135
|
-
| [Response Utilities](https://catbee.in/docs/@catbee/utils/
|
|
136
|
-
| [Stream Utilities](https://catbee.in/docs/@catbee/utils/
|
|
137
|
-
| [String Utilities](https://catbee.in/docs/@catbee/utils/
|
|
138
|
-
| [Type Utilities](https://catbee.in/docs/@catbee/utils/
|
|
139
|
-
| [
|
|
140
|
-
| [
|
|
111
|
+
| Module | Description |
|
|
112
|
+
| --------------------------------------------------------------------------- | ------------------------------------------------------- |
|
|
113
|
+
| [Express Server](https://catbee.in/docs/@catbee/utils/server) | Fast, secure, and scalable server setup |
|
|
114
|
+
| [Array Utilities](https://catbee.in/docs/@catbee/utils/array) | Advanced array manipulation |
|
|
115
|
+
| [Async Utilities](https://catbee.in/docs/@catbee/utils/async) | Promise helpers, concurrency, timing |
|
|
116
|
+
| [Cache Utilities](https://catbee.in/docs/@catbee/utils/cache) | In-memory caching with TTL |
|
|
117
|
+
| [Context Store](https://catbee.in/docs/@catbee/utils/context-store) | Per-request context via AsyncLocalStorage |
|
|
118
|
+
| [Crypto Utilities](https://catbee.in/docs/@catbee/utils/crypto) | Hashing, encryption, tokens |
|
|
119
|
+
| [Date Utilities](https://catbee.in/docs/@catbee/utils/date) | Date/time manipulation |
|
|
120
|
+
| [Decorators Utilities](https://catbee.in/docs/@catbee/utils/decorator) | TypeScript decorators for Express |
|
|
121
|
+
| [Directory Utilities](https://catbee.in/docs/@catbee/utils/directory) | Directory and file system helpers |
|
|
122
|
+
| [Environment Utilities](https://catbee.in/docs/@catbee/utils/environment) | Env variable management |
|
|
123
|
+
| [Exception Utilities](https://catbee.in/docs/@catbee/utils/exception) | HTTP and error handling |
|
|
124
|
+
| [File System Utilities](https://catbee.in/docs/@catbee/utils/fs) | File operations |
|
|
125
|
+
| [HTTP Status Codes](https://catbee.in/docs/@catbee/utils/http-status-codes) | Typed status codes |
|
|
126
|
+
| [ID Utilities](https://catbee.in/docs/@catbee/utils/id) | UUID and ID generation |
|
|
127
|
+
| [Logger Utilities](https://catbee.in/docs/@catbee/utils/logger) | Structured logging with Pino |
|
|
128
|
+
| [Middleware Utilities](https://catbee.in/docs/@catbee/utils/middleware) | Express middleware collection |
|
|
129
|
+
| [Object Utilities](https://catbee.in/docs/@catbee/utils/object) | Deep merge, flatten, pick/omit, etc. |
|
|
130
|
+
| [Performance Utilities](https://catbee.in/docs/@catbee/utils/performance) | Timing, memoization, memory tracking |
|
|
131
|
+
| [Request Utilities](https://catbee.in/docs/@catbee/utils/request) | HTTP request parameter parsing/validation |
|
|
132
|
+
| [Response Utilities](https://catbee.in/docs/@catbee/utils/response) | Standardized API response formatting |
|
|
133
|
+
| [Stream Utilities](https://catbee.in/docs/@catbee/utils/stream) | Stream conversion, batching, throttling, line splitting |
|
|
134
|
+
| [String Utilities](https://catbee.in/docs/@catbee/utils/string) | Casing, masking, slugifying, formatting |
|
|
135
|
+
| [Type Utilities](https://catbee.in/docs/@catbee/utils/type) | Type checking, conversion, guards |
|
|
136
|
+
| [Types Utilities](https://catbee.in/docs/@catbee/utils/types) | Common TypeScript types and interfaces |
|
|
137
|
+
| [URL Utilities](https://catbee.in/docs/@catbee/utils/url) | URL parsing, query manipulation, normalization |
|
|
138
|
+
| [Validate Utilities](https://catbee.in/docs/@catbee/utils/validation) | Input validation functions |
|
|
141
139
|
|
|
142
140
|
---
|
|
143
141
|
|
|
144
142
|
## 🏁 Usage
|
|
145
143
|
|
|
146
|
-
|
|
144
|
+
This library supports flexible import patterns to suit your needs:
|
|
145
|
+
|
|
146
|
+
### Root-level imports (everything available)
|
|
147
|
+
Import any utility directly from the root package:
|
|
147
148
|
|
|
148
149
|
```ts
|
|
149
|
-
import { chunk, sleep, TTLCache, getLogger } from
|
|
150
|
+
import { chunk, sleep, TTLCache, getLogger, ServerConfigBuilder } from '@catbee/utils';
|
|
150
151
|
```
|
|
151
152
|
|
|
153
|
+
### Module-level imports (scoped imports)
|
|
154
|
+
Import only from specific modules for better organization and smaller bundles:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
// Import only server-related exports
|
|
158
|
+
import { ServerConfigBuilder, ExpressServer } from '@catbee/utils/server';
|
|
159
|
+
|
|
160
|
+
// Import only date utilities
|
|
161
|
+
import { formatDate, addDays, DateBuilder } from '@catbee/utils/date';
|
|
162
|
+
|
|
163
|
+
// Import only crypto utilities
|
|
164
|
+
import { hashPassword, verifyPassword } from '@catbee/utils/crypto';
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Both import styles are fully supported and tree-shakable. Use whichever fits your project structure best!
|
|
168
|
+
|
|
152
169
|
---
|
|
153
170
|
|
|
154
171
|
## 📖 Documentation
|
|
@@ -159,4 +176,4 @@ import { chunk, sleep, TTLCache, getLogger } from "@catbee/utils";
|
|
|
159
176
|
|
|
160
177
|
## 📜 License
|
|
161
178
|
|
|
162
|
-
MIT © Catbee Technologies (see the [LICENSE](https://catbee.in/license
|
|
179
|
+
MIT © Catbee Technologies (see the [LICENSE](https://catbee.in/license) file for the full text)
|
package/array/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
'use strict';
|
|
26
26
|
|
|
27
|
-
var
|
|
27
|
+
var object = require('@catbee/utils/object');
|
|
28
28
|
var crypto = require('crypto');
|
|
29
29
|
|
|
30
30
|
var __defProp = Object.defineProperty;
|
|
@@ -79,11 +79,11 @@ function random(array) {
|
|
|
79
79
|
__name(random, "random");
|
|
80
80
|
function groupBy(array, keyOrFn) {
|
|
81
81
|
if (!Array.isArray(array) || array.length === 0) return {};
|
|
82
|
-
const keyFn = typeof keyOrFn === "function" ? keyOrFn : (item) => String(
|
|
82
|
+
const keyFn = typeof keyOrFn === "function" ? keyOrFn : (item) => String(object.getValueByPath(item, keyOrFn));
|
|
83
83
|
const result = {};
|
|
84
84
|
for (const item of array) {
|
|
85
85
|
const key = String(keyFn(item));
|
|
86
|
-
if (Object.hasOwn
|
|
86
|
+
if (Object.hasOwn(result, key)) {
|
|
87
87
|
result[key].push(item);
|
|
88
88
|
} else {
|
|
89
89
|
result[key] = [
|
|
@@ -131,7 +131,7 @@ function mergeSort(array, key, direction = "asc", compareFn) {
|
|
|
131
131
|
if (!Array.isArray(array)) throw new TypeError("Expected array");
|
|
132
132
|
const arr = array.slice();
|
|
133
133
|
if (arr.length <= 1) return arr;
|
|
134
|
-
const keyFn = typeof key === "function" ? key : (item) =>
|
|
134
|
+
const keyFn = typeof key === "function" ? key : (item) => object.getValueByPath(item, key);
|
|
135
135
|
const collator = new Intl.Collator("en", {
|
|
136
136
|
numeric: true
|
|
137
137
|
});
|
|
@@ -325,12 +325,42 @@ function lastOfArr(array) {
|
|
|
325
325
|
return Array.isArray(array) && array.length > 0 ? array.at(-1) : void 0;
|
|
326
326
|
}
|
|
327
327
|
__name(lastOfArr, "lastOfArr");
|
|
328
|
+
function drop(array, n) {
|
|
329
|
+
if (!Array.isArray(array) || n <= 0) return [
|
|
330
|
+
...array
|
|
331
|
+
];
|
|
332
|
+
return array.slice(n);
|
|
333
|
+
}
|
|
334
|
+
__name(drop, "drop");
|
|
335
|
+
function dropWhile(array, predicate) {
|
|
336
|
+
if (!Array.isArray(array)) return [];
|
|
337
|
+
let i = 0;
|
|
338
|
+
while (i < array.length && predicate(array[i], i)) {
|
|
339
|
+
i++;
|
|
340
|
+
}
|
|
341
|
+
return array.slice(i);
|
|
342
|
+
}
|
|
343
|
+
__name(dropWhile, "dropWhile");
|
|
344
|
+
function maxBy(array, keyOrFn) {
|
|
345
|
+
if (!Array.isArray(array) || array.length === 0) return void 0;
|
|
346
|
+
const fn = typeof keyOrFn === "function" ? keyOrFn : (item) => item[keyOrFn];
|
|
347
|
+
return array.reduce((max, item) => fn(item) > fn(max) ? item : max, array[0]);
|
|
348
|
+
}
|
|
349
|
+
__name(maxBy, "maxBy");
|
|
350
|
+
function minBy(array, keyOrFn) {
|
|
351
|
+
if (!Array.isArray(array) || array.length === 0) return void 0;
|
|
352
|
+
const fn = typeof keyOrFn === "function" ? keyOrFn : (item) => item[keyOrFn];
|
|
353
|
+
return array.reduce((min, item) => fn(item) < fn(min) ? item : min, array[0]);
|
|
354
|
+
}
|
|
355
|
+
__name(minBy, "minBy");
|
|
328
356
|
|
|
329
357
|
exports.chunk = chunk;
|
|
330
358
|
exports.chunkBy = chunkBy;
|
|
331
359
|
exports.compact = compact;
|
|
332
360
|
exports.countBy = countBy;
|
|
333
361
|
exports.difference = difference;
|
|
362
|
+
exports.drop = drop;
|
|
363
|
+
exports.dropWhile = dropWhile;
|
|
334
364
|
exports.findLast = findLast;
|
|
335
365
|
exports.findLastIndex = findLastIndex;
|
|
336
366
|
exports.flattenDeep = flattenDeep;
|
|
@@ -339,7 +369,9 @@ exports.headOfArr = headOfArr;
|
|
|
339
369
|
exports.intersect = intersect;
|
|
340
370
|
exports.isSorted = isSorted;
|
|
341
371
|
exports.lastOfArr = lastOfArr;
|
|
372
|
+
exports.maxBy = maxBy;
|
|
342
373
|
exports.mergeSort = mergeSort;
|
|
374
|
+
exports.minBy = minBy;
|
|
343
375
|
exports.partition = partition;
|
|
344
376
|
exports.pluck = pluck;
|
|
345
377
|
exports.random = random;
|
package/array/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -64,6 +64,7 @@ declare function flattenDeep<T>(array: readonly unknown[]): T[];
|
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
66
|
declare function random<T>(array: readonly T[]): T | undefined;
|
|
67
|
+
type StrNumSym = string | number | symbol;
|
|
67
68
|
/**
|
|
68
69
|
* Groups items in an array by a nested key or key function.
|
|
69
70
|
*
|
|
@@ -74,14 +75,14 @@ declare function random<T>(array: readonly T[]): T | undefined;
|
|
|
74
75
|
* @returns {Record<string, readonly T[]>}
|
|
75
76
|
* @overload
|
|
76
77
|
* @param {T[]} array - The array to group.
|
|
77
|
-
* @param {(item: T) =>
|
|
78
|
+
* @param {(item: T) => StrNumSym} keyFn - Function to generate group key from item.
|
|
78
79
|
* @returns {Record<K, readonly T[]>}
|
|
79
80
|
* @param {T[]} array - The array to group.
|
|
80
|
-
* @param {keyof T | ((item: T) =>
|
|
81
|
-
* @returns {Record<
|
|
81
|
+
* @param {keyof T | ((item: T) => StrNumSym)} keyOrFn - Nested property key or key selector.
|
|
82
|
+
* @returns {Record<StrNumSym, readonly T[]>} Grouped result object.
|
|
82
83
|
*/
|
|
83
84
|
declare function groupBy<T>(array: T[], key: keyof T): Record<string, readonly T[]>;
|
|
84
|
-
declare function groupBy<T, K extends
|
|
85
|
+
declare function groupBy<T, K extends StrNumSym>(array: T[], keyFn: (item: T) => K): Record<K, readonly T[]>;
|
|
85
86
|
/**
|
|
86
87
|
* Shuffles an array using the Fisher-Yates algorithm. Uses crypto-secure randomness.
|
|
87
88
|
*
|
|
@@ -209,10 +210,10 @@ declare function compact<T>(array: readonly T[]): NonNullable<T>[];
|
|
|
209
210
|
*
|
|
210
211
|
* @template T The type of array elements.
|
|
211
212
|
* @param {T[]} array - The input array.
|
|
212
|
-
* @param {(item: T) =>
|
|
213
|
+
* @param {(item: T) => StrNumSym} keyFn - Function to generate count key.
|
|
213
214
|
* @returns {Record<string, number>} Object with counts by key.
|
|
214
215
|
*/
|
|
215
|
-
declare function countBy<T>(array: readonly T[], keyFn: (item: T) =>
|
|
216
|
+
declare function countBy<T>(array: readonly T[], keyFn: (item: T) => StrNumSym): Record<string, number>;
|
|
216
217
|
/**
|
|
217
218
|
* Toggles an item in array (adds if not present, removes if present).
|
|
218
219
|
*
|
|
@@ -313,5 +314,55 @@ declare function headOfArr<T>(array: readonly T[]): T | undefined;
|
|
|
313
314
|
* @returns {T | undefined}
|
|
314
315
|
*/
|
|
315
316
|
declare function lastOfArr<T>(array: readonly T[]): T | undefined;
|
|
317
|
+
/**
|
|
318
|
+
* Drops the first n elements from an array.
|
|
319
|
+
*
|
|
320
|
+
* @template T
|
|
321
|
+
* @param {readonly T[]} array - The source array.
|
|
322
|
+
* @param {number} n - Number of elements to drop.
|
|
323
|
+
* @returns {T[]} Array with first n elements removed.
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* drop([1, 2, 3, 4, 5], 2); // [3, 4, 5]
|
|
327
|
+
*/
|
|
328
|
+
declare function drop<T>(array: readonly T[], n: number): T[];
|
|
329
|
+
/**
|
|
330
|
+
* Drops elements from the start of an array while predicate returns true.
|
|
331
|
+
*
|
|
332
|
+
* @template T
|
|
333
|
+
* @param {readonly T[]} array - The source array.
|
|
334
|
+
* @param {(item: T, index: number) => boolean} predicate - Condition function.
|
|
335
|
+
* @returns {T[]} Array with elements dropped.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* dropWhile([1, 2, 3, 4, 1], x => x < 3); // [3, 4, 1]
|
|
339
|
+
*/
|
|
340
|
+
declare function dropWhile<T>(array: readonly T[], predicate: (item: T, index: number) => boolean): T[];
|
|
341
|
+
/**
|
|
342
|
+
* Finds the element with the maximum value for a given key or function.
|
|
343
|
+
*
|
|
344
|
+
* @template T
|
|
345
|
+
* @param {readonly T[]} array - The source array.
|
|
346
|
+
* @param {keyof T | ((item: T) => number)} keyOrFn - Property key or function.
|
|
347
|
+
* @returns {T | undefined} Element with maximum value.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* maxBy([{a: 1}, {a: 5}, {a: 3}], 'a'); // {a: 5}
|
|
351
|
+
* maxBy([{a: 1}, {a: 5}, {a: 3}], x => x.a); // {a: 5}
|
|
352
|
+
*/
|
|
353
|
+
declare function maxBy<T>(array: readonly T[], keyOrFn: keyof T | ((item: T) => number)): T | undefined;
|
|
354
|
+
/**
|
|
355
|
+
* Finds the element with the minimum value for a given key or function.
|
|
356
|
+
*
|
|
357
|
+
* @template T
|
|
358
|
+
* @param {readonly T[]} array - The source array.
|
|
359
|
+
* @param {keyof T | ((item: T) => number)} keyOrFn - Property key or function.
|
|
360
|
+
* @returns {T | undefined} Element with minimum value.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* minBy([{a: 1}, {a: 5}, {a: 3}], 'a'); // {a: 1}
|
|
364
|
+
* minBy([{a: 1}, {a: 5}, {a: 3}], x => x.a); // {a: 1}
|
|
365
|
+
*/
|
|
366
|
+
declare function minBy<T>(array: readonly T[], keyOrFn: keyof T | ((item: T) => number)): T | undefined;
|
|
316
367
|
|
|
317
|
-
export { chunk, chunkBy, compact, countBy, difference, findLast, findLastIndex, flattenDeep, groupBy, headOfArr, intersect, isSorted, lastOfArr, mergeSort, partition, pluck, random, range, remove, secureIndex, secureRandom, shuffle, take, takeWhile, toggle, unique, zip };
|
|
368
|
+
export { chunk, chunkBy, compact, countBy, difference, drop, dropWhile, findLast, findLastIndex, flattenDeep, groupBy, headOfArr, intersect, isSorted, lastOfArr, maxBy, mergeSort, minBy, partition, pluck, random, range, remove, secureIndex, secureRandom, shuffle, take, takeWhile, toggle, unique, zip };
|
package/array/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import { getValueByPath } from '@catbee/utils/
|
|
25
|
+
import { getValueByPath } from '@catbee/utils/object';
|
|
26
26
|
import { randomBytes } from 'crypto';
|
|
27
27
|
|
|
28
28
|
var __defProp = Object.defineProperty;
|
|
@@ -81,7 +81,7 @@ function groupBy(array, keyOrFn) {
|
|
|
81
81
|
const result = {};
|
|
82
82
|
for (const item of array) {
|
|
83
83
|
const key = String(keyFn(item));
|
|
84
|
-
if (Object.hasOwn
|
|
84
|
+
if (Object.hasOwn(result, key)) {
|
|
85
85
|
result[key].push(item);
|
|
86
86
|
} else {
|
|
87
87
|
result[key] = [
|
|
@@ -323,5 +323,33 @@ function lastOfArr(array) {
|
|
|
323
323
|
return Array.isArray(array) && array.length > 0 ? array.at(-1) : void 0;
|
|
324
324
|
}
|
|
325
325
|
__name(lastOfArr, "lastOfArr");
|
|
326
|
+
function drop(array, n) {
|
|
327
|
+
if (!Array.isArray(array) || n <= 0) return [
|
|
328
|
+
...array
|
|
329
|
+
];
|
|
330
|
+
return array.slice(n);
|
|
331
|
+
}
|
|
332
|
+
__name(drop, "drop");
|
|
333
|
+
function dropWhile(array, predicate) {
|
|
334
|
+
if (!Array.isArray(array)) return [];
|
|
335
|
+
let i = 0;
|
|
336
|
+
while (i < array.length && predicate(array[i], i)) {
|
|
337
|
+
i++;
|
|
338
|
+
}
|
|
339
|
+
return array.slice(i);
|
|
340
|
+
}
|
|
341
|
+
__name(dropWhile, "dropWhile");
|
|
342
|
+
function maxBy(array, keyOrFn) {
|
|
343
|
+
if (!Array.isArray(array) || array.length === 0) return void 0;
|
|
344
|
+
const fn = typeof keyOrFn === "function" ? keyOrFn : (item) => item[keyOrFn];
|
|
345
|
+
return array.reduce((max, item) => fn(item) > fn(max) ? item : max, array[0]);
|
|
346
|
+
}
|
|
347
|
+
__name(maxBy, "maxBy");
|
|
348
|
+
function minBy(array, keyOrFn) {
|
|
349
|
+
if (!Array.isArray(array) || array.length === 0) return void 0;
|
|
350
|
+
const fn = typeof keyOrFn === "function" ? keyOrFn : (item) => item[keyOrFn];
|
|
351
|
+
return array.reduce((min, item) => fn(item) < fn(min) ? item : min, array[0]);
|
|
352
|
+
}
|
|
353
|
+
__name(minBy, "minBy");
|
|
326
354
|
|
|
327
|
-
export { chunk, chunkBy, compact, countBy, difference, findLast, findLastIndex, flattenDeep, groupBy, headOfArr, intersect, isSorted, lastOfArr, mergeSort, partition, pluck, random, range, remove, secureIndex, secureRandom, shuffle, take, takeWhile, toggle, unique, zip };
|
|
355
|
+
export { chunk, chunkBy, compact, countBy, difference, drop, dropWhile, findLast, findLastIndex, flattenDeep, groupBy, headOfArr, intersect, isSorted, lastOfArr, maxBy, mergeSort, minBy, partition, pluck, random, range, remove, secureIndex, secureRandom, shuffle, take, takeWhile, toggle, unique, zip };
|
package/async/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -78,10 +78,11 @@ function debounce(fn, delay) {
|
|
|
78
78
|
return debounced;
|
|
79
79
|
}
|
|
80
80
|
__name(debounce, "debounce");
|
|
81
|
-
|
|
81
|
+
var DEFAULT_THROTTLE_OPTS = {
|
|
82
82
|
leading: true,
|
|
83
83
|
trailing: false
|
|
84
|
-
}
|
|
84
|
+
};
|
|
85
|
+
function throttle(fn, limit, opts = DEFAULT_THROTTLE_OPTS) {
|
|
85
86
|
let lastCall = 0;
|
|
86
87
|
let timer = null;
|
|
87
88
|
let savedArgs = null;
|
|
@@ -461,6 +462,25 @@ function optionalRequire(name) {
|
|
|
461
462
|
}
|
|
462
463
|
}
|
|
463
464
|
__name(optionalRequire, "optionalRequire");
|
|
465
|
+
async function raceWithValue(promises) {
|
|
466
|
+
return new Promise((resolve, reject) => {
|
|
467
|
+
let rejectedCount = 0;
|
|
468
|
+
let lastError;
|
|
469
|
+
promises.forEach((p, index) => {
|
|
470
|
+
p.then((value) => resolve({
|
|
471
|
+
value,
|
|
472
|
+
index
|
|
473
|
+
})).catch((err) => {
|
|
474
|
+
rejectedCount++;
|
|
475
|
+
lastError = err;
|
|
476
|
+
if (rejectedCount === promises.length) {
|
|
477
|
+
reject(lastError);
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
__name(raceWithValue, "raceWithValue");
|
|
464
484
|
|
|
465
485
|
exports.CircuitBreakerOpenError = CircuitBreakerOpenError;
|
|
466
486
|
exports.CircuitBreakerState = CircuitBreakerState;
|
|
@@ -471,6 +491,7 @@ exports.createTaskQueue = createTaskQueue;
|
|
|
471
491
|
exports.debounce = debounce;
|
|
472
492
|
exports.memoizeAsync = memoizeAsync;
|
|
473
493
|
exports.optionalRequire = optionalRequire;
|
|
494
|
+
exports.raceWithValue = raceWithValue;
|
|
474
495
|
exports.rateLimit = rateLimit;
|
|
475
496
|
exports.retry = retry;
|
|
476
497
|
exports.runInBatches = runInBatches;
|
package/async/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -294,6 +294,22 @@ declare function runWithConcurrency<T>(tasks: Array<() => Promise<T>>, options?:
|
|
|
294
294
|
* @returns {T | null} The required module or null if not found.
|
|
295
295
|
*/
|
|
296
296
|
declare function optionalRequire<T = any>(name: string): T | null;
|
|
297
|
+
/**
|
|
298
|
+
* Races promises and returns the first fulfilled value with its index.
|
|
299
|
+
* If all promises reject, the last rejection is thrown.
|
|
300
|
+
*
|
|
301
|
+
* @template T
|
|
302
|
+
* @param {Promise<T>[]} promises - Array of promises.
|
|
303
|
+
* @returns {Promise<{ value: T; index: number }>} First fulfilled value with index.
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* const result = await raceWithValue([fetchA(), fetchB(), fetchC()]);
|
|
307
|
+
* console.log(result.value, result.index); // First fulfilled promise result
|
|
308
|
+
*/
|
|
309
|
+
declare function raceWithValue<T>(promises: Promise<T>[]): Promise<{
|
|
310
|
+
value: T;
|
|
311
|
+
index: number;
|
|
312
|
+
}>;
|
|
297
313
|
|
|
298
|
-
export { CircuitBreakerOpenError, CircuitBreakerState, abortable, circuitBreaker, createDeferred, createTaskQueue, debounce, memoizeAsync, optionalRequire, rateLimit, retry, runInBatches, runInSeries, runWithConcurrency, settleAll, singletonAsync, sleep, throttle, waterfall, withTimeout };
|
|
314
|
+
export { CircuitBreakerOpenError, CircuitBreakerState, abortable, circuitBreaker, createDeferred, createTaskQueue, debounce, memoizeAsync, optionalRequire, raceWithValue, rateLimit, retry, runInBatches, runInSeries, runWithConcurrency, settleAll, singletonAsync, sleep, throttle, waterfall, withTimeout };
|
|
299
315
|
export type { CircuitBreakerOptions, TaskQueue };
|
package/async/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -76,10 +76,11 @@ function debounce(fn, delay) {
|
|
|
76
76
|
return debounced;
|
|
77
77
|
}
|
|
78
78
|
__name(debounce, "debounce");
|
|
79
|
-
|
|
79
|
+
var DEFAULT_THROTTLE_OPTS = {
|
|
80
80
|
leading: true,
|
|
81
81
|
trailing: false
|
|
82
|
-
}
|
|
82
|
+
};
|
|
83
|
+
function throttle(fn, limit, opts = DEFAULT_THROTTLE_OPTS) {
|
|
83
84
|
let lastCall = 0;
|
|
84
85
|
let timer = null;
|
|
85
86
|
let savedArgs = null;
|
|
@@ -459,5 +460,24 @@ function optionalRequire(name) {
|
|
|
459
460
|
}
|
|
460
461
|
}
|
|
461
462
|
__name(optionalRequire, "optionalRequire");
|
|
463
|
+
async function raceWithValue(promises) {
|
|
464
|
+
return new Promise((resolve, reject) => {
|
|
465
|
+
let rejectedCount = 0;
|
|
466
|
+
let lastError;
|
|
467
|
+
promises.forEach((p, index) => {
|
|
468
|
+
p.then((value) => resolve({
|
|
469
|
+
value,
|
|
470
|
+
index
|
|
471
|
+
})).catch((err) => {
|
|
472
|
+
rejectedCount++;
|
|
473
|
+
lastError = err;
|
|
474
|
+
if (rejectedCount === promises.length) {
|
|
475
|
+
reject(lastError);
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
__name(raceWithValue, "raceWithValue");
|
|
462
482
|
|
|
463
|
-
export { CircuitBreakerOpenError, CircuitBreakerState, abortable, circuitBreaker, createDeferred, createTaskQueue, debounce, memoizeAsync, optionalRequire, rateLimit, retry, runInBatches, runInSeries, runWithConcurrency, settleAll, singletonAsync, sleep, throttle, waterfall, withTimeout };
|
|
483
|
+
export { CircuitBreakerOpenError, CircuitBreakerState, abortable, circuitBreaker, createDeferred, createTaskQueue, debounce, memoizeAsync, optionalRequire, raceWithValue, rateLimit, retry, runInBatches, runInSeries, runWithConcurrency, settleAll, singletonAsync, sleep, throttle, waterfall, withTimeout };
|
package/cache/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
package/cache/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
package/cache/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
package/config/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
var env = require('@catbee/utils/env');
|
|
28
28
|
var id = require('@catbee/utils/id');
|
|
29
|
-
var
|
|
29
|
+
var object = require('@catbee/utils/object');
|
|
30
30
|
|
|
31
31
|
var __defProp = Object.defineProperty;
|
|
32
32
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -102,9 +102,9 @@ var defaultServerConfig = {
|
|
|
102
102
|
serviceVersion: {
|
|
103
103
|
enable: env.Env.getBoolean("SERVER_SERVICE_VERSION_ENABLE", false),
|
|
104
104
|
headerName: env.Env.get("SERVER_SERVICE_VERSION_HEADER_NAME", "x-service-version"),
|
|
105
|
-
version: env.Env.get("
|
|
105
|
+
version: env.Env.get("${npm_package_version}", "0.0.0")
|
|
106
106
|
},
|
|
107
|
-
|
|
107
|
+
skipHealthzChecksValidation: env.Env.getBoolean("SERVER_SKIP_HEALTHZ_CHECKS_VALIDATION", false)
|
|
108
108
|
};
|
|
109
109
|
var defaultCatbeeConfig = {
|
|
110
110
|
logger: {
|
|
@@ -122,19 +122,19 @@ var defaultCatbeeConfig = {
|
|
|
122
122
|
},
|
|
123
123
|
server: defaultServerConfig
|
|
124
124
|
};
|
|
125
|
-
var _config =
|
|
125
|
+
var _config = object.deepClone(defaultCatbeeConfig);
|
|
126
126
|
function getCatbeeGlobalConfig() {
|
|
127
|
-
return
|
|
127
|
+
return object.deepClone(_config);
|
|
128
128
|
}
|
|
129
129
|
__name(getCatbeeGlobalConfig, "getCatbeeGlobalConfig");
|
|
130
130
|
var getConfig = getCatbeeGlobalConfig;
|
|
131
131
|
function setCatbeeGlobalConfig(value) {
|
|
132
|
-
_config =
|
|
132
|
+
_config = object.deepObjMerge(_config, value);
|
|
133
133
|
}
|
|
134
134
|
__name(setCatbeeGlobalConfig, "setCatbeeGlobalConfig");
|
|
135
135
|
var setConfig = setCatbeeGlobalConfig;
|
|
136
136
|
function setCatbeeServerGlobalConfig(value) {
|
|
137
|
-
_config.server =
|
|
137
|
+
_config.server = object.deepObjMerge(_config.server, value);
|
|
138
138
|
}
|
|
139
139
|
__name(setCatbeeServerGlobalConfig, "setCatbeeServerGlobalConfig");
|
|
140
140
|
function getCatbeeServerGlobalConfig() {
|
package/config/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|