@skmtc/core 0.0.360 → 0.0.361
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/esm/typescript/FunctionParameter.d.ts.map +1 -1
- package/esm/typescript/List.d.ts +22 -18
- package/esm/typescript/List.d.ts.map +1 -1
- package/esm/typescript/List.js +18 -12
- package/package.json +1 -1
- package/script/typescript/FunctionParameter.d.ts.map +1 -1
- package/script/typescript/List.d.ts +22 -18
- package/script/typescript/List.d.ts.map +1 -1
- package/script/typescript/List.js +18 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIhC,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,UAAU,CAAC,gBAAgB,GAAG,cAAc,CAAC,CAAA;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,KAAK,mBAAmB,GACpB,aAAa,GACb,qBAAqB,GACrB,gBAAgB,CAAA;AAEpB,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,cAAc,CAAA;IACpB,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5C,QAAQ,EAAE,IAAI,CAAA;CACf,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IAC3C,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,qBAAa,iBAAiB;IAC5B,UAAU,EAAE,mBAAmB,CAAA;gBAEnB,IAAI,EAAE,UAAU;IAyB5B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAelC,cAAc,IAAI,IAAI;IAYtB,SAAS,IAAI,MAAM;IAUnB,QAAQ,IAAI,MAAM;CAcnB"}
|
package/esm/typescript/List.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import type { Stringable } from '../dsl/Stringable.js';
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type BookendsType = '[]' | '{}' | '()' | '<>' | 'none';
|
|
3
|
+
type ConstructorOptions<Separator extends string = ', ', Bookends extends BookendsType = 'none'> = {
|
|
4
|
+
separator?: Separator;
|
|
5
|
+
bookends?: Bookends;
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
type ExtractArrayItem<ArrayOf> = ArrayOf extends Array<infer Item> ? Item : never;
|
|
8
|
+
type ToFilteredKeyValueReturn<Value extends undefined | Stringable | Stringable[] | List> = Value extends undefined ? undefined : List<[string, Stringable | Stringable[] | List], ': ', 'none'>;
|
|
9
|
+
type ToConditionalReturn<Value extends Stringable, Condition extends boolean> = Condition extends true ? List<[Value], ', ', 'none'> : List<never[], ', ', 'none'>;
|
|
10
|
+
export declare class List<Values extends Stringable[] = Stringable[], Separator extends string = ', ', Bookends extends BookendsType = 'none'> {
|
|
11
|
+
values: ExtractArrayItem<Values>[];
|
|
12
|
+
separator: Separator;
|
|
13
|
+
bookends: Bookends;
|
|
14
|
+
constructor(values: (ExtractArrayItem<Values> | undefined)[], { separator, bookends }?: ConstructorOptions<Separator, Bookends>);
|
|
11
15
|
toString(): string;
|
|
12
16
|
/**
|
|
13
17
|
* Create an empty List that will render as an empty string ''
|
|
14
18
|
* @returns List
|
|
15
19
|
*/
|
|
16
|
-
static toEmpty: () => List
|
|
20
|
+
static toEmpty: () => List<never, ", ", "none">;
|
|
17
21
|
/**
|
|
18
22
|
* Create a List with a single value that will render as `value`
|
|
19
23
|
* @param value
|
|
20
24
|
* @returns List
|
|
21
25
|
*/
|
|
22
|
-
static toSingle: (value: Stringable) => List
|
|
26
|
+
static toSingle: (value: Stringable) => List<[Stringable], ", ", "none">;
|
|
23
27
|
/**
|
|
24
28
|
* If condition is true, return a List with a single value that will render as `value`.
|
|
25
29
|
* Otherwise, return an empty List that will render as an empty string ''.
|
|
@@ -30,46 +34,46 @@ export declare class List {
|
|
|
30
34
|
* @param condition
|
|
31
35
|
* @returns List
|
|
32
36
|
*/
|
|
33
|
-
static toConditional: (value:
|
|
37
|
+
static toConditional: <Value extends Stringable, Condition extends boolean>(value: Value, condition: Condition) => ToConditionalReturn<List<[Value], ", ", "none">, Condition>;
|
|
34
38
|
/**
|
|
35
39
|
* Create a record with Stringable values. KeyValue pairs will be joined with `: ` as separator
|
|
36
40
|
* and the resulting List will be wrapped with `{}`
|
|
37
41
|
* @param record
|
|
38
42
|
* @returns `record` with `Stringable` values
|
|
39
43
|
*/
|
|
40
|
-
static toRecord: (record: Record<string, Stringable | Stringable[] | List>) => List
|
|
44
|
+
static toRecord: (record: Record<string, Stringable | Stringable[] | List>) => List<Stringable[], ", ", "{}">;
|
|
41
45
|
/**
|
|
42
46
|
* Create a record with `undefined` or empty array or List values filtered out.
|
|
43
47
|
* @param record
|
|
44
48
|
* @returns `record` with `undefined` values filtered out
|
|
45
49
|
*/
|
|
46
|
-
static toFilteredRecord: (record: Record<string, undefined | Stringable | Stringable[] | List>) => List
|
|
50
|
+
static toFilteredRecord: (record: Record<string, undefined | Stringable | Stringable[] | List>) => List<Stringable[], ", ", "{}">;
|
|
47
51
|
/**
|
|
48
52
|
* Join `key` and `value` using `: ` as separator
|
|
49
53
|
* @param key
|
|
50
54
|
* @param value
|
|
51
55
|
* @returns `key` and `value` joined with `: ` as separator
|
|
52
56
|
*/
|
|
53
|
-
static toKeyValue: (key: string, value:
|
|
57
|
+
static toKeyValue: <Value extends Stringable | Stringable[] | List>(key: string, value: Value) => List<[string, Value], ": ", "none">;
|
|
54
58
|
/**
|
|
55
59
|
* Join `key` and `value` using `.` as separator
|
|
56
60
|
* @param key
|
|
57
61
|
* @param value
|
|
58
62
|
* @returns `key` and `value` joined with `.` as separator
|
|
59
63
|
*/
|
|
60
|
-
static toObjectKey: (key: string, value:
|
|
64
|
+
static toObjectKey: <Value extends Stringable>(key: string, value: Value) => List<[string, Value], ".", "none">;
|
|
61
65
|
/**
|
|
62
66
|
* Join `values` using `, ` as separator and wrap in `{` and `}`
|
|
63
67
|
* @param values
|
|
64
68
|
* @returns `values` joined with `, ` as separator and wrapped in `{` and `}`
|
|
65
69
|
*/
|
|
66
|
-
static toObject: (values: (Stringable | undefined)[]) => List
|
|
70
|
+
static toObject: (values: (Stringable | undefined)[]) => List<Stringable[], ", ", "{}">;
|
|
67
71
|
/**
|
|
68
72
|
* Create a List using the keys of a record
|
|
69
73
|
* @param record
|
|
70
74
|
* @returns List of record keys
|
|
71
75
|
*/
|
|
72
|
-
static fromRecord: (record: Record<string, Stringable> | undefined) => List
|
|
76
|
+
static fromRecord: (record: Record<string, Stringable> | undefined) => List<string[], ", ", "none">;
|
|
73
77
|
/**
|
|
74
78
|
* Create a keyValue pair if `value` is not undefined and is not an empty array or List.
|
|
75
79
|
* Return `undefined` otherwise.
|
|
@@ -79,7 +83,7 @@ export declare class List {
|
|
|
79
83
|
* @param value
|
|
80
84
|
* @returns `key` and `value` joined with `: ` as separator if `value` is not undefined and is not an empty array or List. `undefined` otherwise.
|
|
81
85
|
*/
|
|
82
|
-
static toFilteredKeyValue:
|
|
86
|
+
static toFilteredKeyValue: <Value extends undefined | Stringable | Stringable[] | List>(key: string, value: Value) => ToFilteredKeyValueReturn<Value>;
|
|
83
87
|
/**
|
|
84
88
|
* Check if `value` is not undefined and is not an empty array or List.
|
|
85
89
|
* @param value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../src/typescript/List.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGtD,KAAK,kBAAkB,GAAG;
|
|
1
|
+
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../src/typescript/List.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGtD,KAAK,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAA;AAEtD,KAAK,kBAAkB,CACrB,SAAS,SAAS,MAAM,GAAG,IAAI,EAC/B,QAAQ,SAAS,YAAY,GAAG,MAAM,IACpC;IACF,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CAAA;AAED,KAAK,gBAAgB,CAAC,OAAO,IAAI,OAAO,SAAS,KAAK,CAAC,MAAM,IAAI,CAAC,GAC9D,IAAI,GACJ,KAAK,CAAA;AAET,KAAK,wBAAwB,CAC3B,KAAK,SAAS,SAAS,GAAG,UAAU,GAAG,UAAU,EAAE,GAAG,IAAI,IACxD,KAAK,SAAS,SAAS,GACvB,SAAS,GACT,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,EAA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CACF"}
|
package/esm/typescript/List.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { match } from 'ts-pattern';
|
|
2
2
|
export class List {
|
|
3
|
-
constructor(values, { separator
|
|
3
|
+
constructor(values, { separator, bookends } = {}) {
|
|
4
4
|
Object.defineProperty(this, "values", {
|
|
5
5
|
enumerable: true,
|
|
6
6
|
configurable: true,
|
|
@@ -20,16 +20,16 @@ export class List {
|
|
|
20
20
|
value: void 0
|
|
21
21
|
});
|
|
22
22
|
this.values = values.filter(value => value !== undefined);
|
|
23
|
-
this.separator = separator;
|
|
24
|
-
this.bookends = bookends;
|
|
23
|
+
this.separator = separator ?? ', ';
|
|
24
|
+
this.bookends = bookends ?? 'none';
|
|
25
25
|
}
|
|
26
26
|
toString() {
|
|
27
27
|
const joined = this.values.join(this.separator);
|
|
28
28
|
return match(this.bookends)
|
|
29
|
-
.with('
|
|
30
|
-
.with('
|
|
31
|
-
.with('
|
|
32
|
-
.with('
|
|
29
|
+
.with('[]', () => `[${joined}]`)
|
|
30
|
+
.with('{}', () => `{${joined}}`)
|
|
31
|
+
.with('()', () => `(${joined})`)
|
|
32
|
+
.with('<>', () => `<${joined}>`)
|
|
33
33
|
.with('none', () => joined)
|
|
34
34
|
.exhaustive();
|
|
35
35
|
}
|
|
@@ -42,7 +42,9 @@ Object.defineProperty(List, "toEmpty", {
|
|
|
42
42
|
enumerable: true,
|
|
43
43
|
configurable: true,
|
|
44
44
|
writable: true,
|
|
45
|
-
value: () =>
|
|
45
|
+
value: () => {
|
|
46
|
+
return new List([], { bookends: 'none' });
|
|
47
|
+
}
|
|
46
48
|
});
|
|
47
49
|
/**
|
|
48
50
|
* Create a List with a single value that will render as `value`
|
|
@@ -72,7 +74,8 @@ Object.defineProperty(List, "toConditional", {
|
|
|
72
74
|
configurable: true,
|
|
73
75
|
writable: true,
|
|
74
76
|
value: (value, condition) => {
|
|
75
|
-
|
|
77
|
+
const out = new List([condition ? value : undefined], { bookends: 'none' });
|
|
78
|
+
return out;
|
|
76
79
|
}
|
|
77
80
|
});
|
|
78
81
|
/**
|
|
@@ -133,7 +136,9 @@ Object.defineProperty(List, "toObjectKey", {
|
|
|
133
136
|
configurable: true,
|
|
134
137
|
writable: true,
|
|
135
138
|
value: (key, value) => {
|
|
136
|
-
return new List([key, value], {
|
|
139
|
+
return new List([key, value], {
|
|
140
|
+
separator: '.'
|
|
141
|
+
});
|
|
137
142
|
}
|
|
138
143
|
});
|
|
139
144
|
/**
|
|
@@ -146,7 +151,7 @@ Object.defineProperty(List, "toObject", {
|
|
|
146
151
|
configurable: true,
|
|
147
152
|
writable: true,
|
|
148
153
|
value: (values) => {
|
|
149
|
-
return new List(values, { bookends: '
|
|
154
|
+
return new List(values, { bookends: '{}' });
|
|
150
155
|
}
|
|
151
156
|
});
|
|
152
157
|
/**
|
|
@@ -176,7 +181,8 @@ Object.defineProperty(List, "toFilteredKeyValue", {
|
|
|
176
181
|
configurable: true,
|
|
177
182
|
writable: true,
|
|
178
183
|
value: (key, value) => {
|
|
179
|
-
|
|
184
|
+
const out = List.hasValue(value) ? List.toKeyValue(key, value) : undefined;
|
|
185
|
+
return out;
|
|
180
186
|
}
|
|
181
187
|
});
|
|
182
188
|
/**
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIhC,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,UAAU,CAAC,gBAAgB,GAAG,cAAc,CAAC,CAAA;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,KAAK,mBAAmB,GACpB,aAAa,GACb,qBAAqB,GACrB,gBAAgB,CAAA;AAEpB,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,cAAc,CAAA;IACpB,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5C,QAAQ,EAAE,IAAI,CAAA;CACf,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IAC3C,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,qBAAa,iBAAiB;IAC5B,UAAU,EAAE,mBAAmB,CAAA;gBAEnB,IAAI,EAAE,UAAU;IAyB5B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAelC,cAAc,IAAI,IAAI;IAYtB,SAAS,IAAI,MAAM;IAUnB,QAAQ,IAAI,MAAM;CAcnB"}
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import type { Stringable } from '../dsl/Stringable.js';
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type BookendsType = '[]' | '{}' | '()' | '<>' | 'none';
|
|
3
|
+
type ConstructorOptions<Separator extends string = ', ', Bookends extends BookendsType = 'none'> = {
|
|
4
|
+
separator?: Separator;
|
|
5
|
+
bookends?: Bookends;
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
type ExtractArrayItem<ArrayOf> = ArrayOf extends Array<infer Item> ? Item : never;
|
|
8
|
+
type ToFilteredKeyValueReturn<Value extends undefined | Stringable | Stringable[] | List> = Value extends undefined ? undefined : List<[string, Stringable | Stringable[] | List], ': ', 'none'>;
|
|
9
|
+
type ToConditionalReturn<Value extends Stringable, Condition extends boolean> = Condition extends true ? List<[Value], ', ', 'none'> : List<never[], ', ', 'none'>;
|
|
10
|
+
export declare class List<Values extends Stringable[] = Stringable[], Separator extends string = ', ', Bookends extends BookendsType = 'none'> {
|
|
11
|
+
values: ExtractArrayItem<Values>[];
|
|
12
|
+
separator: Separator;
|
|
13
|
+
bookends: Bookends;
|
|
14
|
+
constructor(values: (ExtractArrayItem<Values> | undefined)[], { separator, bookends }?: ConstructorOptions<Separator, Bookends>);
|
|
11
15
|
toString(): string;
|
|
12
16
|
/**
|
|
13
17
|
* Create an empty List that will render as an empty string ''
|
|
14
18
|
* @returns List
|
|
15
19
|
*/
|
|
16
|
-
static toEmpty: () => List
|
|
20
|
+
static toEmpty: () => List<never, ", ", "none">;
|
|
17
21
|
/**
|
|
18
22
|
* Create a List with a single value that will render as `value`
|
|
19
23
|
* @param value
|
|
20
24
|
* @returns List
|
|
21
25
|
*/
|
|
22
|
-
static toSingle: (value: Stringable) => List
|
|
26
|
+
static toSingle: (value: Stringable) => List<[Stringable], ", ", "none">;
|
|
23
27
|
/**
|
|
24
28
|
* If condition is true, return a List with a single value that will render as `value`.
|
|
25
29
|
* Otherwise, return an empty List that will render as an empty string ''.
|
|
@@ -30,46 +34,46 @@ export declare class List {
|
|
|
30
34
|
* @param condition
|
|
31
35
|
* @returns List
|
|
32
36
|
*/
|
|
33
|
-
static toConditional: (value:
|
|
37
|
+
static toConditional: <Value extends Stringable, Condition extends boolean>(value: Value, condition: Condition) => ToConditionalReturn<List<[Value], ", ", "none">, Condition>;
|
|
34
38
|
/**
|
|
35
39
|
* Create a record with Stringable values. KeyValue pairs will be joined with `: ` as separator
|
|
36
40
|
* and the resulting List will be wrapped with `{}`
|
|
37
41
|
* @param record
|
|
38
42
|
* @returns `record` with `Stringable` values
|
|
39
43
|
*/
|
|
40
|
-
static toRecord: (record: Record<string, Stringable | Stringable[] | List>) => List
|
|
44
|
+
static toRecord: (record: Record<string, Stringable | Stringable[] | List>) => List<Stringable[], ", ", "{}">;
|
|
41
45
|
/**
|
|
42
46
|
* Create a record with `undefined` or empty array or List values filtered out.
|
|
43
47
|
* @param record
|
|
44
48
|
* @returns `record` with `undefined` values filtered out
|
|
45
49
|
*/
|
|
46
|
-
static toFilteredRecord: (record: Record<string, undefined | Stringable | Stringable[] | List>) => List
|
|
50
|
+
static toFilteredRecord: (record: Record<string, undefined | Stringable | Stringable[] | List>) => List<Stringable[], ", ", "{}">;
|
|
47
51
|
/**
|
|
48
52
|
* Join `key` and `value` using `: ` as separator
|
|
49
53
|
* @param key
|
|
50
54
|
* @param value
|
|
51
55
|
* @returns `key` and `value` joined with `: ` as separator
|
|
52
56
|
*/
|
|
53
|
-
static toKeyValue: (key: string, value:
|
|
57
|
+
static toKeyValue: <Value extends Stringable | Stringable[] | List>(key: string, value: Value) => List<[string, Value], ": ", "none">;
|
|
54
58
|
/**
|
|
55
59
|
* Join `key` and `value` using `.` as separator
|
|
56
60
|
* @param key
|
|
57
61
|
* @param value
|
|
58
62
|
* @returns `key` and `value` joined with `.` as separator
|
|
59
63
|
*/
|
|
60
|
-
static toObjectKey: (key: string, value:
|
|
64
|
+
static toObjectKey: <Value extends Stringable>(key: string, value: Value) => List<[string, Value], ".", "none">;
|
|
61
65
|
/**
|
|
62
66
|
* Join `values` using `, ` as separator and wrap in `{` and `}`
|
|
63
67
|
* @param values
|
|
64
68
|
* @returns `values` joined with `, ` as separator and wrapped in `{` and `}`
|
|
65
69
|
*/
|
|
66
|
-
static toObject: (values: (Stringable | undefined)[]) => List
|
|
70
|
+
static toObject: (values: (Stringable | undefined)[]) => List<Stringable[], ", ", "{}">;
|
|
67
71
|
/**
|
|
68
72
|
* Create a List using the keys of a record
|
|
69
73
|
* @param record
|
|
70
74
|
* @returns List of record keys
|
|
71
75
|
*/
|
|
72
|
-
static fromRecord: (record: Record<string, Stringable> | undefined) => List
|
|
76
|
+
static fromRecord: (record: Record<string, Stringable> | undefined) => List<string[], ", ", "none">;
|
|
73
77
|
/**
|
|
74
78
|
* Create a keyValue pair if `value` is not undefined and is not an empty array or List.
|
|
75
79
|
* Return `undefined` otherwise.
|
|
@@ -79,7 +83,7 @@ export declare class List {
|
|
|
79
83
|
* @param value
|
|
80
84
|
* @returns `key` and `value` joined with `: ` as separator if `value` is not undefined and is not an empty array or List. `undefined` otherwise.
|
|
81
85
|
*/
|
|
82
|
-
static toFilteredKeyValue:
|
|
86
|
+
static toFilteredKeyValue: <Value extends undefined | Stringable | Stringable[] | List>(key: string, value: Value) => ToFilteredKeyValueReturn<Value>;
|
|
83
87
|
/**
|
|
84
88
|
* Check if `value` is not undefined and is not an empty array or List.
|
|
85
89
|
* @param value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../src/typescript/List.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGtD,KAAK,kBAAkB,GAAG;
|
|
1
|
+
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../src/typescript/List.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGtD,KAAK,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAA;AAEtD,KAAK,kBAAkB,CACrB,SAAS,SAAS,MAAM,GAAG,IAAI,EAC/B,QAAQ,SAAS,YAAY,GAAG,MAAM,IAC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G,SAAS,KAC7C,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAE9B;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,kBAAkB,GACvB,KAAK,SAAS,SAAS,GAAG,UAAU,GAAG,UAAU,EAAE,GAAG,IAAI,OAErD,MAAM,SACJ,KAAK,KACX,wBAAwB,CAAC,KAAK,CAAC,CAIjC;IAED;;;;OAIG;IACH,MAAM,CAAC,QAAQ,UACN,SAAS,GAAG,UAAU,GAAG,UAAU,EAAE,GAAG,IAAI,KAClD,KAAK,IAAI,UAAU,GAAG,UAAU,EAAE,GAAG,IAAI,CAc3C;CACF"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.List = void 0;
|
|
4
4
|
const ts_pattern_1 = require("ts-pattern");
|
|
5
5
|
class List {
|
|
6
|
-
constructor(values, { separator
|
|
6
|
+
constructor(values, { separator, bookends } = {}) {
|
|
7
7
|
Object.defineProperty(this, "values", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
configurable: true,
|
|
@@ -23,16 +23,16 @@ class List {
|
|
|
23
23
|
value: void 0
|
|
24
24
|
});
|
|
25
25
|
this.values = values.filter(value => value !== undefined);
|
|
26
|
-
this.separator = separator;
|
|
27
|
-
this.bookends = bookends;
|
|
26
|
+
this.separator = separator ?? ', ';
|
|
27
|
+
this.bookends = bookends ?? 'none';
|
|
28
28
|
}
|
|
29
29
|
toString() {
|
|
30
30
|
const joined = this.values.join(this.separator);
|
|
31
31
|
return (0, ts_pattern_1.match)(this.bookends)
|
|
32
|
-
.with('
|
|
33
|
-
.with('
|
|
34
|
-
.with('
|
|
35
|
-
.with('
|
|
32
|
+
.with('[]', () => `[${joined}]`)
|
|
33
|
+
.with('{}', () => `{${joined}}`)
|
|
34
|
+
.with('()', () => `(${joined})`)
|
|
35
|
+
.with('<>', () => `<${joined}>`)
|
|
36
36
|
.with('none', () => joined)
|
|
37
37
|
.exhaustive();
|
|
38
38
|
}
|
|
@@ -46,7 +46,9 @@ Object.defineProperty(List, "toEmpty", {
|
|
|
46
46
|
enumerable: true,
|
|
47
47
|
configurable: true,
|
|
48
48
|
writable: true,
|
|
49
|
-
value: () =>
|
|
49
|
+
value: () => {
|
|
50
|
+
return new List([], { bookends: 'none' });
|
|
51
|
+
}
|
|
50
52
|
});
|
|
51
53
|
/**
|
|
52
54
|
* Create a List with a single value that will render as `value`
|
|
@@ -76,7 +78,8 @@ Object.defineProperty(List, "toConditional", {
|
|
|
76
78
|
configurable: true,
|
|
77
79
|
writable: true,
|
|
78
80
|
value: (value, condition) => {
|
|
79
|
-
|
|
81
|
+
const out = new List([condition ? value : undefined], { bookends: 'none' });
|
|
82
|
+
return out;
|
|
80
83
|
}
|
|
81
84
|
});
|
|
82
85
|
/**
|
|
@@ -137,7 +140,9 @@ Object.defineProperty(List, "toObjectKey", {
|
|
|
137
140
|
configurable: true,
|
|
138
141
|
writable: true,
|
|
139
142
|
value: (key, value) => {
|
|
140
|
-
return new List([key, value], {
|
|
143
|
+
return new List([key, value], {
|
|
144
|
+
separator: '.'
|
|
145
|
+
});
|
|
141
146
|
}
|
|
142
147
|
});
|
|
143
148
|
/**
|
|
@@ -150,7 +155,7 @@ Object.defineProperty(List, "toObject", {
|
|
|
150
155
|
configurable: true,
|
|
151
156
|
writable: true,
|
|
152
157
|
value: (values) => {
|
|
153
|
-
return new List(values, { bookends: '
|
|
158
|
+
return new List(values, { bookends: '{}' });
|
|
154
159
|
}
|
|
155
160
|
});
|
|
156
161
|
/**
|
|
@@ -180,7 +185,8 @@ Object.defineProperty(List, "toFilteredKeyValue", {
|
|
|
180
185
|
configurable: true,
|
|
181
186
|
writable: true,
|
|
182
187
|
value: (key, value) => {
|
|
183
|
-
|
|
188
|
+
const out = List.hasValue(value) ? List.toKeyValue(key, value) : undefined;
|
|
189
|
+
return out;
|
|
184
190
|
}
|
|
185
191
|
});
|
|
186
192
|
/**
|