@jackens/nnn 2024.3.8 → 2024.4.5
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 +27 -31
- package/nnn.js +5 -39
- package/package.json +1 -4
- package/readme.md +31 -73
package/nnn.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A helper that checks equality of the given arguments.
|
|
3
|
-
*/
|
|
4
|
-
export declare const eq: (x: any, y: any) => boolean;
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* The type of arguments of the `escapeValues` and `escape` helpers.
|
|
8
3
|
*/
|
|
9
|
-
export type EscapeMap = Map<
|
|
4
|
+
export type EscapeMap = Map<unknown, (value?: unknown) => string>;
|
|
10
5
|
|
|
11
6
|
/**
|
|
12
7
|
* A generic helper for escaping `values` by given `escapeMap`.
|
|
13
8
|
*/
|
|
14
|
-
export declare const escapeValues: (escapeMap: EscapeMap, values:
|
|
9
|
+
export declare const escapeValues: (escapeMap: EscapeMap, values: Partial<Array<unknown>>) => Partial<Array<string>>;
|
|
15
10
|
|
|
16
11
|
/**
|
|
17
12
|
* A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
|
|
18
13
|
*/
|
|
19
|
-
export declare const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values:
|
|
14
|
+
export declare const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values: Partial<Array<unknown>>) => string;
|
|
20
15
|
|
|
21
16
|
/**
|
|
22
17
|
* A helper that implements typographic corrections specific to Polish typography.
|
|
@@ -26,7 +21,7 @@ export declare const fixTypography: (node: Node) => void;
|
|
|
26
21
|
/**
|
|
27
22
|
* The type of arguments of the `h` and `s` helpers.
|
|
28
23
|
*/
|
|
29
|
-
export type HArgs1 = Partial<Record<PropertyKey,
|
|
24
|
+
export type HArgs1 = Partial<Record<PropertyKey, unknown>> | null | undefined | Node | string | number | HArgs;
|
|
30
25
|
|
|
31
26
|
/**
|
|
32
27
|
* The type of arguments of the `h` and `s` helpers.
|
|
@@ -38,7 +33,7 @@ export type HArgs = [string | Node, ...HArgs1[]];
|
|
|
38
33
|
*
|
|
39
34
|
* - The first argument of type `string` specifies the tag of the element to be created.
|
|
40
35
|
* - The first argument of type `Node` specifies the element to be modified.
|
|
41
|
-
* - All other arguments of type `Partial<Record<PropertyKey,
|
|
36
|
+
* - All other arguments of type `Partial<Record<PropertyKey, unknown>>` are mappings of attributes and properties.
|
|
42
37
|
* Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
|
|
43
38
|
* (Note that `$` is not a valid attribute name character.)
|
|
44
39
|
* All other keys specify *attributes* to be set by `setAttribute`.
|
|
@@ -49,9 +44,9 @@ export type HArgs = [string | Node, ...HArgs1[]];
|
|
|
49
44
|
* - All other arguments of type `HArgs` are passed to `h` and the results are appended to the element being created or modified.
|
|
50
45
|
*/
|
|
51
46
|
export declare const h: {
|
|
52
|
-
<T extends keyof HTMLElementTagNameMap>(tag: T, ...args1: HArgs1
|
|
53
|
-
<N extends Node>(node: N, ...args1: HArgs1
|
|
54
|
-
(tagOrNode: string | Node, ...args1: HArgs1
|
|
47
|
+
<T extends keyof HTMLElementTagNameMap>(tag: T, ...args1: Partial<Array<HArgs1>>): HTMLElementTagNameMap[T];
|
|
48
|
+
<N extends Node>(node: N, ...args1: Partial<Array<HArgs1>>): N;
|
|
49
|
+
(tagOrNode: string | Node, ...args1: Partial<Array<HArgs1>>): Node;
|
|
55
50
|
};
|
|
56
51
|
|
|
57
52
|
/**
|
|
@@ -59,7 +54,7 @@ export declare const h: {
|
|
|
59
54
|
*
|
|
60
55
|
* - The first argument of type `string` specifies the tag of the element to be created.
|
|
61
56
|
* - The first argument of type `Node` specifies the element to be modified.
|
|
62
|
-
* - All other arguments of type `Partial<Record<PropertyKey,
|
|
57
|
+
* - All other arguments of type `Partial<Record<PropertyKey, unknown>>` are mappings of attributes and properties.
|
|
63
58
|
* Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
|
|
64
59
|
* (Note that `$` is not a valid attribute name character.)
|
|
65
60
|
* All other keys specify *attributes* to be set by `setAttributeNS`.
|
|
@@ -70,33 +65,34 @@ export declare const h: {
|
|
|
70
65
|
* - All other arguments of type `HArgs` are passed to `s` and the results are appended to the element being created or modified.
|
|
71
66
|
*/
|
|
72
67
|
export declare const s: {
|
|
73
|
-
<T extends keyof SVGElementTagNameMap>(tag: T, ...args1: HArgs1
|
|
74
|
-
<N extends Node>(node: N, ...args1: HArgs1
|
|
75
|
-
(tagOrNode: string | Node, ...args1: HArgs1
|
|
68
|
+
<T extends keyof SVGElementTagNameMap>(tag: T, ...args1: Partial<Array<HArgs1>>): SVGElementTagNameMap[T];
|
|
69
|
+
<N extends Node>(node: N, ...args1: Partial<Array<HArgs1>>): N;
|
|
70
|
+
(tagOrNode: string | Node, ...args1: Partial<Array<HArgs1>>): Node;
|
|
76
71
|
};
|
|
77
72
|
|
|
78
73
|
/**
|
|
79
74
|
* A convenient shortcut for `s('svg', ['use', { 'xlink:href': '#' + id }], ...args)`.
|
|
80
75
|
*/
|
|
81
|
-
export declare const svgUse: (id: string, ...args: HArgs1
|
|
76
|
+
export declare const svgUse: (id: string, ...args: Partial<Array<HArgs1>>) => SVGSVGElement;
|
|
82
77
|
|
|
83
78
|
/**
|
|
84
79
|
* A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
|
|
85
80
|
*/
|
|
86
|
-
export declare const has: (key:
|
|
81
|
+
export declare const has: (key: unknown, ref: unknown) => boolean;
|
|
87
82
|
|
|
88
83
|
/**
|
|
89
84
|
* A helper that checks if the given argument is of a certain type.
|
|
90
85
|
*/
|
|
91
86
|
export declare const is: {
|
|
92
|
-
(type:
|
|
93
|
-
(type:
|
|
94
|
-
(type:
|
|
95
|
-
(type:
|
|
96
|
-
(type:
|
|
97
|
-
(type:
|
|
98
|
-
(type:
|
|
99
|
-
|
|
87
|
+
(type: ArrayConstructor, arg: unknown): arg is Partial<Array<unknown>>;
|
|
88
|
+
(type: BigIntConstructor, arg: unknown): arg is bigint;
|
|
89
|
+
(type: BooleanConstructor, arg: unknown): arg is boolean;
|
|
90
|
+
(type: NumberConstructor, arg: unknown): arg is number;
|
|
91
|
+
(type: ObjectConstructor, arg: unknown): arg is Partial<Record<PropertyKey, unknown>>;
|
|
92
|
+
(type: StringConstructor, arg: unknown): arg is string;
|
|
93
|
+
(type: SymbolConstructor, arg: unknown): arg is symbol;
|
|
94
|
+
(type: undefined, arg: unknown): arg is undefined | null;
|
|
95
|
+
<T extends abstract new (...args: Partial<Array<any>>) => unknown>(type: T, arg: unknown): arg is InstanceType<T>;
|
|
100
96
|
};
|
|
101
97
|
|
|
102
98
|
/**
|
|
@@ -159,12 +155,12 @@ export declare const nanolightJs: (code: string) => HArgs1[];
|
|
|
159
155
|
/**
|
|
160
156
|
* A helper that implements TypeScript’s `Pick` utility type.
|
|
161
157
|
*/
|
|
162
|
-
export declare const pick: <T extends Partial<Record<PropertyKey,
|
|
158
|
+
export declare const pick: <T extends Partial<Record<PropertyKey, unknown>>, K extends (keyof T)[]>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Pick<T, K[number]>;
|
|
163
159
|
|
|
164
160
|
/**
|
|
165
161
|
* A helper that implements TypeScript’s `Omit` utility type.
|
|
166
162
|
*/
|
|
167
|
-
export declare const omit: <T extends Partial<Record<PropertyKey,
|
|
163
|
+
export declare const omit: <T extends Partial<Record<PropertyKey, unknown>>, K extends (keyof T)[]>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Omit<T, K[number]>;
|
|
168
164
|
|
|
169
165
|
/**
|
|
170
166
|
* A helper for choosing the correct singular and plural.
|
|
@@ -174,14 +170,14 @@ export declare const plUral: (singular: string, plural2: string, plural5: string
|
|
|
174
170
|
/**
|
|
175
171
|
* A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty object.
|
|
176
172
|
*/
|
|
177
|
-
export declare const pro: (ref:
|
|
173
|
+
export declare const pro: (ref: unknown) => any;
|
|
178
174
|
|
|
179
175
|
/**
|
|
180
176
|
* A helper that provides information about the given `refs`.
|
|
181
177
|
*
|
|
182
178
|
* It returns an array of triples: `[«name», «prototype-name», «array-of-own-property-names»]`.
|
|
183
179
|
*/
|
|
184
|
-
export declare const refsInfo: (...refs:
|
|
180
|
+
export declare const refsInfo: (...refs: Partial<Array<unknown>>) => [string, string, (string | undefined)[]][];
|
|
185
181
|
|
|
186
182
|
/**
|
|
187
183
|
* A helper that generates a UUID v1 identifier (with a creation timestamp).
|
package/nnn.js
CHANGED
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
// src/nnn/eq.ts
|
|
2
|
-
var eq = (x, y) => {
|
|
3
|
-
if (x === y) {
|
|
4
|
-
return true;
|
|
5
|
-
}
|
|
6
|
-
const xConstructor = x?.constructor;
|
|
7
|
-
if (xConstructor === y?.constructor) {
|
|
8
|
-
if (xConstructor === Number) {
|
|
9
|
-
return isNaN(x) && isNaN(y) || +x === +y;
|
|
10
|
-
}
|
|
11
|
-
if (xConstructor === Date) {
|
|
12
|
-
return +x === +y;
|
|
13
|
-
}
|
|
14
|
-
if (xConstructor === String || xConstructor === RegExp) {
|
|
15
|
-
return "" + x === "" + y;
|
|
16
|
-
}
|
|
17
|
-
if (xConstructor === Array) {
|
|
18
|
-
return x.length === y.length && x.every((item, index) => eq(item, y[index]));
|
|
19
|
-
}
|
|
20
|
-
if (xConstructor === Object) {
|
|
21
|
-
const keysOfX = Object.keys(x);
|
|
22
|
-
return keysOfX.length === Object.keys(y).length && keysOfX.every((key) => eq(x[key], y[key]));
|
|
23
|
-
}
|
|
24
|
-
if (xConstructor === Set || xConstructor === Map) {
|
|
25
|
-
if (x.size !== y.size) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const xa = [...x];
|
|
29
|
-
const ya = [...y];
|
|
30
|
-
return xa.every((xv) => ya.find((yv) => eq(xv, yv)));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
1
|
// src/nnn/escape.ts
|
|
37
2
|
var escapeValues = (escapeMap, values) => values.map((value) => (escapeMap.get(value?.constructor) ?? escapeMap.get(undefined))?.(value) ?? "");
|
|
38
3
|
var escape = (escapeMap, template, ...values) => String.raw(template, ...escapeValues(escapeMap, values));
|
|
@@ -203,8 +168,10 @@ var jsOnParse = (handlers, text) => JSON.parse(text, (key, value) => {
|
|
|
203
168
|
}
|
|
204
169
|
isSecondKey = true;
|
|
205
170
|
}
|
|
206
|
-
|
|
207
|
-
|
|
171
|
+
const handler = handlers[key];
|
|
172
|
+
const params = value[key];
|
|
173
|
+
if (is(Function, handler) && is(Array, params)) {
|
|
174
|
+
return handler(...params);
|
|
208
175
|
}
|
|
209
176
|
}
|
|
210
177
|
return value;
|
|
@@ -305,6 +272,5 @@ export {
|
|
|
305
272
|
h,
|
|
306
273
|
fixTypography,
|
|
307
274
|
escapeValues,
|
|
308
|
-
escape
|
|
309
|
-
eq
|
|
275
|
+
escape
|
|
310
276
|
};
|
package/package.json
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
"description": "Jackens’ JavaScript helpers.",
|
|
4
4
|
"homepage": "https://jackens.github.io/nnn/doc/",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"chart",
|
|
7
|
-
"chartable",
|
|
8
|
-
"charts",
|
|
9
6
|
"CSS-in-JS",
|
|
10
7
|
"deepEqual",
|
|
11
8
|
"DOM",
|
|
@@ -43,5 +40,5 @@
|
|
|
43
40
|
"types": "nnn.d.ts",
|
|
44
41
|
"name": "@jackens/nnn",
|
|
45
42
|
"type": "module",
|
|
46
|
-
"version": "2024.
|
|
43
|
+
"version": "2024.4.5"
|
|
47
44
|
}
|
package/readme.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Jackens’ JavaScript helpers.
|
|
4
4
|
|
|
5
|
-
<sub>Version: <code class="version">2024.
|
|
5
|
+
<sub>Version: <code class="version">2024.4.5</code></sub>
|
|
6
6
|
|
|
7
7
|
## Examples
|
|
8
8
|
|
|
9
|
-
- [Chessboard Demo](https://jackens.github.io/nnn/chessboard/)
|
|
10
9
|
- [Documentation](https://jackens.github.io/nnn/doc/)
|
|
10
|
+
- [Chessboard Demo](https://jackens.github.io/nnn/chessboard/)
|
|
11
11
|
- [Gant Chart Demo](https://jackens.github.io/nnn/gantt/)
|
|
12
12
|
- [Responsive Web Design Demo](https://jackens.github.io/nnn/rwd/)
|
|
13
13
|
|
|
@@ -44,7 +44,6 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
44
44
|
- `HArgs1`: The type of arguments of the `h` and `s` helpers.
|
|
45
45
|
- `JcNode`: The type of arguments of the `jc` helper.
|
|
46
46
|
- `JcRoot`: The type of arguments of the `jc` helper.
|
|
47
|
-
- `eq`: A helper that checks equality of the given arguments.
|
|
48
47
|
- `escape`: A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
|
|
49
48
|
- `escapeValues`: A generic helper for escaping `values` by given `escapeMap`.
|
|
50
49
|
- `fixTypography`: A helper that implements typographic corrections specific to Polish typography.
|
|
@@ -68,7 +67,7 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
68
67
|
### EscapeMap
|
|
69
68
|
|
|
70
69
|
```ts
|
|
71
|
-
type EscapeMap = Map<
|
|
70
|
+
type EscapeMap = Map<unknown, (value?: unknown) => string>;
|
|
72
71
|
```
|
|
73
72
|
|
|
74
73
|
The type of arguments of the `escapeValues` and `escape` helpers.
|
|
@@ -84,7 +83,7 @@ The type of arguments of the `h` and `s` helpers.
|
|
|
84
83
|
### HArgs1
|
|
85
84
|
|
|
86
85
|
```ts
|
|
87
|
-
type HArgs1 = Partial<Record<PropertyKey,
|
|
86
|
+
type HArgs1 = Partial<Record<PropertyKey, unknown>> | null | undefined | Node | string | number | HArgs;
|
|
88
87
|
```
|
|
89
88
|
|
|
90
89
|
The type of arguments of the `h` and `s` helpers.
|
|
@@ -107,52 +106,10 @@ type JcRoot = Partial<Record<PropertyKey, JcNode>>;
|
|
|
107
106
|
|
|
108
107
|
The type of arguments of the `jc` helper.
|
|
109
108
|
|
|
110
|
-
### eq
|
|
111
|
-
|
|
112
|
-
```ts
|
|
113
|
-
const eq: (x: any, y: any) => boolean;
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
A helper that checks equality of the given arguments.
|
|
117
|
-
|
|
118
|
-
#### Usage Examples
|
|
119
|
-
|
|
120
|
-
```js
|
|
121
|
-
expect(eq(true, true)).toBeTrue()
|
|
122
|
-
expect(eq(NaN, NaN)).toBeTrue()
|
|
123
|
-
expect(eq(null, undefined)).toBeFalse()
|
|
124
|
-
expect(eq(42, 42)).toBeTrue()
|
|
125
|
-
expect(eq(42, new Number(42))).toBeTrue()
|
|
126
|
-
expect(eq(42, Number(42))).toBeTrue()
|
|
127
|
-
expect(eq(new Number(42), Number(42))).toBeTrue()
|
|
128
|
-
expect(eq(42, '42')).toBeFalse()
|
|
129
|
-
expect(eq('42', '42')).toBeTrue()
|
|
130
|
-
expect(eq('42', new String('42'))).toBeTrue()
|
|
131
|
-
expect(eq('42', String('42'))).toBeTrue()
|
|
132
|
-
expect(eq(String('42'), new String('42'))).toBeTrue()
|
|
133
|
-
expect(eq(/42/, /42/)).toBeTrue()
|
|
134
|
-
expect(eq(/42/, /42/g)).toBeFalse()
|
|
135
|
-
expect(eq(new Date(42), new Date(42))).toBeTrue()
|
|
136
|
-
expect(eq(new Date(), new Date(42))).toBeFalse()
|
|
137
|
-
expect(eq({ j: '42', c: 42 }, { c: 42, j: '42' })).toBeTrue()
|
|
138
|
-
expect(eq([42, '42'], [42, '42'])).toBeTrue()
|
|
139
|
-
expect(eq(new Set(['42', 42]), new Set([42, '42']))).toBeTrue()
|
|
140
|
-
expect(eq(new Set(['42', 42]), new Set([42]))).toBeFalse()
|
|
141
|
-
expect(eq(new Set([42, undefined]), new Set([42]))).toBeFalse()
|
|
142
|
-
expect(eq(
|
|
143
|
-
new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]),
|
|
144
|
-
new Map([[{ c: 42 }, { C: '42' }], [{ j: 42 }, { J: '42' }]])
|
|
145
|
-
)).toBeTrue()
|
|
146
|
-
expect(eq(
|
|
147
|
-
new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]),
|
|
148
|
-
new Map([[{ j: '42' }, { J: 42 }], [{ c: '42' }, { C: 42 }]])
|
|
149
|
-
)).toBeFalse()
|
|
150
|
-
```
|
|
151
|
-
|
|
152
109
|
### escape
|
|
153
110
|
|
|
154
111
|
```ts
|
|
155
|
-
const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values:
|
|
112
|
+
const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values: Partial<Array<unknown>>) => string;
|
|
156
113
|
```
|
|
157
114
|
|
|
158
115
|
A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
|
|
@@ -162,7 +119,7 @@ A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings
|
|
|
162
119
|
```js
|
|
163
120
|
const escapeMap: EscapeMap = new Map([
|
|
164
121
|
[undefined, () => 'NULL'],
|
|
165
|
-
[Array, (values:
|
|
122
|
+
[Array, (values: Partial<Array<unknown>>) => escapeValues(escapeMap, values).join(', ')],
|
|
166
123
|
[Boolean, (value: boolean) => `b'${+value}'`],
|
|
167
124
|
[Date, (value: Date) => `'${value.toISOString().replace(/^(.+)T(.+)\..*$/, '$1 $2')}'`],
|
|
168
125
|
[Number, (value: number) => `${value}`],
|
|
@@ -187,7 +144,7 @@ expect(actual).toStrictEqual(expected)
|
|
|
187
144
|
### escapeValues
|
|
188
145
|
|
|
189
146
|
```ts
|
|
190
|
-
const escapeValues: (escapeMap: EscapeMap, values:
|
|
147
|
+
const escapeValues: (escapeMap: EscapeMap, values: Partial<Array<unknown>>) => Partial<Array<string>>;
|
|
191
148
|
```
|
|
192
149
|
|
|
193
150
|
A generic helper for escaping `values` by given `escapeMap`.
|
|
@@ -216,9 +173,9 @@ expect(p.innerHTML).toStrictEqual(
|
|
|
216
173
|
|
|
217
174
|
```ts
|
|
218
175
|
const h: {
|
|
219
|
-
<T extends keyof HTMLElementTagNameMap>(tag: T, ...args1: HArgs1
|
|
220
|
-
<N extends Node>(node: N, ...args1: HArgs1
|
|
221
|
-
(tagOrNode: string | Node, ...args1: HArgs1
|
|
176
|
+
<T extends keyof HTMLElementTagNameMap>(tag: T, ...args1: Partial<Array<HArgs1>>): HTMLElementTagNameMap[T];
|
|
177
|
+
<N extends Node>(node: N, ...args1: Partial<Array<HArgs1>>): N;
|
|
178
|
+
(tagOrNode: string | Node, ...args1: Partial<Array<HArgs1>>): Node;
|
|
222
179
|
};
|
|
223
180
|
```
|
|
224
181
|
|
|
@@ -226,7 +183,7 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
226
183
|
|
|
227
184
|
- The first argument of type `string` specifies the tag of the element to be created.
|
|
228
185
|
- The first argument of type `Node` specifies the element to be modified.
|
|
229
|
-
- All other arguments of type `Partial<Record<PropertyKey,
|
|
186
|
+
- All other arguments of type `Partial<Record<PropertyKey, unknown>>` are mappings of attributes and properties.
|
|
230
187
|
Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
|
|
231
188
|
(Note that `$` is not a valid attribute name character.)
|
|
232
189
|
All other keys specify *attributes* to be set by `setAttribute`.
|
|
@@ -307,7 +264,7 @@ expect(div.key).toStrictEqual({ one: 1, two: 2 })
|
|
|
307
264
|
### has
|
|
308
265
|
|
|
309
266
|
```ts
|
|
310
|
-
const has: (key:
|
|
267
|
+
const has: (key: unknown, ref: unknown) => boolean;
|
|
311
268
|
```
|
|
312
269
|
|
|
313
270
|
A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
|
|
@@ -347,14 +304,15 @@ expect(has('key', null)).toBeFalse()
|
|
|
347
304
|
|
|
348
305
|
```ts
|
|
349
306
|
const is: {
|
|
350
|
-
(type:
|
|
351
|
-
(type:
|
|
352
|
-
(type:
|
|
353
|
-
(type:
|
|
354
|
-
(type:
|
|
355
|
-
(type:
|
|
356
|
-
(type:
|
|
357
|
-
|
|
307
|
+
(type: ArrayConstructor, arg: unknown): arg is Partial<Array<unknown>>;
|
|
308
|
+
(type: BigIntConstructor, arg: unknown): arg is bigint;
|
|
309
|
+
(type: BooleanConstructor, arg: unknown): arg is boolean;
|
|
310
|
+
(type: NumberConstructor, arg: unknown): arg is number;
|
|
311
|
+
(type: ObjectConstructor, arg: unknown): arg is Partial<Record<PropertyKey, unknown>>;
|
|
312
|
+
(type: StringConstructor, arg: unknown): arg is string;
|
|
313
|
+
(type: SymbolConstructor, arg: unknown): arg is symbol;
|
|
314
|
+
(type: undefined, arg: unknown): arg is undefined | null;
|
|
315
|
+
<T extends abstract new (...args: Partial<Array<any>>) => unknown>(type: T, arg: unknown): arg is InstanceType<T>;
|
|
358
316
|
};
|
|
359
317
|
```
|
|
360
318
|
|
|
@@ -383,7 +341,7 @@ expect(is(Map, new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]))).t
|
|
|
383
341
|
```
|
|
384
342
|
|
|
385
343
|
```js
|
|
386
|
-
const iz = (type:
|
|
344
|
+
const iz = (type: unknown, arg: unknown) => ({}).toString.call(arg).slice(8, -1) === type?.name
|
|
387
345
|
|
|
388
346
|
class FooBar { }
|
|
389
347
|
|
|
@@ -761,7 +719,7 @@ expect(nanolightJs(codeJs)).toStrictEqual([
|
|
|
761
719
|
### omit
|
|
762
720
|
|
|
763
721
|
```ts
|
|
764
|
-
const omit: <T extends Partial<Record<PropertyKey,
|
|
722
|
+
const omit: <T extends Partial<Record<PropertyKey, unknown>>, K extends (keyof T)[]>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Omit<T, K[number]>;
|
|
765
723
|
```
|
|
766
724
|
|
|
767
725
|
A helper that implements TypeScript’s `Omit` utility type.
|
|
@@ -777,7 +735,7 @@ expect(omit(obj, ['c'])).toStrictEqual({ a: 42, b: '42' })
|
|
|
777
735
|
### pick
|
|
778
736
|
|
|
779
737
|
```ts
|
|
780
|
-
const pick: <T extends Partial<Record<PropertyKey,
|
|
738
|
+
const pick: <T extends Partial<Record<PropertyKey, unknown>>, K extends (keyof T)[]>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Pick<T, K[number]>;
|
|
781
739
|
```
|
|
782
740
|
|
|
783
741
|
A helper that implements TypeScript’s `Pick` utility type.
|
|
@@ -819,7 +777,7 @@ expect(car(42)).toStrictEqual('cars')
|
|
|
819
777
|
### pro
|
|
820
778
|
|
|
821
779
|
```ts
|
|
822
|
-
const pro: (ref:
|
|
780
|
+
const pro: (ref: unknown) => any;
|
|
823
781
|
```
|
|
824
782
|
|
|
825
783
|
A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty object.
|
|
@@ -857,7 +815,7 @@ expect(ref).toStrictEqual({ one: { two: { three: { four: 1234 } } } })
|
|
|
857
815
|
### refsInfo
|
|
858
816
|
|
|
859
817
|
```ts
|
|
860
|
-
const refsInfo: (...refs:
|
|
818
|
+
const refsInfo: (...refs: Partial<Array<unknown>>) => [string, string, (string | undefined)[]][];
|
|
861
819
|
```
|
|
862
820
|
|
|
863
821
|
A helper that provides information about the given `refs`.
|
|
@@ -901,9 +859,9 @@ console.log(browserFingerprint())
|
|
|
901
859
|
|
|
902
860
|
```ts
|
|
903
861
|
const s: {
|
|
904
|
-
<T extends keyof SVGElementTagNameMap>(tag: T, ...args1: HArgs1
|
|
905
|
-
<N extends Node>(node: N, ...args1: HArgs1
|
|
906
|
-
(tagOrNode: string | Node, ...args1: HArgs1
|
|
862
|
+
<T extends keyof SVGElementTagNameMap>(tag: T, ...args1: Partial<Array<HArgs1>>): SVGElementTagNameMap[T];
|
|
863
|
+
<N extends Node>(node: N, ...args1: Partial<Array<HArgs1>>): N;
|
|
864
|
+
(tagOrNode: string | Node, ...args1: Partial<Array<HArgs1>>): Node;
|
|
907
865
|
};
|
|
908
866
|
```
|
|
909
867
|
|
|
@@ -911,7 +869,7 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
911
869
|
|
|
912
870
|
- The first argument of type `string` specifies the tag of the element to be created.
|
|
913
871
|
- The first argument of type `Node` specifies the element to be modified.
|
|
914
|
-
- All other arguments of type `Partial<Record<PropertyKey,
|
|
872
|
+
- All other arguments of type `Partial<Record<PropertyKey, unknown>>` are mappings of attributes and properties.
|
|
915
873
|
Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
|
|
916
874
|
(Note that `$` is not a valid attribute name character.)
|
|
917
875
|
All other keys specify *attributes* to be set by `setAttributeNS`.
|
|
@@ -924,7 +882,7 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
924
882
|
### svgUse
|
|
925
883
|
|
|
926
884
|
```ts
|
|
927
|
-
const svgUse: (id: string, ...args: HArgs1
|
|
885
|
+
const svgUse: (id: string, ...args: Partial<Array<HArgs1>>) => SVGSVGElement;
|
|
928
886
|
```
|
|
929
887
|
|
|
930
888
|
A convenient shortcut for `s('svg', ['use', { 'xlink:href': '#' + id }], ...args)`.
|