@jsnw/common-utils 1.4.1 → 1.5.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # jsn-utils
2
2
  ![coverage badge](https://img.shields.io/badge/coverage-100%25-brightgreen)
3
3
 
4
- ## 1.1.0
4
+ ## 1.5.0
5
5
  ## List of utility functions
6
6
 
7
7
  - `noop(): void` - A no-operation function that does nothing
@@ -13,6 +13,7 @@
13
13
  - `createPromisesCache` - deprecated; use createInFlightDeduper instead
14
14
  - `createInFlightDeduper` - Creates a deduplicator for in-flight promises or sync functions. Prevents duplicate executions for the same key while a promise is pending. Clears the entry after settlement
15
15
  - `resultify` - Executes a function and returns its result as a tuple `[value, error]`. Works with both sync and async functions. Never throws.
16
+ - `clamp(num: number, min: number, max: number)` - Clamps a number between min and max
16
17
 
17
18
  ## List of utility classes
18
19
 
package/dist/index.cjs CHANGED
@@ -291,10 +291,20 @@ const promisify = (fn, ...args) => {
291
291
  });
292
292
  };
293
293
  //#endregion
294
+ //#region src/clamp.ts
295
+ /**
296
+ * @param {number} num
297
+ * @param {number} min
298
+ * @param {number} max
299
+ * @returns {number}
300
+ */
301
+ const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
302
+ //#endregion
294
303
  exports.Monitor = Monitor;
295
304
  exports.PerfmonError = PerfmonError;
296
305
  exports.chunk = chunk;
297
306
  exports.chunkStr = chunkStr;
307
+ exports.clamp = clamp;
298
308
  exports.createInFlightDeduper = createInFlightDeduper;
299
309
  exports.defer = defer;
300
310
  exports.ignorePromise = ignorePromise;
package/dist/index.d.cts CHANGED
@@ -181,4 +181,13 @@ declare const withPerfmon: <F extends AnyFn>(fn: F, ...args: Parameters<F>) => W
181
181
  */
182
182
  declare const promisify: <F extends (...args: any[]) => any>(fn: F, ...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>>;
183
183
  //#endregion
184
- export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
184
+ //#region src/clamp.d.ts
185
+ /**
186
+ * @param {number} num
187
+ * @param {number} min
188
+ * @param {number} max
189
+ * @returns {number}
190
+ */
191
+ declare const clamp: (num: number, min: number, max: number) => number;
192
+ //#endregion
193
+ export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, clamp, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
package/dist/index.d.mts CHANGED
@@ -181,4 +181,13 @@ declare const withPerfmon: <F extends AnyFn>(fn: F, ...args: Parameters<F>) => W
181
181
  */
182
182
  declare const promisify: <F extends (...args: any[]) => any>(fn: F, ...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>>;
183
183
  //#endregion
184
- export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
184
+ //#region src/clamp.d.ts
185
+ /**
186
+ * @param {number} num
187
+ * @param {number} min
188
+ * @param {number} max
189
+ * @returns {number}
190
+ */
191
+ declare const clamp: (num: number, min: number, max: number) => number;
192
+ //#endregion
193
+ export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, clamp, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
package/dist/index.mjs CHANGED
@@ -290,4 +290,13 @@ const promisify = (fn, ...args) => {
290
290
  });
291
291
  };
292
292
  //#endregion
293
- export { Monitor, PerfmonError, chunk, chunkStr, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
293
+ //#region src/clamp.ts
294
+ /**
295
+ * @param {number} num
296
+ * @param {number} min
297
+ * @param {number} max
298
+ * @returns {number}
299
+ */
300
+ const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
301
+ //#endregion
302
+ export { Monitor, PerfmonError, chunk, chunkStr, clamp, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@jsnw/common-utils",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Lightweight JavaScript/TypeScript utilities with async helpers, array and string operations",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
5
8
  "exports": {
6
9
  "import": {
7
10
  "types": "./dist/index.d.mts",
@@ -39,9 +42,9 @@
39
42
  "devDependencies": {
40
43
  "@types/jest": "^30.0.0",
41
44
  "@types/node": "^24.13.3",
42
- "jest": "^30.4.2",
43
- "ts-jest": "^29.4.11",
44
- "tsdown": "^0.22.8",
45
+ "jest": "^30.5.1",
46
+ "ts-jest": "^29.4.12",
47
+ "tsdown": "^0.22.14",
45
48
  "typescript": "^5.9.3"
46
49
  },
47
50
  "scripts": {