@jackens/nnn 2025.9.6 → 2025.9.7
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/nnn.d.ts +47 -92
- package/nnn.js +36 -51
- package/package.json +1 -1
- package/readme.md +35 -35
package/nnn.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type C_Node = {
|
|
5
|
-
[attribute_or_selector: string]: string | number | C_Node | undefined;
|
|
1
|
+
/** Argument type for the `c` helper. */
|
|
2
|
+
export type CNode = {
|
|
3
|
+
[attribute_or_selector: string]: string | number | CNode | undefined;
|
|
6
4
|
};
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
export type
|
|
5
|
+
/** Argument type for the `c` helper. */
|
|
6
|
+
export type CRoot = Record<PropertyKey, CNode>;
|
|
7
|
+
/** Argument type accepted by the `escape_values` and `escape` helpers. */
|
|
8
|
+
export type EscapeMap = Map<unknown, (value?: unknown) => string>;
|
|
9
|
+
declare const IS_FINITE: unique symbol;
|
|
10
|
+
/** `number` type excluding `±Infinity` and `NaN`. */
|
|
11
|
+
export type FiniteNumber = number & {
|
|
12
|
+
readonly [IS_FINITE]: true;
|
|
13
|
+
};
|
|
14
|
+
/** Argument type for the `h` and `s` helpers. */
|
|
15
|
+
export type HArgs1 = Record<PropertyKey, unknown> | null | undefined | Node | string | number | HArgs;
|
|
16
|
+
/** Argument type for the `h` and `s` helpers. */
|
|
17
|
+
export type HArgs = [string | Node, ...HArgs1[]];
|
|
11
18
|
/**
|
|
12
19
|
* A minimal JS-to-CSS (CSS‑in‑JS) helper.
|
|
13
20
|
*
|
|
@@ -19,35 +26,15 @@ export type C_Root = Record<PropertyKey, C_Node>;
|
|
|
19
26
|
* - Commas inside selector keys cause them to expand into multiple selectors (e.g. `{div:{margin:1,'.a,.b,.c':{margin:2}}}` → `div{margin:1}div.a,div.b,div.c{margin:2}`).
|
|
20
27
|
* - Top-level keys beginning with `@` (at-rules) are not concatenated with parent keys.
|
|
21
28
|
*/
|
|
22
|
-
export declare const c: (root:
|
|
23
|
-
/**
|
|
24
|
-
* A tiny CSV parsing helper.
|
|
25
|
-
*/
|
|
29
|
+
export declare const c: (root: CRoot, splitter?: string) => string;
|
|
30
|
+
/** A tiny CSV parsing helper. */
|
|
26
31
|
export declare const csv_parse: (csv: string, separator?: string) => string[][];
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
export
|
|
31
|
-
/**
|
|
32
|
-
* Escapes array `values` using the provided `escape_map`.
|
|
33
|
-
*/
|
|
34
|
-
export declare const escape_values: (escape_map: Escape_Map, values: unknown[]) => string[];
|
|
35
|
-
/**
|
|
36
|
-
* Escapes interpolated template `values` using the provided `escape_map`.
|
|
37
|
-
*/
|
|
38
|
-
export declare const escape: (escape_map: Escape_Map, template: TemplateStringsArray, ...values: unknown[]) => string;
|
|
39
|
-
/**
|
|
40
|
-
* Applies Polish‑specific typographic corrections.
|
|
41
|
-
*/
|
|
32
|
+
/** Escapes array `values` using the provided `escape_map`. */
|
|
33
|
+
export declare const escape_values: (escape_map: EscapeMap, values: unknown[]) => string[];
|
|
34
|
+
/** Escapes interpolated template `values` using the provided `escape_map`. */
|
|
35
|
+
export declare const escape: (escape_map: EscapeMap, template: TemplateStringsArray, ...values: unknown[]) => string;
|
|
36
|
+
/** Applies Polish‑specific typographic corrections. */
|
|
42
37
|
export declare const fix_typography: (node: Node) => void;
|
|
43
|
-
/**
|
|
44
|
-
* Argument type for the `h` and `s` helpers.
|
|
45
|
-
*/
|
|
46
|
-
export type H_Args_1 = Record<PropertyKey, unknown> | null | undefined | Node | string | number | H_Args;
|
|
47
|
-
/**
|
|
48
|
-
* Argument type for the `h` and `s` helpers.
|
|
49
|
-
*/
|
|
50
|
-
export type H_Args = [string | Node, ...H_Args_1[]];
|
|
51
38
|
/**
|
|
52
39
|
* A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `HTMLElement`s (see also `s`).
|
|
53
40
|
*
|
|
@@ -63,9 +50,9 @@ export type H_Args = [string | Node, ...H_Args_1[]];
|
|
|
63
50
|
* - `H_Args` arrays are processed recursively.
|
|
64
51
|
*/
|
|
65
52
|
export declare const h: {
|
|
66
|
-
<T extends keyof HTMLElementTagNameMap>(tag: T, ...args1:
|
|
67
|
-
<N extends Node>(node: N, ...args1:
|
|
68
|
-
(tag_or_node: string | Node, ...args1:
|
|
53
|
+
<T extends keyof HTMLElementTagNameMap>(tag: T, ...args1: HArgs1[]): HTMLElementTagNameMap[T];
|
|
54
|
+
<N extends Node>(node: N, ...args1: HArgs1[]): N;
|
|
55
|
+
(tag_or_node: string | Node, ...args1: HArgs1[]): Node;
|
|
69
56
|
};
|
|
70
57
|
/**
|
|
71
58
|
* A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `SVGElement`s (see also `h`).
|
|
@@ -82,45 +69,24 @@ export declare const h: {
|
|
|
82
69
|
* - `H_Args` arrays are processed recursively.
|
|
83
70
|
*/
|
|
84
71
|
export declare const s: {
|
|
85
|
-
<T extends keyof SVGElementTagNameMap>(tag: T, ...args1:
|
|
86
|
-
<N extends Node>(node: N, ...args1:
|
|
87
|
-
(tag_or_node: string | Node, ...args1:
|
|
72
|
+
<T extends keyof SVGElementTagNameMap>(tag: T, ...args1: HArgs1[]): SVGElementTagNameMap[T];
|
|
73
|
+
<N extends Node>(node: N, ...args1: HArgs1[]): N;
|
|
74
|
+
(tag_or_node: string | Node, ...args1: HArgs1[]): Node;
|
|
88
75
|
};
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
*/
|
|
92
|
-
export declare const svg_use: (id: string, ...args: H_Args_1[]) => SVGSVGElement;
|
|
93
|
-
/**
|
|
94
|
-
* A replacement to the `in` operator (not to be confused with `for-in`).
|
|
95
|
-
*/
|
|
76
|
+
/** Shorthand for: `s('svg', ['use', { 'xlink:href': '#' + id }], ...args)`. */
|
|
77
|
+
export declare const svg_use: (id: string, ...args: HArgs1[]) => SVGSVGElement;
|
|
78
|
+
/** A replacement to the `in` operator (not to be confused with `for-in`). */
|
|
96
79
|
export declare const has_own: (ref: unknown, key: unknown) => boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Checks whether the argument is an array.
|
|
99
|
-
*/
|
|
80
|
+
/** Checks whether the argument is an array. */
|
|
100
81
|
export declare const is_array: (arg: unknown) => arg is unknown[];
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
*/
|
|
104
|
-
export type Finite_Number = number & {
|
|
105
|
-
readonly [FINITE_NUMBER]: true;
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Checks whether the argument is a finite number (excluding `±Infinity` and `NaN`).
|
|
109
|
-
*/
|
|
110
|
-
export declare const is_finite_number: (arg: unknown) => arg is Finite_Number;
|
|
111
|
-
/**
|
|
112
|
-
* Checks whether the argument is a number.
|
|
113
|
-
*/
|
|
82
|
+
/** Checks whether the argument is a finite number (excluding `±Infinity` and `NaN`). */
|
|
83
|
+
export declare const is_finite_number: (arg: unknown) => arg is FiniteNumber;
|
|
84
|
+
/** Checks whether the argument is a number. */
|
|
114
85
|
export declare const is_number: (arg: unknown) => arg is number;
|
|
115
|
-
/**
|
|
116
|
-
* Checks whether the argument is a plain object record.
|
|
117
|
-
*/
|
|
86
|
+
/** Checks whether the argument is a plain object record. */
|
|
118
87
|
export declare const is_record: (arg: unknown) => arg is Record<PropertyKey, unknown>;
|
|
119
|
-
/**
|
|
120
|
-
* Checks whether the argument is a string.
|
|
121
|
-
*/
|
|
88
|
+
/** Checks whether the argument is a string. */
|
|
122
89
|
export declare const is_string: (arg: unknown) => arg is string;
|
|
123
|
-
export {};
|
|
124
90
|
/**
|
|
125
91
|
* `JSON.parse` with “JavaScript turned on”.
|
|
126
92
|
*
|
|
@@ -137,29 +103,17 @@ export {};
|
|
|
137
103
|
* ```
|
|
138
104
|
*/
|
|
139
105
|
export declare const js_on_parse: (handlers: Record<PropertyKey, Function>, text: string) => any;
|
|
140
|
-
/**
|
|
141
|
-
|
|
142
|
-
*/
|
|
143
|
-
export declare const
|
|
144
|
-
/**
|
|
145
|
-
* JavaScript syntax highlighting helper (built on `nanolight`).
|
|
146
|
-
*/
|
|
147
|
-
export declare const nanolight_js: (code: string) => H_Args_1[];
|
|
148
|
-
/**
|
|
149
|
-
* Runtime implementation of TypeScript’s `Pick` (see also `omit`).
|
|
150
|
-
*/
|
|
106
|
+
/** Generic syntax highlighting helper (see also `nanolight_js`). */
|
|
107
|
+
export declare const nanolight: (pattern: RegExp, highlighters: ((chunk: string, index: number) => HArgs1)[], code: string) => HArgs1[];
|
|
108
|
+
/** JavaScript syntax highlighting helper (built on `nanolight`). */
|
|
109
|
+
export declare const nanolight_js: (code: string) => HArgs1[];
|
|
110
|
+
/** Runtime implementation of TypeScript’s `Pick` (see also `omit`). */
|
|
151
111
|
export declare const pick: <T, K extends keyof T>(ref: T, keys: K[]) => Pick<T, K>;
|
|
152
|
-
/**
|
|
153
|
-
* Runtime implementation of TypeScript’s `Omit` (see also `pick`).
|
|
154
|
-
*/
|
|
112
|
+
/** Runtime implementation of TypeScript’s `Omit` (see also `pick`). */
|
|
155
113
|
export declare const omit: <T, K extends keyof T>(ref: T, keys: unknown[]) => Omit<T, K>;
|
|
156
|
-
/**
|
|
157
|
-
* Chooses the appropriate Polish noun form based on a numeric value.
|
|
158
|
-
*/
|
|
114
|
+
/** Chooses the appropriate Polish noun form based on a numeric value. */
|
|
159
115
|
export declare const pl_ural: (singular: string, plural_2: string, plural_5: string, value: number) => string;
|
|
160
|
-
/**
|
|
161
|
-
* A `Proxy`-based helper that safely creates nested structures on access and allows deep assignment without guards.
|
|
162
|
-
*/
|
|
116
|
+
/** A `Proxy`-based helper that safely creates nested structures on access and allows deep assignment without guards. */
|
|
163
117
|
export declare const pro: (ref: unknown) => any;
|
|
164
118
|
/**
|
|
165
119
|
* Generates a UUID v1 (time-based) identifier.
|
|
@@ -167,3 +121,4 @@ export declare const pro: (ref: unknown) => any;
|
|
|
167
121
|
* - Optional `node` must match `/^[0-9a-f]*$/`; it is trimmed to the last 12 characters and left-padded with zeros.
|
|
168
122
|
*/
|
|
169
123
|
export declare const uuid_v1: (date?: Date, node?: string) => string;
|
|
124
|
+
export {};
|
package/nnn.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
// src/nnn
|
|
2
|
-
var is_array = Array.isArray;
|
|
3
|
-
var is_finite_number = Number.isFinite;
|
|
4
|
-
var is_number = (arg) => typeof arg === "number";
|
|
5
|
-
var is_record = (arg) => typeof arg === "object" && arg != null && !is_array(arg);
|
|
6
|
-
var is_string = (arg) => typeof arg === "string";
|
|
7
|
-
|
|
8
|
-
// src/nnn/c.ts
|
|
1
|
+
// src/nnn.ts
|
|
9
2
|
var _c = (node, prefix, result, splitter) => {
|
|
10
3
|
const queue = [[node, prefix]];
|
|
11
4
|
while (queue.length > 0) {
|
|
@@ -57,16 +50,43 @@ var c = (root, splitter = "$$") => {
|
|
|
57
50
|
}
|
|
58
51
|
return chunks.join("");
|
|
59
52
|
};
|
|
60
|
-
// src/nnn/csv_parse.ts
|
|
61
53
|
var csv_parse = (csv, separator = ",") => {
|
|
62
54
|
const main_pattern = /\n|(?<!")("(?:[^"]|"")*")(?!")/g;
|
|
63
55
|
const line_pattern = new RegExp(`${separator}|(?<!")\\s*"((?:[^"]|"")*)"\\s*(?!")`, "g");
|
|
64
56
|
return csv.replace(/\r/g, "").replace(/\n+$/, "").replace(main_pattern, (_, chunk) => chunk ?? "\r").split("\r").map((line) => line.replace(line_pattern, (_, chunk) => chunk == null ? "\r" : chunk.replace(/""/g, '"')).split("\r"));
|
|
65
57
|
};
|
|
66
|
-
// src/nnn/escape.ts
|
|
67
58
|
var escape_values = (escape_map, values) => values.map((value) => (escape_map.get(value?.constructor) ?? escape_map.get(undefined))?.(value) ?? "");
|
|
68
59
|
var escape = (escape_map, template, ...values) => String.raw(template, ...escape_values(escape_map, values));
|
|
69
|
-
|
|
60
|
+
var TAGS_TO_SKIP = ["IFRAME", "NOSCRIPT", "PRE", "SCRIPT", "STYLE", "TEXTAREA"];
|
|
61
|
+
var fix_typography = (node) => {
|
|
62
|
+
const queue = [node];
|
|
63
|
+
while (queue.length > 0) {
|
|
64
|
+
const node_0 = queue.shift();
|
|
65
|
+
if (node_0 instanceof Element) {
|
|
66
|
+
node_0.childNodes.forEach((child_node) => {
|
|
67
|
+
if (child_node instanceof Text) {
|
|
68
|
+
queue.push(child_node);
|
|
69
|
+
} else if (child_node instanceof Element && !TAGS_TO_SKIP.includes(child_node.tagName)) {
|
|
70
|
+
queue.push(child_node);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
} else if (node_0 instanceof Text) {
|
|
74
|
+
const node_value = node_0.nodeValue?.trim?.();
|
|
75
|
+
if (node_value != null) {
|
|
76
|
+
let previous_node = node_0;
|
|
77
|
+
node_value.split(/(\s|\(|„)([aiouwz—]\s)/gi).forEach((chunk, i) => {
|
|
78
|
+
i %= 3;
|
|
79
|
+
const current_node = i === 2 ? h("span", { style: "white-space:nowrap" }, chunk) : i === 1 ? document.createTextNode(chunk) : document.createTextNode(chunk.replace(/(\/(?=[^/\s])|\.(?=[^\s]))/g, "$1"));
|
|
80
|
+
if (node_0.parentNode != null) {
|
|
81
|
+
node_0.parentNode.insertBefore(current_node, previous_node.nextSibling);
|
|
82
|
+
}
|
|
83
|
+
previous_node = current_node;
|
|
84
|
+
});
|
|
85
|
+
node_0.parentNode?.removeChild(node_0);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
70
90
|
var _h = (namespace_uri) => {
|
|
71
91
|
const create_element = namespace_uri == null ? (tag) => document.createElement(tag) : (tag) => document.createElementNS(namespace_uri, tag);
|
|
72
92
|
const h = (tag_or_node, ...args) => {
|
|
@@ -128,41 +148,12 @@ var _h = (namespace_uri) => {
|
|
|
128
148
|
var h = _h();
|
|
129
149
|
var s = _h("http://www.w3.org/2000/svg");
|
|
130
150
|
var svg_use = (id, ...args) => s("svg", ["use", { "xlink:href": "#" + id }], ...args);
|
|
131
|
-
|
|
132
|
-
// src/nnn/fix_typography.ts
|
|
133
|
-
var TAGS_TO_SKIP = ["IFRAME", "NOSCRIPT", "PRE", "SCRIPT", "STYLE", "TEXTAREA"];
|
|
134
|
-
var fix_typography = (node) => {
|
|
135
|
-
const queue = [node];
|
|
136
|
-
while (queue.length > 0) {
|
|
137
|
-
const node_0 = queue.shift();
|
|
138
|
-
if (node_0 instanceof Element) {
|
|
139
|
-
node_0.childNodes.forEach((child_node) => {
|
|
140
|
-
if (child_node instanceof Text) {
|
|
141
|
-
queue.push(child_node);
|
|
142
|
-
} else if (child_node instanceof Element && !TAGS_TO_SKIP.includes(child_node.tagName)) {
|
|
143
|
-
queue.push(child_node);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
} else if (node_0 instanceof Text) {
|
|
147
|
-
const node_value = node_0.nodeValue?.trim?.();
|
|
148
|
-
if (node_value != null) {
|
|
149
|
-
let previous_node = node_0;
|
|
150
|
-
node_value.split(/(\s|\(|„)([aiouwz—]\s)/gi).forEach((chunk, i) => {
|
|
151
|
-
i %= 3;
|
|
152
|
-
const current_node = i === 2 ? h("span", { style: "white-space:nowrap" }, chunk) : i === 1 ? document.createTextNode(chunk) : document.createTextNode(chunk.replace(/(\/(?=[^/\s])|\.(?=[^\s]))/g, "$1"));
|
|
153
|
-
if (node_0.parentNode != null) {
|
|
154
|
-
node_0.parentNode.insertBefore(current_node, previous_node.nextSibling);
|
|
155
|
-
}
|
|
156
|
-
previous_node = current_node;
|
|
157
|
-
});
|
|
158
|
-
node_0.parentNode?.removeChild(node_0);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
// src/nnn/has_own.ts
|
|
164
151
|
var has_own = (ref, key) => ref != null && Object.hasOwn(ref, key);
|
|
165
|
-
|
|
152
|
+
var is_array = Array.isArray;
|
|
153
|
+
var is_finite_number = Number.isFinite;
|
|
154
|
+
var is_number = (arg) => typeof arg === "number";
|
|
155
|
+
var is_record = (arg) => typeof arg === "object" && arg != null && !is_array(arg);
|
|
156
|
+
var is_string = (arg) => typeof arg === "string";
|
|
166
157
|
var js_on_parse = (handlers, text) => JSON.parse(text, (key, value) => {
|
|
167
158
|
if (is_record(value)) {
|
|
168
159
|
let is_second_key = false;
|
|
@@ -180,7 +171,6 @@ var js_on_parse = (handlers, text) => JSON.parse(text, (key, value) => {
|
|
|
180
171
|
}
|
|
181
172
|
return value;
|
|
182
173
|
});
|
|
183
|
-
// src/nnn/nanolight.ts
|
|
184
174
|
var nanolight = (pattern, highlighters, code) => {
|
|
185
175
|
const result = [];
|
|
186
176
|
code.split(pattern).forEach((chunk, index) => {
|
|
@@ -191,7 +181,6 @@ var nanolight = (pattern, highlighters, code) => {
|
|
|
191
181
|
});
|
|
192
182
|
return result;
|
|
193
183
|
};
|
|
194
|
-
// src/nnn/nanolight_js.ts
|
|
195
184
|
var nanolight_js = nanolight.bind(0, /('.*?'|".*?"|`[\s\S]*?`)|(\/\/.*?\n|\/\*[\s\S]*?\*\/)|(any|bigint|break|boolean|case|catch|class|const|continue|debugger|default|delete|do|else|eval|export|extends|false|finally|for|from|function|goto|if|import|in|instanceof|is|keyof|let|NaN|new|number|null|package|return|string|super|switch|symbol|this|throw|true|try|type|typeof|undefined|unknown|var|void|while|with|yield)(?!\w)|([<>=.?:&|!^~*/%+-])|(0x[\dabcdef_]+|0o[01234567_]+|0b[01_]+|\d[\d_]*(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?)|([$\w]+)(?=\()|([$\wąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)/, [
|
|
196
185
|
(chunk) => chunk,
|
|
197
186
|
(chunk) => ["span", { class: "string" }, chunk],
|
|
@@ -202,22 +191,18 @@ var nanolight_js = nanolight.bind(0, /('.*?'|".*?"|`[\s\S]*?`)|(\/\/.*?\n|\/\*[\
|
|
|
202
191
|
(chunk) => ["span", { class: "function" }, chunk],
|
|
203
192
|
(chunk) => ["span", { class: "literal" }, chunk]
|
|
204
193
|
]);
|
|
205
|
-
// src/nnn/pick.ts
|
|
206
194
|
var pick = (ref, keys) => Object.fromEntries(Object.entries(ref).filter(([key]) => keys.includes(key)));
|
|
207
195
|
var omit = (ref, keys) => Object.fromEntries(Object.entries(ref).filter(([key]) => !keys.includes(key)));
|
|
208
|
-
// src/nnn/pl_ural.ts
|
|
209
196
|
var pl_ural = (singular, plural_2, plural_5, value) => {
|
|
210
197
|
const abs_value = Math.abs(value);
|
|
211
198
|
const abs_value_mod_10 = abs_value % 10;
|
|
212
199
|
return value === 1 ? singular : (abs_value_mod_10 === 2 || abs_value_mod_10 === 3 || abs_value_mod_10 === 4) && abs_value !== 12 && abs_value !== 13 && abs_value !== 14 ? plural_2 : plural_5;
|
|
213
200
|
};
|
|
214
|
-
// src/nnn/pro.ts
|
|
215
201
|
var pro = (ref) => new Proxy(ref, {
|
|
216
202
|
get(target, key) {
|
|
217
203
|
return pro(target[key] ??= {});
|
|
218
204
|
}
|
|
219
205
|
});
|
|
220
|
-
// src/nnn/uuid_v1.ts
|
|
221
206
|
var ZEROS = "0".repeat(16);
|
|
222
207
|
var counter = 0;
|
|
223
208
|
var uuid_v1 = (date = new Date, node = Math.random().toString(16).slice(2)) => {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -28,12 +28,12 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
28
28
|
|
|
29
29
|
## Exports
|
|
30
30
|
|
|
31
|
-
- [`
|
|
32
|
-
- [`
|
|
33
|
-
- [`
|
|
34
|
-
- [`
|
|
35
|
-
- [`
|
|
36
|
-
- [`
|
|
31
|
+
- [`CNode`](#CNode): Argument type for the `c` helper.
|
|
32
|
+
- [`CRoot`](#CRoot): Argument type for the `c` helper.
|
|
33
|
+
- [`EscapeMap`](#EscapeMap): Argument type accepted by the `escape_values` and `escape` helpers.
|
|
34
|
+
- [`FiniteNumber`](#FiniteNumber): `number` type excluding `±Infinity` and `NaN`.
|
|
35
|
+
- [`HArgs`](#HArgs): Argument type for the `h` and `s` helpers.
|
|
36
|
+
- [`HArgs1`](#HArgs1): Argument type for the `h` and `s` helpers.
|
|
37
37
|
- [`c`](#c): A minimal JS-to-CSS (CSS‑in‑JS) helper.
|
|
38
38
|
- [`csv_parse`](#csv_parse): A tiny CSV parsing helper.
|
|
39
39
|
- [`escape`](#escape): Escapes interpolated template `values` using the provided `escape_map`.
|
|
@@ -57,54 +57,54 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
57
57
|
- [`svg_use`](#svg_use): Shorthand for: `s('svg', ['use', { 'xlink:href': '#' + id }], ...args)`.
|
|
58
58
|
- [`uuid_v1`](#uuid_v1): Generates a UUID v1 (time-based) identifier.
|
|
59
59
|
|
|
60
|
-
###
|
|
60
|
+
### CNode
|
|
61
61
|
|
|
62
62
|
```ts
|
|
63
|
-
type
|
|
64
|
-
[attribute_or_selector: string]: string | number |
|
|
63
|
+
type CNode = {
|
|
64
|
+
[attribute_or_selector: string]: string | number | CNode | undefined;
|
|
65
65
|
};
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
Argument type for the `c` helper.
|
|
69
69
|
|
|
70
|
-
###
|
|
70
|
+
### CRoot
|
|
71
71
|
|
|
72
72
|
```ts
|
|
73
|
-
type
|
|
73
|
+
type CRoot = Record<PropertyKey, CNode>;
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
Argument type for the `c` helper.
|
|
77
77
|
|
|
78
|
-
###
|
|
78
|
+
### EscapeMap
|
|
79
79
|
|
|
80
80
|
```ts
|
|
81
|
-
type
|
|
81
|
+
type EscapeMap = Map<unknown, (value?: unknown) => string>;
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
Argument type accepted by the `escape_values` and `escape` helpers.
|
|
85
85
|
|
|
86
|
-
###
|
|
86
|
+
### FiniteNumber
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
|
-
type
|
|
90
|
-
readonly [
|
|
89
|
+
type FiniteNumber = number & {
|
|
90
|
+
readonly [IS_FINITE]: true;
|
|
91
91
|
};
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
`number` type excluding `±Infinity` and `NaN`.
|
|
95
95
|
|
|
96
|
-
###
|
|
96
|
+
### HArgs
|
|
97
97
|
|
|
98
98
|
```ts
|
|
99
|
-
type
|
|
99
|
+
type HArgs = [string | Node, ...HArgs1[]];
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
Argument type for the `h` and `s` helpers.
|
|
103
103
|
|
|
104
|
-
###
|
|
104
|
+
### HArgs1
|
|
105
105
|
|
|
106
106
|
```ts
|
|
107
|
-
type
|
|
107
|
+
type HArgs1 = Record<PropertyKey, unknown> | null | undefined | Node | string | number | HArgs;
|
|
108
108
|
```
|
|
109
109
|
|
|
110
110
|
Argument type for the `h` and `s` helpers.
|
|
@@ -112,7 +112,7 @@ Argument type for the `h` and `s` helpers.
|
|
|
112
112
|
### c
|
|
113
113
|
|
|
114
114
|
```ts
|
|
115
|
-
const c: (root:
|
|
115
|
+
const c: (root: CRoot, splitter?: string) => string;
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
A minimal JS-to-CSS (CSS‑in‑JS) helper.
|
|
@@ -350,7 +350,7 @@ expect(csv_parse(text)).to.deep.equal([
|
|
|
350
350
|
### escape
|
|
351
351
|
|
|
352
352
|
```ts
|
|
353
|
-
const escape: (escape_map:
|
|
353
|
+
const escape: (escape_map: EscapeMap, template: TemplateStringsArray, ...values: unknown[]) => string;
|
|
354
354
|
```
|
|
355
355
|
|
|
356
356
|
Escapes interpolated template `values` using the provided `escape_map`.
|
|
@@ -358,7 +358,7 @@ Escapes interpolated template `values` using the provided `escape_map`.
|
|
|
358
358
|
#### Usage Examples
|
|
359
359
|
|
|
360
360
|
```ts
|
|
361
|
-
const escape_map:
|
|
361
|
+
const escape_map: EscapeMap = new Map([
|
|
362
362
|
[undefined, () => 'NULL'],
|
|
363
363
|
[Array, (values: unknown[]) => escape_values(escape_map, values).join(', ')],
|
|
364
364
|
[Boolean, (value: boolean) => `b'${+value}'`],
|
|
@@ -385,7 +385,7 @@ expect(actual).to.deep.equal(expected)
|
|
|
385
385
|
### escape_values
|
|
386
386
|
|
|
387
387
|
```ts
|
|
388
|
-
const escape_values: (escape_map:
|
|
388
|
+
const escape_values: (escape_map: EscapeMap, values: unknown[]) => string[];
|
|
389
389
|
```
|
|
390
390
|
|
|
391
391
|
Escapes array `values` using the provided `escape_map`.
|
|
@@ -414,9 +414,9 @@ expect(p.innerHTML).to.deep.equal(
|
|
|
414
414
|
|
|
415
415
|
```ts
|
|
416
416
|
const h: {
|
|
417
|
-
<T extends keyof HTMLElementTagNameMap>(tag: T, ...args1:
|
|
418
|
-
<N extends Node>(node: N, ...args1:
|
|
419
|
-
(tag_or_node: string | Node, ...args1:
|
|
417
|
+
<T extends keyof HTMLElementTagNameMap>(tag: T, ...args1: HArgs1[]): HTMLElementTagNameMap[T];
|
|
418
|
+
<N extends Node>(node: N, ...args1: HArgs1[]): N;
|
|
419
|
+
(tag_or_node: string | Node, ...args1: HArgs1[]): Node;
|
|
420
420
|
};
|
|
421
421
|
```
|
|
422
422
|
|
|
@@ -553,7 +553,7 @@ Checks whether the argument is an array.
|
|
|
553
553
|
### is_finite_number
|
|
554
554
|
|
|
555
555
|
```ts
|
|
556
|
-
const is_finite_number: (arg: unknown) => arg is
|
|
556
|
+
const is_finite_number: (arg: unknown) => arg is FiniteNumber;
|
|
557
557
|
```
|
|
558
558
|
|
|
559
559
|
Checks whether the argument is a finite number (excluding `±Infinity` and `NaN`).
|
|
@@ -578,7 +578,6 @@ Checks whether the argument is a plain object record.
|
|
|
578
578
|
|
|
579
579
|
```ts
|
|
580
580
|
const is_string: (arg: unknown) => arg is string;
|
|
581
|
-
export {};
|
|
582
581
|
```
|
|
583
582
|
|
|
584
583
|
Checks whether the argument is a string.
|
|
@@ -653,7 +652,7 @@ expect(actual).to.deep.equal(expected)
|
|
|
653
652
|
### nanolight
|
|
654
653
|
|
|
655
654
|
```ts
|
|
656
|
-
const nanolight: (pattern: RegExp, highlighters: ((chunk: string, index: number) =>
|
|
655
|
+
const nanolight: (pattern: RegExp, highlighters: ((chunk: string, index: number) => HArgs1)[], code: string) => HArgs1[];
|
|
657
656
|
```
|
|
658
657
|
|
|
659
658
|
Generic syntax highlighting helper (see also `nanolight_js`).
|
|
@@ -661,7 +660,7 @@ Generic syntax highlighting helper (see also `nanolight_js`).
|
|
|
661
660
|
### nanolight_js
|
|
662
661
|
|
|
663
662
|
```ts
|
|
664
|
-
const nanolight_js: (code: string) =>
|
|
663
|
+
const nanolight_js: (code: string) => HArgs1[];
|
|
665
664
|
```
|
|
666
665
|
|
|
667
666
|
JavaScript syntax highlighting helper (built on `nanolight`).
|
|
@@ -782,9 +781,9 @@ expect(ref).to.deep.equal({ one: { two: { three: { four: 1234 } } } })
|
|
|
782
781
|
|
|
783
782
|
```ts
|
|
784
783
|
const s: {
|
|
785
|
-
<T extends keyof SVGElementTagNameMap>(tag: T, ...args1:
|
|
786
|
-
<N extends Node>(node: N, ...args1:
|
|
787
|
-
(tag_or_node: string | Node, ...args1:
|
|
784
|
+
<T extends keyof SVGElementTagNameMap>(tag: T, ...args1: HArgs1[]): SVGElementTagNameMap[T];
|
|
785
|
+
<N extends Node>(node: N, ...args1: HArgs1[]): N;
|
|
786
|
+
(tag_or_node: string | Node, ...args1: HArgs1[]): Node;
|
|
788
787
|
};
|
|
789
788
|
```
|
|
790
789
|
|
|
@@ -804,7 +803,7 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
804
803
|
### svg_use
|
|
805
804
|
|
|
806
805
|
```ts
|
|
807
|
-
const svg_use: (id: string, ...args:
|
|
806
|
+
const svg_use: (id: string, ...args: HArgs1[]) => SVGSVGElement;
|
|
808
807
|
```
|
|
809
808
|
|
|
810
809
|
Shorthand for: `s('svg', ['use', { 'xlink:href': '#' + id }], ...args)`.
|
|
@@ -813,6 +812,7 @@ Shorthand for: `s('svg', ['use', { 'xlink:href': '#' + id }], ...args)`.
|
|
|
813
812
|
|
|
814
813
|
```ts
|
|
815
814
|
const uuid_v1: (date?: Date, node?: string) => string;
|
|
815
|
+
export {};
|
|
816
816
|
```
|
|
817
817
|
|
|
818
818
|
Generates a UUID v1 (time-based) identifier.
|