Comparing version 0.1.2 to 0.1.3
26
index.js
@@ -25,7 +25,9 @@ // @ts-nocheck | ||
const raw = storage.getItem(`${namespace}.${key}`); | ||
return raw !== null ? safeParse(raw) : undefined; | ||
return raw === null ? undefined : safeParse(raw); | ||
} | ||
: function get(key) { | ||
const raw = storage.getItem(`${namespace}.${key}`); | ||
return raw !== null ? raw : undefined; | ||
return raw === null ? undefined : raw; | ||
}, | ||
@@ -50,2 +52,3 @@ }, | ||
} | ||
storage.setItem(`${namespace}.${key}`, value); | ||
@@ -64,4 +67,6 @@ } | ||
const keys = []; | ||
for (let i = 0; i < storage.length; i += 1) { | ||
const key = storage.key(i); | ||
if (key.startsWith(`${namespace}.`)) { | ||
@@ -71,2 +76,3 @@ keys.push(key); | ||
} | ||
return keys; | ||
@@ -92,3 +98,2 @@ }, | ||
value: function valueOf() { | ||
// eslint-disable-next-line unicorn/prefer-object-from-entries | ||
return this.keys.reduce( | ||
@@ -123,1 +128,16 @@ (io, key) => ({ [key]: this.get(key), ...io }), | ||
} | ||
export function smart(store, key) { | ||
return { | ||
get() { | ||
return store.get(key); | ||
}, | ||
set(value) { | ||
if (value !== null && value !== undefined) { | ||
store.set(key, value); | ||
} else { | ||
store.remove(key); | ||
} | ||
}, | ||
}; | ||
} |
{ | ||
"name": "pet-shop", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A simple wrapper of Web Storage API", | ||
@@ -31,3 +31,7 @@ "license": "MIT", | ||
"main": "index.js", | ||
"type": "module" | ||
} | ||
"type": "module", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5406
128