state-in-url 6.0.4 → 6.0.5
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/README.md +1 -1
- package/dist/encodeState/encodeState.js +1 -1
- package/dist/encodeState/encodeState.mjs +1 -1
- package/dist/encoder/encoder.js +1 -1
- package/dist/encoder/encoder.mjs +1 -1
- package/dist/subscribers.js +1 -1
- package/dist/subscribers.mjs +1 -1
- package/dist/useUrlEncode/useUrlEncode.js +1 -1
- package/dist/useUrlEncode/useUrlEncode.mjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.mjs +1 -1
- package/package.json +34 -34
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ This library is a good alternative for NUQS.
|
|
|
75
75
|
### Use cases
|
|
76
76
|
|
|
77
77
|
- Store unsaved user forms or page filters in URL
|
|
78
|
-
-
|
|
78
|
+
- Sync URL with React state
|
|
79
79
|
- Just sync data between unrelated client components without touching URI
|
|
80
80
|
- Shareable URLs with application state (Deep linking, URL state synchronization)
|
|
81
81
|
- Easy state persistence across page reloads
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var a=require("../encoder/encoder.js");var d=require("../utils.js");function
|
|
1
|
+
"use strict";var a=require("../encoder/encoder.js");var d=require("../utils.js");function u(n,c,s){const r=d.getParams(s);const e=Object.keys(n||{});for(let o=0;o<e.length;o++){const t=e[o];const i=n[t];const f=c?.[t];if(JSON.stringify(i)!==JSON.stringify(f)){r.set(t,a.encode(i))}}return r.toString()}function g(n,c){const s=Object.assign({},c||{});const r=d.getParams(n);for(const[e,o]of r){const t=c?.[e];s[e]=a.decode(o,t)??t}return s}exports.decodeState=g;exports.encodeState=u;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{decode as
|
|
1
|
+
import{decode as g,encode as a}from"../encoder/encoder.mjs";import{getParams as f}from"../utils.mjs";function m(n,c,s){const r=f(s);const o=Object.keys(n||{});for(let e=0;e<o.length;e++){const t=o[e];const i=n[t];const d=c?.[t];if(JSON.stringify(i)!==JSON.stringify(d)){r.set(t,a(i))}}return r.toString()}function S(n,c){const s=Object.assign({},c||{});const r=f(n);for(const[o,e]of r){const t=c?.[o];s[o]=g(e,t)??t}return s}export{S as decodeState,m as encodeState};
|
package/dist/encoder/encoder.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=require("../constants/constants.js");var u=require("../utils.js");const
|
|
1
|
+
"use strict";var n=require("../constants/constants.js");var u=require("../utils.js");const O=/['"]/g;const p={"'":"%27",'"':"'"};const v=/'|%27/g;const y={"'":'"',"%27":"'"};const g=new RegExp(`^(${n.SYMBOLS.undefined}|${n.SYMBOLS.date})`);function m(e){if(typeof e==="function"||typeof e==="symbol")return"";if(B(e)){return e}return JSON.stringify(e,c).replace(O,r=>p[r])}function c(e,r){const t=u.typeOf(r);if(t!=="object"&&t!=="array"){return d(r)}if(t==="object"){const i=r;const o={};for(const s of Object.keys(i)){o[s]=c(e,i[s])}return o}if(t==="array"){return r.map(i=>c(e,i))}return r}const d=e=>{switch(u.typeOf(e)){case"date":return n.SYMBOLS.date+new Date(e).toISOString();case"undefined":return n.SYMBOLS.undefined;default:return e}};function l(e,r){return f(e.replace(v,t=>y[t]),r)}function f(e,r){try{return JSON.parse(e,a)}catch{return r}}function a(e,r){return typeof r==="string"?S(r):r}const S=e=>{if(e===n.SYMBOLS.undefined)return void 0;if(e?.startsWith?.(n.SYMBOLS.date))return new Date(e.slice(1));return e};const B=e=>g.test(String(e));exports.decode=l;exports.decodePrimitive=S;exports.encode=m;exports.encodePrimitive=d;exports.parseJSON=f;exports.reviver=a;
|
package/dist/encoder/encoder.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SYMBOLS as n}from"../constants/constants.mjs";import{typeOf as u}from"../utils.mjs";const
|
|
1
|
+
import{SYMBOLS as n}from"../constants/constants.mjs";import{typeOf as u}from"../utils.mjs";const y=/['"]/g;const m={"'":"%27",'"':"'"};const O=/'|%27/g;const S={"'":'"',"%27":"'"};const g=new RegExp(`^(${n.undefined}|${n.date})`);function l(t){if(typeof t==="function"||typeof t==="symbol")return"";if(b(t)){return t}return JSON.stringify(t,i).replace(y,r=>m[r])}function i(t,r){const e=u(r);if(e!=="object"&&e!=="array"){return s(r)}if(e==="object"){const o=r;const c={};for(const f of Object.keys(o)){c[f]=i(t,o[f])}return c}if(e==="array"){return r.map(o=>i(t,o))}return r}const s=t=>{switch(u(t)){case"date":return n.date+new Date(t).toISOString();case"undefined":return n.undefined;default:return t}};function v(t,r){return d(t.replace(O,e=>S[e]),r)}function d(t,r){try{return JSON.parse(t,a)}catch{return r}}function a(t,r){return typeof r==="string"?p(r):r}const p=t=>{if(t===n.undefined)return void 0;if(t?.startsWith?.(n.date))return new Date(t.slice(1));return t};const b=t=>g.test(String(t));export{v as decode,p as decodePrimitive,l as encode,s as encodePrimitive,d as parseJSON,a as reviver};
|
package/dist/subscribers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const c=new WeakMap;const n=new WeakMap;const o={get(t){return n.get(t)||[]},add(t,e){const s=this.get(t);n.set(t,[...s,e]);return()=>this.remove(t,e)},remove(t,e){const s=this.get(t);if(!s)return;const r=s.filter(i=>i!==e);if(r.length){n.set(t,r)}else{n.delete(t)}}};const a={get:function(t){return c.get(t)},set:function(t,e){c.set(t,e)}};exports.stateMap=a;exports.subscribers=o;
|
package/dist/subscribers.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o=new WeakMap;const n=new WeakMap;const
|
|
1
|
+
const o=new WeakMap;const n=new WeakMap;const i={get(t){return n.get(t)||[]},add(t,e){const s=this.get(t);n.set(t,[...s,e]);return()=>this.remove(t,e)},remove(t,e){const s=this.get(t);if(!s)return;const r=s.filter(c=>c!==e);if(r.length){n.set(t,r)}else{n.delete(t)}}};const a={get:function(t){return o.get(t)},set:function(t,e){o.set(t,e)}};export{a as stateMap,i as subscribers};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var c=require("react");var
|
|
1
|
+
"use strict";var c=require("react");var u=require("../encodeState/encodeState.js");function l(e){return e&&e.__esModule?e:{default:e}}var a=l(c);function d(e){const n=a.default.useCallback((t,s)=>{return u.encodeState(t,e,s)},[e]);const r=a.default.useCallback(t=>u.decodeState(t,e),[e]);return{parse:r,stringify:n}}exports.useUrlEncode=d;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import o from"react";import{encodeState as s,decodeState as a}from"../encodeState/encodeState.mjs";function u(e){const n=o.useCallback((t,c)=>{return s(t,e,c)},[e]);const r=o.useCallback(t=>a(t,e),[e]);return{parse:r,stringify:n}}export{u as useUrlEncode};
|
package/dist/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const i=n=>{if(n===null)return"null";const t=typeof n;if(t!=="object")return t;if(Array.isArray(n))return"array";if(n instanceof Date)return"date";return"object"};const u=n=>{const t=i(n);return t!=="object"&&t!=="array"};const a=typeof window==="undefined";const l=n=>{if(n instanceof URLSearchParams){return n}if(typeof n==="string"){const t=n.indexOf("?");return new URLSearchParams(t===-1?n:n.slice(t+1))}return new URLSearchParams};const y=(n,t)=>{if(n.length!==t.length)return false;return n.every((r,s)=>c(r,t[s]))};const w=(n,t)=>{const r=Object.keys(n);const s=Object.keys(t);if(r.length!==s.length)return false;return r.every(e=>c(n[e],t[e]))};const c=(n,t)=>{if(n===t)return true;if(n==null||t==null)return false;const r=i(n);const s=i(t);if(r!==s)return false;if(u(n))return false;if(r==="array"){return y(n,t)}if(r==="object"){return w(n,t)}return JSON.stringify(n)===JSON.stringify(t)};function p(n,t){const r=new URLSearchParams;const s=f(n,[...new URLSearchParams(t||"").entries()]);for(const[e,o]of s){r.set(e,o)}return r.toString()}function g(n,t){return Object.fromEntries(f(n,Object.entries(t||{})))}function f(n,t){const r=Object.keys(n);const s=[];for(let e=0;e<t.length;e++){if(r.includes(t[e]?.[0])){s.push([t[e][0].replace(/\+/g," "),t[e][1]])}}return s}function h(n,t){const r=Object.assign({},n);for(const[s]of Object.entries(n)){const e=s;const o=t[e]!==void 0;r[e]=o?t[e]:n[e]}return r}const S={push:n=>{if(typeof window!=="undefined"){window.history.pushState(null,"",n)}},replace:n=>{if(typeof window!=="undefined"){window.history.replaceState(null,"",n)}}};const d=/apple/i.test(!a&&navigator?.userAgent||"");const m="popstate";function P(){return a?"":window.location.search}exports.assignValue=h;exports.filterUnknown=f;exports.filterUnknownParams=g;exports.filterUnknownParamsClient=p;exports.getParams=l;exports.getSearch=P;exports.isEqual=c;exports.isPrimitive=u;exports.isSSR=a;exports.isSafari=d;exports.popstateEv=m;exports.routerHistory=S;exports.typeOf=i;
|
package/dist/utils.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const o=n=>{if(n===null)return"null";const t=typeof n;if(t!=="object")return t;if(Array.isArray(n))return"array";if(n instanceof Date)return"date";return"object"};const u=n=>{const t=o(n);return t!=="object"&&t!=="array"};const a=typeof window==="undefined";const l=n=>{if(n instanceof URLSearchParams){return n}if(typeof n==="string"){const t=n.indexOf("?");return new URLSearchParams(t===-1?n:n.slice(t+1))}return new URLSearchParams};const y=(n,t)=>{if(n.length!==t.length)return false;return n.every((r,s)=>c(r,t[s]))};const p=(n,t)=>{const r=Object.keys(n);const s=Object.keys(t);if(r.length!==s.length)return false;return r.every(e=>c(n[e],t[e]))};const c=(n,t)=>{if(n===t)return true;if(n==null||t==null)return false;const r=o(n);const s=o(t);if(r!==s)return false;if(u(n))return false;if(r==="array"){return y(n,t)}if(r==="object"){return p(n,t)}return JSON.stringify(n)===JSON.stringify(t)};function w(n,t){const r=new URLSearchParams;const s=f(n,[...new URLSearchParams(t||"").entries()]);for(const[e,i]of s){r.set(e,i)}return r.toString()}function h(n,t){return Object.fromEntries(f(n,Object.entries(t||{})))}function f(n,t){const r=Object.keys(n);const s=[];for(let e=0;e<t.length;e++){if(r.includes(t[e]?.[0])){s.push([t[e][0].replace(/\+/g," "),t[e][1]])}}return s}function d(n,t){const r=Object.assign({},n);for(const[s]of Object.entries(n)){const e=s;const i=t[e]!==void 0;r[e]=i?t[e]:n[e]}return r}const g={push:n=>{if(typeof window!=="undefined"){window.history.pushState(null,"",n)}},replace:n=>{if(typeof window!=="undefined"){window.history.replaceState(null,"",n)}}};const S=/apple/i.test(!a&&navigator?.userAgent||"");const b="popstate";function j(){return a?"":window.location.search}export{d as assignValue,f as filterUnknown,h as filterUnknownParams,w as filterUnknownParamsClient,l as getParams,j as getSearch,c as isEqual,u as isPrimitive,a as isSSR,S as isSafari,b as popstateEv,g as routerHistory,o as typeOf};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-in-url",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.5",
|
|
4
4
|
"description": "Store state in URL as in object, types and structure are preserved, with TS validation. Same API as React.useState, wthout any hasssle or boilerplate. Next.js@14-15, react-router@6-7, and remix@2.",
|
|
5
5
|
"homepage": "https://state-in-url.dev",
|
|
6
6
|
"repository": {
|
|
@@ -403,34 +403,34 @@
|
|
|
403
403
|
}
|
|
404
404
|
},
|
|
405
405
|
"devDependencies": {
|
|
406
|
-
"@babel/core": "^7.
|
|
407
|
-
"@babel/node": "^7.
|
|
408
|
-
"@babel/preset-env": "^7.
|
|
409
|
-
"@babel/preset-typescript": "^7.
|
|
410
|
-
"@commitlint/cli": "^19.
|
|
411
|
-
"@commitlint/config-conventional": "^19.
|
|
412
|
-
"@playwright/test": "^1.
|
|
413
|
-
"@rollup/plugin-node-resolve": "^15.3.
|
|
414
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
406
|
+
"@babel/core": "^7.28.4",
|
|
407
|
+
"@babel/node": "^7.28.0",
|
|
408
|
+
"@babel/preset-env": "^7.28.3",
|
|
409
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
410
|
+
"@commitlint/cli": "^19.8.1",
|
|
411
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
412
|
+
"@playwright/test": "^1.55.1",
|
|
413
|
+
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
414
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
415
415
|
"@semantic-release/changelog": "^6.0.3",
|
|
416
|
-
"@semantic-release/commit-analyzer": "^13.0.
|
|
416
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
417
417
|
"@semantic-release/git": "^10.0.1",
|
|
418
|
-
"@semantic-release/npm": "^12.0.
|
|
419
|
-
"@semantic-release/release-notes-generator": "^14.0
|
|
420
|
-
"@testing-library/dom": "^10.4.
|
|
421
|
-
"@testing-library/jest-dom": "^6.
|
|
422
|
-
"@testing-library/react": "^16.
|
|
418
|
+
"@semantic-release/npm": "^12.0.2",
|
|
419
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
420
|
+
"@testing-library/dom": "^10.4.1",
|
|
421
|
+
"@testing-library/jest-dom": "^6.9.0",
|
|
422
|
+
"@testing-library/react": "^16.3.0",
|
|
423
423
|
"@testing-library/react-hooks": "^8.0.1",
|
|
424
424
|
"@types/glob": "^8.1.0",
|
|
425
|
-
"@types/node": "^20.
|
|
426
|
-
"@types/react": "^18.3.
|
|
427
|
-
"@types/react-dom": "^18.3.
|
|
428
|
-
"@vitest/coverage-istanbul": "^2.1.
|
|
425
|
+
"@types/node": "^20.19.18",
|
|
426
|
+
"@types/react": "^18.3.25",
|
|
427
|
+
"@types/react-dom": "^18.3.7",
|
|
428
|
+
"@vitest/coverage-istanbul": "^2.1.9",
|
|
429
429
|
"auto-changelog": "^2.4.0",
|
|
430
430
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
431
431
|
"chokidar": "^4.0.3",
|
|
432
432
|
"commitizen": "^4.3.0",
|
|
433
|
-
"commitlint": "^19.8.
|
|
433
|
+
"commitlint": "^19.8.1",
|
|
434
434
|
"conventional-recommended-bump": "^10.0.0",
|
|
435
435
|
"cross-env": "^7.0.3",
|
|
436
436
|
"cz": "^1.8.2",
|
|
@@ -441,28 +441,28 @@
|
|
|
441
441
|
"eslint-plugin-prettier": "^5.2.1",
|
|
442
442
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
443
443
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
444
|
-
"happy-dom": "^15.11.
|
|
445
|
-
"husky": "^9.
|
|
446
|
-
"lint-staged": "^15.2
|
|
444
|
+
"happy-dom": "^15.11.7",
|
|
445
|
+
"husky": "^9.1.7",
|
|
446
|
+
"lint-staged": "^15.5.2",
|
|
447
447
|
"nyc": "^17.1.0",
|
|
448
448
|
"only-allow": "^1.2.1",
|
|
449
449
|
"pin-github-action": "^1.9.1",
|
|
450
|
-
"playwright": "^1.
|
|
451
|
-
"prettier": "^3.2
|
|
452
|
-
"prettier-plugin-tailwindcss": "^0.6.
|
|
453
|
-
"release-it": "^17.
|
|
454
|
-
"rollup": "^4.
|
|
450
|
+
"playwright": "^1.55.1",
|
|
451
|
+
"prettier": "^3.6.2",
|
|
452
|
+
"prettier-plugin-tailwindcss": "^0.6.14",
|
|
453
|
+
"release-it": "^17.11.0",
|
|
454
|
+
"rollup": "^4.52.3",
|
|
455
455
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
456
456
|
"rollup-plugin-filesize": "^10.0.0",
|
|
457
457
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
458
458
|
"semantic-release": "^24.1.0",
|
|
459
459
|
"standard-version": "^9.5.0",
|
|
460
460
|
"ts-node": "^10.9.2",
|
|
461
|
-
"typescript": "^5.
|
|
462
|
-
"unplugin-auto-import": "^0.18.
|
|
463
|
-
"vitest": "^2.1.
|
|
464
|
-
"wait-on": "^8.0.
|
|
465
|
-
"wireit": "^0.14.
|
|
461
|
+
"typescript": "^5.9.2",
|
|
462
|
+
"unplugin-auto-import": "^0.18.6",
|
|
463
|
+
"vitest": "^2.1.9",
|
|
464
|
+
"wait-on": "^8.0.5",
|
|
465
|
+
"wireit": "^0.14.12"
|
|
466
466
|
},
|
|
467
467
|
"keywords": [
|
|
468
468
|
"state in url",
|