@straylightagency/utils 1.1.0 → 1.1.1
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/package.json +1 -1
- package/src/index.js +1 -0
- package/src/misc/index.js +2 -1
- package/src/misc/replacer.js +10 -0
- package/src/object/serialize.js +3 -1
- package/src/object/unserialize.js +2 -2
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export { default as debounce } from "./misc/debounce.js";
|
|
|
17
17
|
export { default as nextTick } from "./misc/nextTick.js";
|
|
18
18
|
export { default as throttle } from "./misc/throttle.js";
|
|
19
19
|
export { default as functionReviver } from "./misc/reviver.js";
|
|
20
|
+
export { default as functionReplacer } from "./misc/replacer.js";
|
|
20
21
|
export { default as addEventListeners } from "./dom/addEventListeners.js";
|
|
21
22
|
export { default as closestElement } from "./dom/closestElement.js";
|
|
22
23
|
export { default as delegate } from "./dom/delegate.js";
|
package/src/misc/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { default as throttle } from "./throttle.js";
|
|
|
5
5
|
export { default as attempt } from "./attempt.js";
|
|
6
6
|
export { default as retry } from "./retry.js";
|
|
7
7
|
export { default as reviver } from "./reviver.js";
|
|
8
|
+
export { default as replacer } from "./replacer.js";
|
|
8
9
|
|
|
9
10
|
import {wait, seconds, milliseconds} from "./wait.js";
|
|
10
11
|
import {isClass, isObject, isPlainObject} from "./is.js";
|
|
@@ -19,5 +20,5 @@ export {
|
|
|
19
20
|
isPlainObject,
|
|
20
21
|
decodeBase64,
|
|
21
22
|
encodeBase64,
|
|
22
|
-
isBase64
|
|
23
|
+
isBase64,
|
|
23
24
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Function that can be used with JSON.stringify to replace {function} into string equivalent.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} key
|
|
5
|
+
* @param {*} value
|
|
6
|
+
* @returns {*|undefined}
|
|
7
|
+
*/
|
|
8
|
+
export default function replacer(key, value) {
|
|
9
|
+
return typeof value === 'function' ? value.toString : value;
|
|
10
|
+
}
|
package/src/object/serialize.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import replacer from "../misc/replacer.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Serialize an object into a string, transforms functions into string.
|
|
3
5
|
*
|
|
@@ -8,5 +10,5 @@
|
|
|
8
10
|
* @returns {String}
|
|
9
11
|
*/
|
|
10
12
|
export default function serialize(object) {
|
|
11
|
-
return JSON.stringify( object,
|
|
13
|
+
return JSON.stringify( object, replacer );
|
|
12
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import dateReviver from '../date/reviver.js'
|
|
2
|
+
import functionReviver from '../misc/reviver.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Serialize an object into a string, handling functions and Date objects.
|