Compare commits

..

5 Commits

Author SHA1 Message Date
3b486310de Deleting lock file, seems to mess up build
All checks were successful
Build / Build NPM Project (push) Successful in 1m4s
Build / Tag Version (push) Successful in 11s
Build / Publish Documentation (push) Successful in 46s
2024-10-15 13:51:00 -04:00
8699fb49ff New lock file
Some checks failed
Build / Build NPM Project (push) Failing after 18s
Build / Tag Version (push) Has been skipped
Build / Publish Documentation (push) Has been skipped
2024-10-15 13:49:52 -04:00
fdb29e7984 New lock file
Some checks failed
Build / Tag Version (push) Blocked by required conditions
Build / Publish Documentation (push) Blocked by required conditions
Build / Build NPM Project (push) Has been cancelled
2024-10-15 13:49:17 -04:00
274c22bb83 Fixed localStorage access on node environments
Some checks failed
Build / Build NPM Project (push) Failing after 15s
Build / Tag Version (push) Has been skipped
Build / Publish Documentation (push) Has been skipped
2024-10-15 13:46:11 -04:00
b21f462d35 Added clear function to cache
All checks were successful
Build / Build NPM Project (push) Successful in 37s
Build / Tag Version (push) Successful in 7s
Build / Publish Documentation (push) Successful in 35s
2024-10-14 21:07:59 -04:00
2 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.20.2",
"version": "0.20.4",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -25,7 +25,7 @@ export class Cache<K extends string | number | symbol, T> {
* @param options
*/
constructor(public readonly key?: keyof T, public readonly options: CacheOptions = {}) {
if(options.storageKey && !options.storage)
if(options.storageKey && !options.storage && localStorage)
options.storage = localStorage;
if(options.storageKey && options.storage) {
const stored = options.storage.getItem(options.storageKey);
@ -87,6 +87,13 @@ export class Cache<K extends string | number | symbol, T> {
return this;
}
/**
* Remove all keys from cache
*/
clear() {
this.store = <Record<K, T>>{};
}
/**
* Delete an item from the cache
*