From 414128db9092d70d37c54f82c6f0be4b4a440447 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sat, 15 May 2021 20:18:48 -0400 Subject: [PATCH] Bump to 4.1.0, removed lib --- .gitignore | 2 +- lib/index.d.ts | 1 - lib/index.js | 2 - lib/index.js.map | 1 - lib/webstorage.d.ts | 41 ------------------ lib/webstorage.js | 98 ------------------------------------------- lib/webstorage.js.map | 1 - package.json | 2 +- 8 files changed, 2 insertions(+), 146 deletions(-) delete mode 100644 lib/index.d.ts delete mode 100644 lib/index.js delete mode 100644 lib/index.js.map delete mode 100644 lib/webstorage.d.ts delete mode 100644 lib/webstorage.js delete mode 100644 lib/webstorage.js.map diff --git a/.gitignore b/.gitignore index fbd4da5..3d1618e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ # compiled output /tmp -/out-tsc +/lib # dependencies /node_modules diff --git a/lib/index.d.ts b/lib/index.d.ts deleted file mode 100644 index 71f4dc3..0000000 --- a/lib/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './webstorage'; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 8b307bf..0000000 --- a/lib/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from './webstorage'; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/index.js.map b/lib/index.js.map deleted file mode 100644 index d8d9dd2..0000000 --- a/lib/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"} \ No newline at end of file diff --git a/lib/webstorage.d.ts b/lib/webstorage.d.ts deleted file mode 100644 index aa527e0..0000000 --- a/lib/webstorage.d.ts +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Options to be used with WebStorage decorators - */ -export interface WebStorageOptions { - /** Default value to provide if storage is empty */ - default?: any; - /** Key to prevent plain text storage **/ - encryptWith?: string; - /** Key to save under */ - key?: string; -} -/** - * Automatically syncs localStorage with the decorated property. - * - * **Example** - * ``` - * class Example { - * @LocalStorage() lastLogin: string; - * @LocalStorage(false, {key: '_hideMenu'}) hideMenu: boolean; - * } - * ``` - * - * @param defaultValue Default value to return if property does no exist inside localStorage. - * @param opts Any additional options - */ -export declare function LocalStorage(defaultValue?: any, opts?: WebStorageOptions): (target: object, key: string) => void; -/** - * Automatically syncs sessionStorage with the decorated property. - * - * **Example** - * ``` - * class Example { - * @SessionStorage() lastLogin: string; - * @SessionStorage(false, {key: '_hideMenu'}) hideMenu: boolean; - * } - * ``` - * - * @param defaultValue Default value to return if property does no exist inside sessionStorage. - * @param opts Any additional options - */ -export declare function SessionStorage(defaultValue?: any, opts?: WebStorageOptions): (target: object, key: string) => void; diff --git a/lib/webstorage.js b/lib/webstorage.js deleted file mode 100644 index c191500..0000000 --- a/lib/webstorage.js +++ /dev/null @@ -1,98 +0,0 @@ -import * as crypto from 'crypto-js'; -/** - * Automatically syncs localStorage with the decorated property. - * - * **Example** - * ``` - * class Example { - * @LocalStorage() lastLogin: string; - * @LocalStorage(false, {key: '_hideMenu'}) hideMenu: boolean; - * } - * ``` - * - * @param defaultValue Default value to return if property does no exist inside localStorage. - * @param opts Any additional options - */ -export function LocalStorage(defaultValue, opts = {}) { - opts.default = defaultValue; - return decoratorBuilder(localStorage, opts); -} -/** - * Automatically syncs sessionStorage with the decorated property. - * - * **Example** - * ``` - * class Example { - * @SessionStorage() lastLogin: string; - * @SessionStorage(false, {key: '_hideMenu'}) hideMenu: boolean; - * } - * ``` - * - * @param defaultValue Default value to return if property does no exist inside sessionStorage. - * @param opts Any additional options - */ -export function SessionStorage(defaultValue, opts = {}) { - opts.default = defaultValue; - return decoratorBuilder(sessionStorage, opts); -} -/** - * **Internal use only** - * - * Fetch variable from storage & take care of any defaults, object definitions, encryption & serialization - * - * @param storage Web Storage API - * @param opts Any additional options - */ -function fromStorage(storage, opts) { - let storedVal = storage.getItem(opts.key); - if (storedVal == null || storedVal == "" || storedVal == "undefined") { - if (opts.default == null) - return null; - if (opts.default != 'object') - return opts.default; - if (opts.default.constructor != null) - return Object.assign(new opts.default.constructor(), opts.default); - let temp = Object.assign({}, opts.default); - Object.setPrototypeOf(temp, Object.getPrototypeOf(opts.default)); - return temp; - } - storedVal = JSON.parse(storedVal); - if (opts.encryptWith != null) - storedVal = JSON.parse(crypto.AES.decrypt(storedVal, opts.encryptWith).toString(crypto.enc.Utf8)); - if (typeof storedVal != 'object' || !Array.isArray(storedVal)) - return storedVal; - if (opts.default != null && opts.default.constructor != null) - return Object.assign(new opts.default.constructor(), opts.default, storedVal); - return Object.assign({}, opts.default, storedVal); -} -/** - * **Internal use only** - * - * Overrides the properties getter/setter methods to read/write from the provided storage endpoint. - * - * @param storage Web Storage API - * @param opts Any additional options - */ -function decoratorBuilder(storage, opts) { - return function (target, key) { - if (!opts.key) - opts.key = key; - let field = fromStorage(storage, opts); - Object.defineProperty(target, key, { - get: function () { - if (field != fromStorage(storage, { key: opts.key, encryptWith: opts.encryptWith })) - target[key] = field; - return field; - }, - set: function (value) { - field = value; - if (value == null) - storage.removeItem(opts.key); - if (opts.encryptWith != null) - value = crypto.AES.encrypt(JSON.stringify(value), opts.encryptWith).toString(); - storage.setItem(opts.key, JSON.stringify(value)); - } - }); - }; -} -//# sourceMappingURL=webstorage.js.map \ No newline at end of file diff --git a/lib/webstorage.js.map b/lib/webstorage.js.map deleted file mode 100644 index a24ee7f..0000000 --- a/lib/webstorage.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"webstorage.js","sourceRoot":"","sources":["../src/webstorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AAcpC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAAC,YAAkB,EAAE,OAA0B,EAAE;IACzE,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC;IAC5B,OAAO,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AAChD,CAAC;AAED;;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SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;gBACjH,OAAO,CAAC,OAAO,CAAS,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7D,CAAC;SACJ,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 7fa0a61..1634c2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "webstorage-decorators", - "version": "4.0.0", + "version": "4.2.0", "description": "Decorators to sync class properties to Local/Session storage", "repository": "https://github.com/ztimson/WebstorageDecorators", "main": "./lib/index.js",