@koine/utils 1.0.72 → 1.0.73
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.d.ts +3 -4
- package/createStorage.js +8 -3
- package/node/createStorage.js +8 -3
- package/package.json +1 -1
- package/typings.d.ts +4 -0
package/createStorage.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
declare type NullableRecord<T> = {
|
|
2
|
-
[K in keyof T]: T[K] | null;
|
|
3
|
-
};
|
|
4
1
|
export declare type CreateStorageConfig = Record<string, any>;
|
|
5
2
|
/**
|
|
6
3
|
* Utility to create a storage instance to interact with `localStorage` using
|
|
@@ -16,8 +13,10 @@ export declare const createStorage: <T extends CreateStorageConfig>(config: Part
|
|
|
16
13
|
get<TKey extends keyof T>(key: TKey): T[TKey] | null;
|
|
17
14
|
/**
|
|
18
15
|
* Get all storage values (it uses `localStorage.get()`).
|
|
16
|
+
*
|
|
17
|
+
* `undefined` and `null` values are not returned.
|
|
19
18
|
*/
|
|
20
|
-
getAll():
|
|
19
|
+
getAll(): T;
|
|
21
20
|
/**
|
|
22
21
|
* Set a storage value (it uses `localStorage.set()`).
|
|
23
22
|
*
|
package/createStorage.js
CHANGED
|
@@ -2,7 +2,7 @@ import { __assign } from "tslib";
|
|
|
2
2
|
import { decode } from "./decode";
|
|
3
3
|
import { encode } from "./encode";
|
|
4
4
|
import { isBrowser } from "./isBrowser";
|
|
5
|
-
import {
|
|
5
|
+
import { isNullOrUndefined } from "./isNullOrUndefined";
|
|
6
6
|
import { isString } from "./isString";
|
|
7
7
|
/**
|
|
8
8
|
* Utility to create a storage instance to interact with `localStorage` using
|
|
@@ -48,11 +48,16 @@ export var createStorage = function (config) {
|
|
|
48
48
|
},
|
|
49
49
|
/**
|
|
50
50
|
* Get all storage values (it uses `localStorage.get()`).
|
|
51
|
+
*
|
|
52
|
+
* `undefined` and `null` values are not returned.
|
|
51
53
|
*/
|
|
52
54
|
getAll: function () {
|
|
53
55
|
var all = {};
|
|
54
56
|
for (var key in keys) {
|
|
55
|
-
|
|
57
|
+
var value = this.get(key);
|
|
58
|
+
if (!isNullOrUndefined(value)) {
|
|
59
|
+
all[key] = value;
|
|
60
|
+
}
|
|
56
61
|
}
|
|
57
62
|
return all;
|
|
58
63
|
},
|
|
@@ -73,7 +78,7 @@ export var createStorage = function (config) {
|
|
|
73
78
|
setMany: function (newValues) {
|
|
74
79
|
for (var key in newValues) {
|
|
75
80
|
var value = newValues[key];
|
|
76
|
-
if (!
|
|
81
|
+
if (!isNullOrUndefined(value)) {
|
|
77
82
|
this.set(key, value);
|
|
78
83
|
}
|
|
79
84
|
else {
|
package/node/createStorage.js
CHANGED
|
@@ -5,7 +5,7 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var decode_1 = require("./decode");
|
|
6
6
|
var encode_1 = require("./encode");
|
|
7
7
|
var isBrowser_1 = require("./isBrowser");
|
|
8
|
-
var
|
|
8
|
+
var isNullOrUndefined_1 = require("./isNullOrUndefined");
|
|
9
9
|
var isString_1 = require("./isString");
|
|
10
10
|
/**
|
|
11
11
|
* Utility to create a storage instance to interact with `localStorage` using
|
|
@@ -51,11 +51,16 @@ var createStorage = function (config) {
|
|
|
51
51
|
},
|
|
52
52
|
/**
|
|
53
53
|
* Get all storage values (it uses `localStorage.get()`).
|
|
54
|
+
*
|
|
55
|
+
* `undefined` and `null` values are not returned.
|
|
54
56
|
*/
|
|
55
57
|
getAll: function () {
|
|
56
58
|
var all = {};
|
|
57
59
|
for (var key in keys) {
|
|
58
|
-
|
|
60
|
+
var value = this.get(key);
|
|
61
|
+
if (!(0, isNullOrUndefined_1.isNullOrUndefined)(value)) {
|
|
62
|
+
all[key] = value;
|
|
63
|
+
}
|
|
59
64
|
}
|
|
60
65
|
return all;
|
|
61
66
|
},
|
|
@@ -76,7 +81,7 @@ var createStorage = function (config) {
|
|
|
76
81
|
setMany: function (newValues) {
|
|
77
82
|
for (var key in newValues) {
|
|
78
83
|
var value = newValues[key];
|
|
79
|
-
if (!(0,
|
|
84
|
+
if (!(0, isNullOrUndefined_1.isNullOrUndefined)(value)) {
|
|
80
85
|
this.set(key, value);
|
|
81
86
|
}
|
|
82
87
|
else {
|
package/package.json
CHANGED