Bump to 4.1.0, removed lib
This commit is contained in:
parent
132f23a028
commit
414128db90
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# compiled output
|
# compiled output
|
||||||
/tmp
|
/tmp
|
||||||
/out-tsc
|
/lib
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
/node_modules
|
/node_modules
|
||||||
|
1
lib/index.d.ts
vendored
1
lib/index.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export * from './webstorage';
|
|
@ -1,2 +0,0 @@
|
|||||||
export * from './webstorage';
|
|
||||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
41
lib/webstorage.d.ts
vendored
41
lib/webstorage.d.ts
vendored
@ -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;
|
|
@ -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
|
|
@ -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;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAC,YAAa,EAAE,OAA0B,EAAE;IACtE,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC;IAC5B,OAAO,gBAAgB,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,WAAW,CAAC,OAAgB,EAAE,IAAuB;IAC1D,IAAI,SAAS,GAAG,OAAO,CAAC,OAAO,CAAS,IAAI,CAAC,GAAG,CAAC,CAAC;IAClD,IAAG,SAAS,IAAI,IAAI,IAAI,SAAS,IAAI,EAAE,IAAI,SAAS,IAAI,WAAW,EAAE;QACjE,IAAG,IAAI,CAAC,OAAO,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;QACrC,IAAG,IAAI,CAAC,OAAO,IAAI,QAAQ;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC;QACjD,IAAG,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,IA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C;QAC7B,IAAI,KAAK,GAAG,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACvC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;YAC/B,GAAG,EAAE;gBACD,IAAG,KAAK,IAAI,WAAW,CAAC,OAAO,EAAE,EAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAC,CAAC;oBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBACtG,OAAO,KAAK,CAAC;YACjB,CAAC;YACD,GAAG,EAAE,UAAS,KAAM;gBAChB,KAAK,GAAG,KAAK,CAAC;gBACd,IAAG,KAAK,IAAI,IAAI;oBAAE,OAAO,CAAC,UAAU,CAAS,IAAI,CAAC,GAAG,CAAC,CAAC;gBACvD,IAAG,IAAI,CAAC,WAAW,IAAI,IAAI;oBAAE,KAAK,GAAQ,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,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"}
|
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "webstorage-decorators",
|
"name": "webstorage-decorators",
|
||||||
"version": "4.0.0",
|
"version": "4.2.0",
|
||||||
"description": "Decorators to sync class properties to Local/Session storage",
|
"description": "Decorators to sync class properties to Local/Session storage",
|
||||||
"repository": "https://github.com/ztimson/WebstorageDecorators",
|
"repository": "https://github.com/ztimson/WebstorageDecorators",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
|
Loading…
Reference in New Issue
Block a user