@hkdigital/lib-sveltekit 0.0.46 → 0.0.47

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 CHANGED
@@ -29,9 +29,26 @@ pnpm add @hkdigital/lib-sveltekit
29
29
 
30
30
  ### Update
31
31
 
32
+ We use a global installion of the `ncu` package to upgrade our `package.json`. Install `ncu` first if you don't have it yet
33
+
34
+ ```bash
35
+ npm install -g npm-check-updates
36
+ ```
37
+
38
+ Upgrading works as follows:
39
+
32
40
  ```bash
33
41
  ncu "@hkdigital/*" -u && pnpm install
34
42
  ```
43
+ We use a wildcard to upgrade all installed `node_modules` in the scope `@hkdigital`.
44
+
45
+ You can also add this command to your project's `package.json`. E.g. add the lines:
46
+
47
+ ```bash
48
+ "scripts": {
49
+ "upgrade:hklib": "ncu '@hkdigital/*' -u && pnpm install",
50
+ "upgrade:all": "ncu -u && pnpm install"
51
+ ```
35
52
 
36
53
  ### Import JS & Svelte
37
54
 
@@ -107,5 +124,5 @@ npm publish --access public
107
124
  pnpm run publish:npm
108
125
  ```
109
126
 
110
- ### Contribute
127
+ ## Contribute
111
128
  If your wish to contribute to this library, please contact us [HKdigital](https://hkdigital.nl/contact). Alternatively, the license permits you to fork the library and publish under an alternative name. Change the package name in [package.json](./package.json) to do so.
@@ -11,18 +11,20 @@ export default class Selector {
11
11
  /**
12
12
  * Returns the first item from the list of items that matches the selector
13
13
  *
14
- * @param {object[]|null} items
14
+ * @template {object} T
15
+ * @param {T[]|null} items
15
16
  *
16
- * @returns {object|null} item or null if not found
17
+ * @returns {T|null} item or null if not found
17
18
  */
18
- findFirst(items: object[] | null): object | null;
19
+ findFirst<T extends unknown>(items: T[] | null): T | null;
19
20
  /**
20
21
  * Returns all items from the list of items that match the selector
21
22
  *
22
- * @param {object[]|null} items
23
+ * @template {object} T
24
+ * @param {T[]|null} items
23
25
  *
24
- * @returns {object|null} item or null if not found
26
+ * @returns {T|null} item or null if not found
25
27
  */
26
- findAll(items: object[] | null): object | null;
28
+ findAll<T extends unknown>(items: T[] | null): T | null;
27
29
  #private;
28
30
  }
@@ -53,9 +53,10 @@ export default class Selector {
53
53
  /**
54
54
  * Returns the first item from the list of items that matches the selector
55
55
  *
56
- * @param {object[]|null} items
56
+ * @template {object} T
57
+ * @param {T[]|null} items
57
58
  *
58
- * @returns {object|null} item or null if not found
59
+ * @returns {T|null} item or null if not found
59
60
  */
60
61
  findFirst(items) {
61
62
  if (!items) {
@@ -76,9 +77,10 @@ export default class Selector {
76
77
  /**
77
78
  * Returns all items from the list of items that match the selector
78
79
  *
79
- * @param {object[]|null} items
80
+ * @template {object} T
81
+ * @param {T[]|null} items
80
82
  *
81
- * @returns {object|null} item or null if not found
83
+ * @returns {T|null} item or null if not found
82
84
  */
83
85
  findAll(items) {
84
86
  const result = [];
@@ -135,22 +135,24 @@ export function sortByPathValue(items: any[], path: string[] | string, compareFn
135
135
  * Find the first item in the list of objects that matches the selector
136
136
  * - All items in the supplied array must be objects
137
137
  *
138
- * @param {object[]} arr
138
+ * @template {object} T
139
+ * @param {T[]} arr
139
140
  * @param {object|null} selector
140
141
  *
141
- * @returns {object|null} first matched item
142
+ * @returns {T|null} first matched item
142
143
  */
143
- export function findFirst(arr: object[], selector: object | null): object | null;
144
+ export function findFirst<T extends unknown>(arr: T[], selector: object | null): T | null;
144
145
  /**
145
146
  * Returns all items from the list of items that match the selector
146
147
  * - All items in the supplied array must be objects
147
148
  *
148
- * @param {object[]} arr
149
+ * @template {object} T
150
+ * @param {T[]} arr
149
151
  * @param {object|null} selector
150
152
  *
151
- * @returns {object[]} matching items
153
+ * @returns {T[]} matching items
152
154
  */
153
- export function findAll(arr: object[], selector: object | null): object[];
155
+ export function findAll<T extends unknown>(arr: T[], selector: object | null): T[];
154
156
  /**
155
157
  * Convert array to an object using a list of keys for each index
156
158
  *
@@ -378,10 +378,11 @@ export function sortByPathValue(items, path, compareFn = smallestFirst) {
378
378
  * Find the first item in the list of objects that matches the selector
379
379
  * - All items in the supplied array must be objects
380
380
  *
381
- * @param {object[]} arr
381
+ * @template {object} T
382
+ * @param {T[]} arr
382
383
  * @param {object|null} selector
383
384
  *
384
- * @returns {object|null} first matched item
385
+ * @returns {T|null} first matched item
385
386
  */
386
387
  export function findFirst(arr, selector) {
387
388
  const selectorObj = new Selector(selector);
@@ -395,10 +396,11 @@ export function findFirst(arr, selector) {
395
396
  * Returns all items from the list of items that match the selector
396
397
  * - All items in the supplied array must be objects
397
398
  *
398
- * @param {object[]} arr
399
+ * @template {object} T
400
+ * @param {T[]} arr
399
401
  * @param {object|null} selector
400
402
  *
401
- * @returns {object[]} matching items
403
+ * @returns {T[]} matching items
402
404
  */
403
405
  export function findAll(arr, selector) {
404
406
  const selectorObj = new Selector(selector);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.0.46",
3
+ "version": "0.0.47",
4
4
  "author": "Jens Kleinhout, HKdigital (https://hkdigital.nl)",
5
5
  "license": "ISC",
6
6
  "repository": {