json-storage-formatter 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/lib/bundle.js +1 -1
- package/lib/json-storage-formatter.d.ts +9 -9
- package/package.json +3 -1
package/lib/bundle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["json-storage-formatter"]=t():r["json-storage-formatter"]=t()}(this,(()=>(()=>{"use strict";var r={
|
|
1
|
+
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["json-storage-formatter"]=t():r["json-storage-formatter"]=t()}(this,(()=>(()=>{"use strict";var r={124:(r,t,e)=>{var n=Object.create?function(r,t,e,n){void 0===n&&(n=e);var o=Object.getOwnPropertyDescriptor(t,e);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(r,n,o)}:function(r,t,e,n){void 0===n&&(n=e),r[n]=t[e]};Object.defineProperty(t,"__esModule",{value:!0}),function(r,t){for(var e in r)"default"===e||Object.prototype.hasOwnProperty.call(t,e)||n(t,r,e)}(e(331),t)},331:(r,t)=>{function e(r){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},e(r)}function n(r,t,n){return(t=function(r){var t=function(r){if("object"!=e(r)||!r)return r;var t=r[Symbol.toPrimitive];if(void 0!==t){var n=t.call(r,"string");if("object"!=e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(r)}(r);return"symbol"==e(t)?t:t+""}(t))in r?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n,r}function o(r,t){if(r){if("string"==typeof r)return i(r,t);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?i(r,t):void 0}}function i(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}Object.defineProperty(t,"__esModule",{value:!0}),t.formatToStore=t.formatFromStore=t.isPrimitive=t.isFunction=t.isRegex=t.isDate=t.isString=t.isBoolean=t.isNumber=t.isNil=t.clone=void 0,t.clone=function(r){var e,u=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).shallow;if((0,t.isPrimitive)(r)||(0,t.isDate)(r))return r;if(Array.isArray(r))return u?function(r){if(Array.isArray(r))return i(r)}(e=r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(e)||o(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}():r.map((function(r){return(0,t.clone)(r)}));if(r instanceof Map){var a=Array.from(r.entries());return u?new Map(a):new Map(a.map((function(r){return(0,t.clone)(r)})))}if(r instanceof Set){var f=Array.from(r.values());return u?new Set(f):new Set(f.map((function(r){return(0,t.clone)(r)})))}return r instanceof RegExp?new RegExp(r.toString()):(0,t.isFunction)(r)?u?r:Object.create(r):u?Object.assign({},r):r instanceof Error?new Error(r.message):Object.keys(r).reduce((function(e,o){var i=r[o];return Object.assign(Object.assign({},e),n({},o,(0,t.clone)(i)))}),{})},t.isNil=function(r){return null==r},t.isNumber=function(r){return"number"==typeof r},t.isBoolean=function(r){return"boolean"==typeof r},t.isString=function(r){return"string"==typeof r},t.isDate=function(r){return r instanceof Date},t.isRegex=function(r){return r instanceof RegExp},t.isFunction=function(r){return"function"==typeof r||r instanceof Function},t.isPrimitive=function(r){return(0,t.isNil)(r)||(0,t.isNumber)(r)||(0,t.isBoolean)(r)||(0,t.isString)(r)||"symbol"===e(r)},t.formatFromStore=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=e.jsonParse,u=e.sortKeys;return function(r){var e,i,a;if((0,t.isPrimitive)(r))return r;if("date"===(null==r?void 0:r.$t))return new Date(r.$v);if("map"===(null==r?void 0:r.$t)){var f=(null!==(e=r.$v)&&void 0!==e?e:[]).map((function(r){var e,n,i=(n=2,function(r){if(Array.isArray(r))return r}(e=r)||function(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,o,i,u,a=[],f=!0,c=!1;try{if(i=(e=e.call(r)).next,0===t){if(Object(e)!==e)return;f=!1}else for(;!(f=(n=i.call(e)).done)&&(a.push(n.value),a.length!==t);f=!0);}catch(r){c=!0,o=r}finally{try{if(!f&&null!=e.return&&(u=e.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(e,n)||o(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),u=i[0],a=i[1];return[u,(0,t.formatFromStore)(a)]}));return new Map(f)}if("set"===(null==r?void 0:r.$t)){var c=null!==(i=r.$v)&&void 0!==i?i:[].map((function(r){return(0,t.formatFromStore)(r)}));return new Set(c)}return"regex"===(null==r?void 0:r.$t)?new RegExp(r.$v):"error"===(null==r?void 0:r.$t)?new Error(r.$v):Array.isArray(r)?r.map((function(r){return(0,t.formatFromStore)(r)})):"function"===(null==r?void 0:r.$t)?Function("(".concat(r.$v,")(...arguments)")):(a=Object.keys(r),u?(0,t.isFunction)(u)?a.sort(u):a.sort((function(r,t){return(null!=r?r:"").localeCompare(t)})):a).reduce((function(e,o){var i=r[o];return Object.assign(Object.assign({},e),n({},o,(0,t.formatFromStore)(i)))}),{})}(i?JSON.parse(r):(0,t.clone)(r))},t.formatToStore=function(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stringify:!1},i=o.stringify,u=o.validator,a=o.excludeTypes,f=o.excludeKeys,c=o.sortKeys,s=new Set(null!=a?a:[]),l=new Set(null!=f?f:[]),m=s.size||l.size,v=null!=u?u:function(r){var t=r.key,n=r.value;if(!m)return!0;var o=l.has(t),i=s.has(e(n));return!o&&!i},y=function(r){if((0,t.isPrimitive)(r))return r;var e;if(Array.isArray(r))return r.map((function(r){return y(r)}));if(r instanceof Map)return{$t:"map",$v:Array.from(r.entries()).map((function(r){return y(r)}))};if(r instanceof Set)return{$t:"set",$v:Array.from(r.values()).map((function(r){return y(r)}))};if((0,t.isDate)(r))return{$t:"date",$v:r.toISOString()};if((0,t.isRegex)(r))return{$t:"regex",$v:r.toString()};if((0,t.isFunction)(r)){var o;try{o={$t:"function",$v:r.toString()}}catch(r){o={$t:"error",$v:"Error: Could not serialize function"}}return o}return r instanceof Error?{$t:"error",$v:r.message}:(e=Object.keys(r),c?(0,t.isFunction)(c)?e.sort(c):e.sort((function(r,t){return(null!=r?r:"").localeCompare(t)})):e).reduce((function(t,e){var o=r[e],i=y(o);return v({obj:r,key:e,value:i})?Object.assign(Object.assign({},t),n({},e,y(o))):t}),{})},p=y((0,t.clone)(r));return i?JSON.stringify(p):p}}},t={};return function e(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return r[n](i,i.exports,e),i.exports}(124)})()));
|
|
@@ -21,7 +21,7 @@ export declare const clone: <T>(value: T, { shallow, }?: {
|
|
|
21
21
|
* true if the value is null or undefined
|
|
22
22
|
* false otherwise
|
|
23
23
|
* */
|
|
24
|
-
export declare const isNil: (value: unknown) =>
|
|
24
|
+
export declare const isNil: (value: unknown) => value is null;
|
|
25
25
|
/**
|
|
26
26
|
* Check if a value is a number
|
|
27
27
|
* @param value
|
|
@@ -29,7 +29,7 @@ export declare const isNil: (value: unknown) => boolean;
|
|
|
29
29
|
* true if the value is a number
|
|
30
30
|
* false otherwise
|
|
31
31
|
* */
|
|
32
|
-
export declare const isNumber: (value: unknown) =>
|
|
32
|
+
export declare const isNumber: (value: unknown) => value is number;
|
|
33
33
|
/**
|
|
34
34
|
* Check if a value is a boolean
|
|
35
35
|
* @param value
|
|
@@ -37,7 +37,7 @@ export declare const isNumber: (value: unknown) => boolean;
|
|
|
37
37
|
* true if the value is a boolean
|
|
38
38
|
* false otherwise
|
|
39
39
|
* */
|
|
40
|
-
export declare const isBoolean: (value: unknown) => boolean;
|
|
40
|
+
export declare const isBoolean: (value: unknown) => value is boolean;
|
|
41
41
|
/**
|
|
42
42
|
* Check if a value is a string
|
|
43
43
|
* @param value
|
|
@@ -45,26 +45,26 @@ export declare const isBoolean: (value: unknown) => boolean;
|
|
|
45
45
|
* true if the value is a string
|
|
46
46
|
* false otherwise
|
|
47
47
|
* */
|
|
48
|
-
export declare const isString: (value: unknown) =>
|
|
48
|
+
export declare const isString: (value: unknown) => value is string;
|
|
49
49
|
/** Check if a value is a Date
|
|
50
50
|
* @param value
|
|
51
51
|
* @returns
|
|
52
52
|
* true if the value is a Date
|
|
53
53
|
* false otherwise
|
|
54
54
|
*/
|
|
55
|
-
export declare const isDate: (value: unknown) =>
|
|
55
|
+
export declare const isDate: (value: unknown) => value is Date;
|
|
56
56
|
/**
|
|
57
57
|
* Check if a value is a RegExp
|
|
58
58
|
* @param value The value to check
|
|
59
59
|
* @returns true if the value is a RegExp, false otherwise
|
|
60
60
|
* */
|
|
61
|
-
export declare const isRegex: (value: unknown) =>
|
|
61
|
+
export declare const isRegex: (value: unknown) => value is RegExp;
|
|
62
62
|
/**
|
|
63
63
|
* Check if a value is a function
|
|
64
64
|
* @param value The value to check
|
|
65
65
|
* @returns true if the value is a function, false otherwise
|
|
66
66
|
* */
|
|
67
|
-
export declare const isFunction: (value: unknown) =>
|
|
67
|
+
export declare const isFunction: <T extends (...args: Parameters<T>) => ReturnType<T>>(value: unknown) => value is NonNullable<T>;
|
|
68
68
|
/**
|
|
69
69
|
* Check if a value is a primitive
|
|
70
70
|
* @param value
|
|
@@ -73,7 +73,7 @@ export declare const isFunction: (value: unknown) => boolean;
|
|
|
73
73
|
* false otherwise
|
|
74
74
|
* null, number, boolean, string, symbol
|
|
75
75
|
*/
|
|
76
|
-
export declare const isPrimitive: (value: unknown) => boolean;
|
|
76
|
+
export declare const isPrimitive: (value: unknown) => value is string | number | boolean | symbol;
|
|
77
77
|
/**
|
|
78
78
|
* Format an value with possible metadata to his original form, it also supports Map, Set, Arrays
|
|
79
79
|
* @param value
|
|
@@ -106,6 +106,6 @@ export declare const formatToStore: <TValue, TStringify extends boolean = false>
|
|
|
106
106
|
validator?: ({ obj, key, value, }: {
|
|
107
107
|
obj: unknown;
|
|
108
108
|
key: string;
|
|
109
|
-
value:
|
|
109
|
+
value: unknown;
|
|
110
110
|
}) => boolean | undefined;
|
|
111
111
|
}) => TStringify extends true ? string : unknown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-storage-formatter",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Package for json stringify objects without losing data types",
|
|
5
5
|
"main": "lib/bundle.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
"homepage": "https://github.com/johnny-quesada-developer/json-storage-formatter#readme",
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@babel/core": "^7.21.3",
|
|
39
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
40
|
+
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
|
|
39
41
|
"@babel/plugin-transform-modules-commonjs": "^7.21.2",
|
|
40
42
|
"@babel/preset-env": "^7.20.2",
|
|
41
43
|
"@babel/preset-typescript": "^7.21.0",
|