xypriss 9.13.13 → 9.13.15
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/dist/cjs/src/xhsc/UtilsApi.js +21 -1
- package/dist/cjs/src/xhsc/UtilsApi.js.map +1 -1
- package/dist/cjs/src/xhsc/api/env/XessIpcClient.js +73 -2
- package/dist/cjs/src/xhsc/api/env/XessIpcClient.js.map +1 -1
- package/dist/cjs/src/xhsc/utils/NumberUtils.js +1129 -26
- package/dist/cjs/src/xhsc/utils/NumberUtils.js.map +1 -1
- package/dist/esm/src/xhsc/UtilsApi.js +21 -1
- package/dist/esm/src/xhsc/UtilsApi.js.map +1 -1
- package/dist/esm/src/xhsc/api/env/XessIpcClient.js +73 -2
- package/dist/esm/src/xhsc/api/env/XessIpcClient.js.map +1 -1
- package/dist/esm/src/xhsc/utils/NumberUtils.js +1129 -26
- package/dist/esm/src/xhsc/utils/NumberUtils.js.map +1 -1
- package/dist/index.d.ts +820 -19
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Server, IncomingMessage, ServerResponse } from 'http';
|
|
2
|
-
import { SecureCacheAdapter } from 'xypriss-security';
|
|
2
|
+
import { Random, SecureCacheAdapter } from 'xypriss-security';
|
|
3
3
|
import { __strl__ } from 'strulink';
|
|
4
4
|
import * as reliant_type from 'reliant-type';
|
|
5
5
|
import { Readable, Writable } from 'node:stream';
|
|
@@ -6360,63 +6360,844 @@ declare class StringUtils {
|
|
|
6360
6360
|
uuid(): string;
|
|
6361
6361
|
}
|
|
6362
6362
|
|
|
6363
|
+
/***************************************************************************
|
|
6364
|
+
* XyPrissJS - Fast And Secure
|
|
6365
|
+
*
|
|
6366
|
+
* @author Nehonix
|
|
6367
|
+
* @license Nehonix OSL (NOSL)
|
|
6368
|
+
*
|
|
6369
|
+
* Copyright (c) 2025 Nehonix. All rights reserved.
|
|
6370
|
+
*
|
|
6371
|
+
* This License governs the use, modification, and distribution of software
|
|
6372
|
+
* provided by NEHONIX under its open source projects.
|
|
6373
|
+
* NEHONIX is committed to fostering collaborative innovation while strictly
|
|
6374
|
+
* protecting its intellectual property rights.
|
|
6375
|
+
* Violation of any term of this License will result in immediate termination of all granted rights
|
|
6376
|
+
* and may subject the violator to legal action.
|
|
6377
|
+
*
|
|
6378
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
6379
|
+
* INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
|
|
6380
|
+
* AND NON-INFRINGEMENT.
|
|
6381
|
+
* IN NO EVENT SHALL NEHONIX BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
6382
|
+
* OR CONSEQUENTIAL DAMAGES ARISING FROM THE USE OR INABILITY TO USE THE SOFTWARE,
|
|
6383
|
+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
6384
|
+
*
|
|
6385
|
+
***************************************************************************** */
|
|
6386
|
+
/**
|
|
6387
|
+
* @file NumberUtils.ts
|
|
6388
|
+
* @description XyPriss Number & Math Utilities — A comprehensive suite of
|
|
6389
|
+
* everyday numeric calculations, file & storage conversions, percentage analytics,
|
|
6390
|
+
* pagination algorithms, precision roundings, and localized formatters.
|
|
6391
|
+
*
|
|
6392
|
+
* @remarks
|
|
6393
|
+
* All methods are pure and deterministic unless utilizing cryptographic randomness
|
|
6394
|
+
* provided by `xypriss-security`.
|
|
6395
|
+
*
|
|
6396
|
+
* @example
|
|
6397
|
+
* ```ts
|
|
6398
|
+
* const num = new NumberUtils();
|
|
6399
|
+
*
|
|
6400
|
+
* // File & Storage Calculations
|
|
6401
|
+
* num.formatBytes(15_728_640); // "15 MB"
|
|
6402
|
+
* num.parseBytes("25.5 MB"); // 26738688
|
|
6403
|
+
* num.toMB(104857600); // 100
|
|
6404
|
+
*
|
|
6405
|
+
* // Daily Percentages & Ratios
|
|
6406
|
+
* num.percentage(45, 200); // 22.5 (%)
|
|
6407
|
+
* num.percentageOf(20, 150); // 30
|
|
6408
|
+
* num.percentageChange(100, 125); // 25 (+25%)
|
|
6409
|
+
*
|
|
6410
|
+
* // Pagination Helper
|
|
6411
|
+
* num.paginate(154, 20, 2); // { currentPage: 2, totalPages: 8, offset: 20, limit: 20, ... }
|
|
6412
|
+
* ```
|
|
6413
|
+
*/
|
|
6414
|
+
|
|
6415
|
+
/** Supported standard decimal byte units */
|
|
6416
|
+
type ByteUnit = "B" | "KB" | "MB" | "GB" | "TB" | "PB" | "EB" | "ZB" | "YB";
|
|
6417
|
+
/** Supported binary byte units (IEC standard) */
|
|
6418
|
+
type BinaryByteUnit = "B" | "KiB" | "MiB" | "GiB" | "TiB" | "PiB" | "EiB" | "ZiB" | "YiB";
|
|
6419
|
+
/** Options for customizing byte size formatting */
|
|
6420
|
+
interface FormatBytesOptions {
|
|
6421
|
+
/**
|
|
6422
|
+
* Number of decimal places to include.
|
|
6423
|
+
* @default 2
|
|
6424
|
+
*/
|
|
6425
|
+
decimals?: number;
|
|
6426
|
+
/**
|
|
6427
|
+
* Whether to use binary unit labels (KiB, MiB, GiB...) instead of decimal labels (KB, MB, GB...).
|
|
6428
|
+
* @default false
|
|
6429
|
+
*/
|
|
6430
|
+
binary?: boolean;
|
|
6431
|
+
/**
|
|
6432
|
+
* Custom separator between the numeric value and the unit label.
|
|
6433
|
+
* @default " "
|
|
6434
|
+
*/
|
|
6435
|
+
spacer?: string;
|
|
6436
|
+
}
|
|
6437
|
+
/** Result returned by pagination calculations */
|
|
6438
|
+
interface PaginationResult {
|
|
6439
|
+
/** The current page number (1-indexed and clamped within [1, totalPages]) */
|
|
6440
|
+
currentPage: number;
|
|
6441
|
+
/** Total number of pages */
|
|
6442
|
+
totalPages: number;
|
|
6443
|
+
/** Number of items per page */
|
|
6444
|
+
pageSize: number;
|
|
6445
|
+
/** Total count of items */
|
|
6446
|
+
totalItems: number;
|
|
6447
|
+
/** Number of items to skip for database queries (SQL OFFSET / MongoDB skip) */
|
|
6448
|
+
offset: number;
|
|
6449
|
+
/** Number of items to retrieve for database queries (SQL LIMIT / MongoDB limit) */
|
|
6450
|
+
limit: number;
|
|
6451
|
+
/** 0-based index of the first item on the current page */
|
|
6452
|
+
startIndex: number;
|
|
6453
|
+
/** 0-based index of the last item on the current page */
|
|
6454
|
+
endIndex: number;
|
|
6455
|
+
/** True if a subsequent page exists */
|
|
6456
|
+
hasNext: boolean;
|
|
6457
|
+
/** True if a prior page exists */
|
|
6458
|
+
hasPrev: boolean;
|
|
6459
|
+
}
|
|
6363
6460
|
/**
|
|
6364
6461
|
* **NumberUtils — XyPriss Number & Math Utilities**
|
|
6462
|
+
*
|
|
6463
|
+
* Provides ready-to-use helpers for daily mathematical operations, data storage units,
|
|
6464
|
+
* rates, roundings, statistical metrics, bounds, and formatted output.
|
|
6365
6465
|
*/
|
|
6366
6466
|
declare class NumberUtils {
|
|
6467
|
+
/**
|
|
6468
|
+
* Flattens a variadic list of numbers or number arrays into a flat numeric array.
|
|
6469
|
+
*
|
|
6470
|
+
* @param args - Numbers or arrays of numbers.
|
|
6471
|
+
* @returns A flat array of valid numbers.
|
|
6472
|
+
* @internal
|
|
6473
|
+
*/
|
|
6474
|
+
private flattenNumbers;
|
|
6475
|
+
/**
|
|
6476
|
+
* **Format Bytes**
|
|
6477
|
+
*
|
|
6478
|
+
* Converts a raw number of bytes into a human-readable size string (e.g., `KB`, `MB`, `GB` or `KiB`, `MiB`, `GiB`).
|
|
6479
|
+
* Supports negative values and configurable decimal precision.
|
|
6480
|
+
*
|
|
6481
|
+
* @param bytes - The number of bytes to format.
|
|
6482
|
+
* @param optionsOrDecimals - Number of decimal places (default: `2`) or a {@link FormatBytesOptions} configuration object.
|
|
6483
|
+
* @returns A human-readable file size string.
|
|
6484
|
+
*
|
|
6485
|
+
* @example
|
|
6486
|
+
* ```ts
|
|
6487
|
+
* num.formatBytes(0); // "0 Bytes"
|
|
6488
|
+
* num.formatBytes(1024); // "1 KB"
|
|
6489
|
+
* num.formatBytes(15728640, 1); // "15 MB"
|
|
6490
|
+
* num.formatBytes(1073741824, { binary: true }); // "1 GiB"
|
|
6491
|
+
* ```
|
|
6492
|
+
*/
|
|
6493
|
+
formatBytes(bytes: number, optionsOrDecimals?: number | FormatBytesOptions): string;
|
|
6494
|
+
/**
|
|
6495
|
+
* **Parse Bytes**
|
|
6496
|
+
*
|
|
6497
|
+
* Parses a human-readable storage string (e.g., `"10MB"`, `"1.5 GB"`, `"500KB"`, `"64KiB"`, `"1024 B"`)
|
|
6498
|
+
* into the equivalent raw number of bytes. Very helpful for upload limits, payload sizes, and cache config.
|
|
6499
|
+
*
|
|
6500
|
+
* @param input - The size string to parse or raw byte number.
|
|
6501
|
+
* @returns The parsed number of bytes, or `NaN` if parsing fails.
|
|
6502
|
+
*
|
|
6503
|
+
* @example
|
|
6504
|
+
* ```ts
|
|
6505
|
+
* num.parseBytes("500 KB"); // 512000
|
|
6506
|
+
* num.parseBytes("10MB"); // 10485760
|
|
6507
|
+
* num.parseBytes("1.5 GB"); // 1610612736
|
|
6508
|
+
* num.parseBytes("256 B"); // 256
|
|
6509
|
+
* ```
|
|
6510
|
+
*/
|
|
6511
|
+
parseBytes(input: string | number): number;
|
|
6512
|
+
/**
|
|
6513
|
+
* **Convert Bytes to Kilobytes (KB)**
|
|
6514
|
+
*
|
|
6515
|
+
* @param bytes - Number of raw bytes.
|
|
6516
|
+
* @param decimals - Decimal places (default: `2`).
|
|
6517
|
+
* @returns The value in Kilobytes.
|
|
6518
|
+
*
|
|
6519
|
+
* @example
|
|
6520
|
+
* ```ts
|
|
6521
|
+
* num.toKB(2048); // 2
|
|
6522
|
+
* ```
|
|
6523
|
+
*/
|
|
6524
|
+
toKB(bytes: number, decimals?: number): number;
|
|
6525
|
+
/**
|
|
6526
|
+
* **Convert Bytes to Megabytes (MB)**
|
|
6527
|
+
*
|
|
6528
|
+
* @param bytes - Number of raw bytes.
|
|
6529
|
+
* @param decimals - Decimal places (default: `2`).
|
|
6530
|
+
* @returns The value in Megabytes.
|
|
6531
|
+
*
|
|
6532
|
+
* @example
|
|
6533
|
+
* ```ts
|
|
6534
|
+
* num.toMB(10485760); // 10
|
|
6535
|
+
* ```
|
|
6536
|
+
*/
|
|
6537
|
+
toMB(bytes: number, decimals?: number): number;
|
|
6538
|
+
/**
|
|
6539
|
+
* **Convert Bytes to Gigabytes (GB)**
|
|
6540
|
+
*
|
|
6541
|
+
* @param bytes - Number of raw bytes.
|
|
6542
|
+
* @param decimals - Decimal places (default: `2`).
|
|
6543
|
+
* @returns The value in Gigabytes.
|
|
6544
|
+
*
|
|
6545
|
+
* @example
|
|
6546
|
+
* ```ts
|
|
6547
|
+
* num.toGB(1073741824); // 1
|
|
6548
|
+
* ```
|
|
6549
|
+
*/
|
|
6550
|
+
toGB(bytes: number, decimals?: number): number;
|
|
6551
|
+
/**
|
|
6552
|
+
* **Convert Bytes to Terabytes (TB)**
|
|
6553
|
+
*
|
|
6554
|
+
* @param bytes - Number of raw bytes.
|
|
6555
|
+
* @param decimals - Decimal places (default: `2`).
|
|
6556
|
+
* @returns The value in Terabytes.
|
|
6557
|
+
*
|
|
6558
|
+
* @example
|
|
6559
|
+
* ```ts
|
|
6560
|
+
* num.toTB(1099511627776); // 1
|
|
6561
|
+
* ```
|
|
6562
|
+
*/
|
|
6563
|
+
toTB(bytes: number, decimals?: number): number;
|
|
6564
|
+
/**
|
|
6565
|
+
* **Convert Bytes to Target Unit**
|
|
6566
|
+
*
|
|
6567
|
+
* Converts a byte count to any specified target unit (`KB`, `MB`, `GB`, `TB`, etc.).
|
|
6568
|
+
*
|
|
6569
|
+
* @param bytes - The number of bytes.
|
|
6570
|
+
* @param targetUnit - Destination unit (e.g., `"MB"`, `"GB"`).
|
|
6571
|
+
* @param decimals - Decimal places (default: `2`).
|
|
6572
|
+
* @returns The converted numeric value.
|
|
6573
|
+
*
|
|
6574
|
+
* @example
|
|
6575
|
+
* ```ts
|
|
6576
|
+
* num.convertBytes(52428800, "MB"); // 50
|
|
6577
|
+
* ```
|
|
6578
|
+
*/
|
|
6579
|
+
convertBytes(bytes: number, targetUnit: ByteUnit | BinaryByteUnit, decimals?: number): number;
|
|
6580
|
+
/**
|
|
6581
|
+
* **Transfer Rate / Speed**
|
|
6582
|
+
*
|
|
6583
|
+
* Calculates the transfer throughput given transferred bytes and elapsed duration in milliseconds.
|
|
6584
|
+
*
|
|
6585
|
+
* @param bytes - Transferred bytes.
|
|
6586
|
+
* @param durationMs - Duration in milliseconds.
|
|
6587
|
+
* @param decimals - Decimal places (default: `2`).
|
|
6588
|
+
* @returns A formatted speed string (e.g., `"12.5 MB/s"`).
|
|
6589
|
+
*
|
|
6590
|
+
* @example
|
|
6591
|
+
* ```ts
|
|
6592
|
+
* num.transferRate(10485760, 2000); // "5 MB/s"
|
|
6593
|
+
* ```
|
|
6594
|
+
*/
|
|
6595
|
+
transferRate(bytes: number, durationMs: number, decimals?: number): string;
|
|
6596
|
+
/**
|
|
6597
|
+
* **Transfer Estimated Time of Arrival (ETA)**
|
|
6598
|
+
*
|
|
6599
|
+
* Calculates the remaining time in seconds to complete a file or data transfer.
|
|
6600
|
+
*
|
|
6601
|
+
* @param remainingBytes - Bytes left to transfer.
|
|
6602
|
+
* @param bytesPerSec - Transfer throughput in bytes per second.
|
|
6603
|
+
* @returns Remaining time in seconds (rounded up), or `0` if invalid.
|
|
6604
|
+
*
|
|
6605
|
+
* @example
|
|
6606
|
+
* ```ts
|
|
6607
|
+
* num.transferETA(52428800, 10485760); // 5 (seconds)
|
|
6608
|
+
* ```
|
|
6609
|
+
*/
|
|
6610
|
+
transferETA(remainingBytes: number, bytesPerSec: number): number;
|
|
6611
|
+
/**
|
|
6612
|
+
* **Calculate Percentage (Partial of Total)**
|
|
6613
|
+
*
|
|
6614
|
+
* Returns what percentage `partial` represents relative to `total`: `(partial / total) * 100`.
|
|
6615
|
+
* Safely returns `0` if `total === 0` to prevent division by zero.
|
|
6616
|
+
*
|
|
6617
|
+
* @param partial - The partial amount.
|
|
6618
|
+
* @param total - The reference total.
|
|
6619
|
+
* @param decimals - Decimal places (default: `2`).
|
|
6620
|
+
* @returns The percentage value (e.g. `25` for 25%).
|
|
6621
|
+
*
|
|
6622
|
+
* @example
|
|
6623
|
+
* ```ts
|
|
6624
|
+
* num.percentage(25, 200); // 12.5
|
|
6625
|
+
* num.percentage(50, 100); // 50
|
|
6626
|
+
* num.percentage(0, 0); // 0
|
|
6627
|
+
* ```
|
|
6628
|
+
*/
|
|
6629
|
+
percentage(partial: number, total: number, decimals?: number): number;
|
|
6630
|
+
/**
|
|
6631
|
+
* **Calculate Value From Percentage (X% of Total)**
|
|
6632
|
+
*
|
|
6633
|
+
* Returns the actual value corresponding to `percent` of `total`: `(percent / 100) * total`.
|
|
6634
|
+
*
|
|
6635
|
+
* @param percent - The percentage rate (e.g., `20` for 20%).
|
|
6636
|
+
* @param total - The reference total.
|
|
6637
|
+
* @param decimals - Decimal places (default: `2`).
|
|
6638
|
+
* @returns The calculated portion.
|
|
6639
|
+
*
|
|
6640
|
+
* @example
|
|
6641
|
+
* ```ts
|
|
6642
|
+
* num.percentageOf(20, 150); // 30 (20% of 150 is 30)
|
|
6643
|
+
* num.percentageOf(5.5, 200); // 11
|
|
6644
|
+
* ```
|
|
6645
|
+
*/
|
|
6646
|
+
percentageOf(percent: number, total: number, decimals?: number): number;
|
|
6647
|
+
/**
|
|
6648
|
+
* **Percentage Change / Growth Rate**
|
|
6649
|
+
*
|
|
6650
|
+
* Computes the relative percentage variation from `oldValue` to `newValue`.
|
|
6651
|
+
* Positive indicates an increase, negative indicates a decrease.
|
|
6652
|
+
*
|
|
6653
|
+
* @param oldValue - The baseline value.
|
|
6654
|
+
* @param newValue - The current value.
|
|
6655
|
+
* @param decimals - Decimal precision (default: `2`).
|
|
6656
|
+
* @returns Percentage variation.
|
|
6657
|
+
*
|
|
6658
|
+
* @example
|
|
6659
|
+
* ```ts
|
|
6660
|
+
* num.percentageChange(100, 150); // 50 (+50%)
|
|
6661
|
+
* num.percentageChange(200, 150); // -25 (-25%)
|
|
6662
|
+
* ```
|
|
6663
|
+
*/
|
|
6664
|
+
percentageChange(oldValue: number, newValue: number, decimals?: number): number;
|
|
6665
|
+
/**
|
|
6666
|
+
* **Progress Ratio**
|
|
6667
|
+
*
|
|
6668
|
+
* Calculates a normalized progress value clamped strictly between `0.0` and `1.0`.
|
|
6669
|
+
* Ideal for progress bars and completion meters.
|
|
6670
|
+
*
|
|
6671
|
+
* @param current - The current progress value.
|
|
6672
|
+
* @param total - The target total value.
|
|
6673
|
+
* @returns A float between `0.0` and `1.0`.
|
|
6674
|
+
*
|
|
6675
|
+
* @example
|
|
6676
|
+
* ```ts
|
|
6677
|
+
* num.progress(50, 100); // 0.5
|
|
6678
|
+
* num.progress(120, 100); // 1.0 (clamped)
|
|
6679
|
+
* num.progress(-10, 100); // 0.0 (clamped)
|
|
6680
|
+
* ```
|
|
6681
|
+
*/
|
|
6682
|
+
progress(current: number, total: number): number;
|
|
6683
|
+
/**
|
|
6684
|
+
* **Accurate Decimal Rounding**
|
|
6685
|
+
*
|
|
6686
|
+
* Accurately rounds a number to a specified number of decimal places.
|
|
6687
|
+
* Uses exponential notation internally to avoid common JavaScript floating-point rounding bugs (e.g. `1.005 * 100`).
|
|
6688
|
+
*
|
|
6689
|
+
* @param value - The number to round.
|
|
6690
|
+
* @param decimals - Decimal places (default: `0`).
|
|
6691
|
+
* @returns The rounded number.
|
|
6692
|
+
*
|
|
6693
|
+
* @example
|
|
6694
|
+
* ```ts
|
|
6695
|
+
* num.round(1.005, 2); // 1.01 (avoids standard JS Math.round bug)
|
|
6696
|
+
* num.round(12.3456, 2); // 12.35
|
|
6697
|
+
* num.round(12.3456, 0); // 12
|
|
6698
|
+
* ```
|
|
6699
|
+
*/
|
|
6700
|
+
round(value: number, decimals?: number): number;
|
|
6701
|
+
/**
|
|
6702
|
+
* **Accurate Decimal Ceil**
|
|
6703
|
+
*
|
|
6704
|
+
* Rounds up to the nearest specified decimal precision.
|
|
6705
|
+
*
|
|
6706
|
+
* @param value - The number to round up.
|
|
6707
|
+
* @param decimals - Decimal places (default: `0`).
|
|
6708
|
+
* @returns Ceiled value.
|
|
6709
|
+
*
|
|
6710
|
+
* @example
|
|
6711
|
+
* ```ts
|
|
6712
|
+
* num.ceil(1.234, 2); // 1.24
|
|
6713
|
+
* num.ceil(1.2, 0); // 2
|
|
6714
|
+
* ```
|
|
6715
|
+
*/
|
|
6716
|
+
ceil(value: number, decimals?: number): number;
|
|
6717
|
+
/**
|
|
6718
|
+
* **Accurate Decimal Floor**
|
|
6719
|
+
*
|
|
6720
|
+
* Rounds down to the nearest specified decimal precision.
|
|
6721
|
+
*
|
|
6722
|
+
* @param value - The number to round down.
|
|
6723
|
+
* @param decimals - Decimal places (default: `0`).
|
|
6724
|
+
* @returns Floored value.
|
|
6725
|
+
*
|
|
6726
|
+
* @example
|
|
6727
|
+
* ```ts
|
|
6728
|
+
* num.floor(1.239, 2); // 1.23
|
|
6729
|
+
* num.floor(1.9, 0); // 1
|
|
6730
|
+
* ```
|
|
6731
|
+
*/
|
|
6732
|
+
floor(value: number, decimals?: number): number;
|
|
6733
|
+
/**
|
|
6734
|
+
* **Round to Step / Multiple**
|
|
6735
|
+
*
|
|
6736
|
+
* Rounds a value to the nearest multiple of a given step (e.g., nearest `5`, `0.25`, or `100`).
|
|
6737
|
+
*
|
|
6738
|
+
* @param value - The value to round.
|
|
6739
|
+
* @param step - The increment step size.
|
|
6740
|
+
* @returns Value rounded to the nearest step.
|
|
6741
|
+
*
|
|
6742
|
+
* @example
|
|
6743
|
+
* ```ts
|
|
6744
|
+
* num.roundToStep(23, 5); // 25
|
|
6745
|
+
* num.roundToStep(1.234, 0.05); // 1.25
|
|
6746
|
+
* num.roundToStep(1430, 500); // 1500
|
|
6747
|
+
* ```
|
|
6748
|
+
*/
|
|
6749
|
+
roundToStep(value: number, step: number): number;
|
|
6750
|
+
/**
|
|
6751
|
+
* **Round to Significant Digits**
|
|
6752
|
+
*
|
|
6753
|
+
* Formats a number to a specified number of significant digits.
|
|
6754
|
+
*
|
|
6755
|
+
* @param value - The number to format.
|
|
6756
|
+
* @param digits - Number of significant digits.
|
|
6757
|
+
* @returns The number rounded to significant precision.
|
|
6758
|
+
*
|
|
6759
|
+
* @example
|
|
6760
|
+
* ```ts
|
|
6761
|
+
* num.toPrecision(12345, 3); // 12300
|
|
6762
|
+
* num.toPrecision(0.001234, 2); // 0.0012
|
|
6763
|
+
* ```
|
|
6764
|
+
*/
|
|
6765
|
+
toPrecision(value: number, digits: number): number;
|
|
6367
6766
|
/**
|
|
6368
6767
|
* **Clamp a Value**
|
|
6369
6768
|
*
|
|
6370
|
-
* Restricts a numeric value
|
|
6769
|
+
* Restricts a numeric value within a defined range `[min, max]`.
|
|
6770
|
+
* If `min > max`, the bounds are automatically swapped for safety.
|
|
6371
6771
|
*
|
|
6372
6772
|
* @param value - The value to clamp.
|
|
6373
6773
|
* @param min - The lower bound.
|
|
6374
6774
|
* @param max - The upper bound.
|
|
6375
6775
|
* @returns The clamped value.
|
|
6776
|
+
*
|
|
6777
|
+
* @example
|
|
6778
|
+
* ```ts
|
|
6779
|
+
* num.clamp(15, 0, 10); // 10
|
|
6780
|
+
* num.clamp(-5, 0, 10); // 0
|
|
6781
|
+
* num.clamp(5, 0, 10); // 5
|
|
6782
|
+
* ```
|
|
6376
6783
|
*/
|
|
6377
6784
|
clamp(value: number, min: number, max: number): number;
|
|
6785
|
+
/**
|
|
6786
|
+
* **Check if Value is in Range**
|
|
6787
|
+
*
|
|
6788
|
+
* Determines whether a value falls within `[min, max]`.
|
|
6789
|
+
*
|
|
6790
|
+
* @param value - The value to test.
|
|
6791
|
+
* @param min - Range start.
|
|
6792
|
+
* @param max - Range end.
|
|
6793
|
+
* @param inclusive - Whether the bounds are inclusive (default: `true`).
|
|
6794
|
+
* @returns `true` if value is within bounds.
|
|
6795
|
+
*
|
|
6796
|
+
* @example
|
|
6797
|
+
* ```ts
|
|
6798
|
+
* num.inRange(5, 1, 10); // true
|
|
6799
|
+
* num.inRange(10, 1, 10, true); // true
|
|
6800
|
+
* num.inRange(10, 1, 10, false);// false
|
|
6801
|
+
* ```
|
|
6802
|
+
*/
|
|
6803
|
+
inRange(value: number, min: number, max: number, inclusive?: boolean): boolean;
|
|
6804
|
+
/**
|
|
6805
|
+
* **Normalize a Value (0 to 1)**
|
|
6806
|
+
*
|
|
6807
|
+
* Maps a value from its original range `[min, max]` into a normalized unit float `[0.0, 1.0]`.
|
|
6808
|
+
*
|
|
6809
|
+
* @param value - The input value.
|
|
6810
|
+
* @param min - The minimum of the original range.
|
|
6811
|
+
* @param max - The maximum of the original range.
|
|
6812
|
+
* @returns Normalized float.
|
|
6813
|
+
*
|
|
6814
|
+
* @example
|
|
6815
|
+
* ```ts
|
|
6816
|
+
* num.normalize(50, 0, 100); // 0.5
|
|
6817
|
+
* num.normalize(15, 10, 20); // 0.5
|
|
6818
|
+
* ```
|
|
6819
|
+
*/
|
|
6820
|
+
normalize(value: number, min: number, max: number): number;
|
|
6378
6821
|
/**
|
|
6379
6822
|
* **Linear Interpolation (LERP)**
|
|
6380
6823
|
*
|
|
6381
|
-
* Returns the linear interpolation between `start` and `end` for a factor `t
|
|
6824
|
+
* Returns the linear interpolation between `start` and `end` for a factor `t`:
|
|
6825
|
+
* Formula: `start * (1 - t) + end * t`.
|
|
6382
6826
|
*
|
|
6383
6827
|
* @param start - The start value.
|
|
6384
6828
|
* @param end - The end value.
|
|
6385
|
-
* @param t - The interpolation factor (0.0 to 1.0).
|
|
6829
|
+
* @param t - The interpolation factor (typically `0.0` to `1.0`).
|
|
6386
6830
|
* @returns The interpolated value.
|
|
6831
|
+
*
|
|
6832
|
+
* @example
|
|
6833
|
+
* ```ts
|
|
6834
|
+
* num.lerp(0, 100, 0.5); // 50
|
|
6835
|
+
* num.lerp(20, 80, 0.25); // 35
|
|
6836
|
+
* ```
|
|
6387
6837
|
*/
|
|
6388
6838
|
lerp(start: number, end: number, t: number): number;
|
|
6839
|
+
/**
|
|
6840
|
+
* **Map Range (Re-scale)**
|
|
6841
|
+
*
|
|
6842
|
+
* Maps an input number from an incoming range `[inMin, inMax]` to an outgoing range `[outMin, outMax]`.
|
|
6843
|
+
*
|
|
6844
|
+
* @param value - The number to map.
|
|
6845
|
+
* @param inMin - Lower bound of input range.
|
|
6846
|
+
* @param inMax - Upper bound of input range.
|
|
6847
|
+
* @param outMin - Lower bound of output range.
|
|
6848
|
+
* @param outMax - Upper bound of output range.
|
|
6849
|
+
* @returns The re-scaled value.
|
|
6850
|
+
*
|
|
6851
|
+
* @example
|
|
6852
|
+
* ```ts
|
|
6853
|
+
* // Map a 0-10 rating to a 0-100 percentage
|
|
6854
|
+
* num.mapRange(7.5, 0, 10, 0, 100); // 75
|
|
6855
|
+
*
|
|
6856
|
+
* // Map temperature sensor (0-1023) to degrees C (0-100)
|
|
6857
|
+
* num.mapRange(511.5, 0, 1023, 0, 100); // 50
|
|
6858
|
+
* ```
|
|
6859
|
+
*/
|
|
6860
|
+
mapRange(value: number, inMin: number, inMax: number, outMin: number, outMax: number): number;
|
|
6861
|
+
/**
|
|
6862
|
+
* **Sum of Numbers**
|
|
6863
|
+
*
|
|
6864
|
+
* Computes the sum of all provided numbers or numeric arrays.
|
|
6865
|
+
*
|
|
6866
|
+
* @param numbers - Variadic numbers or number arrays.
|
|
6867
|
+
* @returns Total sum.
|
|
6868
|
+
*
|
|
6869
|
+
* @example
|
|
6870
|
+
* ```ts
|
|
6871
|
+
* num.sum(1, 2, 3, 4); // 10
|
|
6872
|
+
* num.sum([10, 20, 30]); // 60
|
|
6873
|
+
* ```
|
|
6874
|
+
*/
|
|
6875
|
+
sum(...numbers: (number | number[])[]): number;
|
|
6876
|
+
/**
|
|
6877
|
+
* **Average / Arithmetic Mean**
|
|
6878
|
+
*
|
|
6879
|
+
* Computes the arithmetic mean of all provided numbers or numeric arrays.
|
|
6880
|
+
*
|
|
6881
|
+
* @param numbers - Variadic numbers or number arrays.
|
|
6882
|
+
* @returns The average, or `0` if empty.
|
|
6883
|
+
*
|
|
6884
|
+
* @example
|
|
6885
|
+
* ```ts
|
|
6886
|
+
* num.average(10, 20, 30); // 20
|
|
6887
|
+
* num.average([5, 15]); // 10
|
|
6888
|
+
* ```
|
|
6889
|
+
*/
|
|
6890
|
+
average(...numbers: (number | number[])[]): number;
|
|
6891
|
+
/**
|
|
6892
|
+
* **Median**
|
|
6893
|
+
*
|
|
6894
|
+
* Returns the statistical median (middle value) of a set of numbers.
|
|
6895
|
+
*
|
|
6896
|
+
* @param numbers - Variadic numbers or number arrays.
|
|
6897
|
+
* @returns The median value, or `0` if empty.
|
|
6898
|
+
*
|
|
6899
|
+
* @example
|
|
6900
|
+
* ```ts
|
|
6901
|
+
* num.median(1, 3, 5); // 3
|
|
6902
|
+
* num.median([1, 2, 3, 4]); // 2.5
|
|
6903
|
+
* ```
|
|
6904
|
+
*/
|
|
6905
|
+
median(...numbers: (number | number[])[]): number;
|
|
6906
|
+
/**
|
|
6907
|
+
* **Minimum Value**
|
|
6908
|
+
*
|
|
6909
|
+
* Returns the minimum value from numbers or number arrays.
|
|
6910
|
+
*
|
|
6911
|
+
* @param numbers - Variadic numbers or number arrays.
|
|
6912
|
+
* @returns The smallest number, or `Infinity` if no numbers provided.
|
|
6913
|
+
*
|
|
6914
|
+
* @example
|
|
6915
|
+
* ```ts
|
|
6916
|
+
* num.min(10, 5, 20); // 5
|
|
6917
|
+
* num.min([12, 4, 89]); // 4
|
|
6918
|
+
* ```
|
|
6919
|
+
*/
|
|
6920
|
+
min(...numbers: (number | number[])[]): number;
|
|
6921
|
+
/**
|
|
6922
|
+
* **Maximum Value**
|
|
6923
|
+
*
|
|
6924
|
+
* Returns the maximum value from numbers or number arrays.
|
|
6925
|
+
*
|
|
6926
|
+
* @param numbers - Variadic numbers or number arrays.
|
|
6927
|
+
* @returns The largest number, or `-Infinity` if no numbers provided.
|
|
6928
|
+
*
|
|
6929
|
+
* @example
|
|
6930
|
+
* ```ts
|
|
6931
|
+
* num.max(10, 5, 20); // 20
|
|
6932
|
+
* num.max([12, 4, 89]); // 89
|
|
6933
|
+
* ```
|
|
6934
|
+
*/
|
|
6935
|
+
max(...numbers: (number | number[])[]): number;
|
|
6936
|
+
/**
|
|
6937
|
+
* **Calculate Pagination**
|
|
6938
|
+
*
|
|
6939
|
+
* Computes all essential pagination parameters (`totalPages`, `offset`, `limit`, `startIndex`, `endIndex`, `hasNext`, `hasPrev`)
|
|
6940
|
+
* for database queries and user interfaces.
|
|
6941
|
+
*
|
|
6942
|
+
* @param totalItems - Total number of items across the entire dataset.
|
|
6943
|
+
* @param pageSize - Items per page (minimum 1).
|
|
6944
|
+
* @param currentPage - Requested 1-based page number (default: `1`).
|
|
6945
|
+
* @returns A structured {@link PaginationResult} object.
|
|
6946
|
+
*
|
|
6947
|
+
* @example
|
|
6948
|
+
* ```ts
|
|
6949
|
+
* const pageInfo = num.paginate(154, 20, 2);
|
|
6950
|
+
* // {
|
|
6951
|
+
* // currentPage: 2,
|
|
6952
|
+
* // totalPages: 8,
|
|
6953
|
+
* // pageSize: 20,
|
|
6954
|
+
* // totalItems: 154,
|
|
6955
|
+
* // offset: 20,
|
|
6956
|
+
* // limit: 20,
|
|
6957
|
+
* // startIndex: 20,
|
|
6958
|
+
* // endIndex: 39,
|
|
6959
|
+
* // hasNext: true,
|
|
6960
|
+
* // hasPrev: true
|
|
6961
|
+
* // }
|
|
6962
|
+
* ```
|
|
6963
|
+
*/
|
|
6964
|
+
paginate(totalItems: number, pageSize: number, currentPage?: number): PaginationResult;
|
|
6965
|
+
/**
|
|
6966
|
+
* **Euclidean Division (DivMod)**
|
|
6967
|
+
*
|
|
6968
|
+
* Simultaneously calculates the integer quotient and remainder of two numbers: `[quotient, remainder]`.
|
|
6969
|
+
* Extremely convenient for converting time units (seconds to minutes/seconds), grid positioning, and pagination.
|
|
6970
|
+
*
|
|
6971
|
+
* @param numerator - The dividend.
|
|
6972
|
+
* @param denominator - The divisor.
|
|
6973
|
+
* @returns A tuple `[quotient, remainder]`.
|
|
6974
|
+
*
|
|
6975
|
+
* @example
|
|
6976
|
+
* ```ts
|
|
6977
|
+
* const [minutes, seconds] = num.divmod(135, 60); // [2, 15] (2 min 15 sec)
|
|
6978
|
+
* const [hours, remainingMin] = num.divmod(150, 60); // [2, 30] (2 h 30 min)
|
|
6979
|
+
* ```
|
|
6980
|
+
*/
|
|
6981
|
+
divmod(numerator: number, denominator: number): [quotient: number, remainder: number];
|
|
6389
6982
|
/**
|
|
6390
6983
|
* **Get a Random Integer**
|
|
6391
6984
|
*
|
|
6392
|
-
*
|
|
6985
|
+
* Generates a cryptographically secure random integer.
|
|
6986
|
+
* Powered by `xypriss-security` Random core.
|
|
6987
|
+
*
|
|
6988
|
+
* - If one argument is provided: `[0, max)`
|
|
6989
|
+
* - If two arguments are provided: `[min, max)`
|
|
6990
|
+
*
|
|
6991
|
+
* @param minOrMax - Minimum value (inclusive) or maximum if second argument is omitted.
|
|
6992
|
+
* @param max - Maximum value (exclusive).
|
|
6993
|
+
* @returns A secure random integer.
|
|
6393
6994
|
*
|
|
6394
|
-
* @
|
|
6395
|
-
*
|
|
6396
|
-
*
|
|
6995
|
+
* @example
|
|
6996
|
+
* ```ts
|
|
6997
|
+
* num.randomInt(10); // Secure integer in [0, 10)
|
|
6998
|
+
* num.randomInt(10, 50); // Secure integer in [10, 50)
|
|
6999
|
+
* ```
|
|
6397
7000
|
*/
|
|
6398
|
-
randomInt(
|
|
7001
|
+
randomInt(...I: Parameters<typeof Random.Int>): number;
|
|
7002
|
+
/**
|
|
7003
|
+
* **Get a Random Float**
|
|
7004
|
+
*
|
|
7005
|
+
* Generates a cryptographically secure random floating-point number between `min` and `max`.
|
|
7006
|
+
*
|
|
7007
|
+
* @param min - Lower bound (default: `0`).
|
|
7008
|
+
* @param max - Upper bound (default: `1`).
|
|
7009
|
+
* @param decimals - Decimal places (default: `4`).
|
|
7010
|
+
* @returns A secure random float.
|
|
7011
|
+
*
|
|
7012
|
+
* @example
|
|
7013
|
+
* ```ts
|
|
7014
|
+
* num.randomFloat(); // e.g. 0.4821
|
|
7015
|
+
* num.randomFloat(1.5, 9.5, 2); // e.g. 6.34
|
|
7016
|
+
* ```
|
|
7017
|
+
*/
|
|
7018
|
+
randomFloat(min?: number, max?: number, decimals?: number): number;
|
|
7019
|
+
/**
|
|
7020
|
+
* **Random Item Selection**
|
|
7021
|
+
*
|
|
7022
|
+
* Randomly picks an element from an array using cryptographically secure random numbers.
|
|
7023
|
+
*
|
|
7024
|
+
* @param items - The candidate array.
|
|
7025
|
+
* @returns A selected item from the array.
|
|
7026
|
+
*
|
|
7027
|
+
* @example
|
|
7028
|
+
* ```ts
|
|
7029
|
+
* num.randomChoice(["apple", "banana", "cherry"]); // e.g. "banana"
|
|
7030
|
+
* ```
|
|
7031
|
+
*/
|
|
7032
|
+
randomChoice<T>(items: T[]): T;
|
|
6399
7033
|
/**
|
|
6400
7034
|
* **Format Number**
|
|
6401
7035
|
*
|
|
6402
|
-
* Locale-aware number formatting.
|
|
7036
|
+
* Locale-aware number formatting powered by `Intl.NumberFormat`.
|
|
6403
7037
|
*
|
|
6404
7038
|
* @param value - The number to format.
|
|
6405
|
-
* @param locale - Optional locale (default: `en-US`).
|
|
6406
|
-
* @param options - Intl.NumberFormatOptions
|
|
7039
|
+
* @param locale - Optional BCP 47 locale (default: `en-US`).
|
|
7040
|
+
* @param options - `Intl.NumberFormatOptions`.
|
|
6407
7041
|
* @returns A localized string.
|
|
7042
|
+
*
|
|
7043
|
+
* @example
|
|
7044
|
+
* ```ts
|
|
7045
|
+
* num.formatNumber(1250000); // "1,250,000"
|
|
7046
|
+
* num.formatNumber(1250000, "fr-FR"); // "1 250 000"
|
|
7047
|
+
* ```
|
|
6408
7048
|
*/
|
|
6409
7049
|
formatNumber(value: number, locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
6410
7050
|
/**
|
|
6411
|
-
* **
|
|
7051
|
+
* **Compact Number Formatting**
|
|
7052
|
+
*
|
|
7053
|
+
* Formats large numbers compactly for dashboards, views, and metrics (e.g., `1.5K`, `2.3M`, `4.8B`).
|
|
7054
|
+
*
|
|
7055
|
+
* @param value - The number to format.
|
|
7056
|
+
* @param locale - Locale tag (default: `en-US`).
|
|
7057
|
+
* @param decimals - Decimal digits (default: `1`).
|
|
7058
|
+
* @returns A compact string.
|
|
7059
|
+
*
|
|
7060
|
+
* @example
|
|
7061
|
+
* ```ts
|
|
7062
|
+
* num.formatCompact(1500); // "1.5K"
|
|
7063
|
+
* num.formatCompact(2500000); // "2.5M"
|
|
7064
|
+
* num.formatCompact(1200000000); // "1.2B"
|
|
7065
|
+
* ```
|
|
7066
|
+
*/
|
|
7067
|
+
formatCompact(value: number, locale?: string, decimals?: number): string;
|
|
7068
|
+
/**
|
|
7069
|
+
* **Format Currency**
|
|
7070
|
+
*
|
|
7071
|
+
* Formats a numeric value into a localized currency string.
|
|
7072
|
+
*
|
|
7073
|
+
* @param value - The amount to format.
|
|
7074
|
+
* @param currency - ISO 4217 currency code (default: `"USD"`).
|
|
7075
|
+
* @param locale - Locale tag (default: `"en-US"`).
|
|
7076
|
+
* @param options - Additional `Intl.NumberFormatOptions`.
|
|
7077
|
+
* @returns Formatted currency string.
|
|
7078
|
+
*
|
|
7079
|
+
* @example
|
|
7080
|
+
* ```ts
|
|
7081
|
+
* num.formatCurrency(49.99, "USD"); // "$49.99"
|
|
7082
|
+
* num.formatCurrency(49.99, "EUR", "fr-FR"); // "49,99 €"
|
|
7083
|
+
* ```
|
|
7084
|
+
*/
|
|
7085
|
+
formatCurrency(value: number, currency?: string, locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
7086
|
+
/**
|
|
7087
|
+
* **Format Percentage String**
|
|
7088
|
+
*
|
|
7089
|
+
* Formats a numeric value into a localized percentage string with the `%` symbol.
|
|
6412
7090
|
*
|
|
6413
|
-
*
|
|
7091
|
+
* @param value - The percentage value (e.g. `15.5` or `0.155` if `isRatio: true`).
|
|
7092
|
+
* @param decimals - Decimal places (default: `1`).
|
|
7093
|
+
* @param locale - Locale tag (default: `"en-US"`).
|
|
7094
|
+
* @param isRatio - If `true`, multiplies value by 100 first (default: `false`).
|
|
7095
|
+
* @returns Formatted percentage string.
|
|
6414
7096
|
*
|
|
6415
|
-
* @
|
|
6416
|
-
*
|
|
6417
|
-
*
|
|
7097
|
+
* @example
|
|
7098
|
+
* ```ts
|
|
7099
|
+
* num.formatPercent(15.5); // "15.5%"
|
|
7100
|
+
* num.formatPercent(0.155, 1, "en-US", true); // "15.5%"
|
|
7101
|
+
* ```
|
|
6418
7102
|
*/
|
|
6419
|
-
|
|
7103
|
+
formatPercent(value: number, decimals?: number, locale?: string, isRatio?: boolean): string;
|
|
7104
|
+
/**
|
|
7105
|
+
* **Ordinal Number Suffix**
|
|
7106
|
+
*
|
|
7107
|
+
* Appends the appropriate ordinal suffix to a number (e.g. `1st`, `2nd`, `3rd`, `4th` in English, or `1er`, `2e` in French).
|
|
7108
|
+
*
|
|
7109
|
+
* @param num - The integer number.
|
|
7110
|
+
* @param locale - Target locale (default: `"en-US"`).
|
|
7111
|
+
* @returns The number with its ordinal suffix.
|
|
7112
|
+
*
|
|
7113
|
+
* @example
|
|
7114
|
+
* ```ts
|
|
7115
|
+
* num.ordinal(1); // "1st"
|
|
7116
|
+
* num.ordinal(2); // "2nd"
|
|
7117
|
+
* num.ordinal(23); // "23rd"
|
|
7118
|
+
* num.ordinal(1, "fr-FR"); // "1er"
|
|
7119
|
+
* num.ordinal(2, "fr-FR"); // "2e"
|
|
7120
|
+
* ```
|
|
7121
|
+
*/
|
|
7122
|
+
ordinal(num: number, locale?: string): string;
|
|
7123
|
+
/**
|
|
7124
|
+
* **Check Even**
|
|
7125
|
+
*
|
|
7126
|
+
* Returns `true` if the number is an even integer.
|
|
7127
|
+
*
|
|
7128
|
+
* @param value - The number to test.
|
|
7129
|
+
* @returns `true` if even.
|
|
7130
|
+
*
|
|
7131
|
+
* @example
|
|
7132
|
+
* ```ts
|
|
7133
|
+
* num.isEven(4); // true
|
|
7134
|
+
* num.isEven(3); // false
|
|
7135
|
+
* ```
|
|
7136
|
+
*/
|
|
7137
|
+
isEven(value: number): boolean;
|
|
7138
|
+
/**
|
|
7139
|
+
* **Check Odd**
|
|
7140
|
+
*
|
|
7141
|
+
* Returns `true` if the number is an odd integer.
|
|
7142
|
+
*
|
|
7143
|
+
* @param value - The number to test.
|
|
7144
|
+
* @returns `true` if odd.
|
|
7145
|
+
*
|
|
7146
|
+
* @example
|
|
7147
|
+
* ```ts
|
|
7148
|
+
* num.isOdd(3); // true
|
|
7149
|
+
* num.isOdd(4); // false
|
|
7150
|
+
* ```
|
|
7151
|
+
*/
|
|
7152
|
+
isOdd(value: number): boolean;
|
|
7153
|
+
/**
|
|
7154
|
+
* **Check Integer**
|
|
7155
|
+
*
|
|
7156
|
+
* Returns `true` if the value is a safe, finite integer.
|
|
7157
|
+
*
|
|
7158
|
+
* @param value - The number to test.
|
|
7159
|
+
* @returns `true` if an integer.
|
|
7160
|
+
*
|
|
7161
|
+
* @example
|
|
7162
|
+
* ```ts
|
|
7163
|
+
* num.isInteger(42); // true
|
|
7164
|
+
* num.isInteger(42.5); // false
|
|
7165
|
+
* ```
|
|
7166
|
+
*/
|
|
7167
|
+
isInteger(value: number): boolean;
|
|
7168
|
+
/**
|
|
7169
|
+
* **Check Numeric**
|
|
7170
|
+
*
|
|
7171
|
+
* Checks if a value is a valid numeric value or a numeric string representing a finite number.
|
|
7172
|
+
*
|
|
7173
|
+
* @param value - Any value to test.
|
|
7174
|
+
* @returns Type guard confirming if the value is numeric.
|
|
7175
|
+
*
|
|
7176
|
+
* @example
|
|
7177
|
+
* ```ts
|
|
7178
|
+
* num.isNumeric(42); // true
|
|
7179
|
+
* num.isNumeric("42.5"); // true
|
|
7180
|
+
* num.isNumeric("abc"); // false
|
|
7181
|
+
* num.isNumeric(null); // false
|
|
7182
|
+
* ```
|
|
7183
|
+
*/
|
|
7184
|
+
isNumeric(value: unknown): value is number | string;
|
|
7185
|
+
/**
|
|
7186
|
+
* **Sign of a Number**
|
|
7187
|
+
*
|
|
7188
|
+
* Returns `-1` for negative numbers, `1` for positive numbers, and `0` for zero.
|
|
7189
|
+
*
|
|
7190
|
+
* @param value - The number.
|
|
7191
|
+
* @returns `-1 | 0 | 1`.
|
|
7192
|
+
*
|
|
7193
|
+
* @example
|
|
7194
|
+
* ```ts
|
|
7195
|
+
* num.sign(-42); // -1
|
|
7196
|
+
* num.sign(42); // 1
|
|
7197
|
+
* num.sign(0); // 0
|
|
7198
|
+
* ```
|
|
7199
|
+
*/
|
|
7200
|
+
sign(value: number): -1 | 0 | 1;
|
|
6420
7201
|
}
|
|
6421
7202
|
|
|
6422
7203
|
/**
|
|
@@ -9259,7 +10040,27 @@ declare class UtilsApi {
|
|
|
9259
10040
|
*
|
|
9260
10041
|
*/
|
|
9261
10042
|
readonly str: StringUtils;
|
|
9262
|
-
/**
|
|
10043
|
+
/**
|
|
10044
|
+
* **NumberUtils — XyPriss Number & Math Utilities**
|
|
10045
|
+
*
|
|
10046
|
+
* A suite of everyday numeric utilities:
|
|
10047
|
+
* - **File & Storage calculations**: `formatBytes`, `parseBytes`, `toMB`, `toGB`, `transferRate`, `transferETA`.
|
|
10048
|
+
* - **Percentages & Rates**: `percentage`, `percentageOf`, `percentageChange`, `progress`.
|
|
10049
|
+
* - **Pagination & Division**: `paginate`, `divmod`.
|
|
10050
|
+
* - **Rounding & Precision**: `round`, `ceil`, `floor`, `roundToStep`, `toPrecision`.
|
|
10051
|
+
* - **Bounds & Mapping**: `clamp`, `lerp`, `inRange`, `normalize`, `mapRange`.
|
|
10052
|
+
* - **Statistics & Aggregates**: `sum`, `average`, `median`, `min`, `max`.
|
|
10053
|
+
* - **Formatting & Localization**: `formatNumber`, `formatCompact`, `formatCurrency`, `formatPercent`, `ordinal`.
|
|
10054
|
+
* - **Cryptographic Randomness**: `randomInt`, `randomFloat`, `randomChoice`.
|
|
10055
|
+
*
|
|
10056
|
+
* @example
|
|
10057
|
+
* ```ts
|
|
10058
|
+
* __sys__.utils.num.formatBytes(15_728_640); // "15 MB"
|
|
10059
|
+
* __sys__.utils.num.parseBytes("25MB"); // 26214400
|
|
10060
|
+
* __sys__.utils.num.percentage(25, 200); // 12.5
|
|
10061
|
+
* __sys__.utils.num.paginate(154, 20, 2); // { currentPage: 2, totalPages: 8, offset: 20, ... }
|
|
10062
|
+
* __sys__.utils.num.round(1.005, 2); // 1.01
|
|
10063
|
+
* ```
|
|
9263
10064
|
* @see https://xypriss.nehonix.com/docs/system/utils/numbers
|
|
9264
10065
|
*/
|
|
9265
10066
|
readonly num: NumberUtils;
|