@khgtrn/lib 1.0.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.
Files changed (37) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +113 -0
  3. package/dist/cjs/base-enum.d.ts +106 -0
  4. package/dist/cjs/base-enum.js +137 -0
  5. package/dist/cjs/func.d.ts +227 -0
  6. package/dist/cjs/func.js +574 -0
  7. package/dist/cjs/index.d.ts +4 -0
  8. package/dist/cjs/index.js +20 -0
  9. package/dist/cjs/number-to-words/helpers.d.ts +17 -0
  10. package/dist/cjs/number-to-words/helpers.js +72 -0
  11. package/dist/cjs/number-to-words/index.d.ts +30 -0
  12. package/dist/cjs/number-to-words/index.js +50 -0
  13. package/dist/cjs/number-to-words/locales.d.ts +7 -0
  14. package/dist/cjs/number-to-words/locales.js +106 -0
  15. package/dist/cjs/number-to-words/types.d.ts +35 -0
  16. package/dist/cjs/number-to-words/types.js +2 -0
  17. package/dist/cjs/package.json +4 -0
  18. package/dist/cjs/round.d.ts +13 -0
  19. package/dist/cjs/round.js +19 -0
  20. package/dist/esm/base-enum.d.ts +106 -0
  21. package/dist/esm/base-enum.js +133 -0
  22. package/dist/esm/func.d.ts +227 -0
  23. package/dist/esm/func.js +547 -0
  24. package/dist/esm/index.d.ts +4 -0
  25. package/dist/esm/index.js +4 -0
  26. package/dist/esm/number-to-words/helpers.d.ts +17 -0
  27. package/dist/esm/number-to-words/helpers.js +67 -0
  28. package/dist/esm/number-to-words/index.d.ts +30 -0
  29. package/dist/esm/number-to-words/index.js +47 -0
  30. package/dist/esm/number-to-words/locales.d.ts +7 -0
  31. package/dist/esm/number-to-words/locales.js +103 -0
  32. package/dist/esm/number-to-words/types.d.ts +35 -0
  33. package/dist/esm/number-to-words/types.js +1 -0
  34. package/dist/esm/package.json +4 -0
  35. package/dist/esm/round.d.ts +13 -0
  36. package/dist/esm/round.js +16 -0
  37. package/package.json +50 -0
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 Tran Quang Khuong
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # KLib - Library for TS/JS
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@khgtrn/klib.svg)](https://www.npmjs.com/package/@khgtrn/klib)
4
+ [![npm downloads](https://img.shields.io/npm/d18m/@khgtrn/klib.svg)](https://www.npmjs.com/package/@khgtrn/klib)
5
+ [![license](https://img.shields.io/github/license/khgtrn/ts-klib.svg)](https://github.com/khgtrn/ts-klib/blob/main/LICENSE)
6
+
7
+ Shared TypeScript utility library: Java-style enums, common helper functions, number-to-words conversion (Vietnamese/English), and floating-point-safe rounding.
8
+
9
+ Built as both ESM (`dist/esm`) and CJS (`dist/cjs`), with full type declarations, with no runtime dependency beyond standard Web APIs (`crypto`, `TextEncoder`/`TextDecoder`, `btoa`/`atob` — available in browsers and Node.js >= 19).
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pnpm add @khgtrn/klib
15
+ ```
16
+
17
+ Requires Node.js >= 19 at runtime (needed for `crypto.getRandomValues` as a global — see `engines` in [package.json](package.json)). The shipped `.d.ts` files are compatible down to **TypeScript 2.7**, and the compiled JS itself avoids syntax (`?.`, `??`) that older bundlers can't parse — no separate install/config needed to consume this package from a legacy toolchain (e.g. Angular 6).
18
+
19
+ ## BaseEnum — Java-style enums
20
+
21
+ `BaseEnum` is a base class for simulating Java enums: each constant is a singleton instance, and subclasses only need to `extends` and declare `static readonly` fields — no constructor to write.
22
+
23
+ ```ts
24
+ import { BaseEnum } from '@khgtrn/klib';
25
+
26
+ class Role extends BaseEnum<number> {
27
+ static readonly Admin = new Role(1, 'Administrator');
28
+ static readonly User = new Role(0, 'User');
29
+
30
+ isAdmin(): boolean {
31
+ return this === Role.Admin;
32
+ }
33
+ }
34
+
35
+ Role.Admin.label; // 'Administrator'
36
+ Role.Admin === Role.Admin; // true — identity is preserved
37
+ Role.Admin.equals(1); // true — compares by value
38
+ Role.values(); // [Role.Admin, Role.User]
39
+ Role.names(); // ['Admin', 'User']
40
+ Role.valueOf('Admin'); // Role.Admin (looks up by field name, throws if missing)
41
+ Role.fromValue(1); // Role.Admin (looks up by value, returns undefined if missing)
42
+ Role.Admin.name(); // 'Admin'
43
+ new Role(2, 'x'); // compile error — constructor is protected
44
+ ```
45
+
46
+ The constructor also accepts an optional `opts?: Record<string, any>` parameter for storing arbitrary extra data per constant.
47
+
48
+ ## Utility functions (`func.ts`)
49
+
50
+ | Function | Description |
51
+ | --- | --- |
52
+ | `isEmpty(value)` | Checks whether a value is empty (string, `0`, `false`, null/undefined, empty array/object) |
53
+ | `isNumber(value)` | Type-guard: a valid finite number (not NaN/Infinity) |
54
+ | `vi2en(s)` | Strips Vietnamese diacritics (`"Điều chỉnh"` -> `"Dieu chinh"`) |
55
+ | `crlf2lf(value)` | Normalizes `\r\n` -> `\n` |
56
+ | `removeNewline(value)` | Removes all newlines, trims surrounding whitespace |
57
+ | `shuffleArray(array)` | Shuffles an array in place (Fisher-Yates) |
58
+ | `objectValueToArray(obj)` | Collects an object's values into an array |
59
+ | `groupBy(list, fn)` | Groups items by a computed key |
60
+ | `removeByKey(objectOrArray, keys)` | Removes fields by name, recursively through nested structures |
61
+ | `removeEmptyValue(objectOrArray, options?)` | Removes `null`/`undefined`/`""` fields, recursively through nested structures |
62
+ | `randomString(length, opt?, specificChars?)` | Generates a random string, optionally requiring uppercase/lowercase/digit/custom characters |
63
+ | `byte2hex(b)` | Byte (0-255) -> 2-character hex |
64
+ | `uuid7bin()` / `uuid7()` | Generates a UUIDv7 (16 bytes / standard string) |
65
+ | `base64encode(str)` / `base64decode(base64)` | Base64 encode/decode (UTF-8, safe for large strings) |
66
+ | `getObjectValue(object, path)` / `ov(object, path)` | Reads a nested value via a `"a.b.c"` dot path |
67
+ | `toInt(value, defaultValue?)` | Converts to an integer, with a fallback for empty values |
68
+ | `numberToRoman(num)` / `romanToNumber(roman)` | Converts between Roman numerals and numbers (1-3999) |
69
+ | `isRomanNumber(value)` | Validates a Roman numeral string |
70
+ | `base64ToBlob(base64, mimeType, sliceSize?)` | Base64 -> `Blob` (browser) |
71
+ | `downloadFile(fileName, mimeType, base64Content, action?)` | Downloads/opens a file from base64 (browser) |
72
+ | `deepClone(obj)` | Deep-clones an object/array/`Date` |
73
+
74
+ See the JSDoc in [src/func.ts](src/func.ts) for full parameter/return details.
75
+
76
+ ## numberToWords — spelling out numbers
77
+
78
+ ```ts
79
+ import { numberToWords } from '@khgtrn/klib';
80
+
81
+ numberToWords(1005); // "một nghìn không trăm linh năm" (Vietnamese by default)
82
+ numberToWords(1005, 'en'); // "one thousand five"
83
+ numberToWords('1.05', 'vi'); // "một phẩy không năm"
84
+ numberToWords(-123, 'en'); // "negative one hundred twenty-three"
85
+ ```
86
+
87
+ - Integers can be passed as either a `number` or a `string`.
88
+ - Decimals **must be passed as a `string`** (e.g. `'1.05'`), since a `number` can't preserve a leading fractional zero and may pick up floating-point rounding errors — passing a decimal `number` throws with a hint to fix it.
89
+ - Supports up to billion-level magnitude, comfortably covering `Number.MAX_SAFE_INTEGER`.
90
+ - Designed to be easy to extend with more languages: see [src/number-to-words/locales.ts](src/number-to-words/locales.ts).
91
+
92
+ ## round — floating-point-safe rounding
93
+
94
+ ```ts
95
+ import { round } from '@khgtrn/klib';
96
+
97
+ round(491.66999999999996); // 491.67 (default precision = 10)
98
+ round(1.23456, 2); // 1.23
99
+ ```
100
+
101
+ Rounds `value` to `precision` decimal places (default `10`), mainly to clean up binary floating-point noise from arithmetic rather than to reduce genuine precision.
102
+
103
+ ## Development
104
+
105
+ ```bash
106
+ pnpm install
107
+ pnpm run build # builds dist/esm and dist/cjs
108
+ pnpm run play # builds then runs tests/a.ts as a quick smoke test
109
+ ```
110
+
111
+ ## License
112
+
113
+ MIT
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Base class for simulating Java-style enums in TypeScript.
3
+ *
4
+ * Subclasses only need to `extends BaseEnum<...>` and declare constants as
5
+ * `static readonly Xxx = new SubClass(value, label, opts?)`, without
6
+ * redeclaring a constructor. Because `BaseEnum`'s constructor is `protected`,
7
+ * subclasses inherit it while keeping the same protection — instances can't
8
+ * be `new`-ed from outside the class, which preserves enum singleton/identity
9
+ * semantics (`===` comparisons always work as expected).
10
+ *
11
+ * @typeParam T - Type of the `value` field (defaults to `number`).
12
+ */
13
+ export declare abstract class BaseEnum<T = number> {
14
+ readonly value: T;
15
+ readonly label: string;
16
+ readonly opts?: Record<string, any> | undefined;
17
+ /**
18
+ * Registry of every instance created, keyed per subclass and per `value`.
19
+ * The outer key is the subclass constructor (so each subclass has its own
20
+ * list), the inner key is each constant's `value`. Backs `values()`,
21
+ * `fromValue()` and `equals()`.
22
+ */
23
+ private static readonly registry;
24
+ /**
25
+ * Creates an enum constant. Only callable from within a subclass
26
+ * (the constructor is `protected`), typically from a `static readonly`
27
+ * field declaration.
28
+ *
29
+ * @param value - Identifying value of the constant (used by `fromValue()`, `equals()`).
30
+ * @param label - Display label/description of the constant.
31
+ * @param opts - Optional extra data, freely defined by the subclass as needed.
32
+ */
33
+ protected constructor(value: T, label: string, opts?: Record<string, any> | undefined);
34
+ /**
35
+ * Returns the names of the `static readonly` fields declared on the
36
+ * subclass, in declaration order. Mirrors the idea of an enum constant's
37
+ * name in Java, but here returns the names for every constant at once.
38
+ *
39
+ * @returns Array of constant names, e.g. `['Admin', 'User']`.
40
+ */
41
+ static names(this: Function): string[];
42
+ /**
43
+ * Returns every instance (constant) created on the subclass, similar to
44
+ * Java's `Enum.values()`.
45
+ *
46
+ * @returns Array of the subclass's instances, in creation order.
47
+ */
48
+ static values<T extends BaseEnum<any>>(this: Function & {
49
+ prototype: T;
50
+ }): T[];
51
+ /**
52
+ * Looks up a constant by its declared field name (matches Java's standard
53
+ * `Enum.valueOf(String)`). Unlike `fromValue()`, which looks up by `value`,
54
+ * this looks up by the static field's name (key).
55
+ *
56
+ * @param name - Name of the constant to look up, e.g. `'Admin'`.
57
+ * @returns The matching instance.
58
+ * @throws {Error} If no constant with that name exists.
59
+ */
60
+ static valueOf<T extends BaseEnum<any>>(this: Function & {
61
+ prototype: T;
62
+ }, name: string): T;
63
+ /**
64
+ * Looks up a constant by its `value` field.
65
+ *
66
+ * Note: `value`'s type isn't tied to the subclass's own `value` type
67
+ * parameter (unlike a conditional type would give) — that syntax requires
68
+ * TypeScript 2.8+, and this library targets TypeScript 2.7 and up.
69
+ *
70
+ * @param value - Value to look up (of the subclass's `T` type).
71
+ * @returns The matching instance, or `undefined` if none is found.
72
+ */
73
+ static fromValue<T extends BaseEnum<any>>(this: Function & {
74
+ prototype: T;
75
+ }, value: any): T | undefined;
76
+ /**
77
+ * Compares this constant against an arbitrary value.
78
+ *
79
+ * - If `other` is a `BaseEnum` instance: compares identity (`===`)
80
+ * directly, even if `other` belongs to a different enum class (always
81
+ * `false` in that case).
82
+ * - If `other` is a raw value (number/string/...): looks up the matching
83
+ * constant by `value` within this instance's own subclass, then compares
84
+ * identity.
85
+ * - Anything else (wrong type, no match, `null`/`undefined`...): returns
86
+ * `false`.
87
+ *
88
+ * @param other - Value or enum instance to compare against.
89
+ * @returns `true` if both refer to the same enum constant, otherwise `false`.
90
+ */
91
+ equals(other: any): boolean;
92
+ /**
93
+ * Returns the field name this instance was assigned to, similar to Java's
94
+ * `Enum.name()`.
95
+ *
96
+ * @returns The constant's name, e.g. `'Admin'`; an empty string if not
97
+ * found (a theoretical case that shouldn't occur under normal usage).
98
+ */
99
+ name(): string;
100
+ /**
101
+ * Converts the constant to a display string, defaulting to `label`.
102
+ *
103
+ * @returns The constant's display label.
104
+ */
105
+ toString(): string;
106
+ }
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseEnum = void 0;
4
+ /**
5
+ * Base class for simulating Java-style enums in TypeScript.
6
+ *
7
+ * Subclasses only need to `extends BaseEnum<...>` and declare constants as
8
+ * `static readonly Xxx = new SubClass(value, label, opts?)`, without
9
+ * redeclaring a constructor. Because `BaseEnum`'s constructor is `protected`,
10
+ * subclasses inherit it while keeping the same protection — instances can't
11
+ * be `new`-ed from outside the class, which preserves enum singleton/identity
12
+ * semantics (`===` comparisons always work as expected).
13
+ *
14
+ * @typeParam T - Type of the `value` field (defaults to `number`).
15
+ */
16
+ class BaseEnum {
17
+ /**
18
+ * Creates an enum constant. Only callable from within a subclass
19
+ * (the constructor is `protected`), typically from a `static readonly`
20
+ * field declaration.
21
+ *
22
+ * @param value - Identifying value of the constant (used by `fromValue()`, `equals()`).
23
+ * @param label - Display label/description of the constant.
24
+ * @param opts - Optional extra data, freely defined by the subclass as needed.
25
+ */
26
+ constructor(value, label, opts) {
27
+ this.value = value;
28
+ this.label = label;
29
+ this.opts = opts;
30
+ let map = BaseEnum.registry.get(this.constructor);
31
+ if (!map) {
32
+ map = new Map();
33
+ BaseEnum.registry.set(this.constructor, map);
34
+ }
35
+ map.set(value, this);
36
+ }
37
+ /**
38
+ * Returns the names of the `static readonly` fields declared on the
39
+ * subclass, in declaration order. Mirrors the idea of an enum constant's
40
+ * name in Java, but here returns the names for every constant at once.
41
+ *
42
+ * @returns Array of constant names, e.g. `['Admin', 'User']`.
43
+ */
44
+ static names() {
45
+ return Object.getOwnPropertyNames(this).filter((key) => key !== "prototype" && this[key] instanceof BaseEnum);
46
+ }
47
+ /**
48
+ * Returns every instance (constant) created on the subclass, similar to
49
+ * Java's `Enum.values()`.
50
+ *
51
+ * @returns Array of the subclass's instances, in creation order.
52
+ */
53
+ static values() {
54
+ var _a;
55
+ return Array.from(((_a = BaseEnum.registry.get(this)) !== null && _a !== void 0 ? _a : new Map()).values());
56
+ }
57
+ /**
58
+ * Looks up a constant by its declared field name (matches Java's standard
59
+ * `Enum.valueOf(String)`). Unlike `fromValue()`, which looks up by `value`,
60
+ * this looks up by the static field's name (key).
61
+ *
62
+ * @param name - Name of the constant to look up, e.g. `'Admin'`.
63
+ * @returns The matching instance.
64
+ * @throws {Error} If no constant with that name exists.
65
+ */
66
+ static valueOf(name) {
67
+ const constant = this[name];
68
+ if (!(constant instanceof BaseEnum)) {
69
+ throw new Error(`No enum constant ${this.name}.${name}`);
70
+ }
71
+ return constant;
72
+ }
73
+ /**
74
+ * Looks up a constant by its `value` field.
75
+ *
76
+ * Note: `value`'s type isn't tied to the subclass's own `value` type
77
+ * parameter (unlike a conditional type would give) — that syntax requires
78
+ * TypeScript 2.8+, and this library targets TypeScript 2.7 and up.
79
+ *
80
+ * @param value - Value to look up (of the subclass's `T` type).
81
+ * @returns The matching instance, or `undefined` if none is found.
82
+ */
83
+ static fromValue(value) {
84
+ var _a;
85
+ return (_a = BaseEnum.registry.get(this)) === null || _a === void 0 ? void 0 : _a.get(value);
86
+ }
87
+ /**
88
+ * Compares this constant against an arbitrary value.
89
+ *
90
+ * - If `other` is a `BaseEnum` instance: compares identity (`===`)
91
+ * directly, even if `other` belongs to a different enum class (always
92
+ * `false` in that case).
93
+ * - If `other` is a raw value (number/string/...): looks up the matching
94
+ * constant by `value` within this instance's own subclass, then compares
95
+ * identity.
96
+ * - Anything else (wrong type, no match, `null`/`undefined`...): returns
97
+ * `false`.
98
+ *
99
+ * @param other - Value or enum instance to compare against.
100
+ * @returns `true` if both refer to the same enum constant, otherwise `false`.
101
+ */
102
+ equals(other) {
103
+ var _a;
104
+ if (other instanceof BaseEnum) {
105
+ return this === other;
106
+ }
107
+ return ((_a = BaseEnum.registry.get(this.constructor)) === null || _a === void 0 ? void 0 : _a.get(other)) === this;
108
+ }
109
+ /**
110
+ * Returns the field name this instance was assigned to, similar to Java's
111
+ * `Enum.name()`.
112
+ *
113
+ * @returns The constant's name, e.g. `'Admin'`; an empty string if not
114
+ * found (a theoretical case that shouldn't occur under normal usage).
115
+ */
116
+ name() {
117
+ const ctor = this.constructor;
118
+ const key = Object.getOwnPropertyNames(ctor).find((k) => k !== "prototype" && ctor[k] === this);
119
+ return key !== null && key !== void 0 ? key : "";
120
+ }
121
+ /**
122
+ * Converts the constant to a display string, defaulting to `label`.
123
+ *
124
+ * @returns The constant's display label.
125
+ */
126
+ toString() {
127
+ return this.label;
128
+ }
129
+ }
130
+ exports.BaseEnum = BaseEnum;
131
+ /**
132
+ * Registry of every instance created, keyed per subclass and per `value`.
133
+ * The outer key is the subclass constructor (so each subclass has its own
134
+ * list), the inner key is each constant's `value`. Backs `values()`,
135
+ * `fromValue()` and `equals()`.
136
+ */
137
+ BaseEnum.registry = new Map();
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Checks whether a value is considered "empty".
3
+ *
4
+ * - string: empty after trimming.
5
+ * - number: equal to `0`.
6
+ * - boolean: `false`.
7
+ * - `null`/`undefined`: always empty.
8
+ * - array: length `0`.
9
+ * - other objects: no own enumerable keys.
10
+ * - anything else (function, symbol, ...): never empty.
11
+ *
12
+ * @param value - Value to check.
13
+ * @returns `true` if the value is considered empty.
14
+ */
15
+ export declare function isEmpty(value: any): boolean;
16
+ /**
17
+ * Checks whether a value is a valid number (not `NaN`, not `Infinity`).
18
+ * @param value - Value to check.
19
+ * @returns Type-guard: `true` if `value` is a finite number.
20
+ */
21
+ export declare function isNumber(value: any): value is number;
22
+ /**
23
+ * Converts Vietnamese diacritics to their plain ASCII equivalents
24
+ * (e.g. `"Điều chỉnh"` -> `"Dieu chinh"`).
25
+ *
26
+ * @param s - Input string.
27
+ * @returns The string with Vietnamese diacritics removed.
28
+ */
29
+ export declare function vi2en(s: string): string;
30
+ /**
31
+ * Normalizes Windows-style line endings (`\r\n`) to Unix-style (`\n`).
32
+ * @param value - Input string.
33
+ * @returns The string with all `\r\n` replaced by `\n`.
34
+ */
35
+ export declare function crlf2lf(value: string): string;
36
+ /**
37
+ * Removes every newline from a string, after normalizing line endings and
38
+ * trimming surrounding whitespace.
39
+ * @param value - Input string.
40
+ * @returns The string with all newlines removed.
41
+ */
42
+ export declare function removeNewline(value: string): string;
43
+ /**
44
+ * Shuffles an array in place using the Fisher-Yates algorithm.
45
+ * @param array - Array to shuffle (mutated directly).
46
+ * @returns The same array reference, shuffled.
47
+ */
48
+ export declare function shuffleArray(array: any[]): any[];
49
+ /**
50
+ * Collects an object's own enumerable values into an array.
51
+ * @param obj - Source object. `null`/`undefined` yields an empty array.
52
+ * @returns Array of the object's values.
53
+ */
54
+ export declare function objectValueToArray(obj: any): any[];
55
+ /**
56
+ * Groups list items by the key returned from `fn`, similar to Lodash's
57
+ * `groupBy`. Keys are compared by their JSON representation, so they can be
58
+ * primitives or plain objects.
59
+ *
60
+ * @param list - Array-like list of items to group. `null`/`undefined` yields an empty array.
61
+ * @param fn - Maps an item to the value used to group it.
62
+ * @returns Array of groups, each an array of items sharing the same key.
63
+ */
64
+ export declare function groupBy(list: any, fn: (item: any) => any): any[];
65
+ /**
66
+ * Remove keys from object or array
67
+ * @param objectOrArray Object or array
68
+ * @param keys Keys to remove
69
+ * @returns Object or array with keys removed
70
+ */
71
+ export declare function removeByKey<T = any>(objectOrArray: T, keys: string[]): T;
72
+ /**
73
+ * Remove empty values from object or array
74
+ * @param objectOrArray Object or array
75
+ * @param options Options:
76
+ * - removeNull: Remove null values. Default: true
77
+ * - removeUndefined: Remove undefined values. Default: true
78
+ * - removeEmptyString: Remove empty string values. Default: true
79
+ * @returns Object or array with empty values removed
80
+ */
81
+ export declare function removeEmptyValue<T = any>(objectOrArray: T, options?: {
82
+ removeNull?: boolean;
83
+ removeUndefined?: boolean;
84
+ removeEmptyString?: boolean;
85
+ }): T;
86
+ /**
87
+ * Generates a random string of the given length, optionally guaranteeing at
88
+ * least one character from each requested category ("upper", "lower",
89
+ * "number", "specific").
90
+ *
91
+ * @param length - Desired length of the resulting string.
92
+ * @param opt - Character categories that must each appear at least once.
93
+ * `"specific"` only counts as a required category when `specificChars` is
94
+ * non-empty; otherwise it's silently ignored (as if not requested at all).
95
+ * @param specificChars - Custom character set used for the `"specific"` category.
96
+ * @returns A random string of exactly `length` characters. If `opt` is empty
97
+ * (or every requested category ends up unusable), falls back to alphanumeric
98
+ * characters rather than returning an empty string.
99
+ * @throws {Error} If `length` is smaller than the number of required categories,
100
+ * since the "at least one of each" guarantee couldn't fit otherwise.
101
+ */
102
+ export declare function randomString(length: number, opt?: ("upper" | "lower" | "number" | "specific")[], specificChars?: string): string;
103
+ /**
104
+ * Formats a byte value (0-255) as a zero-padded, 2-digit lowercase hex string.
105
+ * Intended for internal use with well-formed byte values (e.g. from a
106
+ * `Uint8Array`); values outside 0-255 are not validated.
107
+ *
108
+ * @param b - Byte value, expected in the 0-255 range.
109
+ * @returns 2-character hex string, e.g. `"0f"`.
110
+ */
111
+ export declare function byte2hex(b: number): string;
112
+ /**
113
+ * Generates the raw 16 bytes of a UUIDv7 (timestamp + random, RFC 4122
114
+ * variant). Relies on the Web Crypto `crypto.getRandomValues` API, available
115
+ * in browsers and modern Node.js.
116
+ *
117
+ * @returns 16-byte `Uint8Array` encoding a UUIDv7.
118
+ */
119
+ export declare function uuid7bin(): Uint8Array;
120
+ /**
121
+ * Generates a UUIDv7 string (e.g. `"01890a5d-ac96-774b-bcce-b302099a8057"`).
122
+ * @returns UUIDv7 in the standard 8-4-4-4-12 hex string format.
123
+ */
124
+ export declare function uuid7(): string;
125
+ /**
126
+ * Encodes a string to base64 (UTF-8 bytes).
127
+ * @param str - String to encode.
128
+ * @returns Base64-encoded string.
129
+ */
130
+ export declare function base64encode(str: string): string;
131
+ /**
132
+ * Decodes a base64 string back to its original (UTF-8) string.
133
+ * @param base64 - Base64-encoded string.
134
+ * @returns Decoded string.
135
+ */
136
+ export declare function base64decode(base64: string): string;
137
+ /**
138
+ * Reads a nested property from an object using a dot-separated path.
139
+ * Example: `getObjectValue(user, 'abc.def')` returns `user.abc.def`.
140
+ *
141
+ * Equivalent to optional chaining (`object?.abc?.def`), for use on
142
+ * TypeScript versions below 3.7 (e.g. Angular versions below 9). On newer
143
+ * TypeScript versions, prefer optional chaining directly instead.
144
+ *
145
+ * @param object - Source object.
146
+ * @param path - Dot-separated property path.
147
+ * @returns The resolved value, or `null`/`undefined` if any segment is missing.
148
+ * @global
149
+ */
150
+ export declare function getObjectValue(object: null | undefined | Record<string, any>, path: string): any;
151
+ /**
152
+ * Short alias for {@link getObjectValue}.
153
+ * @param object - Source object.
154
+ * @param path - Dot-separated property path.
155
+ * @returns The resolved value, or `null`/`undefined` if any segment is missing.
156
+ */
157
+ export declare function ov(object: null | undefined | Record<string, any>, path: string): any;
158
+ /**
159
+ * Converts a value to an integer, similar to `parseInt`/`Number` but with an
160
+ * explicit fallback for empty values (see {@link isEmpty}).
161
+ *
162
+ * @param value - Value to convert.
163
+ * @param defaultValue - Value returned when `value` is empty. Defaults to `0`.
164
+ * @returns The parsed integer, `defaultValue` if `value` is empty, or `NaN`
165
+ * if `value` is a non-numeric, non-empty string.
166
+ */
167
+ export declare function toInt(value: any, defaultValue?: number | null | undefined): number | null | undefined;
168
+ /**
169
+ * Converts a positive integer to a Roman numeral. Only supports the standard
170
+ * range (1-3999); larger numbers produce a non-standard repeating "M" prefix.
171
+ *
172
+ * @param num - Number to convert.
173
+ * @returns Roman numeral string, or `""` if `num` is zero or negative.
174
+ */
175
+ export declare function numberToRoman(num: number): string;
176
+ /**
177
+ * Converts a Roman numeral string to a number. Does not validate that the
178
+ * input is a well-formed Roman numeral (use {@link isRomanNumber} first if
179
+ * that matters) — unrecognized characters make the result `NaN`.
180
+ *
181
+ * @param roman - Roman numeral string (case-sensitive, uppercase letters).
182
+ * @returns The numeric value, or `NaN` if `roman` contains unrecognized characters.
183
+ */
184
+ export declare function romanToNumber(roman: string): number;
185
+ /**
186
+ * Checks whether a string is a well-formed Roman numeral (1-3999), matching
187
+ * the standard subtractive notation. Case-insensitive.
188
+ *
189
+ * @param value - String to validate.
190
+ * @returns `true` if `value` is a valid Roman numeral.
191
+ */
192
+ export declare function isRomanNumber(value: string): boolean;
193
+ /**
194
+ * Converts a base64 string to a `Blob`. Browser-only (relies on `atob` and
195
+ * `Blob`).
196
+ *
197
+ * @param base64 - Base64-encoded content.
198
+ * @param mimeType - MIME type to assign to the resulting `Blob`.
199
+ * @param sliceSize - Chunk size (in decoded characters) used while building
200
+ * the byte arrays, to avoid excessive memory allocation for large inputs.
201
+ * @returns A `Blob` containing the decoded bytes.
202
+ */
203
+ export declare function base64ToBlob(base64: string, mimeType: string, sliceSize?: number): Blob;
204
+ /**
205
+ * Triggers a browser download (or opens in a tab) for base64-encoded file
206
+ * content. Browser-only (relies on `document`, `URL.createObjectURL`).
207
+ *
208
+ * @param fileName - Suggested file name for the download.
209
+ * @param mimeType - MIME type/subtype (a bare subtype like `"pdf"` is
210
+ * expanded to `"application/pdf"`).
211
+ * @param base64Content - Base64-encoded file content.
212
+ * @param action - `"download"` saves the file, `"open"` opens it in the same
213
+ * tab, `"open_blank"` opens it in a new tab. Defaults to `"download"`.
214
+ */
215
+ export declare function downloadFile(fileName: string, mimeType: string, base64Content: string, action?: "download" | "open" | "open_blank"): void;
216
+ /**
217
+ * Recursively clones plain objects, arrays and `Date` instances.
218
+ *
219
+ * Note: `Date` has no own enumerable properties, so a plain for-in copy
220
+ * would silently turn every `Date` into an empty `{}` — it's special-cased
221
+ * here. Other special object types (`Map`, `Set`, `RegExp`, ...) are not
222
+ * handled and will also be cloned as plain `{}`.
223
+ *
224
+ * @param obj - Value to clone.
225
+ * @returns A deep copy of `obj` (primitives are returned as-is).
226
+ */
227
+ export declare function deepClone(obj: any): any;