@helpers4/number 3.1.8 → 3.1.10

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
@@ -51,6 +51,7 @@ A set of helpers for working with URLs.
51
51
  - [node](../node)
52
52
  - [object](../object)
53
53
  - [observable](../observable)
54
+ - [package](../package)
54
55
  - [promise](../promise)
55
56
  - [set](../set)
56
57
  - [string](../string)
@@ -67,7 +68,7 @@ A set of helpers for working with URLs.
67
68
  |------|---------|-------------|-------------|
68
69
  | animation | [@helpers4/animation](https://www.npmjs.com/package/@helpers4/animation) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/animation) | Timing and interpolation for animations |
69
70
  | array | [@helpers4/array](https://www.npmjs.com/package/@helpers4/array) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/array) | Array manipulation utilities |
70
- | binary | [@helpers4/binary](https://www.npmjs.com/package/@helpers4/binary) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/binary) | Read and write binary formats |
71
+ | binary | [@helpers4/binary](https://www.npmjs.com/package/@helpers4/binary) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/binary) | Read, write and identify binary formats |
71
72
  | browser | [@helpers4/browser](https://www.npmjs.com/package/@helpers4/browser) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/browser) | Browser-specific utilities |
72
73
  | ci | [@helpers4/ci](https://www.npmjs.com/package/@helpers4/ci) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/ci) | CI/CD workflow status utilities |
73
74
  | color | [@helpers4/color](https://www.npmjs.com/package/@helpers4/color) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/color) | Color conversion and validation utilities |
@@ -87,6 +88,7 @@ A set of helpers for working with URLs.
87
88
  | number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | Number utility functions and validation |
88
89
  | object | [@helpers4/object](https://www.npmjs.com/package/@helpers4/object) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/object) | Object manipulation utilities |
89
90
  | observable | [@helpers4/observable](https://www.npmjs.com/package/@helpers4/observable) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/observable) | Observable utilities and combinators |
91
+ | package | [@helpers4/package](https://www.npmjs.com/package/@helpers4/package) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/package) | Package metadata parsers |
90
92
  | promise | [@helpers4/promise](https://www.npmjs.com/package/@helpers4/promise) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/promise) | Promise utilities and error handling |
91
93
  | set | [@helpers4/set](https://www.npmjs.com/package/@helpers4/set) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/set) | Native Set manipulation utilities |
92
94
  | string | [@helpers4/string](https://www.npmjs.com/package/@helpers4/string) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/string) | String manipulation and formatting utilities |
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region helpers/number/clamp.ts
1
+ // helpers/number/clamp.ts
2
2
  /**
3
3
  * This file is part of helpers4.
4
4
  * Copyright (C) 2025 baxyz
@@ -15,8 +15,7 @@
15
15
  function clamp(value, min, max) {
16
16
  return Math.min(Math.max(value, min), max);
17
17
  }
18
- //#endregion
19
- //#region helpers/number/correctFloat.ts
18
+ // helpers/number/correctFloat.ts
20
19
  /**
21
20
  * This file is part of helpers4.
22
21
  * Copyright (C) 2025 baxyz
@@ -59,8 +58,7 @@ function correctFloat(value, precision = 14) {
59
58
  const result = parseFloat(value.toPrecision(precision));
60
59
  return Object.is(value, -0) ? -0 : result;
61
60
  }
62
- //#endregion
63
- //#region helpers/number/extractNumber.ts
61
+ // helpers/number/extractNumber.ts
64
62
  var NUMBER_TOKEN = /(-)?(\d+(?:\.\d+)?|(?<![\p{L}\p{N}_])\.\d+)([eE][+-]?\d+)?/u;
65
63
  var WORD_CHAR = /[\p{L}\p{N}_]/u;
66
64
  function isWordChar(char) {
@@ -115,8 +113,7 @@ function extractNumber(value, options = {}) {
115
113
  return Number(numericText);
116
114
  }
117
115
  }
118
- //#endregion
119
- //#region helpers/number/formatCompact.ts
116
+ // helpers/number/formatCompact.ts
120
117
  /**
121
118
  * This file is part of helpers4.
122
119
  * Copyright (C) 2025 baxyz
@@ -141,8 +138,7 @@ function extractNumber(value, options = {}) {
141
138
  function formatCompact(value, locale) {
142
139
  return new Intl.NumberFormat(locale, { notation: "compact" }).format(value);
143
140
  }
144
- //#endregion
145
- //#region helpers/number/formatSize.ts
141
+ // helpers/number/formatSize.ts
146
142
  /**
147
143
  * This file is part of helpers4.
148
144
  * Copyright (C) 2025 baxyz
@@ -188,8 +184,7 @@ function formatSize(bytes, options = {}) {
188
184
  }
189
185
  return `${unitIndex === 0 && integerBelowFirstUnit ? `${size}` : size.toFixed(1)}${unitSeparator}${UNITS[unitIndex]}`;
190
186
  }
191
- //#endregion
192
- //#region helpers/number/inRange.ts
187
+ // helpers/number/inRange.ts
193
188
  /**
194
189
  * Checks whether a number falls within `[min, max]` (both inclusive by default).
195
190
  *
@@ -209,8 +204,7 @@ function inRange(value, min, max, options = {}) {
209
204
  const { inclusive = "both" } = options;
210
205
  return (inclusive === "both" || inclusive === "min" ? value >= min : value > min) && (inclusive === "both" || inclusive === "max" ? value <= max : value < max);
211
206
  }
212
- //#endregion
213
- //#region helpers/number/isEven.ts
207
+ // helpers/number/isEven.ts
214
208
  /**
215
209
  * This file is part of helpers4.
216
210
  * Copyright (C) 2025 baxyz
@@ -235,8 +229,7 @@ function inRange(value, min, max, options = {}) {
235
229
  function isEven(value) {
236
230
  return typeof value === "number" && Number.isInteger(value) && value % 2 === 0;
237
231
  }
238
- //#endregion
239
- //#region helpers/number/isNegative.ts
232
+ // helpers/number/isNegative.ts
240
233
  /**
241
234
  * This file is part of helpers4.
242
235
  * Copyright (C) 2025 baxyz
@@ -261,8 +254,7 @@ function isEven(value) {
261
254
  function isNegative(value) {
262
255
  return typeof value === "number" && value < 0;
263
256
  }
264
- //#endregion
265
- //#region helpers/number/isOdd.ts
257
+ // helpers/number/isOdd.ts
266
258
  /**
267
259
  * This file is part of helpers4.
268
260
  * Copyright (C) 2025 baxyz
@@ -287,8 +279,7 @@ function isNegative(value) {
287
279
  function isOdd(value) {
288
280
  return typeof value === "number" && Number.isInteger(value) && value % 2 !== 0;
289
281
  }
290
- //#endregion
291
- //#region helpers/number/isPositive.ts
282
+ // helpers/number/isPositive.ts
292
283
  /**
293
284
  * This file is part of helpers4.
294
285
  * Copyright (C) 2025 baxyz
@@ -313,8 +304,7 @@ function isOdd(value) {
313
304
  function isPositive(value) {
314
305
  return typeof value === "number" && value > 0;
315
306
  }
316
- //#endregion
317
- //#region helpers/number/lerp.ts
307
+ // helpers/number/lerp.ts
318
308
  /**
319
309
  * This file is part of helpers4.
320
310
  * Copyright (C) 2025 baxyz
@@ -344,8 +334,7 @@ function lerp(start, end, t) {
344
334
  if (Object.is(start, end)) return start;
345
335
  return start + (end - start) * t;
346
336
  }
347
- //#endregion
348
- //#region helpers/number/random.ts
337
+ // helpers/number/random.ts
349
338
  /**
350
339
  * This file is part of helpers4.
351
340
  * Copyright (C) 2025 baxyz
@@ -371,8 +360,7 @@ function randomBetween(min, max) {
371
360
  function randomIntBetween(min, max) {
372
361
  return Math.floor(Math.random() * (max - min + 1)) + min;
373
362
  }
374
- //#endregion
375
- //#region helpers/number/roundTo.ts
363
+ // helpers/number/roundTo.ts
376
364
  /**
377
365
  * This file is part of helpers4.
378
366
  * Copyright (C) 2025 baxyz
@@ -389,7 +377,6 @@ function roundTo(value, decimals) {
389
377
  const multiplier = Math.pow(10, decimals);
390
378
  return Math.round(value * multiplier) / multiplier;
391
379
  }
392
- //#endregion
393
380
  export { clamp, correctFloat, extractNumber, formatCompact, formatSize, inRange, isEven, isNegative, isOdd, isPositive, lerp, randomBetween, randomIntBetween, roundTo };
394
381
 
395
382
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../helpers/number/clamp.ts","../../../helpers/number/correctFloat.ts","../../../helpers/number/extractNumber.ts","../../../helpers/number/formatCompact.ts","../../../helpers/number/formatSize.ts","../../../helpers/number/inRange.ts","../../../helpers/number/isEven.ts","../../../helpers/number/isNegative.ts","../../../helpers/number/isOdd.ts","../../../helpers/number/isPositive.ts","../../../helpers/number/lerp.ts","../../../helpers/number/random.ts","../../../helpers/number/roundTo.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Clamps a number between min and max values\n * @param value - The value to clamp\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Clamped value\n * @since 1.9.0\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Corrects floating-point arithmetic errors by rounding to a given number\n * of significant digits. Useful after calculations that accumulate binary\n * floating-point drift (e.g. `0.1 + 0.2 === 0.30000000000000004`).\n *\n * The default precision of 14 significant digits eliminates typical\n * rounding noise for values in the range used by most applications.\n * Note: for values whose integer part already consumes 14 or more digits\n * (i.e. |value| ≥ 1e13), toPrecision(14) has no room left for decimal\n * digits and will silently truncate them. Increase `precision` if you\n * need to correct drift in very large numbers.\n *\n * Note: IEEE-754 doubles carry at most ~17 significant decimal digits.\n * Precision values above 17 pad with digits that reflect the underlying\n * binary representation rather than correcting drift.\n *\n * @param value - The floating-point value to correct\n * @param precision - Integer number of significant digits between 1 and 100\n * (default: 14). Values above 17 are valid but expose binary noise beyond\n * IEEE-754's meaningful range.\n * @returns The corrected value\n * @example\n * correctFloat(0.1 + 0.2) // => 0.3\n * correctFloat(1.1 - 0.3) // => 0.8\n * correctFloat(0.1 * 3) // => 0.3\n *\n * // Custom precision: keep 4 significant digits\n * correctFloat(1.23456789, 4) // => 1.235\n * correctFloat(1.23456789, 6) // => 1.23457\n * @since 2.0.2\n */\nexport function correctFloat(value: number, precision: number = 14): number {\n if (!Number.isFinite(value)) {\n throw new RangeError(`correctFloat: value must be a finite number, got ${value}`);\n }\n if (!Number.isInteger(precision) || precision < 1 || precision > 100) {\n throw new RangeError(`correctFloat: precision must be an integer between 1 and 100, got ${precision}`);\n }\n const result = parseFloat(value.toPrecision(precision));\n // toPrecision(-0) produces \"0.000…\" (no minus sign per spec) — restore the sign bit.\n return Object.is(value, -0) ? -0 : result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Options for {@link extractNumber}.\n */\nexport interface ExtractNumberOptions {\n /**\n * How to interpret a `-` immediately before the matched digits.\n * - `'auto'`: treated as a minus sign unless it is glued to a preceding letter/digit\n * (e.g. `'-111'` and `'xxx -111'` → negative, but `'xxx-111'` → separator, positive).\n * - `'strict'`: always treated as a minus sign.\n * - `'ignore'`: never treated as a minus sign (always a separator).\n * @default 'auto'\n */\n sign?: 'auto' | 'strict' | 'ignore';\n\n /**\n * How to interpret a trailing scientific-notation suffix (`e`/`E` + digits, e.g. `1.5e-10`).\n * - `'auto'`: treated as an exponent unless it is glued to a following letter/digit\n * (e.g. `'1e5'` and `'1e5 mol'` → exponential, but `'1e5kg'` → mantissa only).\n * - `'strict'`: always treated as an exponent.\n * - `'ignore'`: never treated as an exponent (mantissa only).\n * @default 'auto'\n */\n exponent?: 'auto' | 'strict' | 'ignore';\n}\n\n// (?<![\\p{L}\\p{N}_]) prevents matching a leading-dot decimal immediately after a word\n// character (e.g. the '.5' in 'text.5' is a property separator, not a decimal point).\n// No `g` flag — cloned per call via `new RegExp(…, 'gu')` so each invocation has its own lastIndex.\nconst NUMBER_TOKEN = /(-)?(\\d+(?:\\.\\d+)?|(?<![\\p{L}\\p{N}_])\\.\\d+)([eE][+-]?\\d+)?/u;\nconst WORD_CHAR = /[\\p{L}\\p{N}_]/u;\n\nfunction isWordChar(char: string | undefined): boolean {\n return char !== undefined && WORD_CHAR.test(char);\n}\n\n/**\n * Extracts the first number embedded anywhere in a string, or passes through a `number`.\n *\n * Unlike a plain `parseFloat`/`parseInt`, the number does not need to be at the start of\n * the string: digits are searched for anywhere, so leading/trailing text (units, labels, ...)\n * is ignored. A `-` before the digits and a scientific-notation suffix (`e`/`E`) are\n * disambiguated with {@link ExtractNumberOptions.sign} and {@link ExtractNumberOptions.exponent}.\n *\n * Returns `undefined` if no number can be found.\n *\n * @param value - The value to extract a number from\n * @param options - Options controlling sign and exponent disambiguation\n * @returns The extracted number, or `undefined` if none was found\n * @example\n * extractNumber('16.5px') // => 16.5\n * extractNumber('.5rem') // => 0.5 (leading-dot decimal)\n * extractNumber('-.5') // => -0.5 (leading-dot with sign)\n * extractNumber('Wafer 10') // => 10\n * extractNumber('xxx-111') // => 111 ('-' glued to text → separator)\n * extractNumber('xxx -111') // => -111 ('-' preceded by a space → sign)\n * extractNumber('x-.5') // => 0.5 ('-' glued to 'x' → separator; leading-dot decimal follows)\n * extractNumber('-111') // => -111 ('-' at the start of the string → sign)\n * extractNumber('1e5 mol') // => 100000\n * extractNumber('1e5kg') // => 1 ('e5' glued to text → mantissa only)\n * extractNumber('no number') // => undefined\n * extractNumber(42) // => 42\n * @since 2.0.4\n */\nexport function extractNumber(value: unknown, options: ExtractNumberOptions = {}): number | undefined {\n const { sign = 'auto', exponent = 'auto' } = options;\n\n if (typeof value === 'number') {\n return Number.isNaN(value) ? undefined : value;\n }\n\n if (typeof value !== 'string') {\n return undefined;\n }\n\n const re = new RegExp(NUMBER_TOKEN.source, 'gu');\n let match: RegExpExecArray | null;\n\n while ((match = re.exec(value)) !== null) {\n const [full, signChar, mantissa, exponentPart] = match;\n const start = match.index;\n\n if (signChar) {\n const before = value[start - 1];\n const keepSign = sign === 'strict' ? true : sign === 'ignore' ? false : !isWordChar(before);\n\n if (!keepSign) {\n // Re-scan from right after the '-' so the digits are matched as a fresh, unsigned number.\n re.lastIndex = start + 1;\n continue;\n }\n }\n\n const keepExponent = exponentPart\n ? exponent === 'strict'\n ? true\n : exponent === 'ignore'\n ? false\n : !isWordChar(value[start + full.length])\n : false;\n\n const numericText = (signChar ?? '') + mantissa + (keepExponent ? exponentPart : '');\n return Number(numericText);\n }\n\n return undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Formats a number using compact notation (e.g. `1_500_000 → \"1.5M\"`).\n *\n * Thin wrapper over `Intl.NumberFormat` with `notation: 'compact'`. Companion\n * of `formatSize` in the same `format*` family.\n *\n * @param value - The number to format.\n * @param locale - BCP 47 locale tag. Defaults to the runtime locale.\n * @returns A compact string representation of the number.\n * @example\n * formatCompact(1_500_000); // '1.5M' (en-US locale)\n * formatCompact(1_000); // '1K'\n * formatCompact(999); // '999'\n * formatCompact(1_500_000, 'fr'); // '1,5 M'\n * @since 2.0.0\n */\nexport function formatCompact(value: number, locale?: string): string {\n return new Intl.NumberFormat(locale, { notation: 'compact' }).format(value);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/** Size units in ascending order. */\nconst UNITS = ['B', 'KB', 'MB', 'GB', 'TB'] as const;\n\n/**\n * Options for {@link formatSize}.\n * @since 3.0.8\n */\nexport interface FormatSizeOptions {\n /**\n * Inserted between the number and the unit.\n * @default '' (no separator, e.g. `'1.5KB'`)\n */\n unitSeparator?: string;\n /**\n * Print the base unit (`B`) as a bare integer with no decimal point, since\n * a fractional byte count is meaningless. Units at `KB` and above are\n * unaffected and always keep one decimal place.\n * @default false\n */\n integerBelowFirstUnit?: boolean;\n}\n\n/**\n * Format a byte count into a human-readable string with the appropriate unit.\n *\n * Each unit is 1024 of the previous (binary prefix). The result is formatted\n * with one decimal place, unless `integerBelowFirstUnit` is set.\n *\n * @param bytes - A non-negative integer representing a byte count.\n * @param options - Options.\n * @returns A human-readable string such as `'0.0B'`, `'1.5KB'`, `'3.2MB'`.\n * @example\n * formatSize(0) // '0.0B'\n * formatSize(512) // '512.0B'\n * formatSize(1024) // '1.0KB'\n * formatSize(1536) // '1.5KB'\n * formatSize(1_048_576) // '1.0MB'\n * formatSize(1_073_741_824) // '1.0GB'\n * @example\n * formatSize(1536, { unitSeparator: ' ' }) // '1.5 KB'\n * formatSize(512, { integerBelowFirstUnit: true }) // '512B'\n * formatSize(512, { unitSeparator: ' ', integerBelowFirstUnit: true }) // '512 B'\n * @since 2.0.0\n */\nexport function formatSize(bytes: number, options: FormatSizeOptions = {}): string {\n const { unitSeparator = '', integerBelowFirstUnit = false } = options;\n let size = bytes;\n let unitIndex = 0;\n\n while (size >= 1024 && unitIndex < UNITS.length - 1) {\n size /= 1024;\n unitIndex++;\n }\n\n const formattedSize = unitIndex === 0 && integerBelowFirstUnit ? `${size}` : size.toFixed(1);\n return `${formattedSize}${unitSeparator}${UNITS[unitIndex]}`;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Options for {@link inRange}.\n */\nexport interface InRangeOptions {\n /**\n * Which boundary (or boundaries) are included in the range.\n * - `'both'` (default): `min <= value <= max`\n * - `'min'`: `min <= value < max`\n * - `'max'`: `min < value <= max`\n * - `'none'`: `min < value < max`\n */\n inclusive?: 'both' | 'min' | 'max' | 'none';\n}\n\n/**\n * Checks whether a number falls within `[min, max]` (both inclusive by default).\n *\n * @param value - The number to test\n * @param min - Lower bound\n * @param max - Upper bound\n * @param options - Boundary inclusion mode (default: `'both'`)\n * @returns `true` if `value` is within the specified range\n * @example\n * inRange(5, 1, 10) // => true\n * inRange(1, 1, 10) // => true (min inclusive)\n * inRange(1, 1, 10, { inclusive: 'none' }) // => false\n * inRange(10, 1, 10, { inclusive: 'max' }) // => true\n * @since 2.0.0\n */\nexport function inRange(value: number, min: number, max: number, options: InRangeOptions = {}): boolean {\n const { inclusive = 'both' } = options;\n const minOk = inclusive === 'both' || inclusive === 'min' ? value >= min : value > min;\n const maxOk = inclusive === 'both' || inclusive === 'max' ? value <= max : value < max;\n return minOk && maxOk;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is an even integer.\n *\n * Returns `false` for non-numbers, non-integers, `NaN`, `Infinity`, and odd integers.\n *\n * @param value - The value to check\n * @returns `true` if value is an integer divisible by 2\n * @example\n * isEven(2) // => true\n * isEven(0) // => true\n * isEven(-4) // => true\n * isEven(3) // => false\n * isEven(1.5) // => false (not an integer)\n * isEven('2') // => false\n * @since 2.0.3\n */\nexport function isEven(value: unknown): value is number {\n return typeof value === 'number' && Number.isInteger(value) && value % 2 === 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is a number less than 0.\n *\n * Returns `false` for `NaN`, `0`, positive numbers, and non-number types.\n *\n * @param value - The value to check\n * @returns True if value is a negative number\n * @example\n * isNegative(-1) // => true\n * isNegative(-0.5) // => true\n * isNegative(-Infinity) // => true\n * isNegative(0) // => false\n * isNegative(1) // => false\n * isNegative(NaN) // => false\n * @since 2.0.0\n */\nexport function isNegative(value: unknown): value is number {\n return typeof value === 'number' && value < 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is an odd integer.\n *\n * Returns `false` for non-numbers, non-integers, `NaN`, `Infinity`, and even integers.\n *\n * @param value - The value to check\n * @returns `true` if value is an integer not divisible by 2\n * @example\n * isOdd(3) // => true\n * isOdd(1) // => true\n * isOdd(-7) // => true\n * isOdd(2) // => false\n * isOdd(1.5) // => false (not an integer)\n * isOdd('3') // => false\n * @since 2.0.3\n */\nexport function isOdd(value: unknown): value is number {\n return typeof value === 'number' && Number.isInteger(value) && value % 2 !== 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is a number greater than 0.\n *\n * Returns `false` for `NaN`, `0`, negative numbers, and non-number types.\n *\n * @param value - The value to check\n * @returns True if value is a positive number\n * @example\n * isPositive(42) // => true\n * isPositive(0.1) // => true\n * isPositive(Infinity) // => true\n * isPositive(0) // => false\n * isPositive(-1) // => false\n * isPositive(NaN) // => false\n * @since 2.0.0\n */\nexport function isPositive(value: unknown): value is number {\n return typeof value === 'number' && value > 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Linearly interpolates between `start` and `end` by the factor `t`.\n *\n * - `t = 0` returns `start`.\n * - `t = 1` returns `end`.\n * - Values of `t` outside `[0, 1]` extrapolate beyond the range.\n *\n * @param start - The start value.\n * @param end - The end value.\n * @param t - The interpolation factor.\n * @returns The interpolated value.\n * @example\n * lerp(0, 100, 0); // 0\n * lerp(0, 100, 1); // 100\n * lerp(0, 100, 0.5); // 50\n * lerp(0, 100, 0.25); // 25\n * @since 2.0.0\n */\nexport function lerp(start: number, end: number, t: number): number {\n if (t === 0) return start;\n if (t === 1) return end;\n if (Object.is(start, end)) return start;\n return start + (end - start) * t;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Generates a random number between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random number between min and max\n * @since 1.9.0\n */\nexport function randomBetween(min: number, max: number): number {\n return Math.random() * (max - min) + min;\n}\n\n/**\n * Generates a random integer between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random integer between min and max\n * @since 1.9.0\n */\nexport function randomIntBetween(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Rounds a number to specified decimal places\n * @param value - The number to round\n * @param decimals - Number of decimal places\n * @returns Rounded number\n * @since 1.9.0\n */\nexport function roundTo(value: number, decimals: number): number {\n const multiplier = Math.pow(10, decimals);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../helpers/number/clamp.ts","../../../helpers/number/correctFloat.ts","../../../helpers/number/extractNumber.ts","../../../helpers/number/formatCompact.ts","../../../helpers/number/formatSize.ts","../../../helpers/number/inRange.ts","../../../helpers/number/isEven.ts","../../../helpers/number/isNegative.ts","../../../helpers/number/isOdd.ts","../../../helpers/number/isPositive.ts","../../../helpers/number/lerp.ts","../../../helpers/number/random.ts","../../../helpers/number/roundTo.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Clamps a number between min and max values\n * @param value - The value to clamp\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Clamped value\n * @since 1.9.0\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Corrects floating-point arithmetic errors by rounding to a given number\n * of significant digits. Useful after calculations that accumulate binary\n * floating-point drift (e.g. `0.1 + 0.2 === 0.30000000000000004`).\n *\n * The default precision of 14 significant digits eliminates typical\n * rounding noise for values in the range used by most applications.\n * Note: for values whose integer part already consumes 14 or more digits\n * (i.e. |value| ≥ 1e13), toPrecision(14) has no room left for decimal\n * digits and will silently truncate them. Increase `precision` if you\n * need to correct drift in very large numbers.\n *\n * Note: IEEE-754 doubles carry at most ~17 significant decimal digits.\n * Precision values above 17 pad with digits that reflect the underlying\n * binary representation rather than correcting drift.\n *\n * @param value - The floating-point value to correct\n * @param precision - Integer number of significant digits between 1 and 100\n * (default: 14). Values above 17 are valid but expose binary noise beyond\n * IEEE-754's meaningful range.\n * @returns The corrected value\n * @example\n * correctFloat(0.1 + 0.2) // => 0.3\n * correctFloat(1.1 - 0.3) // => 0.8\n * correctFloat(0.1 * 3) // => 0.3\n *\n * // Custom precision: keep 4 significant digits\n * correctFloat(1.23456789, 4) // => 1.235\n * correctFloat(1.23456789, 6) // => 1.23457\n * @since 2.0.2\n */\nexport function correctFloat(value: number, precision: number = 14): number {\n if (!Number.isFinite(value)) {\n throw new RangeError(`correctFloat: value must be a finite number, got ${value}`);\n }\n if (!Number.isInteger(precision) || precision < 1 || precision > 100) {\n throw new RangeError(`correctFloat: precision must be an integer between 1 and 100, got ${precision}`);\n }\n const result = parseFloat(value.toPrecision(precision));\n // toPrecision(-0) produces \"0.000…\" (no minus sign per spec) — restore the sign bit.\n return Object.is(value, -0) ? -0 : result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Options for {@link extractNumber}.\n */\nexport interface ExtractNumberOptions {\n /**\n * How to interpret a `-` immediately before the matched digits.\n * - `'auto'`: treated as a minus sign unless it is glued to a preceding letter/digit\n * (e.g. `'-111'` and `'xxx -111'` → negative, but `'xxx-111'` → separator, positive).\n * - `'strict'`: always treated as a minus sign.\n * - `'ignore'`: never treated as a minus sign (always a separator).\n * @default 'auto'\n */\n sign?: 'auto' | 'strict' | 'ignore';\n\n /**\n * How to interpret a trailing scientific-notation suffix (`e`/`E` + digits, e.g. `1.5e-10`).\n * - `'auto'`: treated as an exponent unless it is glued to a following letter/digit\n * (e.g. `'1e5'` and `'1e5 mol'` → exponential, but `'1e5kg'` → mantissa only).\n * - `'strict'`: always treated as an exponent.\n * - `'ignore'`: never treated as an exponent (mantissa only).\n * @default 'auto'\n */\n exponent?: 'auto' | 'strict' | 'ignore';\n}\n\n// (?<![\\p{L}\\p{N}_]) prevents matching a leading-dot decimal immediately after a word\n// character (e.g. the '.5' in 'text.5' is a property separator, not a decimal point).\n// No `g` flag — cloned per call via `new RegExp(…, 'gu')` so each invocation has its own lastIndex.\nconst NUMBER_TOKEN = /(-)?(\\d+(?:\\.\\d+)?|(?<![\\p{L}\\p{N}_])\\.\\d+)([eE][+-]?\\d+)?/u;\nconst WORD_CHAR = /[\\p{L}\\p{N}_]/u;\n\nfunction isWordChar(char: string | undefined): boolean {\n return char !== undefined && WORD_CHAR.test(char);\n}\n\n/**\n * Extracts the first number embedded anywhere in a string, or passes through a `number`.\n *\n * Unlike a plain `parseFloat`/`parseInt`, the number does not need to be at the start of\n * the string: digits are searched for anywhere, so leading/trailing text (units, labels, ...)\n * is ignored. A `-` before the digits and a scientific-notation suffix (`e`/`E`) are\n * disambiguated with {@link ExtractNumberOptions.sign} and {@link ExtractNumberOptions.exponent}.\n *\n * Returns `undefined` if no number can be found.\n *\n * @param value - The value to extract a number from\n * @param options - Options controlling sign and exponent disambiguation\n * @returns The extracted number, or `undefined` if none was found\n * @example\n * extractNumber('16.5px') // => 16.5\n * extractNumber('.5rem') // => 0.5 (leading-dot decimal)\n * extractNumber('-.5') // => -0.5 (leading-dot with sign)\n * extractNumber('Wafer 10') // => 10\n * extractNumber('xxx-111') // => 111 ('-' glued to text → separator)\n * extractNumber('xxx -111') // => -111 ('-' preceded by a space → sign)\n * extractNumber('x-.5') // => 0.5 ('-' glued to 'x' → separator; leading-dot decimal follows)\n * extractNumber('-111') // => -111 ('-' at the start of the string → sign)\n * extractNumber('1e5 mol') // => 100000\n * extractNumber('1e5kg') // => 1 ('e5' glued to text → mantissa only)\n * extractNumber('no number') // => undefined\n * extractNumber(42) // => 42\n * @since 2.0.4\n */\nexport function extractNumber(value: unknown, options: ExtractNumberOptions = {}): number | undefined {\n const { sign = 'auto', exponent = 'auto' } = options;\n\n if (typeof value === 'number') {\n return Number.isNaN(value) ? undefined : value;\n }\n\n if (typeof value !== 'string') {\n return undefined;\n }\n\n const re = new RegExp(NUMBER_TOKEN.source, 'gu');\n let match: RegExpExecArray | null;\n\n while ((match = re.exec(value)) !== null) {\n const [full, signChar, mantissa, exponentPart] = match;\n const start = match.index;\n\n if (signChar) {\n const before = value[start - 1];\n const keepSign = sign === 'strict' ? true : sign === 'ignore' ? false : !isWordChar(before);\n\n if (!keepSign) {\n // Re-scan from right after the '-' so the digits are matched as a fresh, unsigned number.\n re.lastIndex = start + 1;\n continue;\n }\n }\n\n const keepExponent = exponentPart\n ? exponent === 'strict'\n ? true\n : exponent === 'ignore'\n ? false\n : !isWordChar(value[start + full.length])\n : false;\n\n const numericText = (signChar ?? '') + mantissa + (keepExponent ? exponentPart : '');\n return Number(numericText);\n }\n\n return undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Formats a number using compact notation (e.g. `1_500_000 → \"1.5M\"`).\n *\n * Thin wrapper over `Intl.NumberFormat` with `notation: 'compact'`. Companion\n * of `formatSize` in the same `format*` family.\n *\n * @param value - The number to format.\n * @param locale - BCP 47 locale tag. Defaults to the runtime locale.\n * @returns A compact string representation of the number.\n * @example\n * formatCompact(1_500_000); // '1.5M' (en-US locale)\n * formatCompact(1_000); // '1K'\n * formatCompact(999); // '999'\n * formatCompact(1_500_000, 'fr'); // '1,5 M'\n * @since 2.0.0\n */\nexport function formatCompact(value: number, locale?: string): string {\n return new Intl.NumberFormat(locale, { notation: 'compact' }).format(value);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/** Size units in ascending order. */\nconst UNITS = ['B', 'KB', 'MB', 'GB', 'TB'] as const;\n\n/**\n * Options for {@link formatSize}.\n * @since 3.0.8\n */\nexport interface FormatSizeOptions {\n /**\n * Inserted between the number and the unit.\n * @default '' (no separator, e.g. `'1.5KB'`)\n */\n unitSeparator?: string;\n /**\n * Print the base unit (`B`) as a bare integer with no decimal point, since\n * a fractional byte count is meaningless. Units at `KB` and above are\n * unaffected and always keep one decimal place.\n * @default false\n */\n integerBelowFirstUnit?: boolean;\n}\n\n/**\n * Format a byte count into a human-readable string with the appropriate unit.\n *\n * Each unit is 1024 of the previous (binary prefix). The result is formatted\n * with one decimal place, unless `integerBelowFirstUnit` is set.\n *\n * @param bytes - A non-negative integer representing a byte count.\n * @param options - Options.\n * @returns A human-readable string such as `'0.0B'`, `'1.5KB'`, `'3.2MB'`.\n * @example\n * formatSize(0) // '0.0B'\n * formatSize(512) // '512.0B'\n * formatSize(1024) // '1.0KB'\n * formatSize(1536) // '1.5KB'\n * formatSize(1_048_576) // '1.0MB'\n * formatSize(1_073_741_824) // '1.0GB'\n * @example\n * formatSize(1536, { unitSeparator: ' ' }) // '1.5 KB'\n * formatSize(512, { integerBelowFirstUnit: true }) // '512B'\n * formatSize(512, { unitSeparator: ' ', integerBelowFirstUnit: true }) // '512 B'\n * @since 2.0.0\n */\nexport function formatSize(bytes: number, options: FormatSizeOptions = {}): string {\n const { unitSeparator = '', integerBelowFirstUnit = false } = options;\n let size = bytes;\n let unitIndex = 0;\n\n while (size >= 1024 && unitIndex < UNITS.length - 1) {\n size /= 1024;\n unitIndex++;\n }\n\n const formattedSize = unitIndex === 0 && integerBelowFirstUnit ? `${size}` : size.toFixed(1);\n return `${formattedSize}${unitSeparator}${UNITS[unitIndex]}`;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Options for {@link inRange}.\n */\nexport interface InRangeOptions {\n /**\n * Which boundary (or boundaries) are included in the range.\n * - `'both'` (default): `min <= value <= max`\n * - `'min'`: `min <= value < max`\n * - `'max'`: `min < value <= max`\n * - `'none'`: `min < value < max`\n */\n inclusive?: 'both' | 'min' | 'max' | 'none';\n}\n\n/**\n * Checks whether a number falls within `[min, max]` (both inclusive by default).\n *\n * @param value - The number to test\n * @param min - Lower bound\n * @param max - Upper bound\n * @param options - Boundary inclusion mode (default: `'both'`)\n * @returns `true` if `value` is within the specified range\n * @example\n * inRange(5, 1, 10) // => true\n * inRange(1, 1, 10) // => true (min inclusive)\n * inRange(1, 1, 10, { inclusive: 'none' }) // => false\n * inRange(10, 1, 10, { inclusive: 'max' }) // => true\n * @since 2.0.0\n */\nexport function inRange(value: number, min: number, max: number, options: InRangeOptions = {}): boolean {\n const { inclusive = 'both' } = options;\n const minOk = inclusive === 'both' || inclusive === 'min' ? value >= min : value > min;\n const maxOk = inclusive === 'both' || inclusive === 'max' ? value <= max : value < max;\n return minOk && maxOk;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is an even integer.\n *\n * Returns `false` for non-numbers, non-integers, `NaN`, `Infinity`, and odd integers.\n *\n * @param value - The value to check\n * @returns `true` if value is an integer divisible by 2\n * @example\n * isEven(2) // => true\n * isEven(0) // => true\n * isEven(-4) // => true\n * isEven(3) // => false\n * isEven(1.5) // => false (not an integer)\n * isEven('2') // => false\n * @since 2.0.3\n */\nexport function isEven(value: unknown): value is number {\n return typeof value === 'number' && Number.isInteger(value) && value % 2 === 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is a number less than 0.\n *\n * Returns `false` for `NaN`, `0`, positive numbers, and non-number types.\n *\n * @param value - The value to check\n * @returns True if value is a negative number\n * @example\n * isNegative(-1) // => true\n * isNegative(-0.5) // => true\n * isNegative(-Infinity) // => true\n * isNegative(0) // => false\n * isNegative(1) // => false\n * isNegative(NaN) // => false\n * @since 2.0.0\n */\nexport function isNegative(value: unknown): value is number {\n return typeof value === 'number' && value < 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is an odd integer.\n *\n * Returns `false` for non-numbers, non-integers, `NaN`, `Infinity`, and even integers.\n *\n * @param value - The value to check\n * @returns `true` if value is an integer not divisible by 2\n * @example\n * isOdd(3) // => true\n * isOdd(1) // => true\n * isOdd(-7) // => true\n * isOdd(2) // => false\n * isOdd(1.5) // => false (not an integer)\n * isOdd('3') // => false\n * @since 2.0.3\n */\nexport function isOdd(value: unknown): value is number {\n return typeof value === 'number' && Number.isInteger(value) && value % 2 !== 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is a number greater than 0.\n *\n * Returns `false` for `NaN`, `0`, negative numbers, and non-number types.\n *\n * @param value - The value to check\n * @returns True if value is a positive number\n * @example\n * isPositive(42) // => true\n * isPositive(0.1) // => true\n * isPositive(Infinity) // => true\n * isPositive(0) // => false\n * isPositive(-1) // => false\n * isPositive(NaN) // => false\n * @since 2.0.0\n */\nexport function isPositive(value: unknown): value is number {\n return typeof value === 'number' && value > 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Linearly interpolates between `start` and `end` by the factor `t`.\n *\n * - `t = 0` returns `start`.\n * - `t = 1` returns `end`.\n * - Values of `t` outside `[0, 1]` extrapolate beyond the range.\n *\n * @param start - The start value.\n * @param end - The end value.\n * @param t - The interpolation factor.\n * @returns The interpolated value.\n * @example\n * lerp(0, 100, 0); // 0\n * lerp(0, 100, 1); // 100\n * lerp(0, 100, 0.5); // 50\n * lerp(0, 100, 0.25); // 25\n * @since 2.0.0\n */\nexport function lerp(start: number, end: number, t: number): number {\n if (t === 0) return start;\n if (t === 1) return end;\n if (Object.is(start, end)) return start;\n return start + (end - start) * t;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Generates a random number between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random number between min and max\n * @since 1.9.0\n */\nexport function randomBetween(min: number, max: number): number {\n return Math.random() * (max - min) + min;\n}\n\n/**\n * Generates a random integer between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random integer between min and max\n * @since 1.9.0\n */\nexport function randomIntBetween(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Rounds a number to specified decimal places\n * @param value - The number to round\n * @param decimals - Number of decimal places\n * @returns Rounded number\n * @since 1.9.0\n */\nexport function roundTo(value: number, decimals: number): number {\n const multiplier = Math.pow(10, decimals);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":"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"}
package/llms.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  # @helpers4/number
2
2
 
3
3
  > Tree-shakable TypeScript utility functions for the `number` domain.
4
- > Package: `@helpers4/number` — Version: 3.1.8
4
+ > Package: `@helpers4/number` — Version: 3.1.10
5
5
  > License: LGPL-3.0-or-later
6
6
 
7
7
  ## Installation
package/meta/api.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "category": "number",
3
- "version": "3.1.8",
3
+ "version": "3.1.10",
4
4
  "functions": [
5
5
  {
6
6
  "name": "clamp",
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@helpers4/number",
3
- "version": "3.1.8",
3
+ "version": "3.1.10",
4
4
  "description": "A set of helpers in TS/JS, compatible with tree-shaking, for number.",
5
5
  "author": "baxyz <craft@baxyz.dev>",
6
- "license": "LGPL-3.0",
6
+ "license": "LGPL-3.0-or-later",
7
7
  "homepage": "https://helpers4.dev/typescript/categories/number/",
8
8
  "repository": {
9
9
  "type": "git",