state-in-url 2.2.1 → 2.2.2

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.
@@ -8,6 +8,8 @@ import { type JSONCompatible } from '../utils';
8
8
  * * Github {@link https://github.com/asmyshlyaev177/state-in-url/tree/main/packages/urlstate/encoder#encode}
9
9
  */
10
10
  export declare function encode(payload: unknown): string;
11
+ export declare const replacer: (_key: string, value: unknown) => unknown;
12
+ export type Primitive = Exclude<ReturnType<typeof decodePrimitive>, typeof errorSym>;
11
13
  /**
12
14
  * Decode value part of URLSearchParams back to JS value
13
15
  *
@@ -18,11 +20,9 @@ export declare function encode(payload: unknown): string;
18
20
  * * Github {@link https://github.com/asmyshlyaev177/state-in-url/tree/main/packages/urlstate/encoder#decode}
19
21
  */
20
22
  export declare function decode<T>(payload: string, fallback?: T): JSONCompatible | Primitive;
21
- export declare const replacer: (key: string, value: unknown) => unknown;
22
- export type Primitive = Exclude<ReturnType<typeof decodePrimitive>, typeof errorSym>;
23
23
  export declare const decodePrimitive: (str: string) => string | number | boolean | Date | typeof errorSym | null | undefined;
24
24
  export declare const errorSym: unique symbol;
25
- export declare const reviver: (key: string, value: unknown) => unknown;
25
+ export declare const reviver: (_key: string, value: unknown) => unknown;
26
26
  /**
27
27
  * Parses a JSON string into a TypeScript object.
28
28
  *
@@ -1 +1 @@
1
- import{SYMBOLS as e}from"../constants/constants.mjs";import{typeOf as t}from"../utils.mjs";function r(r){switch(t(r)){case"function":case"symbol":return"";case"date":return e.date+r.toISOString();case"string":return`${e.string}${encodeURIComponent(r)}`;case"number":return e.number+String(r);case"boolean":return e.boolean+String(r);case"object":case"array":return JSON.stringify(r,s).replaceAll('"',"'");case"null":return e.null;case"undefined":return e.undefined;default:return String(r)}}function n(e,t){return c(e.replaceAll("'",'"'),t)}const s=(e,n)=>{const s=t(n);return e&&"object"!==s&&"array"!==s?r(n):n},a=t=>t===e.null?null:t!==e.undefined?t?.startsWith?.(e.number)?Number.parseFloat(t.replace(e.number,"")):t?.startsWith?.(e.boolean)?!!t.includes("true"):t?.startsWith?.(e.date)?new Date(t.slice(1)):t?.startsWith?.(e.string)?decodeURIComponent(t).replace(/^◖/,""):o:void 0,o=Symbol("isError"),u=(e,t)=>{const r="string"==typeof t,n=r&&a(t);return n===o?t:e&&r?n:t};function c(e,t){try{return JSON.parse(e,u)}catch{const r=a(e);return r!==o?r:t}}export{n as decode,a as decodePrimitive,r as encode,o as errorSym,c as parseJSON,s as replacer,u as reviver};
1
+ import{SYMBOLS as e}from"../constants/constants.mjs";import{typeOf as t}from"../utils.mjs";function n(n){if(l(n))return String(n);switch(t(n)){case"function":case"symbol":return"";case"date":return s(n);case"string":return`${e.string}${encodeURIComponent(n)}`;case"number":return e.number+String(n);case"boolean":return e.boolean+String(n);case"object":case"array":return JSON.stringify(n,r).replaceAll('"',"'");case"null":return e.null;case"undefined":return e.undefined;default:return String(n)}}const r=(e,r)=>{const o=t(r);let a=structuredClone(r);return"object"!==o&&"array"!==o||Object.keys(a).forEach((e=>{const n=a[e];"date"===t(n)&&(a[e]=s(n))})),"object"!==o&&"array"!==o?n(a):a};function s(t){return e.date+new Date(t).toISOString()}function o(e,t){return i(e.replaceAll("'",'"'),t)}const a=t=>t===e.null?null:t!==e.undefined?t?.startsWith?.(e.number)?Number.parseFloat(t.replace(e.number,"")):t?.startsWith?.(e.boolean)?!!t.includes("true"):t?.startsWith?.(e.date)?new Date(t.slice(1)):t?.startsWith?.(e.string)?decodeURIComponent(t).replace(/^◖/,""):u:void 0,u=Symbol("isError"),c=(e,t)=>{const n="string"==typeof t,r=n&&a(t);return r===u?t:n?r:t};function i(e,t){try{return JSON.parse(e,c)}catch{const n=a(e);return n!==u?n:t}}const l=t=>new RegExp(`^(${e.string}|${e.boolean}|${e.null}|${e.undefined}|${e.number}|${e.date})`).test(String(t));export{o as decode,a as decodePrimitive,n as encode,u as errorSym,i as parseJSON,r as replacer,c as reviver};
package/dist/utils.mjs CHANGED
@@ -1 +1 @@
1
- const t=t=>{const e=null===t,n=Array.isArray(t),r=t instanceof Date;return(e?"null":r&&"date")||n&&"array"||!e&&!r&&!n&&"object"==typeof t&&"object"||typeof t},e=()=>"undefined"==typeof window,n=t=>new URLSearchParams("string"==typeof t?r(t):t?.toString?.()||""),r=t=>t.split("?")?.[1]||t||"",o=(t,e)=>JSON.stringify(t)===JSON.stringify(e);export{n as getParams,o as isEqual,e as isSSR,t as typeOf};
1
+ const t=t=>{const n=typeof t,r=null===t,e=Array.isArray(t),i=t instanceof Date;return(r?"null":i&&"date")||e&&"array"||!r&&!i&&!e&&"object"===n&&"object"||n},n=()=>"undefined"==typeof window,r=t=>new URLSearchParams("string"==typeof t?e(t):t?.toString?.()||""),e=t=>t.split("?")?.[1]||t||"",i=(t,n)=>JSON.stringify(t)===JSON.stringify(n);export{r as getParams,i as isEqual,n as isSSR,t as typeOf};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-in-url",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Library to store state in browser URL, includes hook for NextJS, hook for pure React, and low level helpers.",
5
5
  "homepage": "https://github.com/asmyshlyaev177/state-in-url#readme",
6
6
  "keywords": [
@@ -197,7 +197,7 @@
197
197
  "last 5 Firefox versions",
198
198
  "last 5 FirefoxAndroid versions",
199
199
  "Firefox ESR",
200
- "last 3 Safari major versions",
200
+ "last 2 Safari major versions",
201
201
  "last 2 iOS major versions"
202
202
  ],
203
203
  "lint-staged": {
@@ -258,7 +258,6 @@
258
258
  "ts-jest": "^29.1.5",
259
259
  "ts-node": "^10.9.2",
260
260
  "typescript": "^5.3.3",
261
- "wait-on": "^7.2.0",
262
261
  "wireit": "^0.14.4"
263
262
  }
264
263
  }