@jackens/nnn 2025.6.20 → 2025.9.3
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 +13 -8
- package/nnn.js +5 -12
- package/package.json +2 -1
- package/readme.md +19 -37
package/nnn.d.ts
CHANGED
|
@@ -23,11 +23,7 @@ export declare const c: (root: C_Root, splitter?: string) => string;
|
|
|
23
23
|
/**
|
|
24
24
|
* A tiny helper for parsing CSV.
|
|
25
25
|
*/
|
|
26
|
-
export declare const
|
|
27
|
-
/**
|
|
28
|
-
* A tiny helper for parsing CSV.
|
|
29
|
-
*/
|
|
30
|
-
export declare const csv_parse: (csv: string, separator?: string) => Record<PropertyKey, string>[];
|
|
26
|
+
export declare const csv_parse: (csv: string, separator?: string) => string[][];
|
|
31
27
|
/**
|
|
32
28
|
* The type of arguments of the `escape_values` and `escape` helpers.
|
|
33
29
|
*/
|
|
@@ -96,18 +92,27 @@ export declare const has_own: (ref: unknown, key: unknown) => boolean;
|
|
|
96
92
|
* A helper that checks if the given argument is of type `any[]`.
|
|
97
93
|
*/
|
|
98
94
|
export declare const is_array: (arg: any) => arg is any[];
|
|
95
|
+
declare const FINITE_NUMBER: unique symbol;
|
|
96
|
+
type Finite_Number = number & {
|
|
97
|
+
readonly [FINITE_NUMBER]: true;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* A helper that checks if the given argument is of type `number` but not `±Infinity` nor `NaN`.
|
|
101
|
+
*/
|
|
102
|
+
export declare const is_finite_number: ((arg: unknown) => arg is Finite_Number);
|
|
99
103
|
/**
|
|
100
104
|
* A helper that checks if the given argument is of type `number`.
|
|
101
105
|
*/
|
|
102
|
-
export declare const is_number: (arg:
|
|
106
|
+
export declare const is_number: (arg: unknown) => arg is number;
|
|
103
107
|
/**
|
|
104
108
|
* A helper that checks if the given argument is of type `Record<PropertyKey, unknown>`.
|
|
105
109
|
*/
|
|
106
|
-
export declare const is_record: (arg:
|
|
110
|
+
export declare const is_record: (arg: unknown) => arg is Record<PropertyKey, unknown>;
|
|
107
111
|
/**
|
|
108
112
|
* A helper that checks if the given argument is of type `string`.
|
|
109
113
|
*/
|
|
110
|
-
export declare const is_string: (arg:
|
|
114
|
+
export declare const is_string: (arg: unknown) => arg is string;
|
|
115
|
+
export {};
|
|
111
116
|
/**
|
|
112
117
|
* `JSON.parse` with “JavaScript turned on”.
|
|
113
118
|
*
|
package/nnn.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/nnn/is.ts
|
|
2
2
|
var is_array = Array.isArray;
|
|
3
|
+
var is_finite_number = Number.isFinite;
|
|
3
4
|
var is_number = (arg) => typeof arg === "number";
|
|
4
5
|
var is_record = (arg) => typeof arg === "object" && arg != null && !is_array(arg);
|
|
5
6
|
var is_string = (arg) => typeof arg === "string";
|
|
@@ -57,19 +58,11 @@ var c = (root, splitter = "$$") => {
|
|
|
57
58
|
return chunks.join("");
|
|
58
59
|
};
|
|
59
60
|
// src/nnn/csv_parse.ts
|
|
60
|
-
var
|
|
61
|
+
var csv_parse = (csv, separator = ",") => {
|
|
61
62
|
const main_pattern = /\n|(?<!")("(?:[^"]|"")*")(?!")/g;
|
|
62
63
|
const line_pattern = new RegExp(`${separator}|(?<!")\\s*"((?:[^"]|"")*)"\\s*(?!")`, "g");
|
|
63
64
|
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"));
|
|
64
65
|
};
|
|
65
|
-
var csv_parse = (csv, separator = ",") => {
|
|
66
|
-
const rows = csv_parse_raw(csv, separator);
|
|
67
|
-
const keys = rows.shift();
|
|
68
|
-
return keys != null ? rows.map((row) => keys.reduce((record, key, index) => {
|
|
69
|
-
record[key] = row[index];
|
|
70
|
-
return record;
|
|
71
|
-
}, {})) : [];
|
|
72
|
-
};
|
|
73
66
|
// src/nnn/escape.ts
|
|
74
67
|
var escape_values = (escape_map, values) => values.map((value) => (escape_map.get(value?.constructor) ?? escape_map.get(undefined))?.(value) ?? "");
|
|
75
68
|
var escape = (escape_map, template, ...values) => String.raw(template, ...escape_values(escape_map, values));
|
|
@@ -90,7 +83,7 @@ var _h = (namespace_uri) => {
|
|
|
90
83
|
if (name[0] === "$") {
|
|
91
84
|
const name1 = name.slice(1);
|
|
92
85
|
if (is_record(value)) {
|
|
93
|
-
node[name1]
|
|
86
|
+
node[name1] ??= {};
|
|
94
87
|
Object.assign(node[name1], value);
|
|
95
88
|
} else {
|
|
96
89
|
node[name1] = value;
|
|
@@ -221,7 +214,7 @@ var pl_ural = (singular, plural_2, plural_5, value) => {
|
|
|
221
214
|
// src/nnn/pro.ts
|
|
222
215
|
var pro = (ref) => new Proxy(ref, {
|
|
223
216
|
get(target, key) {
|
|
224
|
-
return pro(target[key]
|
|
217
|
+
return pro(target[key] ??= {});
|
|
225
218
|
}
|
|
226
219
|
});
|
|
227
220
|
// src/nnn/uuid_v1.ts
|
|
@@ -246,13 +239,13 @@ export {
|
|
|
246
239
|
is_string,
|
|
247
240
|
is_record,
|
|
248
241
|
is_number,
|
|
242
|
+
is_finite_number,
|
|
249
243
|
is_array,
|
|
250
244
|
has_own,
|
|
251
245
|
h,
|
|
252
246
|
fix_typography,
|
|
253
247
|
escape_values,
|
|
254
248
|
escape,
|
|
255
|
-
csv_parse_raw,
|
|
256
249
|
csv_parse,
|
|
257
250
|
c
|
|
258
251
|
};
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"in",
|
|
16
16
|
"is",
|
|
17
17
|
"is_array",
|
|
18
|
+
"is_finite_number",
|
|
18
19
|
"is_number",
|
|
19
20
|
"is_record",
|
|
20
21
|
"is_string",
|
|
@@ -35,5 +36,5 @@
|
|
|
35
36
|
"name": "@jackens/nnn",
|
|
36
37
|
"type": "module",
|
|
37
38
|
"types": "nnn.d.ts",
|
|
38
|
-
"version": "2025.
|
|
39
|
+
"version": "2025.9.3"
|
|
39
40
|
}
|
package/readme.md
CHANGED
|
@@ -35,13 +35,13 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
35
35
|
- `H_Args_1`: The type of arguments of the `h` and `s` helpers.
|
|
36
36
|
- `c`: A simple JS-to-CSS (aka CSS-in-JS) helper.
|
|
37
37
|
- `csv_parse`: A tiny helper for parsing CSV.
|
|
38
|
-
- `csv_parse_raw`: A tiny helper for parsing CSV.
|
|
39
38
|
- `escape`: A generic helper for escaping `values` by given `escape_map` (in *TemplateStrings* flavor).
|
|
40
39
|
- `escape_values`: A generic helper for escaping `values` by given `escape_map`.
|
|
41
40
|
- `fix_typography`: A helper that implements typographic corrections specific to Polish typography.
|
|
42
41
|
- `h`: A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `HTMLElement`s (see also `s`).
|
|
43
42
|
- `has_own`: A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
|
|
44
43
|
- `is_array`: A helper that checks if the given argument is of type `any[]`.
|
|
44
|
+
- `is_finite_number`: A helper that checks if the given argument is of type `number` but not `±Infinity` nor `NaN`.
|
|
45
45
|
- `is_number`: A helper that checks if the given argument is of type `number`.
|
|
46
46
|
- `is_record`: A helper that checks if the given argument is of type `Record<PropertyKey, unknown>`.
|
|
47
47
|
- `is_string`: A helper that checks if the given argument is of type `string`.
|
|
@@ -313,7 +313,7 @@ expect(actual).to.deep.equal(expected)
|
|
|
313
313
|
### csv_parse
|
|
314
314
|
|
|
315
315
|
```ts
|
|
316
|
-
const csv_parse: (csv: string, separator?: string) =>
|
|
316
|
+
const csv_parse: (csv: string, separator?: string) => string[][];
|
|
317
317
|
```
|
|
318
318
|
|
|
319
319
|
A tiny helper for parsing CSV.
|
|
@@ -329,38 +329,7 @@ yyy",zzz
|
|
|
329
329
|
42 , "42" , 17
|
|
330
330
|
|
|
331
331
|
`
|
|
332
|
-
|
|
333
|
-
expect(csv_parse(text)).to.deep.equal([{
|
|
334
|
-
'aaa\n"aaa"\naaa': 'xxx,xxx',
|
|
335
|
-
bbb: 'yyy\nyyy',
|
|
336
|
-
'ccc,ccc': 'zzz'
|
|
337
|
-
}, {
|
|
338
|
-
'aaa\n"aaa"\naaa': ' 42 ',
|
|
339
|
-
bbb: '42',
|
|
340
|
-
'ccc,ccc': ' 17'
|
|
341
|
-
}])
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
### csv_parse_raw
|
|
345
|
-
|
|
346
|
-
```ts
|
|
347
|
-
const csv_parse_raw: (csv: string, separator?: string) => string[][];
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
A tiny helper for parsing CSV.
|
|
351
|
-
|
|
352
|
-
#### Usage Examples
|
|
353
|
-
|
|
354
|
-
```ts
|
|
355
|
-
const text = `"aaa
|
|
356
|
-
""aaa""
|
|
357
|
-
aaa",bbb, "ccc,ccc"
|
|
358
|
-
"xxx,xxx", "yyy
|
|
359
|
-
yyy",zzz
|
|
360
|
-
42 , "42" , 17
|
|
361
|
-
|
|
362
|
-
`
|
|
363
|
-
expect(csv_parse_raw(text)).to.deep.equal([
|
|
332
|
+
expect(csv_parse(text)).to.deep.equal([
|
|
364
333
|
['aaa\n"aaa"\naaa', 'bbb', 'ccc,ccc'],
|
|
365
334
|
['xxx,xxx', 'yyy\nyyy', 'zzz'],
|
|
366
335
|
[' 42 ', '42', ' 17']
|
|
@@ -563,14 +532,26 @@ expect(has_own(undefined, 'key')).to.be.false
|
|
|
563
532
|
|
|
564
533
|
```ts
|
|
565
534
|
const is_array: (arg: any) => arg is any[];
|
|
535
|
+
declare const FINITE_NUMBER: unique symbol;
|
|
536
|
+
type Finite_Number = number & {
|
|
537
|
+
readonly [FINITE_NUMBER]: true;
|
|
538
|
+
};
|
|
566
539
|
```
|
|
567
540
|
|
|
568
541
|
A helper that checks if the given argument is of type `any[]`.
|
|
569
542
|
|
|
543
|
+
### is_finite_number
|
|
544
|
+
|
|
545
|
+
```ts
|
|
546
|
+
const is_finite_number: ((arg: unknown) => arg is Finite_Number);
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
A helper that checks if the given argument is of type `number` but not `±Infinity` nor `NaN`.
|
|
550
|
+
|
|
570
551
|
### is_number
|
|
571
552
|
|
|
572
553
|
```ts
|
|
573
|
-
const is_number: (arg:
|
|
554
|
+
const is_number: (arg: unknown) => arg is number;
|
|
574
555
|
```
|
|
575
556
|
|
|
576
557
|
A helper that checks if the given argument is of type `number`.
|
|
@@ -578,7 +559,7 @@ A helper that checks if the given argument is of type `number`.
|
|
|
578
559
|
### is_record
|
|
579
560
|
|
|
580
561
|
```ts
|
|
581
|
-
const is_record: (arg:
|
|
562
|
+
const is_record: (arg: unknown) => arg is Record<PropertyKey, unknown>;
|
|
582
563
|
```
|
|
583
564
|
|
|
584
565
|
A helper that checks if the given argument is of type `Record<PropertyKey, unknown>`.
|
|
@@ -586,7 +567,8 @@ A helper that checks if the given argument is of type `Record<PropertyKey, unkno
|
|
|
586
567
|
### is_string
|
|
587
568
|
|
|
588
569
|
```ts
|
|
589
|
-
const is_string: (arg:
|
|
570
|
+
const is_string: (arg: unknown) => arg is string;
|
|
571
|
+
export {};
|
|
590
572
|
```
|
|
591
573
|
|
|
592
574
|
A helper that checks if the given argument is of type `string`.
|