Comparing version 0.0.4 to 0.1.0
84
index.js
@@ -1,8 +0,12 @@ | ||
'use strict'; | ||
module.exports = function PetShop({ storage, namespace, json = false }) { | ||
// @ts-nocheck | ||
export function PetShop({ storage, namespace, json = false }) { | ||
return Object.defineProperties( | ||
{}, | ||
{ | ||
namespace: { value: namespace, enumerable: true }, | ||
namespace: { | ||
value: namespace, | ||
enumerable: true, | ||
writable: false, | ||
configurable: false, | ||
}, | ||
get: { | ||
@@ -12,9 +16,9 @@ enumerable: true, | ||
? function get(key) { | ||
const raw = storage.getItem(`${namespace}.${key}`); | ||
return raw !== null ? JSON.parse(raw) : undefined; | ||
} | ||
const raw = storage.getItem(`${namespace}.${key}`); | ||
return raw !== null ? JSON.parse(raw) : undefined; | ||
} | ||
: function get(key) { | ||
const raw = storage.getItem(`${namespace}.${key}`); | ||
return raw !== null ? raw : undefined; | ||
} | ||
const raw = storage.getItem(`${namespace}.${key}`); | ||
return raw !== null ? raw : undefined; | ||
}, | ||
}, | ||
@@ -25,18 +29,18 @@ set: { | ||
? function set(key, value) { | ||
if (value === undefined) { | ||
this.remove(key); | ||
} else { | ||
storage.setItem(`${namespace}.${key}`, JSON.stringify(value)); | ||
if (value === undefined) { | ||
this.remove(key); | ||
} else { | ||
storage.setItem(`${namespace}.${key}`, JSON.stringify(value)); | ||
} | ||
} | ||
} | ||
: function set(key, value) { | ||
if (value === undefined || value === null) { | ||
this.remove(key); | ||
} else { | ||
if (typeof value !== 'string') { | ||
throw new TypeError('The Value should be a string'); | ||
if (value === undefined || value === null) { | ||
this.remove(key); | ||
} else { | ||
if (typeof value !== 'string') { | ||
throw new TypeError('The Value should be a string'); | ||
} | ||
storage.setItem(`${namespace}.${key}`, value); | ||
} | ||
storage.setItem(`${namespace}.${key}`, value); | ||
} | ||
} | ||
}, | ||
}, | ||
@@ -47,3 +51,3 @@ remove: { | ||
storage.removeItem(`${namespace}.${key}`); | ||
} | ||
}, | ||
}, | ||
@@ -60,3 +64,3 @@ rawKeys: { | ||
return keys; | ||
} | ||
}, | ||
}, | ||
@@ -66,5 +70,6 @@ keys: { | ||
get() { | ||
return this.rawKeys.map(key => | ||
key.replace(new RegExp(`^${namespace}.`), '')); | ||
} | ||
return this.rawKeys.map((key) => | ||
key.replace(new RegExp(`^${namespace}.`), ''), | ||
); | ||
}, | ||
}, | ||
@@ -74,4 +79,4 @@ values: { | ||
get() { | ||
return this.keys.map(key => this.get(key)); | ||
} | ||
return this.keys.map((key) => this.get(key)); | ||
}, | ||
}, | ||
@@ -81,7 +86,8 @@ valueOf: { | ||
value: function valueOf() { | ||
// eslint-disable-next-line unicorn/prefer-object-from-entries | ||
return this.keys.reduce( | ||
(io, key) => ({ [key]: this.get(key), ...io }), | ||
{} | ||
{}, | ||
); | ||
} | ||
}, | ||
}, | ||
@@ -92,3 +98,3 @@ size: { | ||
return this.rawKeys.length; | ||
} | ||
}, | ||
}, | ||
@@ -99,3 +105,3 @@ has: { | ||
return storage.getItem(`${namespace}.${key}`) !== null; | ||
} | ||
}, | ||
}, | ||
@@ -105,9 +111,9 @@ clear: { | ||
value: function clear() { | ||
this.rawKeys.forEach(key => { | ||
this.rawKeys.forEach((key) => { | ||
storage.removeItem(key); | ||
}); | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
}, | ||
); | ||
}; | ||
} |
{ | ||
"name": "pet-shop", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "A simple wrapper of Web Storage API", | ||
@@ -21,11 +21,13 @@ "license": "MIT", | ||
], | ||
"homepage": "https://github.com/airkro/frontend-toolkit/tree/master/packages/pet-shop", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/airkro/frontend-toolkit", | ||
"url": "https://github.com/airkro/frontend-toolkit.git", | ||
"directory": "packages/pet-shop" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/airkro/frontend-toolkit/issues" | ||
}, | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=8.3.0" | ||
} | ||
} | ||
"type": "module" | ||
} |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
4955
109
0
1
61
Yes