UNPKG

ng2-webstorage

Version:
41 lines 1.78 kB
import { LIB_KEY, LIB_KEY_CASE_SENSITIVE, LIB_KEY_SEPARATOR } from '../constants/lib'; var CUSTOM_LIB_KEY = LIB_KEY; var CUSTOM_LIB_KEY_SEPARATOR = LIB_KEY_SEPARATOR; var CUSTOM_LIB_KEY_CASE_SENSITIVE = LIB_KEY_CASE_SENSITIVE; export function isManagedKey(sKey) { return sKey.indexOf(CUSTOM_LIB_KEY + CUSTOM_LIB_KEY_SEPARATOR) === 0; } var KeyStorageHelper = (function () { function KeyStorageHelper() { } KeyStorageHelper.isManagedKey = function (sKey) { return sKey.indexOf(CUSTOM_LIB_KEY + CUSTOM_LIB_KEY_SEPARATOR) === 0; }; KeyStorageHelper.retrieveKeysFromStorage = function (storage) { return Object.keys(storage).filter(isManagedKey); }; KeyStorageHelper.genKey = function (raw) { if (typeof raw !== 'string') throw Error('attempt to generate a storage key with a non string value'); return "" + CUSTOM_LIB_KEY + CUSTOM_LIB_KEY_SEPARATOR + this.formatKey(raw); }; KeyStorageHelper.formatKey = function (raw) { var key = raw.toString(); return CUSTOM_LIB_KEY_CASE_SENSITIVE ? key : key.toLowerCase(); }; KeyStorageHelper.setStorageKeyPrefix = function (key) { if (key === void 0) { key = LIB_KEY; } CUSTOM_LIB_KEY = key; }; KeyStorageHelper.setCaseSensitivity = function (enable) { if (enable === void 0) { enable = LIB_KEY_CASE_SENSITIVE; } CUSTOM_LIB_KEY_CASE_SENSITIVE = enable; }; KeyStorageHelper.setStorageKeySeparator = function (separator) { if (separator === void 0) { separator = LIB_KEY_SEPARATOR; } CUSTOM_LIB_KEY_SEPARATOR = separator; }; return KeyStorageHelper; }()); export { KeyStorageHelper }; //# sourceMappingURL=keyStorage.js.map