@simplysm/core-common 13.0.85 → 13.0.87
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 +105 -27
- package/dist/utils/xml.js +1 -1
- package/dist/utils/xml.js.map +1 -1
- package/docs/features.md +300 -57
- package/docs/types.md +287 -188
- package/docs/utilities.md +359 -0
- package/package.json +2 -2
- package/src/utils/xml.ts +2 -2
- package/docs/byte-utilities.md +0 -55
- package/docs/date-format-utilities.md +0 -96
- package/docs/environment.md +0 -35
- package/docs/error-utilities.md +0 -35
- package/docs/errors.md +0 -79
- package/docs/extensions.md +0 -201
- package/docs/json-utilities.md +0 -57
- package/docs/number-utilities.md +0 -76
- package/docs/object-utilities.md +0 -165
- package/docs/path-utilities.md +0 -54
- package/docs/primitive-utilities.md +0 -40
- package/docs/string-utilities.md +0 -79
- package/docs/template-strings.md +0 -105
- package/docs/transfer-utilities.md +0 -53
- package/docs/wait-utilities.md +0 -50
- package/docs/xml-utilities.md +0 -48
- package/docs/zip-archive.md +0 -61
package/docs/template-strings.md
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
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
|
-
```
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
```
|
package/docs/wait-utilities.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# Wait Utilities
|
|
2
|
-
|
|
3
|
-
Imported as the `wait` namespace. Async timing utilities.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import { wait } from "@simplysm/core-common";
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## time
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
function time(millisecond: number): Promise<void>;
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Waits for the specified number of milliseconds.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## until
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
function until(
|
|
23
|
-
forwarder: () => boolean | Promise<boolean>,
|
|
24
|
-
milliseconds?: number,
|
|
25
|
-
maxCount?: number,
|
|
26
|
-
): Promise<void>;
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Polls a condition at the given interval (default: 100ms) until it returns `true`. Returns immediately if the condition is `true` on the first call. Throws `TimeoutError` if `maxCount` attempts are exhausted.
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## Usage Examples
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
import { wait } from "@simplysm/core-common";
|
|
37
|
-
|
|
38
|
-
// Simple delay
|
|
39
|
-
await wait.time(1000); // wait 1 second
|
|
40
|
-
|
|
41
|
-
// Poll until condition is met
|
|
42
|
-
await wait.until(() => isReady, 100, 50);
|
|
43
|
-
// Checks every 100ms, up to 50 times (5 seconds total)
|
|
44
|
-
|
|
45
|
-
// With async condition
|
|
46
|
-
await wait.until(async () => {
|
|
47
|
-
const status = await checkStatus();
|
|
48
|
-
return status === "complete";
|
|
49
|
-
}, 500);
|
|
50
|
-
```
|
package/docs/xml-utilities.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# XML Utilities
|
|
2
|
-
|
|
3
|
-
Imported as the `xml` namespace. XML parsing and serialization via `fast-xml-parser`.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import { xml } from "@simplysm/core-common";
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## parse
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
function parse(str: string, options?: { stripTagPrefix?: boolean }): unknown;
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Parses an XML string into an object. Attributes are grouped under `$`, text content under `_`, and child elements are converted to arrays (except the root). Set `stripTagPrefix` to remove namespace prefixes from tag names.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## stringify
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
function stringify(obj: unknown, options?: XmlBuilderOptions): string;
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Serializes an object to XML string. Accepts optional `fast-xml-parser` builder options.
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## Usage Examples
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
import { xml } from "@simplysm/core-common";
|
|
33
|
-
|
|
34
|
-
const obj = xml.parse('<root id="1"><item>hello</item><item>world</item></root>');
|
|
35
|
-
// { root: { $: { id: "1" }, item: [{ _: "hello" }, { _: "world" }] } }
|
|
36
|
-
|
|
37
|
-
const xmlStr = xml.stringify({
|
|
38
|
-
root: {
|
|
39
|
-
$: { id: "1" },
|
|
40
|
-
item: [{ _: "hello" }, { _: "world" }],
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
// '<root id="1"><item>hello</item><item>world</item></root>'
|
|
44
|
-
|
|
45
|
-
// Strip namespace prefixes
|
|
46
|
-
xml.parse('<ns:root><ns:item>test</ns:item></ns:root>', { stripTagPrefix: true });
|
|
47
|
-
// { root: { item: [{ _: "test" }] } }
|
|
48
|
-
```
|
package/docs/zip-archive.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# ZIP Archive
|
|
2
|
-
|
|
3
|
-
The `ZipArchive` class for reading, writing, and compressing ZIP files. Uses `@zip.js/zip.js` internally.
|
|
4
|
-
|
|
5
|
-
Directly exported (not namespaced).
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { ZipArchive } from "@simplysm/core-common";
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## ZipArchive
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
class ZipArchive {
|
|
15
|
-
constructor(data?: Blob | Bytes);
|
|
16
|
-
|
|
17
|
-
get(fileName: string): Promise<Bytes | undefined>;
|
|
18
|
-
exists(fileName: string): Promise<boolean>;
|
|
19
|
-
write(fileName: string, bytes: Bytes): void;
|
|
20
|
-
extractAll(progressCallback?: (progress: ZipArchiveProgress) => void): Promise<Map<string, Bytes | undefined>>;
|
|
21
|
-
compress(): Promise<Bytes>;
|
|
22
|
-
close(): Promise<void>;
|
|
23
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface ZipArchiveProgress {
|
|
27
|
-
fileName: string;
|
|
28
|
-
totalSize: number;
|
|
29
|
-
extractedSize: number;
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
- **Read mode:** Pass existing ZIP data (`Blob` or `Uint8Array`) to the constructor. Use `get()` for individual files or `extractAll()` for everything.
|
|
34
|
-
- **Write mode:** Omit the constructor argument. Use `write()` to add files, then `compress()` to generate the ZIP.
|
|
35
|
-
- Supports `await using` syntax for automatic cleanup.
|
|
36
|
-
- Internally caches decompressed files to prevent duplicate extraction.
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
## Usage Examples
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
import { ZipArchive } from "@simplysm/core-common";
|
|
44
|
-
|
|
45
|
-
// Read a ZIP file
|
|
46
|
-
await using archive = new ZipArchive(zipBytes);
|
|
47
|
-
const content = await archive.get("file.txt");
|
|
48
|
-
const exists = await archive.exists("data.json");
|
|
49
|
-
|
|
50
|
-
// Extract all with progress
|
|
51
|
-
const files = await archive.extractAll((progress) => {
|
|
52
|
-
const pct = (progress.extractedSize / progress.totalSize * 100).toFixed(1);
|
|
53
|
-
console.log(`${progress.fileName}: ${pct}%`);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Create a new ZIP file
|
|
57
|
-
await using newArchive = new ZipArchive();
|
|
58
|
-
newArchive.write("hello.txt", new TextEncoder().encode("Hello World"));
|
|
59
|
-
newArchive.write("data.json", new TextEncoder().encode('{"key":"value"}'));
|
|
60
|
-
const zipOutput = await newArchive.compress();
|
|
61
|
-
```
|