@koine/utils 1.0.60 → 1.0.63
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/createStorage.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/moveSortableArrayItemByKey.d.ts +9 -0
- package/moveSortableArrayItemByKey.js +17 -0
- package/node/createStorage.js +1 -1
- package/node/index.js +1 -0
- package/node/moveSortableArrayItemByKey.js +21 -0
- package/node/removeDuplicatesByKey.js +0 -1
- package/package.json +1 -1
- package/removeDuplicatesByKey.d.ts +1 -1
- package/removeDuplicatesByKey.js +0 -1
package/createStorage.js
CHANGED
|
@@ -36,7 +36,7 @@ export var createStorage = function (config) {
|
|
|
36
36
|
return null;
|
|
37
37
|
},
|
|
38
38
|
set: function (key, value) {
|
|
39
|
-
ls("s", keys[key], isString(value) ? encode(value) : JSON.stringify(value));
|
|
39
|
+
ls("s", keys[key], isString(value) ? encode(value) : encode(JSON.stringify(value)));
|
|
40
40
|
},
|
|
41
41
|
has: function (key) {
|
|
42
42
|
var stored = ls("g", keys[key]);
|
package/index.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export * from "./mapListBy";
|
|
|
72
72
|
export * from "./matchSorter";
|
|
73
73
|
export * from "./mergeObjects";
|
|
74
74
|
export * from "./mergeUrlQueryParams";
|
|
75
|
+
export * from "./moveSortableArrayItemByKey";
|
|
75
76
|
export * from "./navigateToHashParams";
|
|
76
77
|
export * from "./navigateToMergedHashParams";
|
|
77
78
|
export * from "./navigateToMergedParams";
|
package/index.js
CHANGED
|
@@ -73,6 +73,7 @@ export * from "./mapListBy";
|
|
|
73
73
|
export * from "./matchSorter";
|
|
74
74
|
export * from "./mergeObjects";
|
|
75
75
|
export * from "./mergeUrlQueryParams";
|
|
76
|
+
export * from "./moveSortableArrayItemByKey";
|
|
76
77
|
export * from "./navigateToHashParams";
|
|
77
78
|
export * from "./navigateToMergedHashParams";
|
|
78
79
|
export * from "./navigateToMergedParams";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Move item from one place to another in a sortable array of objects, re-ordering
|
|
3
|
+
* the array accrodingly (no swapping of position).
|
|
4
|
+
* This is useful for drag and drop functionalities
|
|
5
|
+
*
|
|
6
|
+
* @category arrays, dnd
|
|
7
|
+
*/
|
|
8
|
+
export declare function moveSortableArrayItemByKey<T, K extends keyof T>(items: T[], key: K, fromItem: Pick<T, K>, toItem: Pick<T, K>): T[];
|
|
9
|
+
export default moveSortableArrayItemByKey;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
|
+
/**
|
|
3
|
+
* Move item from one place to another in a sortable array of objects, re-ordering
|
|
4
|
+
* the array accrodingly (no swapping of position).
|
|
5
|
+
* This is useful for drag and drop functionalities
|
|
6
|
+
*
|
|
7
|
+
* @category arrays, dnd
|
|
8
|
+
*/
|
|
9
|
+
export function moveSortableArrayItemByKey(items, key, fromItem, toItem) {
|
|
10
|
+
var itemsKeys = items.map(function (item) { return item[key]; });
|
|
11
|
+
var idxFrom = itemsKeys.indexOf(fromItem[key]);
|
|
12
|
+
var idxTo = itemsKeys.indexOf(toItem[key]);
|
|
13
|
+
var item = items.splice(idxFrom, 1)[0];
|
|
14
|
+
items.splice(idxTo, 0, item);
|
|
15
|
+
return __spreadArray([], items, true);
|
|
16
|
+
}
|
|
17
|
+
export default moveSortableArrayItemByKey;
|
package/node/createStorage.js
CHANGED
|
@@ -39,7 +39,7 @@ var createStorage = function (config) {
|
|
|
39
39
|
return null;
|
|
40
40
|
},
|
|
41
41
|
set: function (key, value) {
|
|
42
|
-
ls("s", keys[key], (0, isString_1.isString)(value) ? (0, encode_1.encode)(value) : JSON.stringify(value));
|
|
42
|
+
ls("s", keys[key], (0, isString_1.isString)(value) ? (0, encode_1.encode)(value) : (0, encode_1.encode)(JSON.stringify(value)));
|
|
43
43
|
},
|
|
44
44
|
has: function (key) {
|
|
45
45
|
var stored = ls("g", keys[key]);
|
package/node/index.js
CHANGED
|
@@ -76,6 +76,7 @@ tslib_1.__exportStar(require("./mapListBy"), exports);
|
|
|
76
76
|
tslib_1.__exportStar(require("./matchSorter"), exports);
|
|
77
77
|
tslib_1.__exportStar(require("./mergeObjects"), exports);
|
|
78
78
|
tslib_1.__exportStar(require("./mergeUrlQueryParams"), exports);
|
|
79
|
+
tslib_1.__exportStar(require("./moveSortableArrayItemByKey"), exports);
|
|
79
80
|
tslib_1.__exportStar(require("./navigateToHashParams"), exports);
|
|
80
81
|
tslib_1.__exportStar(require("./navigateToMergedHashParams"), exports);
|
|
81
82
|
tslib_1.__exportStar(require("./navigateToMergedParams"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.moveSortableArrayItemByKey = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* Move item from one place to another in a sortable array of objects, re-ordering
|
|
7
|
+
* the array accrodingly (no swapping of position).
|
|
8
|
+
* This is useful for drag and drop functionalities
|
|
9
|
+
*
|
|
10
|
+
* @category arrays, dnd
|
|
11
|
+
*/
|
|
12
|
+
function moveSortableArrayItemByKey(items, key, fromItem, toItem) {
|
|
13
|
+
var itemsKeys = items.map(function (item) { return item[key]; });
|
|
14
|
+
var idxFrom = itemsKeys.indexOf(fromItem[key]);
|
|
15
|
+
var idxTo = itemsKeys.indexOf(toItem[key]);
|
|
16
|
+
var item = items.splice(idxFrom, 1)[0];
|
|
17
|
+
items.splice(idxTo, 0, item);
|
|
18
|
+
return tslib_1.__spreadArray([], items, true);
|
|
19
|
+
}
|
|
20
|
+
exports.moveSortableArrayItemByKey = moveSortableArrayItemByKey;
|
|
21
|
+
exports.default = moveSortableArrayItemByKey;
|
package/package.json
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @category array
|
|
6
6
|
*/
|
|
7
|
-
export declare function removeDuplicatesByKey<T extends Record<string | number | symbol, any>>(array
|
|
7
|
+
export declare function removeDuplicatesByKey<T extends Record<string | number | symbol, any>>(array: T[] | undefined, key: keyof T): T[];
|
|
8
8
|
export default removeDuplicatesByKey;
|