Comparing version 0.1.4 to 0.2.0
59
index.js
@@ -120,15 +120,52 @@ // @ts-nocheck | ||
export function smart(store, key) { | ||
return { | ||
get() { | ||
return store.get(key); | ||
}, | ||
set(value) { | ||
if (value !== null && value !== undefined) { | ||
store.set(key, value); | ||
} else { | ||
export function createProxy(store) { | ||
return new Proxy( | ||
{}, | ||
{ | ||
get(_, key) { | ||
return store.get(key); | ||
}, | ||
async set(_, key, value) { | ||
if (value !== null && value !== undefined) { | ||
store.set(key, value); | ||
} else { | ||
store.remove(key); | ||
} | ||
return true; | ||
}, | ||
async deleteProperty(_, key) { | ||
store.remove(key); | ||
} | ||
return true; | ||
}, | ||
}, | ||
}; | ||
); | ||
} | ||
export function createCache(storage, keys) { | ||
return Object.defineProperties( | ||
{ | ||
clear() { | ||
storage.clear(); | ||
}, | ||
}, | ||
Object.fromEntries( | ||
keys.map((key) => [ | ||
key, | ||
{ | ||
get() { | ||
return storage.get(key); | ||
}, | ||
set(value) { | ||
if (value || value === 0 || value === false) { | ||
storage.set(key, value); | ||
} else { | ||
storage.remove(key); | ||
} | ||
}, | ||
}, | ||
]), | ||
), | ||
); | ||
} |
{ | ||
"name": "pet-shop", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "A simple wrapper of Web Storage API", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Eric Chen", | ||
"email": "airkro@qq.com" | ||
}, | ||
"keywords": [ | ||
@@ -36,2 +32,2 @@ "cache", | ||
} | ||
} | ||
} |
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
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
6970
4
159
1