@rickard.antonsson/ts-utility 1.0.3 → 2.0.0
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/README.md +3 -109
- package/build/functions/array/group-by.js.map +1 -0
- package/build/functions/array/multi-sort.d.ts +9 -0
- package/build/functions/array/multi-sort.js +22 -0
- package/build/functions/array/multi-sort.js.map +1 -0
- package/build/functions/list/filter.js.map +1 -0
- package/build/functions/list/map.js.map +1 -0
- package/build/functions/other/create-element.d.ts +2 -0
- package/build/functions/other/create-element.js +16 -0
- package/build/functions/other/create-element.js.map +1 -0
- package/build/{src/functions → functions}/other/deep-partial-set.js +1 -2
- package/build/functions/other/deep-partial-set.js.map +1 -0
- package/build/functions/other/times.d.ts +2 -0
- package/build/functions/other/times.js +7 -0
- package/build/functions/other/times.js.map +1 -0
- package/build/{src/functions → functions}/time/debounce.js +1 -2
- package/build/functions/time/debounce.js.map +1 -0
- package/build/{src/functions → functions}/time/memoize.js +1 -2
- package/build/functions/time/memoize.js.map +1 -0
- package/build/index.d.ts +7 -0
- package/build/index.js +21 -0
- package/build/index.js.map +1 -0
- package/build/{src/interfaces → interfaces}/list.js.map +1 -1
- package/build/types.js.map +1 -0
- package/package.json +21 -16
- package/build/src/functions/array/group-by.js.map +0 -1
- package/build/src/functions/array/index.d.ts +0 -2
- package/build/src/functions/array/index.js +0 -8
- package/build/src/functions/array/index.js.map +0 -1
- package/build/src/functions/array/simple-sort-other.d.ts +0 -6
- package/build/src/functions/array/simple-sort-other.js +0 -41
- package/build/src/functions/array/simple-sort-other.js.map +0 -1
- package/build/src/functions/array/simple-sort.d.ts +0 -6
- package/build/src/functions/array/simple-sort.js +0 -41
- package/build/src/functions/array/simple-sort.js.map +0 -1
- package/build/src/functions/index.d.ts +0 -3
- package/build/src/functions/index.js +0 -20
- package/build/src/functions/index.js.map +0 -1
- package/build/src/functions/list/filter.js.map +0 -1
- package/build/src/functions/list/index.d.ts +0 -2
- package/build/src/functions/list/index.js +0 -8
- package/build/src/functions/list/index.js.map +0 -1
- package/build/src/functions/list/map.js.map +0 -1
- package/build/src/functions/other/deep-partial-set.js.map +0 -1
- package/build/src/functions/time/debounce.js.map +0 -1
- package/build/src/functions/time/memoize.js.map +0 -1
- package/build/src/index.d.ts +0 -4
- package/build/src/index.js +0 -22
- package/build/src/index.js.map +0 -1
- package/build/src/test-speed.d.ts +0 -1
- package/build/src/test-speed.js +0 -53
- package/build/src/test-speed.js.map +0 -1
- package/build/src/types.js.map +0 -1
- /package/build/{src/functions → functions}/array/group-by.d.ts +0 -0
- /package/build/{src/functions → functions}/array/group-by.js +0 -0
- /package/build/{src/functions → functions}/list/filter.d.ts +0 -0
- /package/build/{src/functions → functions}/list/filter.js +0 -0
- /package/build/{src/functions → functions}/list/map.d.ts +0 -0
- /package/build/{src/functions → functions}/list/map.js +0 -0
- /package/build/{src/functions → functions}/other/deep-partial-set.d.ts +0 -0
- /package/build/{src/functions → functions}/time/debounce.d.ts +0 -0
- /package/build/{src/functions → functions}/time/memoize.d.ts +0 -0
- /package/build/{src/interfaces → interfaces}/list.d.ts +0 -0
- /package/build/{src/interfaces → interfaces}/list.js +0 -0
- /package/build/{src/types.d.ts → types.d.ts} +0 -0
- /package/build/{src/types.js → types.js} +0 -0
package/README.md
CHANGED
|
@@ -1,109 +1,3 @@
|
|
|
1
|
-
# ts-utility
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Array functions
|
|
6
|
-
|
|
7
|
-
### simpleSort
|
|
8
|
-
|
|
9
|
-
Sorts an array using supplied functions to get values to sort by.
|
|
10
|
-
Takes functions returning either strings or numbers.
|
|
11
|
-
|
|
12
|
-
Somewhat fast. Speed tests using 58mb json (100k entries) sorted by name length and then name descending took around 300ms
|
|
13
|
-
|
|
14
|
-
Example test case:
|
|
15
|
-
|
|
16
|
-
```typescript
|
|
17
|
-
it('should sort pokemons on first letter of name and then by weight, descending ', () => {
|
|
18
|
-
const result = simpleSort(
|
|
19
|
-
json.pokemon,
|
|
20
|
-
asc(i => i.name[0]),
|
|
21
|
-
desc(i => Number.parseFloat(i.weight))
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
// Below would give the same result.
|
|
25
|
-
// asc|desc functions above actually just returns this type of tuple.
|
|
26
|
-
const result = simpleSort(
|
|
27
|
-
json.pokemon,
|
|
28
|
-
[i => i.name[0], 'asc'],
|
|
29
|
-
[i => Number.parseFloat(i.weight), 'desc']
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
expect(result.slice(0, 10).map(i => `${i.name} ${i.weight}`)).toEqual([
|
|
33
|
-
'Arcanine 155.0 kg',
|
|
34
|
-
'Arbok 65.0 kg',
|
|
35
|
-
'Aerodactyl 59.0 kg',
|
|
36
|
-
'Articuno 55.4 kg',
|
|
37
|
-
'Alakazam 48.0 kg',
|
|
38
|
-
'Abra 19.5 kg',
|
|
39
|
-
'Blastoise 85.5 kg',
|
|
40
|
-
'Butterfree 32.0 kg',
|
|
41
|
-
'Beedrill 29.5 kg',
|
|
42
|
-
'Bulbasaur 6.9 kg',
|
|
43
|
-
]);
|
|
44
|
-
});
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
For more examples see tests
|
|
48
|
-
|
|
49
|
-
### groupBy
|
|
50
|
-
|
|
51
|
-
A small implemententation of groupBy
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
type specificGroupNames = 'first' | 'second' | 'third';
|
|
55
|
-
const itemsWithSpecificGroups = items as Array<{
|
|
56
|
-
id: number;
|
|
57
|
-
group: specificGroupNames;
|
|
58
|
-
}>;
|
|
59
|
-
|
|
60
|
-
const result = groupBy(itemsWithSpecificGroups, item => item.group);
|
|
61
|
-
// result now contains the grouped arrays.
|
|
62
|
-
// typescript error occurs if you try to access result.noneexisting since its not in the group names
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Other
|
|
66
|
-
|
|
67
|
-
### Deep Partial Set
|
|
68
|
-
|
|
69
|
-
As the name implies, sets an objects and subobjects properties.
|
|
70
|
-
Optionally use a function to modify current value.
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
it('should add 10 gold, 10 silver and 10 copper to persons pouch', () => {
|
|
74
|
-
const person = {
|
|
75
|
-
personal: {
|
|
76
|
-
firstName: 'Test',
|
|
77
|
-
lastName: 'Testsson',
|
|
78
|
-
},
|
|
79
|
-
items: {
|
|
80
|
-
pouch: {color: 'blue', contents: {gold: 10, silver: 20, copper: 30}},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const result = deepPartialSet(person, {
|
|
85
|
-
items: {
|
|
86
|
-
pouch: {
|
|
87
|
-
contents: {
|
|
88
|
-
gold: i => i + 10,
|
|
89
|
-
silver: i => i + 10,
|
|
90
|
-
copper: i => i + 10,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
expect(result.items.pouch.contents).toEqual({
|
|
97
|
-
gold: 20,
|
|
98
|
-
silver: 30,
|
|
99
|
-
copper: 40,
|
|
100
|
-
});
|
|
101
|
-
// Keep unchanged objects
|
|
102
|
-
expect(result.personal).toBe(person.personal);
|
|
103
|
-
// New objects for the complete tree where a child has a change
|
|
104
|
-
expect(result).not.toBe(person);
|
|
105
|
-
expect(result.items).not.toBe(person.items);
|
|
106
|
-
expect(result.items.pouch).not.toBe(person.items.pouch);
|
|
107
|
-
expect(result.items.pouch.contents).not.toBe(person.items.pouch.contents);
|
|
108
|
-
});
|
|
109
|
-
```
|
|
1
|
+
# ts-utility
|
|
2
|
+
|
|
3
|
+
My favorite functions I reuse everywhere.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-by.js","sourceRoot":"","sources":["../../../src/functions/array/group-by.ts"],"names":[],"mappings":";;;AAAO,MAAM,OAAO,GAAG,CACrB,IAAS,EACT,MAAsB,EACG,EAAE;IAC3B,MAAM,OAAO,GAA4B,EAAE,CAAC;IAC5C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;;QAClB,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,MAAA,OAAO,CAAC,EAAE,CAAC,mCAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAVW,QAAA,OAAO,WAUlB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Fn } from '../../types';
|
|
2
|
+
export declare const ASC: unique symbol;
|
|
3
|
+
export declare const DESC: unique symbol;
|
|
4
|
+
export type Order = typeof ASC | typeof DESC;
|
|
5
|
+
export declare const multiSort: <T>(list: T[], ...sortFns: Fn<[T, T], number>[]) => T[];
|
|
6
|
+
export declare const sortBy: {
|
|
7
|
+
str: <T>(getter: Fn<[T], string>, order?: Order) => (a: T, b: T) => number;
|
|
8
|
+
num: <T>(getter: Fn<[T], number>, order?: Order) => (a: T, b: T) => number;
|
|
9
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortBy = exports.multiSort = exports.DESC = exports.ASC = void 0;
|
|
4
|
+
exports.ASC = Symbol('Sort ascending');
|
|
5
|
+
exports.DESC = Symbol('Sort descending');
|
|
6
|
+
const multiSort = (list, ...sortFns) => {
|
|
7
|
+
return [...list].sort((a, b) => {
|
|
8
|
+
let result = 0;
|
|
9
|
+
for (let i = 0; i < sortFns.length; i++) {
|
|
10
|
+
result = sortFns[i](a, b);
|
|
11
|
+
if (result !== 0)
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.multiSort = multiSort;
|
|
18
|
+
exports.sortBy = {
|
|
19
|
+
str: (getter, order = exports.ASC) => (a, b) => getter(order === exports.ASC ? a : b).localeCompare(getter(order === exports.ASC ? b : a)),
|
|
20
|
+
num: (getter, order = exports.ASC) => (a, b) => getter(order === exports.ASC ? a : b) - getter(order === exports.ASC ? b : a),
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=multi-sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-sort.js","sourceRoot":"","sources":["../../../src/functions/array/multi-sort.ts"],"names":[],"mappings":";;;AAEa,QAAA,GAAG,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC/B,QAAA,IAAI,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAGvC,MAAM,SAAS,GAAG,CACvB,IAAS,EACT,GAAG,OAA6B,EAC3B,EAAE;IACP,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC7B,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1B,IAAI,MAAM,KAAK,CAAC;gBAAE,OAAO,MAAM,CAAC;QAClC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAZW,QAAA,SAAS,aAYpB;AAEW,QAAA,MAAM,GAAG;IACpB,GAAG,EACD,CAAI,MAAuB,EAAE,QAAe,WAAG,EAAE,EAAE,CACnD,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE,CACb,MAAM,CAAC,KAAK,KAAK,WAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CACzC,MAAM,CAAC,KAAK,KAAK,WAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC9B;IAEL,GAAG,EACD,CAAI,MAAuB,EAAE,QAAe,WAAG,EAAE,EAAE,CACnD,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE,CACb,MAAM,CAAC,KAAK,KAAK,WAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,KAAK,WAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../../src/functions/list/filter.ts"],"names":[],"mappings":";;;AAGO,MAAM,MAAM,GAAG,CACpB,IAAa,EACb,MAA4B,EACnB,EAAE,CACX,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM;AACzB,sEAAsE;AACtE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACnB,IAAI,MAAM,CAAC,IAAI,CAAC;QAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAClC,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAa,CACd,CAAC;AAXS,QAAA,MAAM,UAWf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../../src/functions/list/map.ts"],"names":[],"mappings":";;;AAEO,MAAM,GAAG,GAAG,CACjB,KAAc,EACd,EAAa,EACgB,EAAE,CAC/B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAC1B,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAC,CAAC,EACjD,EAAE,CACH,CAAC;AAPS,QAAA,GAAG,OAOZ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createElement = createElement;
|
|
4
|
+
function createElement(tagName, listOrFn, list) {
|
|
5
|
+
const elm = document.createElement(tagName);
|
|
6
|
+
if (listOrFn !== undefined || listOrFn !== null) {
|
|
7
|
+
if (typeof listOrFn === 'function')
|
|
8
|
+
listOrFn.call(null, elm);
|
|
9
|
+
else
|
|
10
|
+
elm.append(...(listOrFn !== null && listOrFn !== void 0 ? listOrFn : []));
|
|
11
|
+
}
|
|
12
|
+
if (list)
|
|
13
|
+
elm.append(...list);
|
|
14
|
+
return elm;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=create-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-element.js","sourceRoot":"","sources":["../../../src/functions/other/create-element.ts"],"names":[],"mappings":";;AAEA,sCAUC;AAVD,SAAgB,aAAa,CAE3B,OAAU,EAAE,QAAoC,EAAE,IAAa;IAC/D,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAChD,IAAI,OAAO,QAAQ,KAAK,UAAU;YAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;;YACxD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,IAAI;QAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deepPartialSet =
|
|
3
|
+
exports.deepPartialSet = deepPartialSet;
|
|
4
4
|
function deepPartialSet(a, b) {
|
|
5
5
|
const aKeys = Object.keys(a);
|
|
6
6
|
const bKeys = Object.keys(b);
|
|
@@ -28,5 +28,4 @@ function deepPartialSet(a, b) {
|
|
|
28
28
|
});
|
|
29
29
|
return changed ? result : a;
|
|
30
30
|
}
|
|
31
|
-
exports.deepPartialSet = deepPartialSet;
|
|
32
31
|
//# sourceMappingURL=deep-partial-set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-partial-set.js","sourceRoot":"","sources":["../../../src/functions/other/deep-partial-set.ts"],"names":[],"mappings":";;AAEA,wCAgCC;AAhCD,SAAgB,cAAc,CAG5B,CAAI,EAAE,CAAI;IACV,MAAM,KAAK,GAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAM,EAAC,GAAG,CAAC,EAAC,CAAC;IACzB,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAClB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO;QACjC,IAAI,QAAuB,CAAC;QAE5B,QAAQ,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,KAAK,UAAU;gBACb,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC1B,MAAM;YACR,KAAK,QAAQ;gBACX,QAAQ,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC1C,MAAM;YACR;gBACE,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;gBAClB,MAAM;QACV,CAAC;QAED,IAAI,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC;YAAE,OAAO;QAErC,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;QACvB,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"times.js","sourceRoot":"","sources":["../../../src/functions/other/times.ts"],"names":[],"mappings":";;AAEA,sBAEC;AAFD,SAAgB,KAAK,CAAI,CAAS,EAAE,EAAuC;IACzE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.debounce =
|
|
3
|
+
exports.debounce = debounce;
|
|
4
4
|
function debounce(fn, time = 0) {
|
|
5
5
|
let timeoutId;
|
|
6
6
|
return (...args) => {
|
|
@@ -8,5 +8,4 @@ function debounce(fn, time = 0) {
|
|
|
8
8
|
timeoutId = setTimeout(() => fn(...args), time);
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
exports.debounce = debounce;
|
|
12
11
|
//# sourceMappingURL=debounce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../../src/functions/time/debounce.ts"],"names":[],"mappings":";;AAEA,4BAOC;AAPD,SAAgB,QAAQ,CAAmB,EAAM,EAAE,IAAI,GAAG,CAAC;IACzD,IAAI,SAAwC,CAAC;IAE7C,OAAO,CAAC,GAAG,IAAoB,EAAQ,EAAE;QACvC,YAAY,CAAC,SAAS,CAAC,CAAC;QACxB,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.memoize =
|
|
3
|
+
exports.memoize = memoize;
|
|
4
4
|
function memoize(fn) {
|
|
5
5
|
const returned = {};
|
|
6
6
|
return (...args) => {
|
|
@@ -9,5 +9,4 @@ function memoize(fn) {
|
|
|
9
9
|
return (returned[key] = (_a = returned[key]) !== null && _a !== void 0 ? _a : fn(args));
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
exports.memoize = memoize;
|
|
13
12
|
//# sourceMappingURL=memoize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../../src/functions/time/memoize.ts"],"names":[],"mappings":";;AAEA,0BAMC;AAND,SAAgB,OAAO,CAAmB,EAAM;IAC9C,MAAM,QAAQ,GAAoC,EAAE,CAAC;IACrD,OAAO,CAAC,GAAG,IAAoB,EAAkB,EAAE;;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,MAAA,QAAQ,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createElement } from './functions/other/create-element';
|
|
2
|
+
export { debounce } from './functions/time/debounce';
|
|
3
|
+
export { deepPartialSet } from './functions/other/deep-partial-set';
|
|
4
|
+
export { groupBy } from './functions/array/group-by';
|
|
5
|
+
export { memoize } from './functions/time/memoize';
|
|
6
|
+
export { multiSort, ASC, DESC, sortBy } from './functions/array/multi-sort';
|
|
7
|
+
export { times } from './functions/other/times';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.times = exports.sortBy = exports.DESC = exports.ASC = exports.multiSort = exports.memoize = exports.groupBy = exports.deepPartialSet = exports.debounce = exports.createElement = void 0;
|
|
4
|
+
var create_element_1 = require("./functions/other/create-element");
|
|
5
|
+
Object.defineProperty(exports, "createElement", { enumerable: true, get: function () { return create_element_1.createElement; } });
|
|
6
|
+
var debounce_1 = require("./functions/time/debounce");
|
|
7
|
+
Object.defineProperty(exports, "debounce", { enumerable: true, get: function () { return debounce_1.debounce; } });
|
|
8
|
+
var deep_partial_set_1 = require("./functions/other/deep-partial-set");
|
|
9
|
+
Object.defineProperty(exports, "deepPartialSet", { enumerable: true, get: function () { return deep_partial_set_1.deepPartialSet; } });
|
|
10
|
+
var group_by_1 = require("./functions/array/group-by");
|
|
11
|
+
Object.defineProperty(exports, "groupBy", { enumerable: true, get: function () { return group_by_1.groupBy; } });
|
|
12
|
+
var memoize_1 = require("./functions/time/memoize");
|
|
13
|
+
Object.defineProperty(exports, "memoize", { enumerable: true, get: function () { return memoize_1.memoize; } });
|
|
14
|
+
var multi_sort_1 = require("./functions/array/multi-sort");
|
|
15
|
+
Object.defineProperty(exports, "multiSort", { enumerable: true, get: function () { return multi_sort_1.multiSort; } });
|
|
16
|
+
Object.defineProperty(exports, "ASC", { enumerable: true, get: function () { return multi_sort_1.ASC; } });
|
|
17
|
+
Object.defineProperty(exports, "DESC", { enumerable: true, get: function () { return multi_sort_1.DESC; } });
|
|
18
|
+
Object.defineProperty(exports, "sortBy", { enumerable: true, get: function () { return multi_sort_1.sortBy; } });
|
|
19
|
+
var times_1 = require("./functions/other/times");
|
|
20
|
+
Object.defineProperty(exports, "times", { enumerable: true, get: function () { return times_1.times; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mEAA+D;AAAvD,+GAAA,aAAa,OAAA;AACrB,sDAAmD;AAA3C,oGAAA,QAAQ,OAAA;AAChB,uEAAkE;AAA1D,kHAAA,cAAc,OAAA;AACtB,uDAAmD;AAA3C,mGAAA,OAAO,OAAA;AACf,oDAAiD;AAAzC,kGAAA,OAAO,OAAA;AACf,2DAA0E;AAAlE,uGAAA,SAAS,OAAA;AAAE,iGAAA,GAAG,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,oGAAA,MAAM,OAAA;AACpC,iDAA8C;AAAtC,8FAAA,KAAK,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/interfaces/list.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rickard.antonsson/ts-utility",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "build/
|
|
6
|
-
"types": "build/
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "My favorite small helper functions",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"build
|
|
8
|
+
"build/**/*"
|
|
9
9
|
],
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"keywords": [],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"lint": "gts lint",
|
|
15
|
+
"clean": "gts clean",
|
|
16
|
+
"compile": "tsc",
|
|
17
|
+
"fix": "gts fix",
|
|
18
|
+
"prepare": "pnpm run compile",
|
|
19
|
+
"pretest": "pnpm run compile",
|
|
20
|
+
"posttest": "pnpm run lint"
|
|
21
|
+
},
|
|
12
22
|
"devDependencies": {
|
|
13
23
|
"@babel/core": "^7.16.0",
|
|
14
24
|
"@babel/preset-env": "^7.23.3",
|
|
15
25
|
"@babel/preset-typescript": "^7.16.0",
|
|
16
26
|
"@faker-js/faker": "^6.0.0",
|
|
17
27
|
"@types/jest": "^27.0.3",
|
|
18
|
-
"@types/node": "^
|
|
28
|
+
"@types/node": "^22.5.4",
|
|
29
|
+
"@typescript-eslint/typescript-estree": "^8.7.0",
|
|
19
30
|
"babel-jest": "^27.4.2",
|
|
20
31
|
"gts": "^3.1.0",
|
|
21
32
|
"jest": "^27.4.3",
|
|
22
|
-
"typescript": "
|
|
33
|
+
"typescript": "~5.5.3"
|
|
23
34
|
},
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"lint": "gts lint",
|
|
27
|
-
"clean": "gts clean",
|
|
28
|
-
"compile": "tsc",
|
|
29
|
-
"fix": "gts fix",
|
|
30
|
-
"pretest": "pnpm run compile",
|
|
31
|
-
"posttest": "pnpm run lint"
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@rickard.antonsson/ts-utility": "file:"
|
|
32
37
|
}
|
|
33
|
-
}
|
|
38
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"group-by.js","sourceRoot":"","sources":["../../../../src/functions/array/group-by.ts"],"names":[],"mappings":";;;AAAO,MAAM,OAAO,GAAG,CACrB,IAAS,EACT,MAAsB,EACG,EAAE;IAC3B,MAAM,OAAO,GAA4B,EAAE,CAAC;IAC5C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;;QAClB,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,MAAA,OAAO,CAAC,EAAE,CAAC,mCAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAVW,QAAA,OAAO,WAUlB"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.simpleSort = exports.groupBy = void 0;
|
|
4
|
-
var group_by_1 = require("./group-by");
|
|
5
|
-
Object.defineProperty(exports, "groupBy", { enumerable: true, get: function () { return group_by_1.groupBy; } });
|
|
6
|
-
var simple_sort_1 = require("./simple-sort");
|
|
7
|
-
Object.defineProperty(exports, "simpleSort", { enumerable: true, get: function () { return simple_sort_1.simpleSort; } });
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/functions/array/index.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAA3B,mGAAA,OAAO,OAAA;AACf,6CAAyC;AAAjC,yGAAA,UAAU,OAAA"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
type SortByFunction<T> = ((item: T) => string) | ((item: T) => number);
|
|
2
|
-
type SortOrder = 'asc' | 'desc';
|
|
3
|
-
export declare const asc: <T>(sortBy: SortByFunction<T>) => [SortByFunction<T>, SortOrder];
|
|
4
|
-
export declare const desc: <T>(sortBy: SortByFunction<T>) => [SortByFunction<T>, SortOrder];
|
|
5
|
-
export declare const simpleSortOther: <T extends object>(list: T[], ...sortByList: (SortByFunction<T> | [SortByFunction<T>, SortOrder])[]) => T[];
|
|
6
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.simpleSortOther = exports.desc = exports.asc = void 0;
|
|
4
|
-
const asc = (sortBy) => [sortBy, 'asc'];
|
|
5
|
-
exports.asc = asc;
|
|
6
|
-
const desc = (sortBy) => [sortBy, 'desc'];
|
|
7
|
-
exports.desc = desc;
|
|
8
|
-
const simpleSortOther = (list, ...sortByList) => {
|
|
9
|
-
if (!(sortByList === null || sortByList === void 0 ? void 0 : sortByList.length))
|
|
10
|
-
return [...list];
|
|
11
|
-
const sortByListWithOrder = sortByList.map(sortBy => {
|
|
12
|
-
return Array.isArray(sortBy) ? sortBy : [sortBy, 'asc'];
|
|
13
|
-
});
|
|
14
|
-
const values = new WeakMap(list.map(i => [i, Array.from(Array(sortByList.length))]));
|
|
15
|
-
return [...list].sort((a, b) => {
|
|
16
|
-
var _a, _b;
|
|
17
|
-
for (let i = 0; i < sortByListWithOrder.length; i++) {
|
|
18
|
-
const [sortBy, order] = sortByListWithOrder[i];
|
|
19
|
-
const aArray = values.get(a);
|
|
20
|
-
const bArray = values.get(b);
|
|
21
|
-
const aValue = (_a = aArray[i]) !== null && _a !== void 0 ? _a : (aArray[i] = sortBy(a));
|
|
22
|
-
const bValue = (_b = bArray[i]) !== null && _b !== void 0 ? _b : (bArray[i] = sortBy(b));
|
|
23
|
-
const sortAscending = order !== 'desc';
|
|
24
|
-
let result = 0;
|
|
25
|
-
if (typeof aValue === 'string' && typeof bValue === 'string') {
|
|
26
|
-
result = sortAscending
|
|
27
|
-
? aValue.localeCompare(bValue)
|
|
28
|
-
: bValue.localeCompare(aValue);
|
|
29
|
-
}
|
|
30
|
-
if (typeof aValue === 'number' && typeof bValue === 'number') {
|
|
31
|
-
result = sortAscending ? aValue - bValue : bValue - aValue;
|
|
32
|
-
}
|
|
33
|
-
if (result === 0)
|
|
34
|
-
continue;
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
return 0;
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
exports.simpleSortOther = simpleSortOther;
|
|
41
|
-
//# sourceMappingURL=simple-sort-other.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simple-sort-other.js","sourceRoot":"","sources":["../../../../src/functions/array/simple-sort-other.ts"],"names":[],"mappings":";;;AAGO,MAAM,GAAG,GAAG,CACjB,MAAyB,EACO,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAFxC,QAAA,GAAG,OAEqC;AAC9C,MAAM,IAAI,GAAG,CAClB,MAAyB,EACO,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAFzC,QAAA,IAAI,QAEqC;AAE/C,MAAM,eAAe,GAAG,CAC7B,IAAS,EACT,GAAG,UAAqE,EACnE,EAAE;IACP,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,CAAA;QAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IAE1C,MAAM,mBAAmB,GAAqC,UAAU,CAAC,GAAG,CAC1E,MAAM,CAAC,EAAE;QACP,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC,CACF,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,OAAO,CACxB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CACzD,CAAC;IAEF,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnD,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;YAC/C,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAwB,CAAC;YACpD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAwB,CAAC;YACpD,MAAM,MAAM,GAAG,MAAA,MAAM,CAAC,CAAC,CAAC,mCAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD,MAAM,MAAM,GAAG,MAAA,MAAM,CAAC,CAAC,CAAC,mCAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD,MAAM,aAAa,GAAG,KAAK,KAAK,MAAM,CAAC;YAEvC,IAAI,MAAM,GAAG,CAAC,CAAC;YAEf,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;gBAC5D,MAAM,GAAG,aAAa;oBACpB,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;oBAC9B,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;aAClC;YAED,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;gBAC5D,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC;aAC5D;YAED,IAAI,MAAM,KAAK,CAAC;gBAAE,SAAS;YAE3B,OAAO,MAAM,CAAC;SACf;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA1CW,QAAA,eAAe,mBA0C1B"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
type Getter<T> = ((item: T) => string) | ((item: T) => number);
|
|
2
|
-
type SortOrder = 'asc' | 'desc';
|
|
3
|
-
export declare const asc: <T>(getter: Getter<T>) => [Getter<T>, SortOrder];
|
|
4
|
-
export declare const desc: <T>(getter: Getter<T>) => [Getter<T>, SortOrder];
|
|
5
|
-
export declare const simpleSort: <T>(list: T[], ...getterList: [Getter<T>, SortOrder][]) => T[];
|
|
6
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.simpleSort = exports.desc = exports.asc = void 0;
|
|
4
|
-
const asc = (getter) => [
|
|
5
|
-
getter,
|
|
6
|
-
'asc',
|
|
7
|
-
];
|
|
8
|
-
exports.asc = asc;
|
|
9
|
-
const desc = (getter) => [
|
|
10
|
-
getter,
|
|
11
|
-
'desc',
|
|
12
|
-
];
|
|
13
|
-
exports.desc = desc;
|
|
14
|
-
const simpleSort = (list, ...getterList) => {
|
|
15
|
-
if (!(getterList === null || getterList === void 0 ? void 0 : getterList.length))
|
|
16
|
-
return [...list];
|
|
17
|
-
const indexAndValuesList = list.map((item, index) => [index, ...getterList.map(([sortBy]) => sortBy(item))]);
|
|
18
|
-
indexAndValuesList.sort((a, b) => {
|
|
19
|
-
for (let i = 0; i < getterList.length; i++) {
|
|
20
|
-
const aValue = a[i + 1];
|
|
21
|
-
const bValue = b[i + 1];
|
|
22
|
-
const sortAscending = getterList[i][1] !== 'desc';
|
|
23
|
-
let result = 0;
|
|
24
|
-
if (typeof aValue === 'string' && typeof bValue === 'string') {
|
|
25
|
-
result = sortAscending
|
|
26
|
-
? aValue.localeCompare(bValue)
|
|
27
|
-
: bValue.localeCompare(aValue);
|
|
28
|
-
}
|
|
29
|
-
if (typeof aValue === 'number' && typeof bValue === 'number') {
|
|
30
|
-
result = sortAscending ? aValue - bValue : bValue - aValue;
|
|
31
|
-
}
|
|
32
|
-
if (result === 0)
|
|
33
|
-
continue;
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
return 0;
|
|
37
|
-
});
|
|
38
|
-
return indexAndValuesList.map(([index]) => list[index]);
|
|
39
|
-
};
|
|
40
|
-
exports.simpleSort = simpleSort;
|
|
41
|
-
//# sourceMappingURL=simple-sort.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simple-sort.js","sourceRoot":"","sources":["../../../../src/functions/array/simple-sort.ts"],"names":[],"mappings":";;;AAGO,MAAM,GAAG,GAAG,CAAI,MAAiB,EAA0B,EAAE,CAAC;IACnE,MAAM;IACN,KAAK;CACN,CAAC;AAHW,QAAA,GAAG,OAGd;AACK,MAAM,IAAI,GAAG,CAAI,MAAiB,EAA0B,EAAE,CAAC;IACpE,MAAM;IACN,MAAM;CACP,CAAC;AAHW,QAAA,IAAI,QAGf;AAEK,MAAM,UAAU,GAAG,CACxB,IAAS,EACT,GAAG,UAAoC,EAClC,EAAE;IACP,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,CAAA;QAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IAE1C,MAAM,kBAAkB,GAA4C,IAAI,CAAC,GAAG,CAC1E,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CACxE,CAAC;IAEF,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC1C,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACxB,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACxB,MAAM,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC;YAElD,IAAI,MAAM,GAAG,CAAC,CAAC;YAEf,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;gBAC5D,MAAM,GAAG,aAAa;oBACpB,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;oBAC9B,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;aAClC;YAED,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;gBAC5D,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC;aAC5D;YAED,IAAI,MAAM,KAAK,CAAC;gBAAE,SAAS;YAE3B,OAAO,MAAM,CAAC;SACf;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;IAEH,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC,CAAC;AApCW,QAAA,UAAU,cAoCrB"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./array"), exports);
|
|
18
|
-
__exportStar(require("./list"), exports);
|
|
19
|
-
__exportStar(require("./other/deep-partial-set"), exports);
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,yCAAuB;AACvB,2DAAyC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../../../src/functions/list/filter.ts"],"names":[],"mappings":";;;AAGO,MAAM,MAAM,GAAG,CACpB,IAAa,EACb,MAA4B,EACnB,EAAE,CACX,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM;AACzB,sEAAsE;AACtE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACnB,IAAI,MAAM,CAAC,IAAI,CAAC;QAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAClC,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAa,CACd,CAAC;AAXS,QAAA,MAAM,UAWf"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.map = exports.filter = void 0;
|
|
4
|
-
var filter_1 = require("./filter");
|
|
5
|
-
Object.defineProperty(exports, "filter", { enumerable: true, get: function () { return filter_1.filter; } });
|
|
6
|
-
var map_1 = require("./map");
|
|
7
|
-
Object.defineProperty(exports, "map", { enumerable: true, get: function () { return map_1.map; } });
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/functions/list/index.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAAxB,gGAAA,MAAM,OAAA;AACd,6BAA0B;AAAlB,0FAAA,GAAG,OAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../../../src/functions/list/map.ts"],"names":[],"mappings":";;;AAEO,MAAM,GAAG,GAAG,CACjB,KAAc,EACd,EAAa,EACgB,EAAE,CAC/B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAC1B,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAC,CAAC,EACjD,EAAE,CACH,CAAC;AAPS,QAAA,GAAG,OAOZ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deep-partial-set.js","sourceRoot":"","sources":["../../../../src/functions/other/deep-partial-set.ts"],"names":[],"mappings":";;;AAEA,SAAgB,cAAc,CAG5B,CAAI,EAAE,CAAI;IACV,MAAM,KAAK,GAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAM,EAAC,GAAG,CAAC,EAAC,CAAC;IACzB,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAClB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO;QACjC,IAAI,QAAuB,CAAC;QAE5B,QAAQ,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE;YACrB,KAAK,UAAU;gBACb,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC1B,MAAM;YACR,KAAK,QAAQ;gBACX,QAAQ,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC1C,MAAM;YACR;gBACE,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;gBAClB,MAAM;SACT;QAED,IAAI,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC;YAAE,OAAO;QAErC,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;QACvB,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC;AAhCD,wCAgCC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../../../src/functions/time/debounce.ts"],"names":[],"mappings":";;;AAEA,SAAgB,QAAQ,CAAmB,EAAM,EAAE,IAAI,GAAG,CAAC;IACzD,IAAI,SAAwC,CAAC;IAE7C,OAAO,CAAC,GAAG,IAAoB,EAAQ,EAAE;QACvC,YAAY,CAAC,SAAS,CAAC,CAAC;QACxB,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC;AAPD,4BAOC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../../../src/functions/time/memoize.ts"],"names":[],"mappings":";;;AAEA,SAAgB,OAAO,CAAmB,EAAM;IAC9C,MAAM,QAAQ,GAAoC,EAAE,CAAC;IACrD,OAAO,CAAC,GAAG,IAAoB,EAAkB,EAAE;;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,MAAA,QAAQ,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC;AAND,0BAMC"}
|
package/build/src/index.d.ts
DELETED
package/build/src/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.deepPartialSet = void 0;
|
|
18
|
-
__exportStar(require("./functions"), exports);
|
|
19
|
-
__exportStar(require("./types"), exports);
|
|
20
|
-
var deep_partial_set_1 = require("./functions/other/deep-partial-set");
|
|
21
|
-
Object.defineProperty(exports, "deepPartialSet", { enumerable: true, get: function () { return deep_partial_set_1.deepPartialSet; } });
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/build/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB;AAExB,uEAAkE;AAA1D,kHAAA,cAAc,OAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/src/test-speed.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const promises_1 = require("node:fs/promises");
|
|
4
|
-
const functions_1 = require("./functions");
|
|
5
|
-
const simple_sort_1 = require("./functions/array/simple-sort");
|
|
6
|
-
// import faker from '@faker-js/faker';
|
|
7
|
-
// function generatePerson() {
|
|
8
|
-
// const contextualCard = faker.helpers.contextualCard();
|
|
9
|
-
// return {
|
|
10
|
-
// ...contextualCard,
|
|
11
|
-
// joined: faker.date.past(10),
|
|
12
|
-
// };
|
|
13
|
-
// }
|
|
14
|
-
// console.time('Generate');
|
|
15
|
-
// const personList = Array(1000);
|
|
16
|
-
// for (let i = 0; i < 1000; i++) {
|
|
17
|
-
// if (i % 10000 === 0) console.log(i / 1000);
|
|
18
|
-
// personList[i] = generatePerson();
|
|
19
|
-
// }
|
|
20
|
-
// console.timeEnd('Generate');
|
|
21
|
-
// writeFile('person-list.json', JSON.stringify(personList));
|
|
22
|
-
async function main() {
|
|
23
|
-
const cards = JSON.parse(await (0, promises_1.readFile)('person-list.json', 'utf-8'));
|
|
24
|
-
console.log(cards[0]);
|
|
25
|
-
console.time('Time to sort other');
|
|
26
|
-
// const sortedCardsOther =
|
|
27
|
-
Array.from(Array(10)).forEach(() => {
|
|
28
|
-
(0, functions_1.simpleSort)(cards, (0, simple_sort_1.asc)(i => i.name.length), (0, simple_sort_1.desc)(i => i.name), (0, simple_sort_1.asc)(i => recursivelyCountObjectsPropertiesLetters(i)));
|
|
29
|
-
});
|
|
30
|
-
console.timeEnd('Time to sort other');
|
|
31
|
-
console.time('Time to sort');
|
|
32
|
-
// const sortedCards =
|
|
33
|
-
Array.from(Array(10)).forEach(() => {
|
|
34
|
-
(0, functions_1.simpleSort)(cards, (0, simple_sort_1.asc)(i => i.name.length), (0, simple_sort_1.desc)(i => i.name), (0, simple_sort_1.asc)(i => recursivelyCountObjectsPropertiesLetters(i)));
|
|
35
|
-
});
|
|
36
|
-
console.timeEnd('Time to sort');
|
|
37
|
-
// console.log(
|
|
38
|
-
// sortedCards.slice(0, 100).map(card => `${card.name.length} ${card.name}`)
|
|
39
|
-
// );
|
|
40
|
-
}
|
|
41
|
-
main();
|
|
42
|
-
function recursivelyCountObjectsPropertiesLetters(item) {
|
|
43
|
-
return Object.keys(item).reduce((count, key) => {
|
|
44
|
-
switch (typeof item[key]) {
|
|
45
|
-
case 'string':
|
|
46
|
-
return count + item[key].length;
|
|
47
|
-
case 'object':
|
|
48
|
-
return recursivelyCountObjectsPropertiesLetters(item[key]);
|
|
49
|
-
}
|
|
50
|
-
return count;
|
|
51
|
-
}, 0);
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=test-speed.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-speed.js","sourceRoot":"","sources":["../../src/test-speed.ts"],"names":[],"mappings":";;AACA,+CAA0C;AAC1C,2CAAuC;AACvC,+DAAwD;AAGxD,uCAAuC;AAEvC,8BAA8B;AAC9B,0DAA0D;AAC1D,aAAa;AACb,yBAAyB;AACzB,mCAAmC;AACnC,OAAO;AACP,IAAI;AAEJ,4BAA4B;AAC5B,kCAAkC;AAClC,mCAAmC;AACnC,gDAAgD;AAChD,sCAAsC;AACtC,IAAI;AACJ,+BAA+B;AAC/B,6DAA6D;AAE7D,KAAK,UAAU,IAAI;IACjB,MAAM,KAAK,GAAqB,IAAI,CAAC,KAAK,CACxC,MAAM,IAAA,mBAAQ,EAAC,kBAAkB,EAAE,OAAO,CAAC,CAC5C,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACtB,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACnC,2BAA2B;IAC3B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;QACjC,IAAA,sBAAU,EACR,KAAK,EACL,IAAA,iBAAG,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EACvB,IAAA,kBAAI,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EACjB,IAAA,iBAAG,EAAC,CAAC,CAAC,EAAE,CAAC,wCAAwC,CAAC,CAAC,CAAC,CAAC,CACtD,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC7B,sBAAsB;IACtB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;QACjC,IAAA,sBAAU,EACR,KAAK,EACL,IAAA,iBAAG,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EACvB,IAAA,kBAAI,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EACjB,IAAA,iBAAG,EAAC,CAAC,CAAC,EAAE,CAAC,wCAAwC,CAAC,CAAC,CAAC,CAAC,CACtD,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAChC,eAAe;IACf,8EAA8E;IAC9E,KAAK;AACP,CAAC;AAED,IAAI,EAAE,CAAC;AAEP,SAAS,wCAAwC,CAAC,IAAe;IAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC7C,QAAQ,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE;YACxB,KAAK,QAAQ;gBACX,OAAO,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;YAClC,KAAK,QAAQ;gBACX,OAAO,wCAAwC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;SAC9D;QACD,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,CAAC,CAAC,CAAC;AACR,CAAC"}
|
package/build/src/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|