@superutils/store 0.1.15 → 0.1.18

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 CHANGED
@@ -6,7 +6,7 @@ Built on RxJS for reactive data handling, it is optimized for small to medium da
6
6
 
7
7
  <div v-if="false">
8
8
 
9
- For full API reference check out the [docs page](https://alien45.github.io/superutils/packages/@superutils/store/).
9
+ For full API reference and example code playground check out the [docs page](https://alien45.github.io/superutils/packages/@superutils/store/).
10
10
 
11
11
  </div>
12
12
 
@@ -18,6 +18,7 @@ For full API reference check out the [docs page](https://alien45.github.io/super
18
18
  - [Object-based Store](#object-based-store)
19
19
  - [Persistent Storage (NodeJS)](#persistent-storage-nodejs)
20
20
  - [Advanced Usage](#advanced-usage)
21
+ - [Data Validation](#data-validation)
21
22
  - [Reactive Updates (RxJS & Callbacks)](#reactive-updates-rxjs--callbacks)
22
23
  - [Search and Filtering](#search-and-filtering)
23
24
  - [Attaching Context (Business Logic)](#attaching-context-business-logic)
@@ -57,10 +58,10 @@ OR,
57
58
  The `Store` class can be used just like a standard JavaScript `Map`, but with the added benefit of optional persistence and reactivity.
58
59
 
59
60
  ```javascript
60
- import { createStore, Store } from '@superutils/store'
61
+ import { createStore } from '@superutils/store'
61
62
 
62
- // Initialize a store (in-memory only if no name is provided)
63
- const userStorage = createStore('users') // or `new Store('users')`
63
+ // Initialize a store
64
+ const userStorage = createStore('users') // or `createStore()` for in-memory store
64
65
 
65
66
  // Set and get values
66
67
  userStorage.set('alice', { name: 'Alice', age: 30 })
@@ -117,6 +118,42 @@ createStore('settings.json', { storage: new LocalStorage('./data', 1e7) })
117
118
 
118
119
  ## Advanced Usage
119
120
 
121
+ ### Data Validation
122
+
123
+ To ensure data integrity, you can provide a `validate` object containing hooks for various operations (`set`, `setAll`, `delete`, `clear`, `write`). These hooks are executed immediately before the store's internal state is updated. If a validator throws an error, the operation is aborted.
124
+
125
+ ```javascript
126
+ import { createObjectStore } from '@superutils/store'
127
+
128
+ const settingsStore = createObjectStore('app-settings', {
129
+ initialValue: {
130
+ theme: 'light',
131
+ version: '1.0.0',
132
+ },
133
+ validate: {
134
+ set: ([key, value]) => {
135
+ if (key !== 'theme' || ['light', 'dark', 'system'].includes(value)) return
136
+
137
+ // throw error to abort operation
138
+ throw new Error(`Invalid theme: ${value}`)
139
+ },
140
+ delete: ([keys]) => {
141
+ if (!keys.includes('version')) return
142
+
143
+ throw new Error('The "version" key is protected and cannot be deleted')
144
+ },
145
+ },
146
+ })
147
+
148
+ settingsStore.set('theme', 'system')
149
+ console.log(settingsStore.get('theme')) // 'system
150
+ try {
151
+ settingsStore.set('theme', 'invalid') // throws error
152
+ } catch (err) {
153
+ console.log(err)
154
+ }
155
+ ```
156
+
120
157
  ### Reactive Updates (RxJS & Callbacks)
121
158
 
122
159
  You can subscribe to changes using the internal RxJS Subject or a simple `onChange` callback.
@@ -208,7 +245,7 @@ const userStore = createObjectStore('user-profile', {
208
245
  context: store => ({
209
246
  promoteToAdmin() {
210
247
  // Update properties with type safety
211
- store.set('roles', (prev = []) => [...prev, 'admin'])
248
+ store.set('roles', roles => [...roles, 'admin'])
212
249
  },
213
250
  }),
214
251
  })
@@ -231,19 +268,22 @@ interface Product {
231
268
  inStock: boolean
232
269
  }
233
270
 
234
- class ProductStore extends Store<number, Product> {
235
- constructor(name: string, options?: Parameters<typeof Store>[1]) {
271
+ class ProductStore extends Store<number, Product, false> {
272
+ constructor(
273
+ ...[name, options]: ConstructorParameters<
274
+ typeof Store<number, Product, false>
275
+ >
276
+ ) {
236
277
  super(name, { ...options, delay: 100 }) // Set a default delay for this store type
237
278
  }
238
279
 
239
- getInStockProducts(): Map<number, Product> {
240
- return this.filter(product => product.inStock)
280
+ getInStockProducts(limit?: number) {
281
+ return this.filter(product => product.inStock, limit)
241
282
  }
242
283
  }
243
284
 
244
285
  const products = new ProductStore('my-products')
245
286
  products.set(1, { id: 1, name: 'Laptop', price: 1200, inStock: true })
246
287
  products.set(2, { id: 2, name: 'Mouse', price: 25, inStock: false })
247
-
248
288
  console.log(products.getInStockProducts()) // Map { 1 => { id: 1, name: 'Laptop', price: 1200, inStock: true } }
249
289
  ```
@@ -1,4 +1,4 @@
1
- this.superutils=this.superutils||{};this.superutils.store=(function(exports){'use strict';var g=(r,e=true)=>!!r&&typeof r=="object"&&(!e||[Object.prototype,null].includes(Object.getPrototypeOf(r)));var T=r=>Array.isArray(r);var re=r=>T(r)&&r.every(T),We=r=>T(r)||r instanceof Set||r instanceof Map;var Je=r=>Number.isInteger(r);var te=r=>typeof r=="number"&&!Number.isNaN(r)&&Number.isFinite(r),qe=r=>Je(r)&&r>0,ge=r=>te(r)&&r>0,xe=(r,e=false,t=false)=>{if(r==null)return true;switch(typeof r){case "number":return !te(r);case "string":return !r.replaceAll(" ","").trim().length;case "boolean":case "bigint":case "symbol":case "function":return false}if(r instanceof Date)return Number.isNaN(r.getTime());if(r instanceof Map||r instanceof Set)return !r.size;if(Array.isArray(r)||r instanceof Uint8Array)return !r.length;if(r instanceof Error)return !r.message.length;let o=typeof r=="object"&&Object.getPrototypeOf(r);return o===Object.prototype||o===null?e?!Object.getOwnPropertyNames(r).length:!Object.keys(r).length:t};var m=r=>typeof r=="function";var S=r=>r instanceof Map;var Se=r=>r!=null;var He=r=>r instanceof Promise,$=r=>r instanceof RegExp,Ge=r=>r instanceof Set,M=r=>typeof r=="string";var Ye=r=>typeof r=="symbol";var E=(r,e,t)=>{try{let o=m(r)?r(...m(e)?e():e):r;return He(o)?o.catch(n=>m(t)?t(n):t):o}catch(o){return m(t)?t(o):t}},j=E;new Date().getTime();var Xe=(r,e=true,t=true)=>j(()=>[...t&&Object.getOwnPropertySymbols(r)||[],...e?Object.keys(r).sort():Object.keys(r)],[],[]),Ze=Xe,F=(r,e="null")=>JSON.parse(j(JSON.stringify,[r],e)),we=(r,e,t,o=false,n=true)=>{let i=g(e,false)||m(e)?e:{};if(!g(r,false)&&!m(e))return i;let s=new Set(t!=null?t:[]),a=Ze(r,true,true).filter(l=>!s.has(l));for(let l of a){let c=l,u=r[c];if(i.hasOwnProperty(c)&&(o==="empty"?!xe(i[c]):m(o)?!o(c,i[c],u):true))continue;if([void 0,null,1/0,NaN].includes(u)||!g(u,false)){i[c]=u;continue}i[c]=(()=>{switch(Object.getPrototypeOf(u)){case Array.prototype:return F(u,"[]");case ArrayBuffer.prototype:return u.slice(0);case Date.prototype:return new Date(u.getTime());case Map.prototype:return new Map(F(Array.from(u),"[]"));case RegExp.prototype:return new RegExp(u);case Set.prototype:return new Set(F(Array.from(u)));case Uint8Array.prototype:return new Uint8Array([...u]);case URL.prototype:return new URL(u);}if(Ye(c)||!n)return F(u);let b=[...s].map(x=>String(x).startsWith(String(c).concat("."))&&String(x).split(String(c).concat("."))[1]).filter(Boolean);return b.length?we(u,i[c],b,o,n):F(u)})();}return i},Qe=(r=[],e=[],t)=>{g(t)||(t={});for(let o=0;o<(T(r)?r:[]).length;o++)t[r[o]]=e==null?void 0:e[o];return t};function q(r){let e=Object.entries(g(r)?r:{});return new Map(e.map(([t,o])=>[t,o]))}var ye=(r,e=true,t=false)=>T(r)?(t&&(r=[...r]),e?r.reverse():r):[];var J=(r,e=50,t={})=>{let{leading:o=J.defaults.leading,onError:n=J.defaults.onError,thisArg:i}=t,{tid:s}=t;i!==void 0&&(r=r.bind(i));let a=(...u)=>j(r,u,n),l=null,c=o==="global";return (...u)=>{clearTimeout(s),s=setTimeout(()=>{l!==u&&a(...u),l=c?true:null;},e),!(!o||l)&&(l=u,a(...u));}};J.defaults={leading:false,onError:void 0};var er=J,oe=(r,e=50,t={})=>{let{defaults:o}=oe,{onError:n=o.onError,trailing:i=o.trailing,thisArg:s}=t,{tid:a}=t,l=(...u)=>j(s!==void 0?r.bind(s):r,u,m(n)?f=>j(n,[f],void 0):void 0),c=null;return (...u)=>{if(a){c=u;return}a=setTimeout(()=>{if(a=void 0,!i)return;let f=c;c=null,f&&f!==u&&l(...f);},e),l(...u);}};oe.defaults={onError:void 0,trailing:false};var rr=oe,_e=(r,e=50,t={})=>t.throttle?rr(r,e,t):er(r,e,t),ne=(r,e,t,o,n)=>{var i;S(n)||(n=new Map),qe(t)||(t=1/0);for(let[s,a]of ((i=r==null?void 0:r.entries)==null?void 0:i.call(r))||[]){if(n.size>=t)break;j(e!=null?e:a,[a,s,r],false)&&n.set(s,a);}return o?n:[...n.values()]},tr=ne,or=r=>{if(!r)return 0;try{let e="size"in r?r.size:"length"in r?r.length:0;return te(e)?e:0}catch(e){return 0}},nr=or,ie=r=>{var e;return [...((e=r==null?void 0:r.values)==null?void 0:e.call(r))||[]]},ve=ie,D=(r,e)=>{var t;let o=!nr(r)||xe(e==null?void 0:e.query),n=S(e==null?void 0:e.result)?e.result:new Map,i=(t=e==null?void 0:e.asMap)!=null?t:D.defaults.asMap;if(o)return i?n:ve(n);e=we(D.defaults,e,[],"empty");let{ignoreCase:s,limit:a=1/0,matchAll:l,matchExact:c,ranked:u}=e,{query:f}=e,h=M(f),b=$(f),x=j(Object.keys,[f],[]);if(s&&!c&&!b&&(f=h?f.toLowerCase():Qe(x,Object.values(f).map(p=>$(p)?p:`${p}`.toLowerCase()))),e.query=f,u){let p=[];for(let[d,v]of r.entries()){let _=-1;if(h||b){_=W(e,v,void 0),_>=0&&p.push([_,d,v]);continue}let be=[];x[l?"every":"some"](N=>{let L=W(e,v,N);return be.push(L),L>=0})&&(_=be.sort((N,L)=>N-L).filter(N=>N!==-1)[0],_>=0&&p.push([_,d,v]));}p.sort((d,v)=>d[0]-v[0]).slice(0,a).forEach(([d,v,_])=>n.set(v,_));}else for(let[p,d]of r.entries()){if(n.size>=a)break;(h||b?W(e,d,void 0)>=0:x[l?"every":"some"](_=>W(e,d,_)>=0))&&n.set(p,d);}return i?n:ve(n)};D.defaults={asMap:true,ignoreCase:true,limit:1/0,matchAll:false,ranked:false,transform:true};function W({query:r,ignoreCase:e,matchExact:t,transform:o=true},n,i){var s,a;let l=M(r)||$(r)||i===void 0,c=l?r:r[i],u=l||!g(n)?n:n[i],f=j(()=>m(o)?o(n,l?void 0:u,i):t&&o===!1?u:g(u,!1)?JSON.stringify(We(u)?[...u.values()]:Object.values(u)):String(u!=null?u:""),[],"");if(f===c)return 0;if(t&&!$(c))return -1;let h=String(f);return h.trim()?$(c)?(a=(s=h.match(c))==null?void 0:s.index)!=null?a:-1:(e&&(h=h.toLowerCase()),h.indexOf(String(c))):-1}var ir=D;function Oe(r,e){return (m(e)?tr(r,e,1):ir(r,{...e,asMap:true,limit:1}))[e!=null&&e.includeKey?"entries":"values"]().next().value}var Te=r=>{var e;return [...((e=r==null?void 0:r.entries)==null?void 0:e.call(r))||[]]},Ee=r=>{var e;return [...((e=r==null?void 0:r.keys)==null?void 0:e.call(r))||[]]};function H(r,e,t){let o=T(r)?1:S(r)?2:Ge(r)?3:0;if(!o)return r;let{asString:n,ignoreCase:i,newInstance:s,reverse:a,undefinedFirst:l}={...H.defaults,...g(t)?t:g(e)?e:{}};if(o===1&&m(e))return ye(r.sort(e),a,s);let c=n?l?"":"Z".repeat(10):l?-1/0:1/0,u=m(e)?ye([...r.entries()].sort(e),a,false):(()=>{let f=1,h=p=>{let d=g(p)&&f!==0?p[e]:p;if(!n)return d;let v=`${d!=null?d:c}`;return i?v.toLowerCase():v},[b,x]=a?[-1,1]:[1,-1];return [1,3].includes(o)?(o===3||s?[...r]:r).sort((p,d)=>h(p)>h(d)?b:x):(f=e===true?0:1,[...r.entries()].sort((p,d)=>h(p==null?void 0:p[f])>h(d==null?void 0:d[f])?b:x))})();if(o===1)return u;if(s)return o===2?new Map(u):new Set(u);r.clear();for(let f of u)o===2?r.set(...f):r.add(f);return r}H.defaults={asString:true,ignoreCase:true,newInstance:false,reverse:false,undefinedFirst:false};var je=(...r)=>{var e;return new Map((e=r==null?void 0:r.flatMap)==null?void 0:e.call(r,t=>S(t)?Array.from(t.entries()):re(t)?t:[]))};var se=function(r,e){return se=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o;}||function(t,o){for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n]);},se(r,e)};function O(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");se(r,e);function t(){this.constructor=r;}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t);}function k(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],o=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return {next:function(){return r&&o>=r.length&&(r=void 0),{value:r&&r[o++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function I(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var o=t.call(r),n,i=[],s;try{for(;(e===void 0||e-- >0)&&!(n=o.next()).done;)i.push(n.value);}catch(a){s={error:a};}finally{try{n&&!n.done&&(t=o.return)&&t.call(o);}finally{if(s)throw s.error}}return i}function V(r,e,t){if(arguments.length===2)for(var o=0,n=e.length,i;o<n;o++)(i||!(o in e))&&(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return r.concat(i||Array.prototype.slice.call(e))}function y(r){return typeof r=="function"}function G(r){var e=function(o){Error.call(o),o.stack=new Error().stack;},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var Y=G(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
1
+ this.superutils=this.superutils||{};this.superutils.store=(function(exports){'use strict';var v=(r,e=true)=>!!r&&typeof r=="object"&&(!e||[Object.prototype,null].includes(Object.getPrototypeOf(r)));var j=r=>Array.isArray(r);var te=r=>j(r)&&r.every(j),We=r=>j(r)||r instanceof Set||r instanceof Map;var Je=r=>Number.isInteger(r);var oe=r=>typeof r=="number"&&!Number.isNaN(r)&&Number.isFinite(r),qe=r=>Je(r)&&r>0,ge=r=>oe(r)&&r>0,xe=(r,e=false,t=false)=>{if(r==null)return true;switch(typeof r){case "number":return !oe(r);case "string":return !r.replaceAll(" ","").trim().length;case "boolean":case "bigint":case "symbol":case "function":return false}if(r instanceof Date)return Number.isNaN(r.getTime());if(r instanceof Map||r instanceof Set)return !r.size;if(Array.isArray(r)||r instanceof Uint8Array)return !r.length;if(r instanceof Error)return !r.message.length;let o=typeof r=="object"&&Object.getPrototypeOf(r);return o===Object.prototype||o===null?e?!Object.getOwnPropertyNames(r).length:!Object.keys(r).length:t};var b=r=>typeof r=="function";var S=r=>r instanceof Map;var Se=r=>r!=null;var He=r=>r instanceof Promise,$=r=>r instanceof RegExp,Ge=r=>r instanceof Set,M=r=>typeof r=="string";var Ye=r=>typeof r=="symbol";var w=(r,e,t)=>{try{let o=b(r)?r(...b(e)?e():e):r;return He(o)?o.catch(n=>b(t)?t(n):t):o}catch(o){return b(t)?t(o):t}},E=w;new Date().getTime();var Xe=(r,e=true,t=true)=>E(()=>[...t&&Object.getOwnPropertySymbols(r)||[],...e?Object.keys(r).sort():Object.keys(r)],[],[]),Ze=Xe,F=(r,e="null")=>JSON.parse(E(JSON.stringify,[r],e)),we=(r,e,t,o=false,n=true)=>{let i=v(e,false)||b(e)?e:{};if(!v(r,false)&&!b(e))return i;let s=new Set(t!=null?t:[]),a=Ze(r,true,true).filter(u=>!s.has(u));for(let u of a){let c=u,l=r[c];if(i.hasOwnProperty(c)&&(o==="empty"?!xe(i[c]):b(o)?!o(c,i[c],l):true))continue;if([void 0,null,1/0,NaN].includes(l)||!v(l,false)){i[c]=l;continue}i[c]=(()=>{switch(Object.getPrototypeOf(l)){case Array.prototype:return F(l,"[]");case ArrayBuffer.prototype:return l.slice(0);case Date.prototype:return new Date(l.getTime());case Map.prototype:return new Map(F(Array.from(l),"[]"));case RegExp.prototype:return new RegExp(l);case Set.prototype:return new Set(F(Array.from(l)));case Uint8Array.prototype:return new Uint8Array([...l]);case URL.prototype:return new URL(l);}if(Ye(c)||!n)return F(l);let m=[...s].map(y=>String(y).startsWith(String(c).concat("."))&&String(y).split(String(c).concat("."))[1]).filter(Boolean);return m.length?we(l,i[c],m,o,n):F(l)})();}return i},Qe=(r=[],e=[],t)=>{v(t)||(t={});for(let o=0;o<(j(r)?r:[]).length;o++)t[r[o]]=e==null?void 0:e[o];return t};function q(r){let e=Object.entries(v(r)?r:{});return new Map(e.map(([t,o])=>[t,o]))}var ye=(r,e=true,t=false)=>j(r)?(t&&(r=[...r]),e?r.reverse():r):[];var J=(r,e=50,t={})=>{let{leading:o=J.defaults.leading,onError:n=J.defaults.onError,thisArg:i}=t,{tid:s}=t;i!==void 0&&(r=r.bind(i));let a=(...l)=>E(r,l,n),u=null,c=o==="global";return (...l)=>{clearTimeout(s),s=setTimeout(()=>{u!==l&&a(...l),u=c?true:null;},e),!(!o||u)&&(u=l,a(...l));}};J.defaults={leading:false,onError:void 0};var er=J,ne=(r,e=50,t={})=>{let{defaults:o}=ne,{onError:n=o.onError,trailing:i=o.trailing,thisArg:s}=t,{tid:a}=t,u=(...l)=>E(s!==void 0?r.bind(s):r,l,b(n)?f=>E(n,[f],void 0):void 0),c=null;return (...l)=>{if(a){c=l;return}a=setTimeout(()=>{if(a=void 0,!i)return;let f=c;c=null,f&&f!==l&&u(...f);},e),u(...l);}};ne.defaults={onError:void 0,trailing:false};var rr=ne,_e=(r,e=50,t={})=>t.throttle?rr(r,e,t):er(r,e,t),ie=(r,e,t,o,n)=>{var i;S(n)||(n=new Map),qe(t)||(t=1/0);for(let[s,a]of ((i=r==null?void 0:r.entries)==null?void 0:i.call(r))||[]){if(n.size>=t)break;E(e!=null?e:a,[a,s,r],false)&&n.set(s,a);}return o?n:[...n.values()]},tr=ie,or=r=>{if(!r)return 0;try{let e="size"in r?r.size:"length"in r?r.length:0;return oe(e)?e:0}catch(e){return 0}},nr=or,se=r=>{var e;return [...((e=r==null?void 0:r.values)==null?void 0:e.call(r))||[]]},ve=se,D=(r,e)=>{var t;let o=!nr(r)||xe(e==null?void 0:e.query),n=S(e==null?void 0:e.result)?e.result:new Map,i=(t=e==null?void 0:e.asMap)!=null?t:D.defaults.asMap;if(o)return i?n:ve(n);e=we(D.defaults,e,[],"empty");let{ignoreCase:s,limit:a=1/0,matchAll:u,matchExact:c,ranked:l}=e,{query:f}=e,h=M(f),m=$(f),y=E(Object.keys,[f],[]);if(s&&!c&&!m&&(f=h?f.toLowerCase():Qe(y,Object.values(f).map(p=>$(p)?p:`${p}`.toLowerCase()))),e.query=f,l){let p=[];for(let[d,x]of r.entries()){let O=-1;if(h||m){O=W(e,x,void 0),O>=0&&p.push([O,d,x]);continue}let be=[];y[u?"every":"some"](N=>{let z=W(e,x,N);return be.push(z),z>=0})&&(O=be.sort((N,z)=>N-z).filter(N=>N!==-1)[0],O>=0&&p.push([O,d,x]));}p.sort((d,x)=>d[0]-x[0]).slice(0,a).forEach(([d,x,O])=>n.set(x,O));}else for(let[p,d]of r.entries()){if(n.size>=a)break;(h||m?W(e,d,void 0)>=0:y[u?"every":"some"](O=>W(e,d,O)>=0))&&n.set(p,d);}return i?n:ve(n)};D.defaults={asMap:true,ignoreCase:true,limit:1/0,matchAll:false,ranked:false,transform:true};function W({query:r,ignoreCase:e,matchExact:t,transform:o=true},n,i){var s,a;let u=M(r)||$(r)||i===void 0,c=u?r:r[i],l=u||!v(n)?n:n[i],f=E(()=>b(o)?o(n,u?void 0:l,i):t&&o===!1?l:v(l,!1)?JSON.stringify(We(l)?[...l.values()]:Object.values(l)):String(l!=null?l:""),[],"");if(f===c)return 0;if(t&&!$(c))return -1;let h=String(f);return h.trim()?$(c)?(a=(s=h.match(c))==null?void 0:s.index)!=null?a:-1:(e&&(h=h.toLowerCase()),h.indexOf(String(c))):-1}var ir=D;function Oe(r,e){return (b(e)?tr(r,e,1):ir(r,{...e,asMap:true,limit:1}))[e!=null&&e.includeKey?"entries":"values"]().next().value}var Te=r=>{var e;return [...((e=r==null?void 0:r.entries)==null?void 0:e.call(r))||[]]},je=r=>{var e;return [...((e=r==null?void 0:r.keys)==null?void 0:e.call(r))||[]]};function H(r,e,t){let o=j(r)?1:S(r)?2:Ge(r)?3:0;if(!o)return r;let{asString:n,ignoreCase:i,newInstance:s,reverse:a,undefinedFirst:u}={...H.defaults,...v(t)?t:v(e)?e:{}};if(o===1&&b(e))return ye(r.sort(e),a,s);let c=n?u?"":"Z".repeat(10):u?-1/0:1/0,l=b(e)?ye([...r.entries()].sort(e),a,false):(()=>{let f=1,h=p=>{let d=v(p)&&f!==0?p[e]:p;if(!n)return d;let x=`${d!=null?d:c}`;return i?x.toLowerCase():x},[m,y]=a?[-1,1]:[1,-1];return [1,3].includes(o)?(o===3||s?[...r]:r).sort((p,d)=>h(p)>h(d)?m:y):(f=e===true?0:1,[...r.entries()].sort((p,d)=>h(p==null?void 0:p[f])>h(d==null?void 0:d[f])?m:y))})();if(o===1)return l;if(s)return o===2?new Map(l):new Set(l);r.clear();for(let f of l)o===2?r.set(...f):r.add(f);return r}H.defaults={asString:true,ignoreCase:true,newInstance:false,reverse:false,undefinedFirst:false};var Ee=(...r)=>{var e;return new Map((e=r==null?void 0:r.flatMap)==null?void 0:e.call(r,t=>S(t)?Array.from(t.entries()):te(t)?t:[]))};var ae=function(r,e){return ae=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o;}||function(t,o){for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n]);},ae(r,e)};function T(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");ae(r,e);function t(){this.constructor=r;}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t);}function B(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],o=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return {next:function(){return r&&o>=r.length&&(r=void 0),{value:r&&r[o++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function I(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var o=t.call(r),n,i=[],s;try{for(;(e===void 0||e-- >0)&&!(n=o.next()).done;)i.push(n.value);}catch(a){s={error:a};}finally{try{n&&!n.done&&(t=o.return)&&t.call(o);}finally{if(s)throw s.error}}return i}function K(r,e,t){if(arguments.length===2)for(var o=0,n=e.length,i;o<n;o++)(i||!(o in e))&&(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return r.concat(i||Array.prototype.slice.call(e))}function g(r){return typeof r=="function"}function G(r){var e=function(o){Error.call(o),o.stack=new Error().stack;},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var Y=G(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
2
2
  `+t.map(function(o,n){return n+1+") "+o.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=t;}});function B(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1);}}var K=(function(){function r(e){this.initialTeardown=e,this.closed=false,this._parentage=null,this._finalizers=null;}return r.prototype.unsubscribe=function(){var e,t,o,n,i;if(!this.closed){this.closed=true;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=k(s),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this);}}catch(p){e={error:p};}finally{try{l&&!l.done&&(t=a.return)&&t.call(a);}finally{if(e)throw e.error}}else s.remove(this);var u=this.initialTeardown;if(y(u))try{u();}catch(p){i=p instanceof Y?p.errors:[p];}var f=this._finalizers;if(f){this._finalizers=null;try{for(var h=k(f),b=h.next();!b.done;b=h.next()){var x=b.value;try{Ce(x);}catch(p){i=i!=null?i:[],p instanceof Y?i=V(V([],I(i)),I(p.errors)):i.push(p);}}}catch(p){o={error:p};}finally{try{b&&!b.done&&(n=h.return)&&n.call(h);}finally{if(o)throw o.error}}}if(i)throw new Y(i)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Ce(e);else {if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this);}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e);}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e;},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&B(t,e);},r.prototype.remove=function(e){var t=this._finalizers;t&&B(t,e),e instanceof r&&e._removeParent(this);},r.EMPTY=(function(){var e=new r;return e.closed=true,e})(),r})();var ae=K.EMPTY;function X(r){return r instanceof K||r&&"closed"in r&&y(r.remove)&&y(r.add)&&y(r.unsubscribe)}function Ce(r){y(r)?r():r.unsubscribe();}var w={Promise:void 0};var R={setTimeout:function(r,e){for(var t=[],o=2;o<arguments.length;o++)t[o-2]=arguments[o];return setTimeout.apply(void 0,V([r,e],I(t)))},clearTimeout:function(r){return (clearTimeout)(r)},delegate:void 0};function Ae(r){R.setTimeout(function(){throw r});}function ue(){}function U(r){r();}var z=(function(r){O(e,r);function e(t){var o=r.call(this)||this;return o.isStopped=false,t?(o.destination=t,X(t)&&t.add(o)):o.destination=lr,o}return e.create=function(t,o,n){return new Q(t,o,n)},e.prototype.next=function(t){this.isStopped?fe():this._next(t);},e.prototype.error=function(t){this.isStopped?fe():(this.isStopped=true,this._error(t));},e.prototype.complete=function(){this.isStopped?fe():(this.isStopped=true,this._complete());},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=true,r.prototype.unsubscribe.call(this),this.destination=null);},e.prototype._next=function(t){this.destination.next(t);},e.prototype._error=function(t){try{this.destination.error(t);}finally{this.unsubscribe();}},e.prototype._complete=function(){try{this.destination.complete();}finally{this.unsubscribe();}},e})(K);var ar=(function(){function r(e){this.partialObserver=e;}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e);}catch(o){Z(o);}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e);}catch(o){Z(o);}else Z(e);},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete();}catch(t){Z(t);}},r})(),Q=(function(r){O(e,r);function e(t,o,n){var i=r.call(this)||this,s;if(y(t)||!t)s={next:t!=null?t:void 0,error:o!=null?o:void 0,complete:n!=null?n:void 0};else {s=t;}return i.destination=new ar(s),i}return e})(z);function Z(r){Ae(r);}function ur(r){throw r}function fe(r,e){}var lr={closed:true,next:ue,error:ur,complete:ue};var Ve=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Ke(r){return r}function Re(r){return r.length===0?Ke:r.length===1?r[0]:function(t){return r.reduce(function(o,n){return n(o)},t)}}var pe=(function(){function r(e){e&&(this._subscribe=e);}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,o){var n=this,i=fr(e)?e:new Q(e,t,o);return U(function(){var s=n,a=s.operator,l=s.source;i.add(a?a.call(i,l):l?n._subscribe(i):n._trySubscribe(i));}),i},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t);}},r.prototype.forEach=function(e,t){var o=this;return t=Ue(t),new t(function(n,i){var s=new Q({next:function(a){try{e(a);}catch(l){i(l),s.unsubscribe();}},error:i,complete:n});o.subscribe(s);})},r.prototype._subscribe=function(e){var t;return (t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Ve]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Re(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=Ue(e),new e(function(o,n){var i;t.subscribe(function(s){return i=s},function(s){return n(s)},function(){return o(i)});})},r.create=function(e){return new r(e)},r})();function Ue(r){var e;return (e=r!=null?r:w.Promise)!==null&&e!==void 0?e:Promise}function cr(r){return r&&y(r.next)&&y(r.error)&&y(r.complete)}function fr(r){return r&&r instanceof z||cr(r)&&X(r)}function pr(r){return y(r==null?void 0:r.lift)}function Ne(r){return function(e){if(pr(e))return e.lift(function(t){try{return r(t,this)}catch(o){this.error(o);}});throw new TypeError("Unable to lift unknown Observable type")}}function Fe(r,e,t,o,n){return new hr(r,e,t,o,n)}var hr=(function(r){O(e,r);function e(t,o,n,i,s,a){var l=r.call(this,t)||this;return l.onFinalize=s,l.shouldUnsubscribe=a,l._next=o?function(c){try{o(c);}catch(u){t.error(u);}}:r.prototype._next,l._error=i?function(c){try{i(c);}catch(u){t.error(u);}finally{this.unsubscribe();}}:r.prototype._error,l._complete=n?function(){try{n();}catch(c){t.error(c);}finally{this.unsubscribe();}}:r.prototype._complete,l}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var o=this.closed;r.prototype.unsubscribe.call(this),!o&&((t=this.onFinalize)===null||t===void 0||t.call(this));}},e})(z);var $e=G(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed";}});var A=(function(r){O(e,r);function e(){var t=r.call(this)||this;return t.closed=false,t.currentObservers=null,t.observers=[],t.isStopped=false,t.hasError=false,t.thrownError=null,t}return e.prototype.lift=function(t){var o=new ke(this,this);return o.operator=t,o},e.prototype._throwIfClosed=function(){if(this.closed)throw new $e},e.prototype.next=function(t){var o=this;U(function(){var n,i;if(o._throwIfClosed(),!o.isStopped){o.currentObservers||(o.currentObservers=Array.from(o.observers));try{for(var s=k(o.currentObservers),a=s.next();!a.done;a=s.next()){var l=a.value;l.next(t);}}catch(c){n={error:c};}finally{try{a&&!a.done&&(i=s.return)&&i.call(s);}finally{if(n)throw n.error}}}});},e.prototype.error=function(t){var o=this;U(function(){if(o._throwIfClosed(),!o.isStopped){o.hasError=o.isStopped=true,o.thrownError=t;for(var n=o.observers;n.length;)n.shift().error(t);}});},e.prototype.complete=function(){var t=this;U(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=true;for(var o=t.observers;o.length;)o.shift().complete();}});},e.prototype.unsubscribe=function(){this.isStopped=this.closed=true,this.observers=this.currentObservers=null;},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return ((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:false,configurable:true}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var o=this,n=this,i=n.hasError,s=n.isStopped,a=n.observers;return i||s?ae:(this.currentObservers=null,a.push(t),new K(function(){o.currentObservers=null,B(a,t);}))},e.prototype._checkFinalizedStatuses=function(t){var o=this,n=o.hasError,i=o.thrownError,s=o.isStopped;n?t.error(i):s&&t.complete();},e.prototype.asObservable=function(){var t=new pe;return t.source=this,t},e.create=function(t,o){return new ke(t,o)},e})(pe);var ke=(function(r){O(e,r);function e(t,o){var n=r.call(this)||this;return n.destination=t,n.source=o,n}return e.prototype.next=function(t){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.next)===null||n===void 0||n.call(o,t);},e.prototype.error=function(t){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.error)===null||n===void 0||n.call(o,t);},e.prototype.complete=function(){var t,o;(o=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||o===void 0||o.call(t);},e.prototype._subscribe=function(t){var o,n;return (n=(o=this.source)===null||o===void 0?void 0:o.subscribe(t))!==null&&n!==void 0?n:ae},e})(A);var he=(function(r){O(e,r);function e(t){var o=r.call(this)||this;return o._value=t,o}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:false,configurable:true}),e.prototype._subscribe=function(t){var o=r.prototype._subscribe.call(this,t);return !o.closed&&t.next(this._value),o},e.prototype.getValue=function(){var t=this,o=t.hasError,n=t.thrownError,i=t._value;if(o)throw n;return this._throwIfClosed(),i},e.prototype.next=function(t){r.prototype.next.call(this,this._value=t);},e})(A);function Be(r,e){return Ne(function(t,o){var n=0;t.subscribe(Fe(o,function(i){return r.call(e,i,n++)&&o.next(i)}));})}function de(r){return Be(function(e,t){return r<=t})}var dr=(s=>(s.onChange="onChange",s.parse="parse",s.parse_json="parse-json",s.stringify="stringify",s.stringify_json="stringify-json",s.write="write",s))(dr||{});var ze=new A,P=class P{constructor(e,t){this.initialized=false;this.subscriptions={subject:void 0,forceUpdateCache:void 0};this.type="map";this.clear=()=>this.setAll(new Map,true);this.delete=e=>{T(e)||(e=[e]);let t=this.getAll();for(let o of e)t.delete(o);return this.setAll(t,true),this};this.filter=(...e)=>ne(this.getAll(),...e);this.find=e=>Oe(this.getAll(),e);this.get=e=>this.getAll().get(e);this.getAll=(e=false)=>{let t=this.initialized;if(t||this.init(),this.cacheDisabled||this.storage&&e){let n=this.read();return (e||!t&&n.size)&&this.subject$.next(n),n}return this.subject$.value};this.handleForceUpdateCache=e=>{if(!(this.name?T(e)?e.includes(this.name):M(e)?e===this.name:e===true:false))return;let o=this.read();this.subject$.next(o);};this.handleSubjectChange=e=>{var t;if(!S(e))return this.subject$.next(new Map);this.write(e),E((t=this.onChange)==null?void 0:t.bind(this),[e],this.triggerOnErrorCb("onChange"));};this.has=e=>this.getAll().has(e);this.init=(e,t=true)=>{var i;if(this.initialized)return false;if(this.initialized=true,t&&this.name&&!this.storage)throw new Error(P.messages.invalidOptionsStorage);let o=!!this.cacheDisabled,n=e;if(e!=null&&e.size||!this.cacheDisabled){let s=this.name?(i=this.storage)==null?void 0:i.getItem(this.name):null,a=this.read(s!=null?s:null);Se(s)&&(n=a),o=this.cacheDisabled||a.size===0;}return n!=null&&n.size&&this.subject$.next(n),this.unsubscribe(),this.cacheDisabled||(this.subscriptions.forceUpdateCache=ze.subscribe(this.handleForceUpdateCache)),this.subscriptions.subject=this.subject$.pipe(de(o?0:1)).subscribe(!this.cacheDisabled&&this.delay>0?_e(this.handleSubjectChange,this.delay,{thisArg:this,...this.delayOptions}):this.handleSubjectChange),true};this.keys=()=>Ee(this.getAll());this.map=e=>this.toArray().map(([t,o],n,i)=>e(o,t,i,n));this.read=(e=(o=>(o=this.name&&(t=>(t=this.storage)==null?void 0:t.getItem(this.name))())!=null?o:null)())=>{var i;let n=E(this.parse,[e],this.triggerOnErrorCb("parse",void 0));return S(n)||!M(e)?(i=m(this.parse)?n:this.subject$.value)!=null?i:new Map:new Map(E(()=>{let s=JSON.parse(e);if(!re(s))throw new Error(P.messages.invalidJsonEntries);return s},[],this.triggerOnErrorCb("parse-json")))};this.search=(...e)=>D(this.getAll(),...e);this.set=(e,t)=>{let o=this.getAll();return o.set(e,m(t)?t(o.get(e)):t),this.setAll(o,true)};this.setAll=(e,t=false)=>S(e)?(e=t?e:je(this.getAll(),e),this.subject$.next(new Map(e)),this):this;this.sort=(...e)=>{var o;let t=H(this.getAll(),e[0],e[1]);return (o=e[1])!=null&&o.save&&this.setAll(t,true),t};this.toArray=()=>Te(this.getAll());this.toJSON=(e,t=this.spaces,o=this.getAll())=>{let n=E(this.stringify,[o],this.triggerOnErrorCb("stringify",""));return M(n)?n:E(()=>JSON.stringify(Array.from(o),e,t),[],this.triggerOnErrorCb("stringify-json",""))};this.toObject=(e=this.getAll())=>{let t={};if(!S(e))return t;for(let[o,n]of e)t[o]=n;return t};this.toString=(e=this.getAll())=>this.toJSON(void 0,void 0,e);this.triggerOnErrorCb=(e,t=void 0)=>o=>{var n;return E((n=this.onError)==null?void 0:n.bind(this),[o,e],""),t};this.unsubscribe=()=>{var e,t;(e=this.subscriptions.forceUpdateCache)==null||e.unsubscribe(),(t=this.subscriptions.subject)==null||t.unsubscribe(),this.subscriptions={};};this.values=()=>ie(this.getAll());this.write=e=>{var t;try{if(!this.initialized&&this.init(),e!=null||(e=(t=this.subject$)==null?void 0:t.value),!S(e))return !1;let o=this.toString(e);return !this.name||!this.storage?!1:(this.storage.setItem(this.name,o),!0)}catch(o){return this.triggerOnErrorCb("write")(o),false}};let{cacheDisabled:o=false,delay:n,delayOptions:i,initialValue:s,onError:a,onChange:l,parse:c,spaces:u,storage:f=E(()=>globalThis.localStorage,[],void 0),stringify:h}=t!=null?t:{};if(this.name=`${e!=null?e:""}`.trim()||null,this.name&&!f&&!(t!=null&&t.checkStorageOnInit))throw new Error(P.messages.invalidOptionsStorage);this.cacheDisabled=!!f&&o,this.delay=n===0||ge(n)?n:300,this.delayOptions=i,this.onError=a,this.onChange=l,this.parse=c==null?void 0:c.bind(this),this.storage=f,this.stringify=h==null?void 0:h.bind(this),this.spaces=u,this.subject$=this.cacheDisabled?new A:new he(new Map),S(s)&&s.size&&this.init(s,false);}get size(){return this.getAll().size}};P.messages=Object.seal({invalidJsonEntries:"Invalid JSON format. Parsed value must be a 2D array representing key-value pairs.",invalidOptionsStorage:"options.storage: LocalStorage instance or equivalent required"}),P.forceUpdateCache=e=>{ze.next(e);};var me=P,ee=me;function mr(r,e){let t=new ee(r,e);return Object.defineProperty(t,"context",{configurable:false,enumerable:false,value:m(e==null?void 0:e.context)?e.context(t):e==null?void 0:e.context,writable:false}),t}var Le=mr;function qt(r,e){let t=Le(r,{parse:o=>q(JSON.parse(o!=null?o:"{}")),stringify:function(o){return JSON.stringify(this.toObject(o))},...e,initialValue:g(e==null?void 0:e.initialValue,true)?q(e.initialValue):e==null?void 0:e.initialValue});return t.type="object",t}var Yt=ee;exports.Store=me;exports.Store_OnErrorType=dr;exports.createObjectStore=qt;exports.createStore=mr;exports.default=Yt;exports.forceUpdateCache$=ze;exports.objToMap=q;Object.defineProperty(exports,'__esModule',{value:true});return exports;})({});//# sourceMappingURL=index.min.js.map
3
+ `):"",this.name="UnsubscriptionError",this.errors=t;}});function k(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1);}}var V=(function(){function r(e){this.initialTeardown=e,this.closed=false,this._parentage=null,this._finalizers=null;}return r.prototype.unsubscribe=function(){var e,t,o,n,i;if(!this.closed){this.closed=true;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=B(s),u=a.next();!u.done;u=a.next()){var c=u.value;c.remove(this);}}catch(p){e={error:p};}finally{try{u&&!u.done&&(t=a.return)&&t.call(a);}finally{if(e)throw e.error}}else s.remove(this);var l=this.initialTeardown;if(g(l))try{l();}catch(p){i=p instanceof Y?p.errors:[p];}var f=this._finalizers;if(f){this._finalizers=null;try{for(var h=B(f),m=h.next();!m.done;m=h.next()){var y=m.value;try{Ce(y);}catch(p){i=i!=null?i:[],p instanceof Y?i=K(K([],I(i)),I(p.errors)):i.push(p);}}}catch(p){o={error:p};}finally{try{m&&!m.done&&(n=h.return)&&n.call(h);}finally{if(o)throw o.error}}}if(i)throw new Y(i)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Ce(e);else {if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this);}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e);}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e;},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&k(t,e);},r.prototype.remove=function(e){var t=this._finalizers;t&&k(t,e),e instanceof r&&e._removeParent(this);},r.EMPTY=(function(){var e=new r;return e.closed=true,e})(),r})();var le=V.EMPTY;function X(r){return r instanceof V||r&&"closed"in r&&g(r.remove)&&g(r.add)&&g(r.unsubscribe)}function Ce(r){g(r)?r():r.unsubscribe();}var _={Promise:void 0};var R={setTimeout:function(r,e){for(var t=[],o=2;o<arguments.length;o++)t[o-2]=arguments[o];return setTimeout.apply(void 0,K([r,e],I(t)))},clearTimeout:function(r){return (clearTimeout)(r)},delegate:void 0};function Ae(r){R.setTimeout(function(){throw r});}function ue(){}function U(r){r();}var L=(function(r){T(e,r);function e(t){var o=r.call(this)||this;return o.isStopped=false,t?(o.destination=t,X(t)&&t.add(o)):o.destination=ur,o}return e.create=function(t,o,n){return new Q(t,o,n)},e.prototype.next=function(t){this.isStopped?pe():this._next(t);},e.prototype.error=function(t){this.isStopped?pe():(this.isStopped=true,this._error(t));},e.prototype.complete=function(){this.isStopped?pe():(this.isStopped=true,this._complete());},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=true,r.prototype.unsubscribe.call(this),this.destination=null);},e.prototype._next=function(t){this.destination.next(t);},e.prototype._error=function(t){try{this.destination.error(t);}finally{this.unsubscribe();}},e.prototype._complete=function(){try{this.destination.complete();}finally{this.unsubscribe();}},e})(V);var ar=(function(){function r(e){this.partialObserver=e;}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e);}catch(o){Z(o);}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e);}catch(o){Z(o);}else Z(e);},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete();}catch(t){Z(t);}},r})(),Q=(function(r){T(e,r);function e(t,o,n){var i=r.call(this)||this,s;if(g(t)||!t)s={next:t!=null?t:void 0,error:o!=null?o:void 0,complete:n!=null?n:void 0};else {s=t;}return i.destination=new ar(s),i}return e})(L);function Z(r){Ae(r);}function lr(r){throw r}function pe(r,e){}var ur={closed:true,next:ue,error:lr,complete:ue};var Ke=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Ve(r){return r}function Re(r){return r.length===0?Ve:r.length===1?r[0]:function(t){return r.reduce(function(o,n){return n(o)},t)}}var he=(function(){function r(e){e&&(this._subscribe=e);}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,o){var n=this,i=fr(e)?e:new Q(e,t,o);return U(function(){var s=n,a=s.operator,u=s.source;i.add(a?a.call(i,u):u?n._subscribe(i):n._trySubscribe(i));}),i},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t);}},r.prototype.forEach=function(e,t){var o=this;return t=Ue(t),new t(function(n,i){var s=new Q({next:function(a){try{e(a);}catch(u){i(u),s.unsubscribe();}},error:i,complete:n});o.subscribe(s);})},r.prototype._subscribe=function(e){var t;return (t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Ke]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Re(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=Ue(e),new e(function(o,n){var i;t.subscribe(function(s){return i=s},function(s){return n(s)},function(){return o(i)});})},r.create=function(e){return new r(e)},r})();function Ue(r){var e;return (e=r!=null?r:_.Promise)!==null&&e!==void 0?e:Promise}function cr(r){return r&&g(r.next)&&g(r.error)&&g(r.complete)}function fr(r){return r&&r instanceof L||cr(r)&&X(r)}function pr(r){return g(r==null?void 0:r.lift)}function Ne(r){return function(e){if(pr(e))return e.lift(function(t){try{return r(t,this)}catch(o){this.error(o);}});throw new TypeError("Unable to lift unknown Observable type")}}function Fe(r,e,t,o,n){return new hr(r,e,t,o,n)}var hr=(function(r){T(e,r);function e(t,o,n,i,s,a){var u=r.call(this,t)||this;return u.onFinalize=s,u.shouldUnsubscribe=a,u._next=o?function(c){try{o(c);}catch(l){t.error(l);}}:r.prototype._next,u._error=i?function(c){try{i(c);}catch(l){t.error(l);}finally{this.unsubscribe();}}:r.prototype._error,u._complete=n?function(){try{n();}catch(c){t.error(c);}finally{this.unsubscribe();}}:r.prototype._complete,u}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var o=this.closed;r.prototype.unsubscribe.call(this),!o&&((t=this.onFinalize)===null||t===void 0||t.call(this));}},e})(L);var $e=G(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed";}});var A=(function(r){T(e,r);function e(){var t=r.call(this)||this;return t.closed=false,t.currentObservers=null,t.observers=[],t.isStopped=false,t.hasError=false,t.thrownError=null,t}return e.prototype.lift=function(t){var o=new Be(this,this);return o.operator=t,o},e.prototype._throwIfClosed=function(){if(this.closed)throw new $e},e.prototype.next=function(t){var o=this;U(function(){var n,i;if(o._throwIfClosed(),!o.isStopped){o.currentObservers||(o.currentObservers=Array.from(o.observers));try{for(var s=B(o.currentObservers),a=s.next();!a.done;a=s.next()){var u=a.value;u.next(t);}}catch(c){n={error:c};}finally{try{a&&!a.done&&(i=s.return)&&i.call(s);}finally{if(n)throw n.error}}}});},e.prototype.error=function(t){var o=this;U(function(){if(o._throwIfClosed(),!o.isStopped){o.hasError=o.isStopped=true,o.thrownError=t;for(var n=o.observers;n.length;)n.shift().error(t);}});},e.prototype.complete=function(){var t=this;U(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=true;for(var o=t.observers;o.length;)o.shift().complete();}});},e.prototype.unsubscribe=function(){this.isStopped=this.closed=true,this.observers=this.currentObservers=null;},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return ((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:false,configurable:true}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var o=this,n=this,i=n.hasError,s=n.isStopped,a=n.observers;return i||s?le:(this.currentObservers=null,a.push(t),new V(function(){o.currentObservers=null,k(a,t);}))},e.prototype._checkFinalizedStatuses=function(t){var o=this,n=o.hasError,i=o.thrownError,s=o.isStopped;n?t.error(i):s&&t.complete();},e.prototype.asObservable=function(){var t=new he;return t.source=this,t},e.create=function(t,o){return new Be(t,o)},e})(he);var Be=(function(r){T(e,r);function e(t,o){var n=r.call(this)||this;return n.destination=t,n.source=o,n}return e.prototype.next=function(t){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.next)===null||n===void 0||n.call(o,t);},e.prototype.error=function(t){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.error)===null||n===void 0||n.call(o,t);},e.prototype.complete=function(){var t,o;(o=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||o===void 0||o.call(t);},e.prototype._subscribe=function(t){var o,n;return (n=(o=this.source)===null||o===void 0?void 0:o.subscribe(t))!==null&&n!==void 0?n:le},e})(A);var ee=(function(r){T(e,r);function e(t){var o=r.call(this)||this;return o._value=t,o}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:false,configurable:true}),e.prototype._subscribe=function(t){var o=r.prototype._subscribe.call(this,t);return !o.closed&&t.next(this._value),o},e.prototype.getValue=function(){var t=this,o=t.hasError,n=t.thrownError,i=t._value;if(o)throw n;return this._throwIfClosed(),i},e.prototype.next=function(t){r.prototype.next.call(this,this._value=t);},e})(A);function ke(r,e){return Ne(function(t,o){var n=0;t.subscribe(Fe(o,function(i){return r.call(e,i,n++)&&o.next(i)}));})}function de(r){return ke(function(e,t){return r<=t})}var dr=(s=>(s.onChange="onChange",s.parse="parse",s.parse_json="parse-json",s.stringify="stringify",s.stringify_json="stringify-json",s.write="write",s))(dr||{});var Le=new A,P=class P{constructor(e,t){this.initialized=false;this.subscriptions={subject:void 0,forceUpdateCache:void 0};this.type="map";this.clear=()=>{var e,t;return (t=(e=this.validate)==null?void 0:e.clear)==null||t.call(this,[],"clear"),this.setAll(new Map,true)};this.delete=e=>{var o,n;j(e)||(e=[e]),(n=(o=this.validate)==null?void 0:o.delete)==null||n.call(this,[e],"delete");let t=this.getAll();for(let i of e)t.delete(i);return this.setAll(t,true),this};this.filter=(...e)=>ie(this.getAll(),...e);this.find=e=>Oe(this.getAll(),e);this.get=e=>this.getAll().get(e);this.getAll=(e=false)=>{let t=this.initialized;if(t||this.init(),this.cacheDisabled||this.storage&&e){let n=this.read();return (e||!t&&n.size)&&this.subject$.next(n),n}return this.subject$.value};this.handleForceUpdateCache=e=>{if(!(this.name?j(e)?e.includes(this.name):M(e)?e===this.name:e===true:false))return;let o=this.read();this.subject$.next(o);};this.handleSubjectChange=e=>{var t;if(!S(e))return this.subject$.next(new Map);w(this.write,[e],null),w((t=this.onChange)==null?void 0:t.bind(this),[e],this.triggerOnErrorCb("onChange"));};this.has=e=>this.getAll().has(e);this.init=(e,t=true)=>{var i;if(this.initialized)return false;if(this.name&&t&&(Object.defineProperty(this,"storage",{value:w(()=>{var s;return (s=this.storage)!=null?s:globalThis.localStorage},[],void 0)}),!this.storage))throw new Error(P.messages.invalidStorageOptions);Object.defineProperty(this,"initialized",{value:true});let o=e;if(e!=null&&e.size||!this.cacheDisabled){let s=this.name?(i=this.storage)==null?void 0:i.getItem(this.name):null,a=this.read(s!=null?s:null);Se(s)&&(o=a);}o!=null&&o.size&&this.subject$.next(o),this.unsubscribe(),this.cacheDisabled||(this.subscriptions.forceUpdateCache=Le.subscribe(this.handleForceUpdateCache));let n=this.subject$ instanceof ee&&(o!=null&&o.size)&&o!==e?1:0;return this.subscriptions.subject=this.subject$.pipe(de(n)).subscribe(!this.cacheDisabled&&this.delay>0?_e(this.handleSubjectChange,this.delay,{thisArg:this,...this.delayOptions}):this.handleSubjectChange),true};this.keys=()=>je(this.getAll());this.map=e=>this.toArray().map(([t,o],n,i)=>e(o,t,i,n));this.read=(e=(o=>(o=this.name&&(t=>(t=this.storage)==null?void 0:t.getItem(this.name))())!=null?o:null)())=>{var i;let n=w(this.parse,[e],this.triggerOnErrorCb("parse",void 0));return S(n)||!M(e)?(i=b(this.parse)?n:this.subject$.value)!=null?i:new Map:new Map(w(()=>{let s=JSON.parse(e);if(!te(s))throw new Error(P.messages.invalidJsonEntries);return s},[],this.triggerOnErrorCb("parse-json")))};this.search=(...e)=>D(this.getAll(),...e);this.set=(e,t)=>{var i,s;let o=this.getAll(),n=b(t)?t(o.get(e)):t;return (s=(i=this.validate)==null?void 0:i.set)==null||s.call(this,[e,n],"set"),o.set(e,n),this.setAll(o,true)};this.setAll=(e,t=false)=>{var o,n;return S(e)?((n=(o=this.validate)==null?void 0:o.setAll)==null||n.call(this,[e,t],"setAll"),e=t?e:Ee(this.getAll(),e),this.subject$.next(new Map(e)),this):this};this.sort=(...e)=>{var o;let t=H(this.getAll(),e[0],e[1]);return (o=e[1])!=null&&o.save&&this.setAll(t,true),t};this.toArray=()=>Te(this.getAll());this.toJSON=(e,t=this.spaces,o=this.getAll())=>{let n=w(this.stringify,[o],this.triggerOnErrorCb("stringify",""));return M(n)?n:w(()=>JSON.stringify(Array.from(o),e,t),[],this.triggerOnErrorCb("stringify-json",""))};this.toObject=(e=this.getAll())=>{let t={};if(!S(e))return t;for(let[o,n]of e)t[o]=n;return t};this.toString=(e=this.getAll())=>this.toJSON(void 0,void 0,e);this.triggerOnErrorCb=(e,t=void 0)=>o=>{var n;return w((n=this.onError)==null?void 0:n.bind(this),[o,e],""),t};this.unsubscribe=()=>{var e,t;(e=this.subscriptions.forceUpdateCache)==null||e.unsubscribe(),(t=this.subscriptions.subject)==null||t.unsubscribe(),this.subscriptions={forceUpdateCache:void 0,subject:void 0};};this.values=()=>se(this.getAll());this.write=e=>{var t,o,n;if(this.init(),e!=null||(e=(t=this.subject$)==null?void 0:t.value),!S(e)||!this.name||!this.storage)return false;(n=(o=this.validate)==null?void 0:o.write)==null||n.call(this,[e],"write");try{let i=this.toString(e);return this.storage.setItem(this.name,i),!0}catch(i){return this.triggerOnErrorCb("write")(i),false}};this.name=`${e!=null?e:""}`.trim()||null;let{cacheDisabled:o=false,delay:n,delayOptions:i,initialValue:s,onError:a,onChange:u,parse:c,spaces:l,storage:f=w(()=>e?globalThis.localStorage:void 0,[],void 0),stringify:h,validate:m={}}=t!=null?t:{};if(this.name&&!f&&f!==null)throw new Error(P.messages.invalidStorageOptions);this.cacheDisabled=!!f&&o,this.delay=n===0||ge(n)?n:300,this.delayOptions=i,this.onError=a,this.onChange=u,this.parse=c==null?void 0:c.bind(this),this.spaces=l,this.storage=f,this.stringify=h==null?void 0:h.bind(this),this.subject$=this.cacheDisabled?new A:new ee(new Map);let y={...m};for(let[p,d]of Object.entries(y))y[p]=d;this.validate=y,S(s)&&s.size&&this.init(s,false);}get size(){return this.getAll().size}};P.messages=Object.seal({invalidJsonEntries:"Invalid JSON format. Parsed value must be a 2D array representing key-value pairs.",invalidStorageOptions:"options.storage: LocalStorage instance or equivalent required. For NodeJS, use `node-localstorage` NPM module.",validationError:"Validation failed. Action: "}),P.forceUpdateCache=e=>{Le.next(e);};var me=P,re=me;function mr(r,e){v(r)&&(e=r,r=null);let t=new re(r,e);return Object.defineProperty(t,"context",{configurable:false,enumerable:false,value:b(e==null?void 0:e.context)?e.context(t):e==null?void 0:e.context,writable:false}),t}var ze=mr;function Wt(r,e){v(r)&&(e=r,r=null);let t=ze(r,{parse:o=>q(JSON.parse(o!=null?o:"{}")),stringify:function(o){return JSON.stringify(this.toObject(o))},...e,initialValue:v(e==null?void 0:e.initialValue,true)?q(e.initialValue):e==null?void 0:e.initialValue});return t.type="object",t}var Ht=re;exports.Store=me;exports.Store_OnErrorType=dr;exports.createObjectStore=Wt;exports.createStore=mr;exports.default=Ht;exports.forceUpdateCache$=Le;exports.objToMap=q;Object.defineProperty(exports,'__esModule',{value:true});return exports;})({});//# sourceMappingURL=index.min.js.map
4
4
  //# sourceMappingURL=index.min.js.map