@jackens/nnn 2024.10.4 → 2025.2.1
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 +0 -24
- package/nnn.js +2 -15
- package/package.json +1 -1
- package/readme.md +15 -10
package/nnn.d.ts
CHANGED
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
export type CNode = {
|
|
5
5
|
[attributeOrSelector: string]: string | number | CNode | undefined;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* The type of arguments of the `c` helper.
|
|
10
9
|
*/
|
|
11
10
|
export type CRoot = Partial<Record<PropertyKey, CNode>>;
|
|
12
|
-
|
|
13
11
|
/**
|
|
14
12
|
* A simple JS-to-CSS (aka CSS-in-JS) helper.
|
|
15
13
|
*
|
|
@@ -22,7 +20,6 @@ export type CRoot = Partial<Record<PropertyKey, CNode>>;
|
|
|
22
20
|
* - Top-level keys that begin with `@` are not concatenated with sub-object keys.
|
|
23
21
|
*/
|
|
24
22
|
export declare const c: (root: CRoot, splitter?: string) => string;
|
|
25
|
-
|
|
26
23
|
/**
|
|
27
24
|
* A tiny helper for CSV parsing.
|
|
28
25
|
*
|
|
@@ -43,37 +40,30 @@ export declare const csvParse: {
|
|
|
43
40
|
separator: string;
|
|
44
41
|
}>): Partial<Array<Partial<Record<PropertyKey, string>>>> | Partial<Array<Partial<Array<string>>>>;
|
|
45
42
|
};
|
|
46
|
-
|
|
47
43
|
/**
|
|
48
44
|
* The type of arguments of the `escapeValues` and `escape` helpers.
|
|
49
45
|
*/
|
|
50
46
|
export type EscapeMap = Map<unknown, (value?: unknown) => string>;
|
|
51
|
-
|
|
52
47
|
/**
|
|
53
48
|
* A generic helper for escaping `values` by given `escapeMap`.
|
|
54
49
|
*/
|
|
55
50
|
export declare const escapeValues: (escapeMap: EscapeMap, values: Partial<Array<unknown>>) => Partial<Array<string>>;
|
|
56
|
-
|
|
57
51
|
/**
|
|
58
52
|
* A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
|
|
59
53
|
*/
|
|
60
54
|
export declare const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values: Partial<Array<unknown>>) => string;
|
|
61
|
-
|
|
62
55
|
/**
|
|
63
56
|
* A helper that implements typographic corrections specific to Polish typography.
|
|
64
57
|
*/
|
|
65
58
|
export declare const fixTypography: (node: Node) => void;
|
|
66
|
-
|
|
67
59
|
/**
|
|
68
60
|
* The type of arguments of the `h` and `s` helpers.
|
|
69
61
|
*/
|
|
70
62
|
export type HArgs1 = Partial<Record<PropertyKey, unknown>> | null | undefined | Node | string | number | HArgs;
|
|
71
|
-
|
|
72
63
|
/**
|
|
73
64
|
* The type of arguments of the `h` and `s` helpers.
|
|
74
65
|
*/
|
|
75
66
|
export type HArgs = [string | Node, ...HArgs1[]];
|
|
76
|
-
|
|
77
67
|
/**
|
|
78
68
|
* A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `HTMLElement`s (see also `s`).
|
|
79
69
|
*
|
|
@@ -90,7 +80,6 @@ export declare const h: {
|
|
|
90
80
|
<N extends Node>(node: N, ...args1: Partial<Array<HArgs1>>): N;
|
|
91
81
|
(tagOrNode: string | Node, ...args1: Partial<Array<HArgs1>>): Node;
|
|
92
82
|
};
|
|
93
|
-
|
|
94
83
|
/**
|
|
95
84
|
* A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `SVGElement`s (see also `h`).
|
|
96
85
|
*
|
|
@@ -107,17 +96,14 @@ export declare const s: {
|
|
|
107
96
|
<N extends Node>(node: N, ...args1: Partial<Array<HArgs1>>): N;
|
|
108
97
|
(tagOrNode: string | Node, ...args1: Partial<Array<HArgs1>>): Node;
|
|
109
98
|
};
|
|
110
|
-
|
|
111
99
|
/**
|
|
112
100
|
* A convenient shortcut for `s('svg', ['use', { 'xlink:href': '#' + id }], ...args)`.
|
|
113
101
|
*/
|
|
114
102
|
export declare const svgUse: (id: string, ...args: Partial<Array<HArgs1>>) => SVGSVGElement;
|
|
115
|
-
|
|
116
103
|
/**
|
|
117
104
|
* A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
|
|
118
105
|
*/
|
|
119
106
|
export declare const has: (key: unknown, ref: unknown) => boolean;
|
|
120
|
-
|
|
121
107
|
/**
|
|
122
108
|
* A helper that checks if the given argument is of a certain type.
|
|
123
109
|
*/
|
|
@@ -132,7 +118,6 @@ export declare const is: {
|
|
|
132
118
|
(type: undefined, arg: unknown): arg is undefined | null;
|
|
133
119
|
<T extends abstract new (...args: Partial<Array<any>>) => unknown>(type: T, arg: unknown): arg is InstanceType<T>;
|
|
134
120
|
};
|
|
135
|
-
|
|
136
121
|
/**
|
|
137
122
|
* `JSON.parse` with “JavaScript turned on”.
|
|
138
123
|
*
|
|
@@ -149,50 +134,41 @@ export declare const is: {
|
|
|
149
134
|
* ```
|
|
150
135
|
*/
|
|
151
136
|
export declare const jsOnParse: (handlers: Partial<Record<PropertyKey, Function>>, text: string) => any;
|
|
152
|
-
|
|
153
137
|
/**
|
|
154
138
|
* Language translations helper.
|
|
155
139
|
*/
|
|
156
140
|
export declare const locale: (map: Partial<Record<PropertyKey, Partial<Record<PropertyKey, string>>>>, defaultVersion: string) => (text: string, version?: string) => string;
|
|
157
|
-
|
|
158
141
|
/**
|
|
159
142
|
* A generic helper for syntax highlighting (see also `nanolightJs`).
|
|
160
143
|
*/
|
|
161
144
|
export declare const nanolight: (pattern: RegExp, highlighters: Partial<Array<(chunk: string, index: number) => HArgs1>>, code: string) => HArgs1[];
|
|
162
|
-
|
|
163
145
|
/**
|
|
164
146
|
* A helper for highlighting JavaScript (see also `nanolight`).
|
|
165
147
|
*/
|
|
166
148
|
export declare const nanolightJs: (code: string) => HArgs1[];
|
|
167
|
-
|
|
168
149
|
/**
|
|
169
150
|
* A helper that implements TypeScript’s `Pick` utility type (see also `omit`).
|
|
170
151
|
*/
|
|
171
152
|
export declare const pick: <T extends Partial<Record<PropertyKey, unknown>>, K extends Array<keyof T>>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Pick<T, K[number]>;
|
|
172
|
-
|
|
173
153
|
/**
|
|
174
154
|
* A helper that implements TypeScript’s `Omit` utility type (see also `pick`).
|
|
175
155
|
*/
|
|
176
156
|
export declare const omit: <T extends Partial<Record<PropertyKey, unknown>>, K extends Array<keyof T>>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Omit<T, K[number]>;
|
|
177
|
-
|
|
178
157
|
/**
|
|
179
158
|
* A helper for choosing the correct singular and plural.
|
|
180
159
|
*/
|
|
181
160
|
export declare const plUral: (singular: string, plural2: string, plural5: string, value: number) => string;
|
|
182
|
-
|
|
183
161
|
/**
|
|
184
162
|
* A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty
|
|
185
163
|
* object.
|
|
186
164
|
*/
|
|
187
165
|
export declare const pro: (ref: unknown) => any;
|
|
188
|
-
|
|
189
166
|
/**
|
|
190
167
|
* A helper that provides information about the given `refs`.
|
|
191
168
|
*
|
|
192
169
|
* It returns an array of triples: `[«name», «prototype-name», «array-of-own-property-names»]`.
|
|
193
170
|
*/
|
|
194
171
|
export declare const refsInfo: (...refs: Partial<Array<unknown>>) => Partial<Array<[string, string, Partial<Array<string>>]>>;
|
|
195
|
-
|
|
196
172
|
/**
|
|
197
173
|
* A helper that generates a UUID v1 identifier (with a creation timestamp).
|
|
198
174
|
*
|
package/nnn.js
CHANGED
|
@@ -53,7 +53,6 @@ var c = (root, splitter = "$$") => {
|
|
|
53
53
|
}
|
|
54
54
|
return chunks.join("");
|
|
55
55
|
};
|
|
56
|
-
|
|
57
56
|
// src/nnn/csvParse.ts
|
|
58
57
|
var _csvParseHeaderFalse = (text, separator) => {
|
|
59
58
|
const regExp = new RegExp(`${separator}|(?<!")\\s*"((?:[^"]|"")*)"\\s*(?!")`, "g");
|
|
@@ -68,11 +67,9 @@ var _csvParseHeaderTrue = (text, separator) => {
|
|
|
68
67
|
}, {}));
|
|
69
68
|
};
|
|
70
69
|
var csvParse = (text, { header = true, separator = "," } = {}) => header ? _csvParseHeaderTrue(text, separator) : _csvParseHeaderFalse(text, separator);
|
|
71
|
-
|
|
72
70
|
// src/nnn/escape.ts
|
|
73
71
|
var escapeValues = (escapeMap, values) => values.map((value) => (escapeMap.get(value?.constructor) ?? escapeMap.get(undefined))?.(value) ?? "");
|
|
74
72
|
var escape = (escapeMap, template, ...values) => String.raw(template, ...escapeValues(escapeMap, values));
|
|
75
|
-
|
|
76
73
|
// src/nnn/h.ts
|
|
77
74
|
var NS = {
|
|
78
75
|
xlink: "http://www.w3.org/1999/xlink"
|
|
@@ -158,7 +155,7 @@ var fixTypography = (node) => {
|
|
|
158
155
|
let previousNode = node0;
|
|
159
156
|
nodeValue.split(/(\s|\(|„)([aiouwz—]\s)/gi).forEach((chunk, i) => {
|
|
160
157
|
i %= 3;
|
|
161
|
-
const currentNode = i === 2 ? h("span", { style: "white-space:nowrap" }, chunk) : i === 1 ? document.createTextNode(chunk) : document.createTextNode(chunk.replace(/(\/(?=[^/\s])|\.(?=[^\s]))/g, "$1
|
|
158
|
+
const currentNode = i === 2 ? h("span", { style: "white-space:nowrap" }, chunk) : i === 1 ? document.createTextNode(chunk) : document.createTextNode(chunk.replace(/(\/(?=[^/\s])|\.(?=[^\s]))/g, "$1"));
|
|
162
159
|
if (node0.parentNode != null) {
|
|
163
160
|
node0.parentNode.insertBefore(currentNode, previousNode.nextSibling);
|
|
164
161
|
}
|
|
@@ -169,10 +166,8 @@ var fixTypography = (node) => {
|
|
|
169
166
|
}
|
|
170
167
|
}
|
|
171
168
|
};
|
|
172
|
-
|
|
173
169
|
// src/nnn/has.ts
|
|
174
|
-
var has = (key, ref) =>
|
|
175
|
-
|
|
170
|
+
var has = (key, ref) => ref != null && Object.hasOwnProperty.call(ref, key);
|
|
176
171
|
// src/nnn/jsOnParse.ts
|
|
177
172
|
var jsOnParse = (handlers, text) => JSON.parse(text, (key, value) => {
|
|
178
173
|
if (is(Object, value)) {
|
|
@@ -191,14 +186,12 @@ var jsOnParse = (handlers, text) => JSON.parse(text, (key, value) => {
|
|
|
191
186
|
}
|
|
192
187
|
return value;
|
|
193
188
|
});
|
|
194
|
-
|
|
195
189
|
// src/nnn/locale.ts
|
|
196
190
|
var locale = (map, defaultVersion) => (text, version = defaultVersion) => {
|
|
197
191
|
const textV = map?.[version]?.[text];
|
|
198
192
|
const textD = map?.[defaultVersion]?.[text];
|
|
199
193
|
return is(String, textV) ? textV : is(String, textD) ? textD : text;
|
|
200
194
|
};
|
|
201
|
-
|
|
202
195
|
// src/nnn/nanolight.ts
|
|
203
196
|
var nanolight = (pattern, highlighters, code) => {
|
|
204
197
|
const result = [];
|
|
@@ -210,7 +203,6 @@ var nanolight = (pattern, highlighters, code) => {
|
|
|
210
203
|
});
|
|
211
204
|
return result;
|
|
212
205
|
};
|
|
213
|
-
|
|
214
206
|
// src/nnn/nanolightJs.ts
|
|
215
207
|
var nanolightJs = 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ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)/, [
|
|
216
208
|
(chunk) => chunk,
|
|
@@ -222,25 +214,21 @@ var nanolightJs = nanolight.bind(0, /('.*?'|".*?"|`[\s\S]*?`)|(\/\/.*?\n|\/\*[\s
|
|
|
222
214
|
(chunk) => ["span", { class: "function" }, chunk],
|
|
223
215
|
(chunk) => ["span", { class: "literal" }, chunk]
|
|
224
216
|
]);
|
|
225
|
-
|
|
226
217
|
// src/nnn/pick.ts
|
|
227
218
|
var pick = (obj, keys) => Object.fromEntries(Object.entries(obj).filter(([key]) => keys.includes(key)));
|
|
228
219
|
var omit = (obj, keys) => Object.fromEntries(Object.entries(obj).filter(([key]) => !keys.includes(key)));
|
|
229
|
-
|
|
230
220
|
// src/nnn/plUral.ts
|
|
231
221
|
var plUral = (singular, plural2, plural5, value) => {
|
|
232
222
|
const absValue = Math.abs(value);
|
|
233
223
|
const absValueMod10 = absValue % 10;
|
|
234
224
|
return value === 1 ? singular : (absValueMod10 === 2 || absValueMod10 === 3 || absValueMod10 === 4) && absValue !== 12 && absValue !== 13 && absValue !== 14 ? plural2 : plural5;
|
|
235
225
|
};
|
|
236
|
-
|
|
237
226
|
// src/nnn/pro.ts
|
|
238
227
|
var pro = (ref) => new Proxy(ref, {
|
|
239
228
|
get(target, key) {
|
|
240
229
|
return pro(target[key] = target[key] ?? {});
|
|
241
230
|
}
|
|
242
231
|
});
|
|
243
|
-
|
|
244
232
|
// src/nnn/refsInfo.ts
|
|
245
233
|
var refsInfo = (...refs) => {
|
|
246
234
|
const fns = new Set;
|
|
@@ -259,7 +247,6 @@ var refsInfo = (...refs) => {
|
|
|
259
247
|
Object.getOwnPropertyNames(fn.prototype ?? Object.create(null)).sort()
|
|
260
248
|
]).sort((a, b) => -(a[0] < b[0]));
|
|
261
249
|
};
|
|
262
|
-
|
|
263
250
|
// src/nnn/uuid1.ts
|
|
264
251
|
var ZEROS = "0".repeat(16);
|
|
265
252
|
var counter = 0;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Jackens’ JavaScript helpers.
|
|
4
4
|
|
|
5
|
-
<sub>Version: <code class="version">
|
|
5
|
+
<sub>Version: <code class="version">2025.2.1</code></sub>
|
|
6
6
|
|
|
7
7
|
* [Documentation](https://jackens.github.io/nnn/doc/)
|
|
8
8
|
* [Tests](https://jackens.github.io/nnn/test/)
|
|
@@ -28,16 +28,16 @@ npm i @jackens/nnn
|
|
|
28
28
|
import { «something» } from '@jackens/nnn'
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
or
|
|
31
|
+
or
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
34
|
import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
or
|
|
37
|
+
or
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
|
-
import { «something» } from 'https://unpkg.com/@jackens/nnn@
|
|
40
|
+
import { «something» } from 'https://unpkg.com/@jackens/nnn@2025.2.1/nnn.js'
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
## Exports
|
|
@@ -536,16 +536,19 @@ A replacement for the `in` operator (not to be confused with the `for-in` loop)
|
|
|
536
536
|
#### Usage Examples
|
|
537
537
|
|
|
538
538
|
```js
|
|
539
|
-
const obj = {
|
|
539
|
+
const obj = { 'k,e,y': 42, null: 42 }
|
|
540
|
+
|
|
541
|
+
expect('k,e,y' in obj).to.be.true
|
|
542
|
+
expect(has('k,e,y', obj)).to.be.true
|
|
540
543
|
|
|
541
|
-
expect('
|
|
542
|
-
expect(has('
|
|
544
|
+
expect(['k', 'e', 'y'] in obj).to.be.true
|
|
545
|
+
expect(has(['k', 'e', 'y'], obj)).to.be.true
|
|
543
546
|
|
|
544
547
|
expect('null' in obj).to.be.true
|
|
545
548
|
expect(has('null', obj)).to.be.true
|
|
546
549
|
|
|
547
550
|
expect(null in obj).to.be.true
|
|
548
|
-
expect(has(null, obj)).to.be.
|
|
551
|
+
expect(has(null, obj)).to.be.true
|
|
549
552
|
|
|
550
553
|
expect('toString' in obj).to.be.true
|
|
551
554
|
expect(has('toString', obj)).to.be.false
|
|
@@ -587,17 +590,19 @@ A helper that checks if the given argument is of a certain type.
|
|
|
587
590
|
```js
|
|
588
591
|
expect(is(Number, 42)).to.be.true
|
|
589
592
|
expect(is(Number, Number(42))).to.be.true
|
|
590
|
-
|
|
591
593
|
expect(is(Number, new Number(42))).to.be.true
|
|
592
594
|
expect(is(Number, NaN)).to.be.true
|
|
595
|
+
|
|
593
596
|
expect(is(String, '42')).to.be.true
|
|
594
597
|
expect(is(String, String('42'))).to.be.true
|
|
595
|
-
|
|
596
598
|
expect(is(String, new String('42'))).to.be.true
|
|
599
|
+
|
|
597
600
|
expect(is(Symbol, Symbol('42'))).to.be.true
|
|
598
601
|
expect(is(Symbol, Object(Symbol('42')))).to.be.true
|
|
602
|
+
|
|
599
603
|
expect(is(undefined, undefined)).to.be.true
|
|
600
604
|
expect(is(undefined, null)).to.be.true
|
|
605
|
+
|
|
601
606
|
expect(is(Object, {})).to.be.true
|
|
602
607
|
expect(is(Array, [])).to.be.true
|
|
603
608
|
expect(is(RegExp, /42/)).to.be.true
|