@simplysm/core-common 13.0.81 → 13.0.83

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.
@@ -0,0 +1,76 @@
1
+ # Number Utilities
2
+
3
+ Imported as the `num` namespace.
4
+
5
+ ```typescript
6
+ import { num } from "@simplysm/core-common";
7
+ ```
8
+
9
+ ## parseInt
10
+
11
+ ```typescript
12
+ function parseInt(text: unknown): number | undefined;
13
+ ```
14
+
15
+ Parses a string to integer after stripping non-numeric characters (except `0-9`, `-`, `.`). Returns `undefined` for non-parsable input. For strings with decimals, returns only the integer part (truncates).
16
+
17
+ ---
18
+
19
+ ## parseFloat
20
+
21
+ ```typescript
22
+ function parseFloat(text: unknown): number | undefined;
23
+ ```
24
+
25
+ Parses a string to float after stripping non-numeric characters. Returns `undefined` for non-parsable input.
26
+
27
+ ---
28
+
29
+ ## parseRoundedInt
30
+
31
+ ```typescript
32
+ function parseRoundedInt(text: unknown): number | undefined;
33
+ ```
34
+
35
+ Parses to float then rounds to the nearest integer.
36
+
37
+ ---
38
+
39
+ ## isNullOrEmpty
40
+
41
+ ```typescript
42
+ function isNullOrEmpty(val: number | undefined): val is 0 | undefined;
43
+ ```
44
+
45
+ Type guard that returns `true` for `undefined`, `null`, or `0`.
46
+
47
+ ---
48
+
49
+ ## format
50
+
51
+ ```typescript
52
+ function format(val: number, digit?: { max?: number; min?: number }): string;
53
+ function format(val: number | undefined, digit?: { max?: number; min?: number }): string | undefined;
54
+ ```
55
+
56
+ Formats a number with locale-aware thousand separators. Control decimal places with `max` (maximum) and `min` (minimum, zero-padded).
57
+
58
+ ---
59
+
60
+ ## Usage Examples
61
+
62
+ ```typescript
63
+ import { num } from "@simplysm/core-common";
64
+
65
+ num.parseInt("$1,234"); // 1234
66
+ num.parseInt("12.34"); // 12
67
+ num.parseFloat("$1,234.56"); // 1234.56
68
+ num.parseRoundedInt("12.6"); // 13
69
+
70
+ num.isNullOrEmpty(0); // true
71
+ num.isNullOrEmpty(undefined); // true
72
+ num.isNullOrEmpty(42); // false
73
+
74
+ num.format(1234.567, { max: 2 }); // "1,234.57"
75
+ num.format(1234, { min: 2 }); // "1,234.00"
76
+ ```
@@ -0,0 +1,165 @@
1
+ # Object Utilities
2
+
3
+ Imported as the `obj` namespace. Provides deep clone, equality, merge, object manipulation, and chain-path access.
4
+
5
+ ```typescript
6
+ import { obj } from "@simplysm/core-common";
7
+ ```
8
+
9
+ ## clone
10
+
11
+ ```typescript
12
+ function clone<T>(source: T): T;
13
+ ```
14
+
15
+ Deep clone supporting circular references, custom types (`DateTime`, `DateOnly`, `Time`, `Uuid`, `Uint8Array`, `Error`, `RegExp`, `Map`, `Set`), and prototype chain preservation. Functions and Symbols maintain references.
16
+
17
+ ---
18
+
19
+ ## equal
20
+
21
+ ```typescript
22
+ function equal(source: unknown, target: unknown, options?: EqualOptions): boolean;
23
+
24
+ interface EqualOptions {
25
+ topLevelIncludes?: string[];
26
+ topLevelExcludes?: string[];
27
+ ignoreArrayIndex?: boolean;
28
+ shallow?: boolean;
29
+ }
30
+ ```
31
+
32
+ Deep equality comparison with support for custom types. Options allow filtering compared keys at top level, ignoring array order (O(n^2)), or doing shallow reference comparison.
33
+
34
+ ---
35
+
36
+ ## merge
37
+
38
+ ```typescript
39
+ function merge<S, T>(source: S, target: T, opt?: MergeOptions): S & T;
40
+
41
+ interface MergeOptions {
42
+ arrayProcess?: "replace" | "concat";
43
+ useDelTargetNull?: boolean;
44
+ }
45
+ ```
46
+
47
+ Deep merge of target into source. Returns a new object (immutable). Arrays default to replacement; use `"concat"` for deduplication via Set. When `useDelTargetNull` is true, `null` in target deletes the key.
48
+
49
+ ---
50
+
51
+ ## merge3
52
+
53
+ ```typescript
54
+ function merge3<S, O, T>(
55
+ source: S,
56
+ origin: O,
57
+ target: T,
58
+ optionsObj?: Record<string, Merge3KeyOptions>,
59
+ ): { conflict: boolean; result: O & S & T };
60
+
61
+ interface Merge3KeyOptions {
62
+ keys?: string[];
63
+ excludes?: string[];
64
+ ignoreArrayIndex?: boolean;
65
+ }
66
+ ```
67
+
68
+ Three-way merge comparing source, origin, and target. Returns whether a conflict occurred and the merged result.
69
+
70
+ ---
71
+
72
+ ## omit / pick
73
+
74
+ ```typescript
75
+ function omit<T, K extends keyof T>(item: T, omitKeys: K[]): Omit<T, K>;
76
+ function pick<T, K extends keyof T>(item: T, pickKeys: K[]): Pick<T, K>;
77
+ ```
78
+
79
+ Create new objects by excluding or including specific keys.
80
+
81
+ ---
82
+
83
+ ## Chain Access
84
+
85
+ ```typescript
86
+ function getChainValue(obj: unknown, chain: string): unknown;
87
+ function getChainValue(obj: unknown, chain: string, optional: true): unknown | undefined;
88
+ function setChainValue(obj: unknown, chain: string, value: unknown): void;
89
+ function deleteChainValue(obj: unknown, chain: string): void;
90
+ ```
91
+
92
+ Get, set, or delete values using dot-bracket chain paths (e.g., `"a.b[0].c"`).
93
+
94
+ ---
95
+
96
+ ## keys / entries / fromEntries
97
+
98
+ ```typescript
99
+ function keys<T extends object>(obj: T): (keyof T)[];
100
+ function entries<T extends object>(obj: T): [keyof T, T[keyof T]][];
101
+ function fromEntries<T extends [string, unknown]>(entries: T[]): { [K in T[0]]: T[1] };
102
+ ```
103
+
104
+ Type-safe wrappers around `Object.keys`, `Object.entries`, and `Object.fromEntries`.
105
+
106
+ ---
107
+
108
+ ## map
109
+
110
+ ```typescript
111
+ function map<S extends object, K extends string, V>(
112
+ obj: S,
113
+ fn: (key: keyof S, value: S[keyof S]) => [K | null, V],
114
+ ): Record<K | Extract<keyof S, string>, V>;
115
+ ```
116
+
117
+ Transforms each entry of an object. Return `[null, newValue]` to keep the original key, or `[newKey, newValue]` to rename.
118
+
119
+ ---
120
+
121
+ ## Type Utilities
122
+
123
+ ```typescript
124
+ type UndefToOptional<T>; // { a: string; b: string | undefined } -> { a: string; b?: string | undefined }
125
+ type OptionalToUndef<T>; // { a: string; b?: string } -> { a: string; b: string | undefined }
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Usage Examples
131
+
132
+ ```typescript
133
+ import { obj } from "@simplysm/core-common";
134
+
135
+ // Clone
136
+ const original = { a: 1, nested: { b: 2 } };
137
+ const copy = obj.clone(original);
138
+
139
+ // Equal
140
+ obj.equal({ a: 1 }, { a: 1 }); // true
141
+ obj.equal([1, 2], [2, 1], { ignoreArrayIndex: true }); // true
142
+
143
+ // Merge
144
+ obj.merge({ a: 1, b: 2 }, { b: 3, c: 4 }); // { a: 1, b: 3, c: 4 }
145
+
146
+ // 3-way merge
147
+ const { conflict, result } = obj.merge3(
148
+ { a: 1, b: 2 }, // source
149
+ { a: 1, b: 1 }, // origin
150
+ { a: 2, b: 1 }, // target
151
+ );
152
+ // conflict: false, result: { a: 2, b: 2 }
153
+
154
+ // Omit / Pick
155
+ obj.omit({ name: "Alice", age: 30, email: "a@b.c" }, ["email"]);
156
+ // { name: "Alice", age: 30 }
157
+
158
+ // Chain access
159
+ const data = { a: { b: [{ c: 42 }] } };
160
+ obj.getChainValue(data, "a.b[0].c"); // 42
161
+ obj.setChainValue(data, "a.b[0].c", 99);
162
+
163
+ // Type-safe Object helpers
164
+ obj.keys({ x: 1, y: 2 }); // ["x", "y"] with type (keyof { x; y })[]
165
+ ```
@@ -0,0 +1,54 @@
1
+ # Path Utilities
2
+
3
+ Imported as the `path` namespace. Browser-safe replacements for Node.js `path` module functions.
4
+
5
+ ```typescript
6
+ import { path } from "@simplysm/core-common";
7
+ ```
8
+
9
+ **Note:** Supports POSIX-style paths (forward slash `/`) only. Windows backslash paths are not supported.
10
+
11
+ ## join
12
+
13
+ ```typescript
14
+ function join(...segments: string[]): string;
15
+ ```
16
+
17
+ Combines path segments (replacement for `path.join`).
18
+
19
+ ---
20
+
21
+ ## basename
22
+
23
+ ```typescript
24
+ function basename(filePath: string, ext?: string): string;
25
+ ```
26
+
27
+ Extracts the filename from a path. Optionally removes the specified extension.
28
+
29
+ ---
30
+
31
+ ## extname
32
+
33
+ ```typescript
34
+ function extname(filePath: string): string;
35
+ ```
36
+
37
+ Extracts the file extension. Hidden files (e.g., `.gitignore`) return an empty string, matching Node.js behavior.
38
+
39
+ ---
40
+
41
+ ## Usage Examples
42
+
43
+ ```typescript
44
+ import { path } from "@simplysm/core-common";
45
+
46
+ path.join("a", "b", "c.txt"); // "a/b/c.txt"
47
+ path.join("/root/", "/dir/", "file"); // "/root/dir/file"
48
+
49
+ path.basename("/dir/file.txt"); // "file.txt"
50
+ path.basename("/dir/file.txt", ".txt"); // "file"
51
+
52
+ path.extname("archive.tar.gz"); // ".gz"
53
+ path.extname(".gitignore"); // ""
54
+ ```
@@ -0,0 +1,40 @@
1
+ # Primitive Utilities
2
+
3
+ Imported as the `primitive` namespace. Runtime type-string inference.
4
+
5
+ ```typescript
6
+ import { primitive } from "@simplysm/core-common";
7
+ ```
8
+
9
+ ## typeStr
10
+
11
+ ```typescript
12
+ function typeStr(value: PrimitiveTypeMap[PrimitiveTypeStr]): PrimitiveTypeStr;
13
+ ```
14
+
15
+ Infers the `PrimitiveTypeStr` from a runtime value. Throws `ArgumentError` if the type is not supported.
16
+
17
+ **Mapping:**
18
+ - `string` -> `"string"`
19
+ - `number` -> `"number"`
20
+ - `boolean` -> `"boolean"`
21
+ - `DateTime` -> `"DateTime"`
22
+ - `DateOnly` -> `"DateOnly"`
23
+ - `Time` -> `"Time"`
24
+ - `Uuid` -> `"Uuid"`
25
+ - `Uint8Array` -> `"Bytes"`
26
+
27
+ ---
28
+
29
+ ## Usage Examples
30
+
31
+ ```typescript
32
+ import { primitive, DateTime, Uuid } from "@simplysm/core-common";
33
+
34
+ primitive.typeStr("hello"); // "string"
35
+ primitive.typeStr(123); // "number"
36
+ primitive.typeStr(true); // "boolean"
37
+ primitive.typeStr(new DateTime()); // "DateTime"
38
+ primitive.typeStr(Uuid.generate()); // "Uuid"
39
+ primitive.typeStr(new Uint8Array()); // "Bytes"
40
+ ```
@@ -0,0 +1,79 @@
1
+ # String Utilities
2
+
3
+ Imported as the `str` namespace.
4
+
5
+ ```typescript
6
+ import { str } from "@simplysm/core-common";
7
+ ```
8
+
9
+ ## getKoreanSuffix
10
+
11
+ ```typescript
12
+ function getKoreanSuffix(text: string, type: "eul" | "eun" | "i" | "wa" | "rang" | "ro" | "ra"): string;
13
+ ```
14
+
15
+ Returns the appropriate Korean grammatical particle based on whether the last character has a final consonant (jongseong). Supports seven particle types.
16
+
17
+ ---
18
+
19
+ ## replaceFullWidth
20
+
21
+ ```typescript
22
+ function replaceFullWidth(str: string): string;
23
+ ```
24
+
25
+ Converts full-width characters to half-width: uppercase/lowercase letters, digits, spaces, and parentheses.
26
+
27
+ ---
28
+
29
+ ## Case Conversion
30
+
31
+ ```typescript
32
+ function toPascalCase(str: string): string; // "hello-world" -> "HelloWorld"
33
+ function toCamelCase(str: string): string; // "hello-world" -> "helloWorld"
34
+ function toKebabCase(str: string): string; // "HelloWorld" -> "hello-world"
35
+ function toSnakeCase(str: string): string; // "HelloWorld" -> "hello_world"
36
+ ```
37
+
38
+ Converts between PascalCase, camelCase, kebab-case, and snake_case. Input separators (`-`, `_`, `.`) are recognized.
39
+
40
+ ---
41
+
42
+ ## isNullOrEmpty
43
+
44
+ ```typescript
45
+ function isNullOrEmpty(str: string | undefined): str is "" | undefined;
46
+ ```
47
+
48
+ Type guard that returns `true` for `undefined`, `null`, or empty string.
49
+
50
+ ---
51
+
52
+ ## insert
53
+
54
+ ```typescript
55
+ function insert(str: string, index: number, insertString: string): string;
56
+ ```
57
+
58
+ Inserts a string at the specified position.
59
+
60
+ ---
61
+
62
+ ## Usage Examples
63
+
64
+ ```typescript
65
+ import { str } from "@simplysm/core-common";
66
+
67
+ str.toPascalCase("hello-world"); // "HelloWorld"
68
+ str.toCamelCase("HelloWorld"); // "helloWorld"
69
+ str.toKebabCase("HelloWorld"); // "hello-world"
70
+ str.toSnakeCase("helloWorld"); // "hello_world"
71
+
72
+ str.replaceFullWidth("ABC123"); // "ABC123"
73
+
74
+ str.isNullOrEmpty(""); // true
75
+ str.isNullOrEmpty(undefined); // true
76
+ str.isNullOrEmpty("hello"); // false
77
+
78
+ str.insert("Hello World", 5, ","); // "Hello, World"
79
+ ```
@@ -0,0 +1,105 @@
1
+ # Template Strings
2
+
3
+ Tagged template literals for IDE code highlighting with automatic indentation normalization.
4
+
5
+ These are directly exported (not namespaced).
6
+
7
+ ```typescript
8
+ import { js, ts, html, tsql, mysql, pgsql } from "@simplysm/core-common";
9
+ ```
10
+
11
+ ## js
12
+
13
+ ```typescript
14
+ function js(strings: TemplateStringsArray, ...values: unknown[]): string;
15
+ ```
16
+
17
+ Template tag for JavaScript code. Provides syntax highlighting in supported IDEs and normalizes indentation.
18
+
19
+ ---
20
+
21
+ ## ts
22
+
23
+ ```typescript
24
+ function ts(strings: TemplateStringsArray, ...values: unknown[]): string;
25
+ ```
26
+
27
+ Template tag for TypeScript code.
28
+
29
+ ---
30
+
31
+ ## html
32
+
33
+ ```typescript
34
+ function html(strings: TemplateStringsArray, ...values: unknown[]): string;
35
+ ```
36
+
37
+ Template tag for HTML markup.
38
+
39
+ ---
40
+
41
+ ## tsql
42
+
43
+ ```typescript
44
+ function tsql(strings: TemplateStringsArray, ...values: unknown[]): string;
45
+ ```
46
+
47
+ Template tag for MSSQL T-SQL queries.
48
+
49
+ ---
50
+
51
+ ## mysql
52
+
53
+ ```typescript
54
+ function mysql(strings: TemplateStringsArray, ...values: unknown[]): string;
55
+ ```
56
+
57
+ Template tag for MySQL SQL queries.
58
+
59
+ ---
60
+
61
+ ## pgsql
62
+
63
+ ```typescript
64
+ function pgsql(strings: TemplateStringsArray, ...values: unknown[]): string;
65
+ ```
66
+
67
+ Template tag for PostgreSQL SQL queries.
68
+
69
+ ---
70
+
71
+ ## Behavior
72
+
73
+ All template tags perform the same operations:
74
+ 1. Concatenate the template strings with interpolated values.
75
+ 2. Strip leading and trailing empty lines.
76
+ 3. Determine the minimum indentation across all non-empty lines.
77
+ 4. Remove that common indentation prefix from every line.
78
+
79
+ ---
80
+
81
+ ## Usage Examples
82
+
83
+ ```typescript
84
+ import { js, html, tsql } from "@simplysm/core-common";
85
+
86
+ const name = "World";
87
+ const code = js`
88
+ function hello() {
89
+ return "${name}";
90
+ }
91
+ `;
92
+ // "function hello() {\n return \"World\";\n}"
93
+
94
+ const markup = html`
95
+ <div class="container">
96
+ <span>${name}</span>
97
+ </div>
98
+ `;
99
+
100
+ const query = tsql`
101
+ SELECT TOP 10 *
102
+ FROM Users
103
+ WHERE Name LIKE '%${name}%'
104
+ `;
105
+ ```
@@ -0,0 +1,53 @@
1
+ # Transfer Utilities
2
+
3
+ Imported as the `transfer` namespace. Serialization/deserialization for Worker data transfer.
4
+
5
+ ```typescript
6
+ import { transfer } from "@simplysm/core-common";
7
+ ```
8
+
9
+ ## encode
10
+
11
+ ```typescript
12
+ function encode(obj: unknown): {
13
+ result: unknown;
14
+ transferList: Transferable[];
15
+ };
16
+ ```
17
+
18
+ Converts objects with custom types into plain objects suitable for `postMessage`. Returns the encoded result and a list of transferable `ArrayBuffer` objects for zero-copy transfer. Throws `TypeError` on circular references (with path info).
19
+
20
+ **Supported types:** `Date`, `DateTime`, `DateOnly`, `Time`, `Uuid`, `RegExp`, `Error`, `Uint8Array`, `Array`, `Map`, `Set`, plain objects.
21
+
22
+ ---
23
+
24
+ ## decode
25
+
26
+ ```typescript
27
+ function decode(obj: unknown): unknown;
28
+ ```
29
+
30
+ Restores tagged objects (with `__type__` markers) back to their original custom types. Use this on the receiving side of Worker messages.
31
+
32
+ ---
33
+
34
+ ## Usage Examples
35
+
36
+ ```typescript
37
+ import { transfer, DateTime, Uuid } from "@simplysm/core-common";
38
+
39
+ // Sending data to Worker
40
+ const data = {
41
+ id: Uuid.generate(),
42
+ timestamp: new DateTime(),
43
+ buffer: new Uint8Array([1, 2, 3]),
44
+ };
45
+ const { result, transferList } = transfer.encode(data);
46
+ worker.postMessage(result, transferList);
47
+
48
+ // Receiving data from Worker
49
+ worker.onmessage = (event) => {
50
+ const decoded = transfer.decode(event.data);
51
+ // decoded.id is Uuid, decoded.timestamp is DateTime, etc.
52
+ };
53
+ ```