@jackens/nnn 2024.3.31 → 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 +20 -20
- package/package.json +1 -1
- package/readme.md +24 -24
package/nnn.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The type of arguments of the `escapeValues` and `escape` helpers.
|
|
3
3
|
*/
|
|
4
|
-
export type EscapeMap = Map<
|
|
4
|
+
export type EscapeMap = Map<unknown, (value?: unknown) => string>;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A generic helper for escaping `values` by given `escapeMap`.
|
|
8
8
|
*/
|
|
9
|
-
export declare const escapeValues: (escapeMap: EscapeMap, values: Partial<Array<
|
|
9
|
+
export declare const escapeValues: (escapeMap: EscapeMap, values: Partial<Array<unknown>>) => Partial<Array<string>>;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
|
|
13
13
|
*/
|
|
14
|
-
export declare const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values: Partial<Array<
|
|
14
|
+
export declare const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values: Partial<Array<unknown>>) => string;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* A helper that implements typographic corrections specific to Polish typography.
|
|
@@ -21,7 +21,7 @@ export declare const fixTypography: (node: Node) => void;
|
|
|
21
21
|
/**
|
|
22
22
|
* The type of arguments of the `h` and `s` helpers.
|
|
23
23
|
*/
|
|
24
|
-
export type HArgs1 = Partial<Record<PropertyKey,
|
|
24
|
+
export type HArgs1 = Partial<Record<PropertyKey, unknown>> | null | undefined | Node | string | number | HArgs;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* The type of arguments of the `h` and `s` helpers.
|
|
@@ -33,7 +33,7 @@ export type HArgs = [string | Node, ...HArgs1[]];
|
|
|
33
33
|
*
|
|
34
34
|
* - The first argument of type `string` specifies the tag of the element to be created.
|
|
35
35
|
* - The first argument of type `Node` specifies the element to be modified.
|
|
36
|
-
* - All other arguments of type `Partial<Record<PropertyKey,
|
|
36
|
+
* - All other arguments of type `Partial<Record<PropertyKey, unknown>>` are mappings of attributes and properties.
|
|
37
37
|
* Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
|
|
38
38
|
* (Note that `$` is not a valid attribute name character.)
|
|
39
39
|
* All other keys specify *attributes* to be set by `setAttribute`.
|
|
@@ -54,7 +54,7 @@ export declare const h: {
|
|
|
54
54
|
*
|
|
55
55
|
* - The first argument of type `string` specifies the tag of the element to be created.
|
|
56
56
|
* - The first argument of type `Node` specifies the element to be modified.
|
|
57
|
-
* - All other arguments of type `Partial<Record<PropertyKey,
|
|
57
|
+
* - All other arguments of type `Partial<Record<PropertyKey, unknown>>` are mappings of attributes and properties.
|
|
58
58
|
* Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
|
|
59
59
|
* (Note that `$` is not a valid attribute name character.)
|
|
60
60
|
* All other keys specify *attributes* to be set by `setAttributeNS`.
|
|
@@ -78,21 +78,21 @@ export declare const svgUse: (id: string, ...args: Partial<Array<HArgs1>>) => SV
|
|
|
78
78
|
/**
|
|
79
79
|
* A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
|
|
80
80
|
*/
|
|
81
|
-
export declare const has: (key:
|
|
81
|
+
export declare const has: (key: unknown, ref: unknown) => boolean;
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* A helper that checks if the given argument is of a certain type.
|
|
85
85
|
*/
|
|
86
86
|
export declare const is: {
|
|
87
|
-
(type: ArrayConstructor, arg:
|
|
88
|
-
(type: BigIntConstructor, arg:
|
|
89
|
-
(type: BooleanConstructor, arg:
|
|
90
|
-
(type: NumberConstructor, arg:
|
|
91
|
-
(type: ObjectConstructor, arg:
|
|
92
|
-
(type: StringConstructor, arg:
|
|
93
|
-
(type: SymbolConstructor, arg:
|
|
94
|
-
(type: undefined, arg:
|
|
95
|
-
<T extends abstract new (...args: Partial<Array<any>>) =>
|
|
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>;
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
/**
|
|
@@ -155,12 +155,12 @@ export declare const nanolightJs: (code: string) => HArgs1[];
|
|
|
155
155
|
/**
|
|
156
156
|
* A helper that implements TypeScript’s `Pick` utility type.
|
|
157
157
|
*/
|
|
158
|
-
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]>;
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
161
|
* A helper that implements TypeScript’s `Omit` utility type.
|
|
162
162
|
*/
|
|
163
|
-
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]>;
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
166
|
* A helper for choosing the correct singular and plural.
|
|
@@ -170,14 +170,14 @@ export declare const plUral: (singular: string, plural2: string, plural5: string
|
|
|
170
170
|
/**
|
|
171
171
|
* A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty object.
|
|
172
172
|
*/
|
|
173
|
-
export declare const pro: (ref:
|
|
173
|
+
export declare const pro: (ref: unknown) => any;
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
176
|
* A helper that provides information about the given `refs`.
|
|
177
177
|
*
|
|
178
178
|
* It returns an array of triples: `[«name», «prototype-name», «array-of-own-property-names»]`.
|
|
179
179
|
*/
|
|
180
|
-
export declare const refsInfo: (...refs: Partial<Array<
|
|
180
|
+
export declare const refsInfo: (...refs: Partial<Array<unknown>>) => [string, string, (string | undefined)[]][];
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
183
|
* A helper that generates a UUID v1 identifier (with a creation timestamp).
|
package/package.json
CHANGED
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
|
|
|
@@ -67,7 +67,7 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
67
67
|
### EscapeMap
|
|
68
68
|
|
|
69
69
|
```ts
|
|
70
|
-
type EscapeMap = Map<
|
|
70
|
+
type EscapeMap = Map<unknown, (value?: unknown) => string>;
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
The type of arguments of the `escapeValues` and `escape` helpers.
|
|
@@ -83,7 +83,7 @@ The type of arguments of the `h` and `s` helpers.
|
|
|
83
83
|
### HArgs1
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
|
-
type HArgs1 = Partial<Record<PropertyKey,
|
|
86
|
+
type HArgs1 = Partial<Record<PropertyKey, unknown>> | null | undefined | Node | string | number | HArgs;
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
The type of arguments of the `h` and `s` helpers.
|
|
@@ -109,7 +109,7 @@ The type of arguments of the `jc` helper.
|
|
|
109
109
|
### escape
|
|
110
110
|
|
|
111
111
|
```ts
|
|
112
|
-
const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values: Partial<Array<
|
|
112
|
+
const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values: Partial<Array<unknown>>) => string;
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
|
|
@@ -119,7 +119,7 @@ A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings
|
|
|
119
119
|
```js
|
|
120
120
|
const escapeMap: EscapeMap = new Map([
|
|
121
121
|
[undefined, () => 'NULL'],
|
|
122
|
-
[Array, (values: Partial<Array<
|
|
122
|
+
[Array, (values: Partial<Array<unknown>>) => escapeValues(escapeMap, values).join(', ')],
|
|
123
123
|
[Boolean, (value: boolean) => `b'${+value}'`],
|
|
124
124
|
[Date, (value: Date) => `'${value.toISOString().replace(/^(.+)T(.+)\..*$/, '$1 $2')}'`],
|
|
125
125
|
[Number, (value: number) => `${value}`],
|
|
@@ -144,7 +144,7 @@ expect(actual).toStrictEqual(expected)
|
|
|
144
144
|
### escapeValues
|
|
145
145
|
|
|
146
146
|
```ts
|
|
147
|
-
const escapeValues: (escapeMap: EscapeMap, values: Partial<Array<
|
|
147
|
+
const escapeValues: (escapeMap: EscapeMap, values: Partial<Array<unknown>>) => Partial<Array<string>>;
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
A generic helper for escaping `values` by given `escapeMap`.
|
|
@@ -183,7 +183,7 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
183
183
|
|
|
184
184
|
- The first argument of type `string` specifies the tag of the element to be created.
|
|
185
185
|
- The first argument of type `Node` specifies the element to be modified.
|
|
186
|
-
- All other arguments of type `Partial<Record<PropertyKey,
|
|
186
|
+
- All other arguments of type `Partial<Record<PropertyKey, unknown>>` are mappings of attributes and properties.
|
|
187
187
|
Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
|
|
188
188
|
(Note that `$` is not a valid attribute name character.)
|
|
189
189
|
All other keys specify *attributes* to be set by `setAttribute`.
|
|
@@ -264,7 +264,7 @@ expect(div.key).toStrictEqual({ one: 1, two: 2 })
|
|
|
264
264
|
### has
|
|
265
265
|
|
|
266
266
|
```ts
|
|
267
|
-
const has: (key:
|
|
267
|
+
const has: (key: unknown, ref: unknown) => boolean;
|
|
268
268
|
```
|
|
269
269
|
|
|
270
270
|
A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
|
|
@@ -304,15 +304,15 @@ expect(has('key', null)).toBeFalse()
|
|
|
304
304
|
|
|
305
305
|
```ts
|
|
306
306
|
const is: {
|
|
307
|
-
(type: ArrayConstructor, arg:
|
|
308
|
-
(type: BigIntConstructor, arg:
|
|
309
|
-
(type: BooleanConstructor, arg:
|
|
310
|
-
(type: NumberConstructor, arg:
|
|
311
|
-
(type: ObjectConstructor, arg:
|
|
312
|
-
(type: StringConstructor, arg:
|
|
313
|
-
(type: SymbolConstructor, arg:
|
|
314
|
-
(type: undefined, arg:
|
|
315
|
-
<T extends abstract new (...args: Partial<Array<any>>) =>
|
|
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>;
|
|
316
316
|
};
|
|
317
317
|
```
|
|
318
318
|
|
|
@@ -341,7 +341,7 @@ expect(is(Map, new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]))).t
|
|
|
341
341
|
```
|
|
342
342
|
|
|
343
343
|
```js
|
|
344
|
-
const iz = (type:
|
|
344
|
+
const iz = (type: unknown, arg: unknown) => ({}).toString.call(arg).slice(8, -1) === type?.name
|
|
345
345
|
|
|
346
346
|
class FooBar { }
|
|
347
347
|
|
|
@@ -719,7 +719,7 @@ expect(nanolightJs(codeJs)).toStrictEqual([
|
|
|
719
719
|
### omit
|
|
720
720
|
|
|
721
721
|
```ts
|
|
722
|
-
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]>;
|
|
723
723
|
```
|
|
724
724
|
|
|
725
725
|
A helper that implements TypeScript’s `Omit` utility type.
|
|
@@ -735,7 +735,7 @@ expect(omit(obj, ['c'])).toStrictEqual({ a: 42, b: '42' })
|
|
|
735
735
|
### pick
|
|
736
736
|
|
|
737
737
|
```ts
|
|
738
|
-
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]>;
|
|
739
739
|
```
|
|
740
740
|
|
|
741
741
|
A helper that implements TypeScript’s `Pick` utility type.
|
|
@@ -777,7 +777,7 @@ expect(car(42)).toStrictEqual('cars')
|
|
|
777
777
|
### pro
|
|
778
778
|
|
|
779
779
|
```ts
|
|
780
|
-
const pro: (ref:
|
|
780
|
+
const pro: (ref: unknown) => any;
|
|
781
781
|
```
|
|
782
782
|
|
|
783
783
|
A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty object.
|
|
@@ -815,7 +815,7 @@ expect(ref).toStrictEqual({ one: { two: { three: { four: 1234 } } } })
|
|
|
815
815
|
### refsInfo
|
|
816
816
|
|
|
817
817
|
```ts
|
|
818
|
-
const refsInfo: (...refs: Partial<Array<
|
|
818
|
+
const refsInfo: (...refs: Partial<Array<unknown>>) => [string, string, (string | undefined)[]][];
|
|
819
819
|
```
|
|
820
820
|
|
|
821
821
|
A helper that provides information about the given `refs`.
|
|
@@ -869,7 +869,7 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
869
869
|
|
|
870
870
|
- The first argument of type `string` specifies the tag of the element to be created.
|
|
871
871
|
- The first argument of type `Node` specifies the element to be modified.
|
|
872
|
-
- All other arguments of type `Partial<Record<PropertyKey,
|
|
872
|
+
- All other arguments of type `Partial<Record<PropertyKey, unknown>>` are mappings of attributes and properties.
|
|
873
873
|
Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
|
|
874
874
|
(Note that `$` is not a valid attribute name character.)
|
|
875
875
|
All other keys specify *attributes* to be set by `setAttributeNS`.
|