UNPKG

state-in-url

Version:

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 and react-router@6-7.

2 lines (1 loc) 284 B
import{decode as c}from"./encoder/encoder.mjs";function o(n,t){return{...t,...s(JSON.stringify(n),t)}}function s(n,t){try{return JSON.parse(n,i)}catch{return t}}const i=(n,t)=>{const r=typeof t==="string";const e=r&&c(t?.replace?.(/'/g,'"'));return n&&r?e:t};export{o as parseSPObj};