itemsholdr
Advanced tools
Comparing version 0.7.3 to 0.7.4
@@ -63,3 +63,3 @@ define(function() { return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 0); | ||
/******/ return __webpack_require__(__webpack_require__.s = 2); | ||
/******/ }) | ||
@@ -71,6 +71,110 @@ /************************************************************************/ | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(1), __webpack_require__(2)], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, createPlaceholderStorage_1, ItemValue_1) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Creates a basic implementation of the Storage API. | ||
* | ||
* @returns Basic Storage object. | ||
*/ | ||
exports.createStorage = function () { | ||
var output = { | ||
clear: function () { | ||
for (var i in output) { | ||
if ({}.hasOwnProperty.call(output, i)) { | ||
delete output[i]; | ||
} | ||
} | ||
}, | ||
getItem: function (key) { return output[key]; }, | ||
key: function (index) { return output.keys[index]; }, | ||
get keys() { | ||
return Object.keys(output); | ||
}, | ||
get length() { | ||
return output.keys.length; | ||
}, | ||
removeItem: function (key) { | ||
delete output[key]; | ||
}, | ||
setItem: function (key, value) { | ||
output[key] = value; | ||
}, | ||
}; | ||
return output; | ||
}; | ||
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), | ||
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); | ||
/***/ }), | ||
/* 1 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Proliferates all members of the donor to the recipient recursively, as | ||
* a deep copy. | ||
* | ||
* @param recipient An object receiving the donor's members. | ||
* @param donor An object whose members are copied to recipient. | ||
* @param noOverride Whether recipient properties may be overriden (by default, false). | ||
* @returns The recipient, which should have the donor proliferated onto it. | ||
*/ | ||
exports.proliferate = function (recipient, donor, noOverride) { | ||
// For each attribute of the donor: | ||
for (var i in donor) { | ||
if (!donor.hasOwnProperty(i)) { | ||
continue; | ||
} | ||
// If noOverride, don't override already existing properties | ||
if (noOverride && recipient.hasOwnProperty(i)) { | ||
continue; | ||
} | ||
// If it's an object, recurse on a new version of it | ||
var setting = donor[i]; | ||
if (typeof setting === "object") { | ||
if (!recipient.hasOwnProperty(i)) { | ||
recipient[i] = new setting.constructor(); | ||
} | ||
exports.proliferate(recipient[i], setting, noOverride); | ||
} | ||
else { | ||
// Regular primitives are easy to copy otherwise | ||
recipient[i] = setting; | ||
} | ||
} | ||
return recipient; | ||
}; | ||
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), | ||
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); | ||
/***/ }), | ||
/* 2 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(0), __webpack_require__(3), __webpack_require__(1)], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, createStorage_1, ItemsHoldr_1, proliferate_1) { | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(createStorage_1); | ||
__export(ItemsHoldr_1); | ||
__export(proliferate_1); | ||
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), | ||
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); | ||
/***/ }), | ||
/* 3 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(0), __webpack_require__(4)], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, createStorage_1, ItemContainer_1) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* A versatile container to store and manipulate values in localStorage, and | ||
@@ -89,17 +193,32 @@ * optionally keep an updated HTML container showing these values. | ||
this.autoSave = !!settings.autoSave; | ||
this.items = {}; | ||
this.itemKeys = []; | ||
this.prefix = settings.prefix || ""; | ||
this.allowNewItems = settings.allowNewItems === undefined | ||
? true : settings.allowNewItems; | ||
if (settings.localStorage) { | ||
this.localStorage = settings.localStorage; | ||
this.values = this.settings.values || {}; | ||
if (settings.storage) { | ||
this.storage = settings.storage; | ||
} | ||
else if (typeof localStorage === "undefined") { | ||
this.localStorage = createPlaceholderStorage_1.createPlaceholderStorage(); | ||
this.storage = createStorage_1.createStorage(); | ||
} | ||
else { | ||
this.localStorage = localStorage; | ||
this.storage = localStorage; | ||
} | ||
this.defaults = settings.defaults || {}; | ||
this.clear(); | ||
this.containerSettings = { | ||
autoSave: this.autoSave, | ||
defaults: this.settings.defaults || {}, | ||
prefix: this.prefix, | ||
storage: this.storage, | ||
}; | ||
} | ||
Object.defineProperty(ItemsHoldr.prototype, "length", { | ||
/** | ||
* How many items are being stored. | ||
*/ | ||
get: function () { | ||
return this.itemKeys.length; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
@@ -115,60 +234,15 @@ * Gets the key at an index. | ||
/** | ||
* Gets the contained values. | ||
* Creates a new item with settings. | ||
* | ||
* @returns The values contained within, keyed by their keys. | ||
* @param key Unique key to store the item under. | ||
* @param settings Any additional settings for the item. | ||
*/ | ||
ItemsHoldr.prototype.getValues = function () { | ||
return this.items; | ||
ItemsHoldr.prototype.addItem = function (key, settings) { | ||
if (settings === void 0) { settings = {}; } | ||
this.items[key] = new ItemContainer_1.ItemContainer(this.containerSettings, key, settings); | ||
this.itemKeys.push(key); | ||
}; | ||
/** | ||
* Gets the default attributes for values. | ||
* Gets the value under a key. | ||
* | ||
* @returns Default attributes for values. | ||
*/ | ||
ItemsHoldr.prototype.getDefaults = function () { | ||
return this.defaults; | ||
}; | ||
/** | ||
* Gets the reference to localStorage or its placeholder. | ||
* | ||
* @returns A reference to localStorage or its placeholder. | ||
*/ | ||
ItemsHoldr.prototype.getLocalStorage = function () { | ||
return this.localStorage; | ||
}; | ||
/** | ||
* Gets whether this should save changes to localStorage automatically. | ||
* | ||
* @returns Whether this should save changes to localStorage automatically. | ||
*/ | ||
ItemsHoldr.prototype.getAutoSave = function () { | ||
return this.autoSave; | ||
}; | ||
/** | ||
* Gets the prefix for localStorage keys. | ||
* | ||
* @returns The prefix to store keys under in localStorage. | ||
*/ | ||
ItemsHoldr.prototype.getPrefix = function () { | ||
return this.prefix; | ||
}; | ||
/** | ||
* Gets all keys for all items. | ||
* | ||
* @returns String keys for each of the stored ItemValues. | ||
*/ | ||
ItemsHoldr.prototype.getKeys = function () { | ||
return Object.keys(this.items); | ||
}; | ||
/** | ||
* Gets all stored keys of items. | ||
* | ||
* @returns All keys of items. | ||
*/ | ||
ItemsHoldr.prototype.getItemKeys = function () { | ||
return this.itemKeys; | ||
}; | ||
/** | ||
* Gets the value for a known key. | ||
* | ||
* @param key The key for a known value. | ||
@@ -182,45 +256,2 @@ * @returns The known value of a key, assuming that key exists. | ||
/** | ||
* Gets the value for a potentially unknown key. | ||
* | ||
* @param key The key for a potentially unknown value. | ||
* @returns The settings for that particular key. | ||
*/ | ||
ItemsHoldr.prototype.getObject = function (key) { | ||
return this.items[key]; | ||
}; | ||
/** | ||
* Checks whether a key exists. | ||
* | ||
* @param key The key for a potentially known value. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
ItemsHoldr.prototype.hasKey = function (key) { | ||
return this.items.hasOwnProperty(key); | ||
}; | ||
/** | ||
* Maps key names to their values. | ||
* | ||
* @returns A mapping of key names to the actual values of all objects being stored. | ||
*/ | ||
ItemsHoldr.prototype.exportItems = function () { | ||
var output = {}; | ||
for (var i in this.items) { | ||
output[i] = this.items[i].getValue(); | ||
} | ||
return output; | ||
}; | ||
/** | ||
* Adds a new key & value pair to by linking to a newly created ItemValue. | ||
* | ||
* @param key The key to reference by new ItemValue by. | ||
* @param settings The settings for the new ItemValue. | ||
* @returns The newly created ItemValue. | ||
*/ | ||
ItemsHoldr.prototype.addItem = function (key, settings) { | ||
if (settings === void 0) { settings = {}; } | ||
this.items[key] = new ItemValue_1.ItemValue(this, key, settings); | ||
this.itemKeys.push(key); | ||
return this.items[key]; | ||
}; | ||
/** | ||
* Clears a value from the listing, and removes its element from the | ||
@@ -232,3 +263,3 @@ * container (if they both exist). | ||
ItemsHoldr.prototype.removeItem = function (key) { | ||
if (!this.items.hasOwnProperty(key)) { | ||
if (!{}.hasOwnProperty.call(this.items, key)) { | ||
return; | ||
@@ -238,26 +269,12 @@ } | ||
delete this.items[key]; | ||
delete this.localStorage[this.prefix + key]; | ||
}; | ||
/** | ||
* Completely clears all values from the ItemsHoldr, removing their | ||
* elements from the container (if they both exist) as well. | ||
*/ | ||
ItemsHoldr.prototype.clear = function () { | ||
this.items = {}; | ||
this.itemKeys = []; | ||
if (!this.settings.values) { | ||
return; | ||
this.storage.removeItem(this.prefix + key); | ||
if ({}.hasOwnProperty.call(this.values, key)) { | ||
this.addItem(key, this.values[key]); | ||
} | ||
for (var key in this.settings.values) { | ||
if (this.settings.values.hasOwnProperty(key)) { | ||
this.addItem(key, this.settings.values[key]); | ||
} | ||
} | ||
}; | ||
/** | ||
* Sets the value for the ItemValue under the given key, then updates the ItemValue | ||
* (including the ItemValue's element and localStorage, if needed). | ||
* Sets the value for an item under the given key. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param value The new value for the ItemValue. | ||
* @param key Key of an item. | ||
* @param value The new value for the item. | ||
*/ | ||
@@ -269,7 +286,6 @@ ItemsHoldr.prototype.setItem = function (key, value) { | ||
/** | ||
* Increases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Increases the value of an item as a number or string. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to increase by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to increase by (by default, 1). | ||
*/ | ||
@@ -284,7 +300,6 @@ ItemsHoldr.prototype.increase = function (key, amount) { | ||
/** | ||
* Decreases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Decreases the value of an item as a number | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to decrease by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to decrease by (by default, 1). | ||
*/ | ||
@@ -298,5 +313,5 @@ ItemsHoldr.prototype.decrease = function (key, amount) { | ||
/** | ||
* Toggles whether a value is true or false. | ||
* Toggles whether an item is true or false. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param key Key of an item. | ||
*/ | ||
@@ -309,24 +324,41 @@ ItemsHoldr.prototype.toggle = function (key) { | ||
/** | ||
* Toggles this.autoSave. | ||
* Gets whether an item exists under the key. | ||
* | ||
* @param key Key of an item. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
ItemsHoldr.prototype.toggleAutoSave = function () { | ||
this.autoSave = !this.autoSave; | ||
ItemsHoldr.prototype.hasKey = function (key) { | ||
return {}.hasOwnProperty.call(this.items, key); | ||
}; | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* Gets a summary of keys and their values. | ||
* | ||
* @param key | ||
* @returns A mapping of key to their stored values. | ||
*/ | ||
ItemsHoldr.prototype.checkExistence = function (key) { | ||
if (this.items.hasOwnProperty(key)) { | ||
return; | ||
ItemsHoldr.prototype.exportItems = function () { | ||
var output = {}; | ||
for (var _i = 0, _a = this.itemKeys; _i < _a.length; _i++) { | ||
var itemKey = _a[_i]; | ||
output[itemKey] = this.items[itemKey].getValue(); | ||
} | ||
if (!this.allowNewItems) { | ||
throw new Error("Unknown key given to ItemsHoldr: '" + key + "'."); | ||
return output; | ||
}; | ||
/** | ||
* Completely clears all items. | ||
*/ | ||
ItemsHoldr.prototype.clear = function () { | ||
for (var _i = 0, _a = this.itemKeys; _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
this.storage.removeItem(this.prefix + key); | ||
} | ||
this.addItem(key); | ||
this.items = {}; | ||
this.itemKeys = []; | ||
for (var key in this.values) { | ||
if ({}.hasOwnProperty.call(this.values, key)) { | ||
this.addItem(key, this.values[key]); | ||
} | ||
} | ||
}; | ||
/** | ||
* Manually saves an item's value to localStorage, ignoring the autoSave flag. | ||
* Manually saves an item's value to storage, ignoring autoSave settings. | ||
* | ||
@@ -336,15 +368,26 @@ * @param key The key of the item to save. | ||
ItemsHoldr.prototype.saveItem = function (key) { | ||
if (!this.items.hasOwnProperty(key)) { | ||
if (!{}.hasOwnProperty.call(this.items, key)) { | ||
throw new Error("Unknown key given to ItemsHoldr: '" + key + "'."); | ||
} | ||
this.items[key].updateLocalStorage(true); | ||
this.items[key].updateStorage(true); | ||
}; | ||
/** | ||
* Manually saves all values to localStorage, ignoring the autoSave flag. | ||
* Manually saves all items to storage, ignoring autoSave settings. | ||
*/ | ||
ItemsHoldr.prototype.saveAll = function () { | ||
for (var key in this.items) { | ||
this.items[key].updateLocalStorage(true); | ||
this.items[key].updateStorage(true); | ||
} | ||
}; | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* | ||
* @param key | ||
*/ | ||
ItemsHoldr.prototype.checkExistence = function (key) { | ||
if (!{}.hasOwnProperty.call(this.items, key)) { | ||
this.addItem(key, this.values[key]); | ||
} | ||
}; | ||
return ItemsHoldr; | ||
@@ -358,55 +401,12 @@ }()); | ||
/***/ }), | ||
/* 1 */ | ||
/* 4 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(1)], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, proliferate_1) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Creates an Object that can be used to create a new LocalStorage | ||
* replacement, if the JavaScript environment doesn't have one. | ||
* | ||
* @returns Placeholder Storage object. | ||
*/ | ||
exports.createPlaceholderStorage = function () { | ||
var output = { | ||
clear: function () { | ||
for (var i in output) { | ||
if ({}.hasOwnProperty.call(output, i)) { | ||
delete output[i]; | ||
} | ||
} | ||
}, | ||
getItem: function (key) { return output[key]; }, | ||
key: function (index) { return output.keys[index]; }, | ||
get keys() { | ||
return Object.keys(output); | ||
}, | ||
get length() { | ||
return output.keys.length; | ||
}, | ||
removeItem: function (key) { | ||
delete output[key]; | ||
}, | ||
setItem: function (key, value) { | ||
output[key] = value; | ||
}, | ||
}; | ||
return output; | ||
}; | ||
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), | ||
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); | ||
/***/ }), | ||
/* 2 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, proliferate_1) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Storage container for a single ItemsHoldr value. | ||
*/ | ||
var ItemValue = /** @class */ (function () { | ||
var ItemContainer = /** @class */ (function () { | ||
/** | ||
@@ -418,9 +418,9 @@ * Creates a new ItemValue with the given key and settings. Defaults are given | ||
* @param key The key to reference this new ItemValue by. | ||
* @param settings Any optional custom settings. | ||
* @param item Any custom settings for the value. | ||
*/ | ||
function ItemValue(itemsHolder, key, settings) { | ||
if (settings === void 0) { settings = {}; } | ||
this.itemsHolder = itemsHolder; | ||
proliferate_1.proliferate(this, itemsHolder.getDefaults()); | ||
proliferate_1.proliferate(this, settings); | ||
function ItemContainer(settings, key, item) { | ||
if (item === void 0) { item = {}; } | ||
this.settings = settings; | ||
proliferate_1.proliferate(this, settings.defaults); | ||
proliferate_1.proliferate(this, item); | ||
this.key = key; | ||
@@ -430,35 +430,27 @@ if (!this.hasOwnProperty("value")) { | ||
} | ||
if (this.storeLocally) { | ||
// If there exists an old version of this property, get it | ||
if (itemsHolder.getLocalStorage().hasOwnProperty(itemsHolder.getPrefix() + key)) { | ||
this.value = this.retrieveLocalStorage(); | ||
this.update(); | ||
} | ||
else { | ||
// Otherwise save the new version to memory | ||
this.updateLocalStorage(); | ||
} | ||
// If there exists an old version of this property, get it | ||
if ({}.hasOwnProperty.call(settings.storage, settings.prefix + key)) { | ||
this.value = this.retrieveLocalStorage(); | ||
this.update(); | ||
} | ||
else { | ||
// Otherwise save the new version to memory | ||
this.updateStorage(); | ||
} | ||
} | ||
/** | ||
* Gets a stored value, with a transformGet applied if one exists. | ||
* Gets the stored value. | ||
* | ||
* @returns The value being stored. | ||
*/ | ||
ItemValue.prototype.getValue = function () { | ||
if (this.transformGet) { | ||
return this.transformGet(this.value); | ||
} | ||
ItemContainer.prototype.getValue = function () { | ||
return this.value; | ||
}; | ||
/** | ||
* Sets the value being stored, with a is a transformSet applied if one exists. | ||
* Any attached triggers to the new value will be called. | ||
* Sets the value being stored. | ||
* | ||
* @param value The desired value to now store. | ||
* @param value New value to store. | ||
*/ | ||
ItemValue.prototype.setValue = function (value) { | ||
this.value = this.transformSet === undefined | ||
? value | ||
: this.transformSet(value); | ||
ItemContainer.prototype.setValue = function (value) { | ||
this.value = value; | ||
this.update(); | ||
@@ -469,3 +461,3 @@ }; | ||
*/ | ||
ItemValue.prototype.update = function () { | ||
ItemContainer.prototype.update = function () { | ||
// Mins and maxes must be obeyed before any other considerations | ||
@@ -490,5 +482,3 @@ if (this.hasOwnProperty("minimum") && Number(this.value) <= Number(this.minimum)) { | ||
} | ||
if (this.storeLocally) { | ||
this.updateLocalStorage(); | ||
} | ||
this.updateStorage(); | ||
}; | ||
@@ -498,9 +488,9 @@ /** | ||
* | ||
* @param [overrideAutoSave] Whether the policy on saving should be | ||
* ignored (so saving happens regardless). By | ||
* default, false. | ||
* @param overrideAutoSave Whether the policy on saving should be | ||
* ignored (so saving happens regardless). By | ||
* default, false. | ||
*/ | ||
ItemValue.prototype.updateLocalStorage = function (overrideAutoSave) { | ||
if (overrideAutoSave || this.itemsHolder.getAutoSave()) { | ||
this.itemsHolder.getLocalStorage()[this.itemsHolder.getPrefix() + this.key] = JSON.stringify(this.value); | ||
ItemContainer.prototype.updateStorage = function (overrideAutoSave) { | ||
if (overrideAutoSave || this.settings.autoSave) { | ||
this.settings.storage.setItem(this.settings.prefix + this.key, JSON.stringify(this.value)); | ||
} | ||
@@ -511,5 +501,5 @@ }; | ||
*/ | ||
ItemValue.prototype.checkTriggers = function () { | ||
ItemContainer.prototype.checkTriggers = function () { | ||
if (this.triggers.hasOwnProperty(this.value)) { | ||
this.triggers[this.value](); | ||
this.triggers[this.value](this.value); | ||
} | ||
@@ -522,4 +512,4 @@ }; | ||
*/ | ||
ItemValue.prototype.checkModularity = function () { | ||
if (this.value.constructor !== Number || !this.modularity) { | ||
ItemContainer.prototype.checkModularity = function () { | ||
if (typeof this.value !== "number" || !this.modularity) { | ||
return; | ||
@@ -538,8 +528,8 @@ } | ||
*/ | ||
ItemValue.prototype.retrieveLocalStorage = function () { | ||
var value = this.itemsHolder.getLocalStorage()[this.itemsHolder.getPrefix() + this.key]; | ||
if (typeof value === "undefined" || value === "undefined") { | ||
ItemContainer.prototype.retrieveLocalStorage = function () { | ||
var value = this.settings.storage.getItem(this.settings.prefix + this.key); | ||
if (value === undefined || value === "undefined") { | ||
return undefined; | ||
} | ||
if (value.constructor !== String) { | ||
if (typeof value !== "string") { | ||
return value; | ||
@@ -549,5 +539,5 @@ } | ||
}; | ||
return ItemValue; | ||
return ItemContainer; | ||
}()); | ||
exports.ItemValue = ItemValue; | ||
exports.ItemContainer = ItemContainer; | ||
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), | ||
@@ -557,49 +547,3 @@ __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); | ||
/***/ }), | ||
/* 3 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Proliferates all members of the donor to the recipient recursively, as | ||
* a deep copy. | ||
* | ||
* @param recipient An object receiving the donor's members. | ||
* @param donor An object whose members are copied to recipient. | ||
* @param noOverride If recipient properties may be overriden (by | ||
* default, false). | ||
* @returns The recipient, which should have the donor proliferated onto it. | ||
*/ | ||
exports.proliferate = function (recipient, donor, noOverride) { | ||
// For each attribute of the donor: | ||
for (var i in donor) { | ||
if (!donor.hasOwnProperty(i)) { | ||
continue; | ||
} | ||
// If noOverride, don't override already existing properties | ||
if (noOverride && recipient.hasOwnProperty(i)) { | ||
continue; | ||
} | ||
// If it's an object, recurse on a new version of it | ||
var setting = donor[i]; | ||
if (typeof setting === "object") { | ||
if (!recipient.hasOwnProperty(i)) { | ||
recipient[i] = new setting.constructor(); | ||
} | ||
exports.proliferate(recipient[i], setting, noOverride); | ||
} | ||
else { | ||
// Regular primitives are easy to copy otherwise | ||
recipient[i] = setting; | ||
} | ||
} | ||
return recipient; | ||
}; | ||
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), | ||
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); | ||
/***/ }) | ||
/******/ ])});; |
var typedoc = typedoc || {}; | ||
typedoc.search = typedoc.search || {}; | ||
typedoc.search.data = {"kinds":{"1":"External module","64":"Function","128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method"},"rows":[{"id":0,"kind":1,"name":"\"createPlaceholderStorage\"","url":"modules/_createplaceholderstorage_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":64,"name":"createPlaceholderStorage","url":"modules/_createplaceholderstorage_.html#createplaceholderstorage","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"createPlaceholderStorage\""},{"id":2,"kind":1,"name":"\"IItemValue\"","url":"modules/_iitemvalue_.html","classes":"tsd-kind-external-module"},{"id":3,"kind":256,"name":"ITriggers","url":"interfaces/_iitemvalue_.itriggers.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemValue\""},{"id":4,"kind":256,"name":"IItemValueDefaults","url":"interfaces/_iitemvalue_.iitemvaluedefaults.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemValue\""},{"id":5,"kind":256,"name":"IItemValueSettings","url":"interfaces/_iitemvalue_.iitemvaluesettings.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemValue\""},{"id":6,"kind":1024,"name":"value","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#value","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":7,"kind":1024,"name":"valueDefault","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#valuedefault","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":8,"kind":1024,"name":"storeLocally","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#storelocally","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":9,"kind":1024,"name":"triggers","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#triggers","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":10,"kind":1024,"name":"minimum","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#minimum","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":11,"kind":1024,"name":"onMinimum","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#onminimum","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":12,"kind":1024,"name":"maximum","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#maximum","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":13,"kind":1024,"name":"onMaximum","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#onmaximum","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":14,"kind":1024,"name":"modularity","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#modularity","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":15,"kind":1024,"name":"onModular","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#onmodular","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":16,"kind":1024,"name":"transformGet","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#transformget","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":17,"kind":1024,"name":"transformSet","url":"interfaces/_iitemvalue_.iitemvaluesettings.html#transformset","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValueSettings"},{"id":18,"kind":256,"name":"IItemValue","url":"interfaces/_iitemvalue_.iitemvalue.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemValue\""},{"id":19,"kind":2048,"name":"getValue","url":"interfaces/_iitemvalue_.iitemvalue.html#getvalue","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValue"},{"id":20,"kind":2048,"name":"setValue","url":"interfaces/_iitemvalue_.iitemvalue.html#setvalue","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValue"},{"id":21,"kind":2048,"name":"update","url":"interfaces/_iitemvalue_.iitemvalue.html#update","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValue"},{"id":22,"kind":2048,"name":"updateLocalStorage","url":"interfaces/_iitemvalue_.iitemvalue.html#updatelocalstorage","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemValue\".IItemValue"},{"id":23,"kind":1,"name":"\"IItemsHoldr\"","url":"modules/_iitemsholdr_.html","classes":"tsd-kind-external-module"},{"id":24,"kind":256,"name":"IItems","url":"interfaces/_iitemsholdr_.iitems.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":25,"kind":256,"name":"IItemsHoldrSettings","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":26,"kind":1024,"name":"values","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#values","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":27,"kind":1024,"name":"allowNewItems","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#allownewitems","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":28,"kind":1024,"name":"autoSave","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#autosave","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":29,"kind":1024,"name":"localStorage","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#localstorage","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":30,"kind":1024,"name":"prefix","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#prefix","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":31,"kind":1024,"name":"defaults","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#defaults","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":32,"kind":256,"name":"IItemsHoldr","url":"interfaces/_iitemsholdr_.iitemsholdr.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":33,"kind":2048,"name":"getValues","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getvalues","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":34,"kind":2048,"name":"getDefaults","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getdefaults","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":35,"kind":2048,"name":"getLocalStorage","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getlocalstorage","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":36,"kind":2048,"name":"getAutoSave","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getautosave","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":37,"kind":2048,"name":"getPrefix","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getprefix","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":38,"kind":2048,"name":"getKeys","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getkeys","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":39,"kind":2048,"name":"getItemKeys","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getitemkeys","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":40,"kind":2048,"name":"getItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getitem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":41,"kind":2048,"name":"getObject","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getobject","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":42,"kind":2048,"name":"hasKey","url":"interfaces/_iitemsholdr_.iitemsholdr.html#haskey","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":43,"kind":2048,"name":"exportItems","url":"interfaces/_iitemsholdr_.iitemsholdr.html#exportitems","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":44,"kind":2048,"name":"addItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#additem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":45,"kind":2048,"name":"removeItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#removeitem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":46,"kind":2048,"name":"clear","url":"interfaces/_iitemsholdr_.iitemsholdr.html#clear","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":47,"kind":2048,"name":"setItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#setitem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":48,"kind":2048,"name":"increase","url":"interfaces/_iitemsholdr_.iitemsholdr.html#increase","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":49,"kind":2048,"name":"decrease","url":"interfaces/_iitemsholdr_.iitemsholdr.html#decrease","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":50,"kind":2048,"name":"toggle","url":"interfaces/_iitemsholdr_.iitemsholdr.html#toggle","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":51,"kind":2048,"name":"checkExistence","url":"interfaces/_iitemsholdr_.iitemsholdr.html#checkexistence","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":52,"kind":2048,"name":"saveItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#saveitem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":53,"kind":2048,"name":"saveAll","url":"interfaces/_iitemsholdr_.iitemsholdr.html#saveall","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":54,"kind":1,"name":"\"proliferate\"","url":"modules/_proliferate_.html","classes":"tsd-kind-external-module"},{"id":55,"kind":64,"name":"proliferate","url":"modules/_proliferate_.html#proliferate","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"proliferate\""},{"id":56,"kind":1,"name":"\"ItemValue\"","url":"modules/_itemvalue_.html","classes":"tsd-kind-external-module"},{"id":57,"kind":128,"name":"ItemValue","url":"classes/_itemvalue_.itemvalue.html","classes":"tsd-kind-class tsd-parent-kind-external-module","parent":"\"ItemValue\""},{"id":58,"kind":1024,"name":"itemsHolder","url":"classes/_itemvalue_.itemvalue.html#itemsholder","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":59,"kind":1024,"name":"key","url":"classes/_itemvalue_.itemvalue.html#key","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":60,"kind":1024,"name":"valueDefault","url":"classes/_itemvalue_.itemvalue.html#valuedefault","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":61,"kind":1024,"name":"storeLocally","url":"classes/_itemvalue_.itemvalue.html#storelocally","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":62,"kind":1024,"name":"triggers","url":"classes/_itemvalue_.itemvalue.html#triggers","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":63,"kind":1024,"name":"minimum","url":"classes/_itemvalue_.itemvalue.html#minimum","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":64,"kind":1024,"name":"onMinimum","url":"classes/_itemvalue_.itemvalue.html#onminimum","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":65,"kind":1024,"name":"maximum","url":"classes/_itemvalue_.itemvalue.html#maximum","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":66,"kind":1024,"name":"onMaximum","url":"classes/_itemvalue_.itemvalue.html#onmaximum","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":67,"kind":1024,"name":"modularity","url":"classes/_itemvalue_.itemvalue.html#modularity","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":68,"kind":1024,"name":"onModular","url":"classes/_itemvalue_.itemvalue.html#onmodular","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":69,"kind":1024,"name":"transformGet","url":"classes/_itemvalue_.itemvalue.html#transformget","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":70,"kind":1024,"name":"transformSet","url":"classes/_itemvalue_.itemvalue.html#transformset","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":71,"kind":1024,"name":"value","url":"classes/_itemvalue_.itemvalue.html#value","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":72,"kind":512,"name":"constructor","url":"classes/_itemvalue_.itemvalue.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"ItemValue\".ItemValue"},{"id":73,"kind":2048,"name":"getValue","url":"classes/_itemvalue_.itemvalue.html#getvalue","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemValue\".ItemValue"},{"id":74,"kind":2048,"name":"setValue","url":"classes/_itemvalue_.itemvalue.html#setvalue","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemValue\".ItemValue"},{"id":75,"kind":2048,"name":"update","url":"classes/_itemvalue_.itemvalue.html#update","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemValue\".ItemValue"},{"id":76,"kind":2048,"name":"updateLocalStorage","url":"classes/_itemvalue_.itemvalue.html#updatelocalstorage","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemValue\".ItemValue"},{"id":77,"kind":2048,"name":"checkTriggers","url":"classes/_itemvalue_.itemvalue.html#checktriggers","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":78,"kind":2048,"name":"checkModularity","url":"classes/_itemvalue_.itemvalue.html#checkmodularity","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":79,"kind":2048,"name":"retrieveLocalStorage","url":"classes/_itemvalue_.itemvalue.html#retrievelocalstorage","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ItemValue\".ItemValue"},{"id":80,"kind":1,"name":"\"ItemsHoldr\"","url":"modules/_itemsholdr_.html","classes":"tsd-kind-external-module"},{"id":81,"kind":128,"name":"ItemsHoldr","url":"classes/_itemsholdr_.itemsholdr.html","classes":"tsd-kind-class tsd-parent-kind-external-module","parent":"\"ItemsHoldr\""},{"id":82,"kind":1024,"name":"settings","url":"classes/_itemsholdr_.itemsholdr.html#settings","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":83,"kind":1024,"name":"defaults","url":"classes/_itemsholdr_.itemsholdr.html#defaults","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":84,"kind":1024,"name":"localStorage","url":"classes/_itemsholdr_.itemsholdr.html#localstorage","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":85,"kind":1024,"name":"prefix","url":"classes/_itemsholdr_.itemsholdr.html#prefix","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":86,"kind":1024,"name":"allowNewItems","url":"classes/_itemsholdr_.itemsholdr.html#allownewitems","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":87,"kind":1024,"name":"items","url":"classes/_itemsholdr_.itemsholdr.html#items","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":88,"kind":1024,"name":"itemKeys","url":"classes/_itemsholdr_.itemsholdr.html#itemkeys","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":89,"kind":1024,"name":"autoSave","url":"classes/_itemsholdr_.itemsholdr.html#autosave","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":90,"kind":512,"name":"constructor","url":"classes/_itemsholdr_.itemsholdr.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":91,"kind":2048,"name":"key","url":"classes/_itemsholdr_.itemsholdr.html#key","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":92,"kind":2048,"name":"getValues","url":"classes/_itemsholdr_.itemsholdr.html#getvalues","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":93,"kind":2048,"name":"getDefaults","url":"classes/_itemsholdr_.itemsholdr.html#getdefaults","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":94,"kind":2048,"name":"getLocalStorage","url":"classes/_itemsholdr_.itemsholdr.html#getlocalstorage","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":95,"kind":2048,"name":"getAutoSave","url":"classes/_itemsholdr_.itemsholdr.html#getautosave","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":96,"kind":2048,"name":"getPrefix","url":"classes/_itemsholdr_.itemsholdr.html#getprefix","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":97,"kind":2048,"name":"getKeys","url":"classes/_itemsholdr_.itemsholdr.html#getkeys","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":98,"kind":2048,"name":"getItemKeys","url":"classes/_itemsholdr_.itemsholdr.html#getitemkeys","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":99,"kind":2048,"name":"getItem","url":"classes/_itemsholdr_.itemsholdr.html#getitem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":100,"kind":2048,"name":"getObject","url":"classes/_itemsholdr_.itemsholdr.html#getobject","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":101,"kind":2048,"name":"hasKey","url":"classes/_itemsholdr_.itemsholdr.html#haskey","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":102,"kind":2048,"name":"exportItems","url":"classes/_itemsholdr_.itemsholdr.html#exportitems","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":103,"kind":2048,"name":"addItem","url":"classes/_itemsholdr_.itemsholdr.html#additem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":104,"kind":2048,"name":"removeItem","url":"classes/_itemsholdr_.itemsholdr.html#removeitem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":105,"kind":2048,"name":"clear","url":"classes/_itemsholdr_.itemsholdr.html#clear","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":106,"kind":2048,"name":"setItem","url":"classes/_itemsholdr_.itemsholdr.html#setitem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":107,"kind":2048,"name":"increase","url":"classes/_itemsholdr_.itemsholdr.html#increase","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":108,"kind":2048,"name":"decrease","url":"classes/_itemsholdr_.itemsholdr.html#decrease","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":109,"kind":2048,"name":"toggle","url":"classes/_itemsholdr_.itemsholdr.html#toggle","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":110,"kind":2048,"name":"toggleAutoSave","url":"classes/_itemsholdr_.itemsholdr.html#toggleautosave","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":111,"kind":2048,"name":"checkExistence","url":"classes/_itemsholdr_.itemsholdr.html#checkexistence","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":112,"kind":2048,"name":"saveItem","url":"classes/_itemsholdr_.itemsholdr.html#saveitem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":113,"kind":2048,"name":"saveAll","url":"classes/_itemsholdr_.itemsholdr.html#saveall","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":114,"kind":1,"name":"\"fakes\"","url":"modules/_fakes_.html","classes":"tsd-kind-external-module"},{"id":115,"kind":64,"name":"stubItemValue","url":"modules/_fakes_.html#stubitemvalue","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"fakes\""},{"id":116,"kind":64,"name":"stubItemsHoldr","url":"modules/_fakes_.html#stubitemsholdr","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"fakes\""},{"id":117,"kind":64,"name":"stubItemValueSettings","url":"modules/_fakes_.html#stubitemvaluesettings","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"fakes\""},{"id":118,"kind":1,"name":"\"index\"","url":"modules/_index_.html","classes":"tsd-kind-external-module"},{"id":119,"kind":1,"name":"\"ItemsHoldr.test\"","url":"modules/_itemsholdr_test_.html","classes":"tsd-kind-external-module"},{"id":120,"kind":1,"name":"\"proliferate.test\"","url":"modules/_proliferate_test_.html","classes":"tsd-kind-external-module"}]}; | ||
typedoc.search.data = {"kinds":{"1":"External module","64":"Function","128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal","262144":"Accessor","4194304":"Type alias"},"rows":[{"id":0,"kind":1,"name":"\"createStorage\"","url":"modules/_createstorage_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":64,"name":"createStorage","url":"modules/_createstorage_.html#createstorage","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"createStorage\""},{"id":2,"kind":1,"name":"\"IItemsHoldr\"","url":"modules/_iitemsholdr_.html","classes":"tsd-kind-external-module"},{"id":3,"kind":256,"name":"ITriggers","url":"interfaces/_iitemsholdr_.itriggers.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":4,"kind":256,"name":"IItemValues","url":"interfaces/_iitemsholdr_.iitemvalues.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":5,"kind":256,"name":"IItemSettings","url":"interfaces/_iitemsholdr_.iitemsettings.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":6,"kind":1024,"name":"maximum","url":"interfaces/_iitemsholdr_.iitemsettings.html#maximum","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemSettings"},{"id":7,"kind":1024,"name":"onMaximum","url":"interfaces/_iitemsholdr_.iitemsettings.html#onmaximum","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemSettings"},{"id":8,"kind":1024,"name":"minimum","url":"interfaces/_iitemsholdr_.iitemsettings.html#minimum","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemSettings"},{"id":9,"kind":1024,"name":"onMinimum","url":"interfaces/_iitemsholdr_.iitemsettings.html#onminimum","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemSettings"},{"id":10,"kind":1024,"name":"modularity","url":"interfaces/_iitemsholdr_.iitemsettings.html#modularity","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemSettings"},{"id":11,"kind":1024,"name":"onModular","url":"interfaces/_iitemsholdr_.iitemsettings.html#onmodular","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemSettings"},{"id":12,"kind":1024,"name":"triggers","url":"interfaces/_iitemsholdr_.iitemsettings.html#triggers","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemSettings"},{"id":13,"kind":1024,"name":"valueDefault","url":"interfaces/_iitemsholdr_.iitemsettings.html#valuedefault","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemSettings"},{"id":14,"kind":256,"name":"IExportedItems","url":"interfaces/_iitemsholdr_.iexporteditems.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":15,"kind":256,"name":"IItemsHoldrSettings","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":16,"kind":1024,"name":"autoSave","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#autosave","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":17,"kind":1024,"name":"defaults","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#defaults","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":18,"kind":1024,"name":"prefix","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#prefix","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":19,"kind":1024,"name":"storage","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#storage","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":20,"kind":1024,"name":"values","url":"interfaces/_iitemsholdr_.iitemsholdrsettings.html#values","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldrSettings"},{"id":21,"kind":256,"name":"IItemsHoldr","url":"interfaces/_iitemsholdr_.iitemsholdr.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":22,"kind":1024,"name":"length","url":"interfaces/_iitemsholdr_.iitemsholdr.html#length","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":23,"kind":2048,"name":"key","url":"interfaces/_iitemsholdr_.iitemsholdr.html#key","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":24,"kind":2048,"name":"addItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#additem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":25,"kind":2048,"name":"getItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#getitem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":26,"kind":2048,"name":"removeItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#removeitem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":27,"kind":2048,"name":"setItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#setitem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":28,"kind":2048,"name":"increase","url":"interfaces/_iitemsholdr_.iitemsholdr.html#increase","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":29,"kind":2048,"name":"decrease","url":"interfaces/_iitemsholdr_.iitemsholdr.html#decrease","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":30,"kind":2048,"name":"toggle","url":"interfaces/_iitemsholdr_.iitemsholdr.html#toggle","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":31,"kind":2048,"name":"hasKey","url":"interfaces/_iitemsholdr_.iitemsholdr.html#haskey","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":32,"kind":2048,"name":"exportItems","url":"interfaces/_iitemsholdr_.iitemsholdr.html#exportitems","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":33,"kind":2048,"name":"clear","url":"interfaces/_iitemsholdr_.iitemsholdr.html#clear","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":34,"kind":2048,"name":"saveItem","url":"interfaces/_iitemsholdr_.iitemsholdr.html#saveitem","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":35,"kind":2048,"name":"saveAll","url":"interfaces/_iitemsholdr_.iitemsholdr.html#saveall","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IItemsHoldr\".IItemsHoldr"},{"id":36,"kind":4194304,"name":"IValueCallback","url":"modules/_iitemsholdr_.html#ivaluecallback","classes":"tsd-kind-type-alias tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":37,"kind":65536,"name":"__type","url":"modules/_iitemsholdr_.html#ivaluecallback.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"IItemsHoldr\".IValueCallback"},{"id":38,"kind":4194304,"name":"IValueTransform","url":"modules/_iitemsholdr_.html#ivaluetransform","classes":"tsd-kind-type-alias tsd-parent-kind-external-module","parent":"\"IItemsHoldr\""},{"id":39,"kind":65536,"name":"__type","url":"modules/_iitemsholdr_.html#ivaluetransform.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-has-type-parameter tsd-is-not-exported","parent":"\"IItemsHoldr\".IValueTransform"},{"id":40,"kind":1,"name":"\"proliferate\"","url":"modules/_proliferate_.html","classes":"tsd-kind-external-module"},{"id":41,"kind":64,"name":"proliferate","url":"modules/_proliferate_.html#proliferate","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"proliferate\""},{"id":42,"kind":1,"name":"\"ItemContainer\"","url":"modules/_itemcontainer_.html","classes":"tsd-kind-external-module"},{"id":43,"kind":256,"name":"IItemContainerSettings","url":"interfaces/_itemcontainer_.iitemcontainersettings.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"ItemContainer\""},{"id":44,"kind":1024,"name":"autoSave","url":"interfaces/_itemcontainer_.iitemcontainersettings.html#autosave","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"ItemContainer\".IItemContainerSettings"},{"id":45,"kind":1024,"name":"defaults","url":"interfaces/_itemcontainer_.iitemcontainersettings.html#defaults","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"ItemContainer\".IItemContainerSettings"},{"id":46,"kind":1024,"name":"prefix","url":"interfaces/_itemcontainer_.iitemcontainersettings.html#prefix","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"ItemContainer\".IItemContainerSettings"},{"id":47,"kind":1024,"name":"storage","url":"interfaces/_itemcontainer_.iitemcontainersettings.html#storage","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"ItemContainer\".IItemContainerSettings"},{"id":48,"kind":128,"name":"ItemContainer","url":"classes/_itemcontainer_.itemcontainer.html","classes":"tsd-kind-class tsd-parent-kind-external-module","parent":"\"ItemContainer\""},{"id":49,"kind":1024,"name":"settings","url":"classes/_itemcontainer_.itemcontainer.html#settings","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":50,"kind":1024,"name":"key","url":"classes/_itemcontainer_.itemcontainer.html#key","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":51,"kind":1024,"name":"valueDefault","url":"classes/_itemcontainer_.itemcontainer.html#valuedefault","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":52,"kind":1024,"name":"triggers","url":"classes/_itemcontainer_.itemcontainer.html#triggers","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":53,"kind":1024,"name":"minimum","url":"classes/_itemcontainer_.itemcontainer.html#minimum","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":54,"kind":1024,"name":"onMinimum","url":"classes/_itemcontainer_.itemcontainer.html#onminimum","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":55,"kind":1024,"name":"maximum","url":"classes/_itemcontainer_.itemcontainer.html#maximum","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":56,"kind":1024,"name":"onMaximum","url":"classes/_itemcontainer_.itemcontainer.html#onmaximum","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":57,"kind":1024,"name":"modularity","url":"classes/_itemcontainer_.itemcontainer.html#modularity","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":58,"kind":1024,"name":"onModular","url":"classes/_itemcontainer_.itemcontainer.html#onmodular","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":59,"kind":1024,"name":"value","url":"classes/_itemcontainer_.itemcontainer.html#value","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":60,"kind":512,"name":"constructor","url":"classes/_itemcontainer_.itemcontainer.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"ItemContainer\".ItemContainer"},{"id":61,"kind":2048,"name":"getValue","url":"classes/_itemcontainer_.itemcontainer.html#getvalue","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemContainer\".ItemContainer"},{"id":62,"kind":2048,"name":"setValue","url":"classes/_itemcontainer_.itemcontainer.html#setvalue","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemContainer\".ItemContainer"},{"id":63,"kind":2048,"name":"update","url":"classes/_itemcontainer_.itemcontainer.html#update","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemContainer\".ItemContainer"},{"id":64,"kind":2048,"name":"updateStorage","url":"classes/_itemcontainer_.itemcontainer.html#updatestorage","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemContainer\".ItemContainer"},{"id":65,"kind":2048,"name":"checkTriggers","url":"classes/_itemcontainer_.itemcontainer.html#checktriggers","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":66,"kind":2048,"name":"checkModularity","url":"classes/_itemcontainer_.itemcontainer.html#checkmodularity","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":67,"kind":2048,"name":"retrieveLocalStorage","url":"classes/_itemcontainer_.itemcontainer.html#retrievelocalstorage","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ItemContainer\".ItemContainer"},{"id":68,"kind":1,"name":"\"ItemsHoldr\"","url":"modules/_itemsholdr_.html","classes":"tsd-kind-external-module"},{"id":69,"kind":256,"name":"IItems","url":"interfaces/_itemsholdr_.iitems.html","classes":"tsd-kind-interface tsd-parent-kind-external-module tsd-is-not-exported","parent":"\"ItemsHoldr\""},{"id":70,"kind":128,"name":"ItemsHoldr","url":"classes/_itemsholdr_.itemsholdr.html","classes":"tsd-kind-class tsd-parent-kind-external-module","parent":"\"ItemsHoldr\""},{"id":71,"kind":1024,"name":"settings","url":"classes/_itemsholdr_.itemsholdr.html#settings","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":72,"kind":1024,"name":"prefix","url":"classes/_itemsholdr_.itemsholdr.html#prefix","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":73,"kind":1024,"name":"storage","url":"classes/_itemsholdr_.itemsholdr.html#storage","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":74,"kind":1024,"name":"values","url":"classes/_itemsholdr_.itemsholdr.html#values","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":75,"kind":1024,"name":"containerSettings","url":"classes/_itemsholdr_.itemsholdr.html#containersettings","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":76,"kind":1024,"name":"autoSave","url":"classes/_itemsholdr_.itemsholdr.html#autosave","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":77,"kind":1024,"name":"itemKeys","url":"classes/_itemsholdr_.itemsholdr.html#itemkeys","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":78,"kind":1024,"name":"items","url":"classes/_itemsholdr_.itemsholdr.html#items","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":79,"kind":512,"name":"constructor","url":"classes/_itemsholdr_.itemsholdr.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":80,"kind":262144,"name":"length","url":"classes/_itemsholdr_.itemsholdr.html#length","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":81,"kind":2048,"name":"key","url":"classes/_itemsholdr_.itemsholdr.html#key","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":82,"kind":2048,"name":"addItem","url":"classes/_itemsholdr_.itemsholdr.html#additem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":83,"kind":2048,"name":"getItem","url":"classes/_itemsholdr_.itemsholdr.html#getitem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":84,"kind":2048,"name":"removeItem","url":"classes/_itemsholdr_.itemsholdr.html#removeitem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":85,"kind":2048,"name":"setItem","url":"classes/_itemsholdr_.itemsholdr.html#setitem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":86,"kind":2048,"name":"increase","url":"classes/_itemsholdr_.itemsholdr.html#increase","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":87,"kind":2048,"name":"decrease","url":"classes/_itemsholdr_.itemsholdr.html#decrease","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":88,"kind":2048,"name":"toggle","url":"classes/_itemsholdr_.itemsholdr.html#toggle","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":89,"kind":2048,"name":"hasKey","url":"classes/_itemsholdr_.itemsholdr.html#haskey","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":90,"kind":2048,"name":"exportItems","url":"classes/_itemsholdr_.itemsholdr.html#exportitems","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":91,"kind":2048,"name":"clear","url":"classes/_itemsholdr_.itemsholdr.html#clear","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":92,"kind":2048,"name":"saveItem","url":"classes/_itemsholdr_.itemsholdr.html#saveitem","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":93,"kind":2048,"name":"saveAll","url":"classes/_itemsholdr_.itemsholdr.html#saveall","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":94,"kind":2048,"name":"checkExistence","url":"classes/_itemsholdr_.itemsholdr.html#checkexistence","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ItemsHoldr\".ItemsHoldr"},{"id":95,"kind":1,"name":"\"fakes\"","url":"modules/_fakes_.html","classes":"tsd-kind-external-module"},{"id":96,"kind":64,"name":"stubItemsHoldr","url":"modules/_fakes_.html#stubitemsholdr","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"fakes\""},{"id":97,"kind":64,"name":"stubItemValueSettings","url":"modules/_fakes_.html#stubitemvaluesettings","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"fakes\""},{"id":98,"kind":1,"name":"\"index\"","url":"modules/_index_.html","classes":"tsd-kind-external-module"},{"id":99,"kind":1,"name":"\"ItemsHoldr.test\"","url":"modules/_itemsholdr_test_.html","classes":"tsd-kind-external-module"},{"id":100,"kind":1,"name":"\"proliferate.test\"","url":"modules/_proliferate_test_.html","classes":"tsd-kind-external-module"}]}; |
@@ -10,9 +10,10 @@ { | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
}, | ||
"description": "Cache-based wrapper around localStorage.", | ||
"devDependencies": { | ||
"@types/chai": "^4.0.4", | ||
"@types/lolex": "^1.5.32", | ||
"@types/mocha": "^2.2.44", | ||
"@types/sinon": "^4.0.0", | ||
"@types/lolex": "^2.1.1", | ||
"@types/mocha": "^2.2.46", | ||
"@types/sinon": "^4.1.3", | ||
"@types/sinon-chai": "^2.7.29", | ||
@@ -22,11 +23,12 @@ "chai": "^4.1.2", | ||
"lolex": "^2.3.0", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^4.0.1", | ||
"mocha-headless-chrome": "^1.7.1", | ||
"mocha-headless-chrome": "^1.8.1", | ||
"requirejs": "^2.3.5", | ||
"run-for-every-file": "^1.1.0", | ||
"shenanigans-manager": "^0.2.5", | ||
"sinon": "^4.1.2", | ||
"shenanigans-manager": "^0.2.20", | ||
"sinon": "^4.1.5", | ||
"sinon-chai": "^2.14.0", | ||
"tslint": "5.8.0", | ||
"tsutils": "^2.14.0", | ||
"tslint": "5.9.1", | ||
"tsutils": "^2.17.0", | ||
"typedoc": "^0.9.0", | ||
@@ -55,8 +57,9 @@ "typescript": "^2.6.2", | ||
"src:tsc": "tsc -p .", | ||
"src:tslint": "tslint -c tslint.json -e ./node_modules/**/*.ts* -p tsconfig.json -t stylish", | ||
"src:tslint": "tslint -c tslint.json -p tsconfig.json -t stylish", | ||
"test": "npm run test:setup && npm run test:run", | ||
"test:run": "mocha-headless-chrome --file test/index.html", | ||
"test:setup": "npm run test:setup:copy && npm run test:setup:html && npm run test:setup:tsc", | ||
"test:setup": "npm run test:setup:dir && npm run test:setup:copy && npm run test:setup:html && npm run test:setup:tsc", | ||
"test:setup:copy": "npm run test:setup:copy:default", | ||
"test:setup:copy:default": "run-for-every-file --dot --src \"node_modules/shenanigans-manager/setup/test/\" --file \"**/*\" --run \"mustache package.json {{src-file}} ./test/{{file}}\" --dest \".\" --only-files", | ||
"test:setup:dir": "mkdirp test", | ||
"test:setup:html": "shenanigans-manager generate-test-html", | ||
@@ -71,3 +74,3 @@ "test:setup:tsc": "tsc -p test", | ||
"types": "./src/index.d.ts", | ||
"version": "0.7.3" | ||
} | ||
"version": "0.7.4" | ||
} |
515
README.md
<!-- {{Top}} --> | ||
# ItemsHoldr | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/FullScreenShenanigans/ItemsHoldr.svg)](https://greenkeeper.io/) | ||
[![Build Status](https://travis-ci.org/FullScreenShenanigans/ItemsHoldr.svg?branch=master)](https://travis-ci.org/FullScreenShenanigans/ItemsHoldr) | ||
@@ -9,8 +10,520 @@ [![NPM version](https://badge.fury.io/js/itemsholdr.svg)](http://badge.fury.io/js/itemsholdr) | ||
ItemsHoldr instances intentionally implement the DOM `Storage` interface _(except for the hacky string- and number-based indexing)_. | ||
You can use them wherever you would use `localStorage`. | ||
ItemsHoldr adds a layer of caching and value-based hooks that makes it useful for applications where state isn't always saved immediately. | ||
It also defaults values to `undefined` instead of `null` for sanity. | ||
## Usage | ||
### Constructor | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.setItem("name", "Blue"); | ||
itemsHolder.getItem("name"); // "Blue" | ||
``` | ||
#### `autoSave` | ||
Whether values should be saved immediately upon being set. | ||
An internal reference to a storage container is kept that defaults to `localStorage`. | ||
Keys won't be saved to that container until `.saveItem(key)` or `saveAll()` are called. | ||
Providing `autoSave` changes that behavior to always save the items to the internal container. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
autoSave: true, | ||
}); | ||
itemsHolder.setItem("name", "Blue"); | ||
localStorage.getItem("name"); // "Blue" | ||
``` | ||
#### `defaults` | ||
Default attributes for item values. | ||
These are applied to all items, and will be overriden per item by an item-specific `values`. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
defaults: { | ||
valueDefault: "Red", | ||
}, | ||
}); | ||
itemsHolder.getItem("name"); // "Red" | ||
``` | ||
#### `prefix` | ||
Prefix to add before keys in storage. | ||
Useful to distinguish keys from other stored items in the same storage container, such as a webpage's `localStorage`. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
prefix: "MyState::", | ||
}); | ||
itemsHolder.saveItem("name", "Red"); | ||
Object.keys(localStorage); // ["MyState::name"] | ||
``` | ||
#### `storage` | ||
Storage object to use instead of the global localStorage. | ||
This can be anything that satisfies the `Storage` API and acts like `localStorage`. | ||
ItemsHoldr exposes a `createStorage` that can be useful for testing. | ||
```typescript | ||
import { createStorage, ItemsHoldr } from "itemsholdr"; | ||
const storage = createStorage(); | ||
const itemsHolder = new ItemsHoldr({ | ||
storage, | ||
}); | ||
itemsHolder.saveItem("name", "Red"); | ||
storage.getItem("name"); // "Red" | ||
storage.name; // "Red" | ||
``` | ||
#### `values` | ||
Initial settings for item values to store. | ||
These are factored on top of `defaults` for created items. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
values: { | ||
name: { | ||
valueDefault: "Blue", | ||
}, | ||
}, | ||
}); | ||
itemsHolder.getItem("name"); // "Blue" | ||
``` | ||
--- | ||
### Value Settings | ||
Declaring items with `defaults` and/or `values` allows for individual settings applied to that item. | ||
These are also applied when using `.addItem(name, settings)`. | ||
#### `maximum` | ||
Maximum value the item may equal if a number. | ||
If set to something higher, it will immediately be set to the `maximum`. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
values: { | ||
coins: { | ||
maximum: 100, | ||
}, | ||
}, | ||
}); | ||
itemsHolder.setItem("coins", 101); | ||
itemsHolder.getItem("coins"); // 100 | ||
``` | ||
#### `onMaximum` | ||
Callback for when the value reaches the maximum value. | ||
Takes in the value _before_ capped to the the `maximum`. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
values: { | ||
coins: { | ||
maximum: 100, | ||
onMaximum: (coins) => { | ||
console.log("Got", coins, "coins."); | ||
}, | ||
}, | ||
}, | ||
}); | ||
// Got 101 coins. | ||
itemsHolder.setItem("coins", 101); | ||
itemsHolder.getItem("coins"); // 100 | ||
``` | ||
#### `minimum` | ||
Minimum value the item may equal if a number. | ||
If set to something lower, it will immediately be set to the `minimum`. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
values: { | ||
lives: { | ||
minimum: 100, | ||
}, | ||
}, | ||
}); | ||
itemsHolder.setItem("lives", -1); | ||
itemsHolder.getItem("lives"); // 0 | ||
``` | ||
#### `onMinimum` | ||
Callback for when the value reaches the minimum value. | ||
Takes in the value _before_ floored to the the `minimum`. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
values: { | ||
lives: { | ||
minimum: 0, | ||
onMinimum: (lives) => { | ||
console.log("Dropped to", lives, "lives."); | ||
}, | ||
}, | ||
}, | ||
}); | ||
// Dropped to -1 lives. | ||
itemsHolder.setItem("lives", -1); | ||
itemsHolder.getItem("lives"); // 0 | ||
``` | ||
#### `modularity` | ||
Maximum number to modulo the value against if a number. | ||
If set to something higher, it will be reduced by `modularity` until less than. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
values: { | ||
coins: { | ||
modularity: 100, | ||
}, | ||
}, | ||
}); | ||
itemsHolder.setItem("coins", 250); | ||
itemsHolder.getItem("coins"); // 50 | ||
``` | ||
#### `onModular` | ||
Callback for when the value reaches modularity. | ||
Unlike `onMaximum`, this will be repeatedly called while the value is greater, decreasing by `modularity` each time. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
values: { | ||
coins: { | ||
modularity: 100, | ||
onModular: (reduced) => { | ||
console.log("Reduced", coins, "coins."); | ||
}, | ||
}, | ||
}, | ||
}); | ||
// Reduced 100 coins. | ||
// Reduced 50 coins. | ||
itemsHolder.setItem("coins", 250); | ||
itemsHolder.getItem("coins"); // 50 | ||
``` | ||
#### `triggers` | ||
A mapping of values to callbacks that should be triggered when the value is equal to them. | ||
These all take in the item's value. | ||
```typescript | ||
const logForSpeed = (speed: number) => { | ||
console.log("Achieved", speed, "speed."); | ||
}; | ||
const itemsHolder = new ItemsHoldr({ | ||
values: { | ||
speed: { | ||
triggers: { | ||
0: logForSpeed, | ||
10: logForSpeed, | ||
}, | ||
}, | ||
}, | ||
}); | ||
// Achieved 0 speed. | ||
itemsHolder.setItem("coins", 0); | ||
itemsHolder.setItem("coins", 5); | ||
// Achieved 10 speed. | ||
itemsHolder.setItem("coins", 10); | ||
``` | ||
#### `valueDefault` | ||
An initial value to use if before any is set. | ||
Will be overriden by what's in `storage` if `storeLocally` is true. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
values: { | ||
name: { | ||
valueDefault: "Blue", | ||
}, | ||
}, | ||
}); | ||
itemsHolder.getItem("name"); // "Blue" | ||
``` | ||
--- | ||
### `addItem` | ||
Parameters: | ||
* `name: string`: Unique key to store the item under. | ||
* `settings: Object` _(optional)_: Any additional settings for the item. | ||
Adds a new item to storage. | ||
If an existing item exists under the same, its settings are discarded. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.addItem("name", { | ||
valueDefault: "Blue", | ||
}); | ||
itemsHolder.getItem("name"); // "Blue" | ||
``` | ||
### `getItem` | ||
Parameters: | ||
* `key: string`: Key of an item. | ||
Gets the value under the name. | ||
Unlike `localStorage`, this will throw an error if the item doesn't exist. | ||
Use `hasKey` if you want to check whether an item exists. | ||
### `removeItem` | ||
Parameters: | ||
* `key: string`: Key of an item. | ||
Removes the item under that key from storage. | ||
If `getItem` is called after `removeItem` with the same key, it's as if the item was never added in the first place. | ||
Any settings passed into the constructor will be re-applied. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
defaults: { | ||
valueDefault: "Blue", | ||
}, | ||
}); | ||
itemsHolder.setItem("name", "Blue"); | ||
itemsHolder.removeItem("name"); | ||
itemsHolder.getItem("name"); // "Red" | ||
``` | ||
### `setItem` | ||
Parameters: | ||
* `key: string`: Key of an item. | ||
Sets the value of an item. | ||
If the item doesn't yet exist, it's created. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.setItem("name", "Blue"); | ||
itemsHolder.getItem("name"); // "Blue" | ||
``` | ||
### `increase` | ||
Parameters: | ||
* `key: string`: Key of an item. | ||
* `amount: number | string` Amount to increase by (by default, `1`). | ||
Increases the value of an item as a number or string. | ||
This uses the native `+` operator regardless of the value type. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.setItem("coins", 7); | ||
itemsHolder.increase("coins", 3); | ||
itemsHolder.getItem("coins"); // 10 | ||
``` | ||
### `increase` | ||
Parameters: | ||
* `key: string`: Key of an item. | ||
* `amount: number` Amount to decreases by (by default, `1`). | ||
Decreases the value of an item as a number. | ||
This uses the native `-` operator regardless of the value type. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.setItem("coins", 7); | ||
itemsHolder.decrease("coins", 3); | ||
itemsHolder.getItem("coins"); // 4 | ||
``` | ||
### `toggle` | ||
Parameters: | ||
* `key: string`: Key of an item. | ||
Toggles whether an item is true or false. | ||
This evaluates the item in a ternary for truthiness. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.setItem("alive", false); | ||
itemsHolder.toggle("alive"); | ||
itemsHolder.getItem("alive"); // true | ||
``` | ||
### `hasKey` | ||
Parameters: | ||
* `key: string`: Key of an item. | ||
Gets whether an item exists under the key. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.setItem("alive", false); | ||
itemsHolder.hasKey("alive"); // true | ||
itemsHolder.hasKey("unknown"); // false | ||
``` | ||
### `exportItems` | ||
Gets a summary of keys and their values. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.setItem("alive", false); | ||
itemsHolder.setItem("coins", 10); | ||
itemsHolder.setItem("name", "Blue"); | ||
/* | ||
{ | ||
alive: false, | ||
coins: 10, | ||
name: "Blue", | ||
} | ||
*/ | ||
itemsHolder.exportItems(); | ||
``` | ||
### `clear` | ||
Completely clears all items. | ||
This is equivalent to calling `removeItem` on all keys. | ||
Any settings passed into the constructor will be re-applied. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr({ | ||
defaults: { | ||
valueDefault: "Blue", | ||
}, | ||
}); | ||
itemsHolder.setItem("name", "Blue"); | ||
itemsHolder.clear(); | ||
itemsHolder.getItem("name"); // "Red" | ||
``` | ||
### `saveItem` | ||
Parameters: | ||
* `key: string`: Name of an item. | ||
Manually saves an item's value to storage, ignoring `autoSave` settings. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.setItem("name", "Blue"); | ||
localStorage.getItem("name"); // null | ||
itemsHolder.saveItem("name"); | ||
localStorage.getItem("name"); // "Blue" | ||
``` | ||
### `saveAll` | ||
Manually saves all items to storage, ignoring `autoSave` settings. | ||
```typescript | ||
const itemsHolder = new ItemsHoldr(); | ||
itemsHolder.setItem("name", "Blue"); | ||
localStorage.getItem("name"); // null | ||
itemsHolder.saveAll(); | ||
localStorage.getItem("name"); // "Blue" | ||
``` | ||
<!-- {{Development}} --> | ||
## Development | ||
After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo/): | ||
``` | ||
git clone https://github.com/FullScreenShenanigans/ItemsHoldr | ||
git clone https://github.com/<your-name-here>/ItemsHoldr | ||
cd ItemsHoldr | ||
npm install | ||
npm run setup | ||
@@ -17,0 +530,0 @@ npm run verify |
@@ -1,15 +0,13 @@ | ||
import { IItemsHoldr, IItemsHoldrSettings } from "./IItemsHoldr"; | ||
import { IItemValue } from "./IItemValue"; | ||
import { IItemsHoldrSettings } from "./IItemsHoldr"; | ||
import { ItemsHoldr } from "./ItemsHoldr"; | ||
/** | ||
* @param itemsHolder ItemsHolder object. | ||
* @param key Key for the item. | ||
* @param settings Settings for the ItemValue. | ||
* @returns An ItemValue instance. | ||
*/ | ||
export declare const stubItemValue: (itemsHolder: IItemsHoldr, key: string, settings?: any) => IItemValue; | ||
/** | ||
* Creates a stub ItemsHoldr for testing. | ||
* | ||
* @param settings Settings for the ItemsHoldr. | ||
* @returns An ItemsHoldr instance. | ||
* @returns Stub ItemsHoldr and its storage. | ||
*/ | ||
export declare const stubItemsHoldr: (settings?: IItemsHoldrSettings | undefined) => IItemsHoldr; | ||
export declare const stubItemsHoldr: (settings?: IItemsHoldrSettings | undefined) => { | ||
itemsHolder: ItemsHoldr; | ||
storage: Storage; | ||
}; | ||
/** | ||
@@ -16,0 +14,0 @@ * @returns An object with a valueDefault property for ItemValue object instantiation. |
@@ -1,19 +0,23 @@ | ||
define(["require", "exports", "./ItemsHoldr", "./ItemValue"], function (require, exports, ItemsHoldr_1, ItemValue_1) { | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
define(["require", "exports", "./createStorage", "./ItemsHoldr"], function (require, exports, createStorage_1, ItemsHoldr_1) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* @param itemsHolder ItemsHolder object. | ||
* @param key Key for the item. | ||
* @param settings Settings for the ItemValue. | ||
* @returns An ItemValue instance. | ||
*/ | ||
exports.stubItemValue = function (itemsHolder, key, settings) { | ||
return new ItemValue_1.ItemValue(itemsHolder, key, settings); | ||
}; | ||
/** | ||
* Creates a stub ItemsHoldr for testing. | ||
* | ||
* @param settings Settings for the ItemsHoldr. | ||
* @returns An ItemsHoldr instance. | ||
* @returns Stub ItemsHoldr and its storage. | ||
*/ | ||
exports.stubItemsHoldr = function (settings) { | ||
return new ItemsHoldr_1.ItemsHoldr(settings); | ||
var storage = createStorage_1.createStorage(); | ||
settings = __assign({ storage: storage }, settings); | ||
var itemsHolder = new ItemsHoldr_1.ItemsHoldr(settings); | ||
return { itemsHolder: itemsHolder, storage: storage }; | ||
}; | ||
@@ -20,0 +24,0 @@ /** |
@@ -1,22 +0,24 @@ | ||
import { IItemsHoldr, IItemsHoldrSettings } from "./IItemsHoldr"; | ||
import { IItemValue } from "./IItemValue"; | ||
import { createStorage } from "./createStorage"; | ||
import { IItemsHoldrSettings } from "./IItemsHoldr"; | ||
import { ItemsHoldr } from "./ItemsHoldr"; | ||
import { ItemValue } from "./ItemValue"; | ||
/** | ||
* @param itemsHolder ItemsHolder object. | ||
* @param key Key for the item. | ||
* @param settings Settings for the ItemValue. | ||
* @returns An ItemValue instance. | ||
*/ | ||
export const stubItemValue = (itemsHolder: IItemsHoldr, key: string, settings?: any): IItemValue => | ||
new ItemValue(itemsHolder, key, settings); | ||
/** | ||
* Creates a stub ItemsHoldr for testing. | ||
* | ||
* @param settings Settings for the ItemsHoldr. | ||
* @returns An ItemsHoldr instance. | ||
* @returns Stub ItemsHoldr and its storage. | ||
*/ | ||
export const stubItemsHoldr = (settings?: IItemsHoldrSettings): IItemsHoldr => | ||
new ItemsHoldr(settings); | ||
export const stubItemsHoldr = (settings?: IItemsHoldrSettings) => { | ||
const storage = createStorage(); | ||
settings = { | ||
storage, | ||
...settings, | ||
}; | ||
const itemsHolder = new ItemsHoldr(settings); | ||
return { itemsHolder, storage }; | ||
}; | ||
/** | ||
@@ -23,0 +25,0 @@ * @returns An object with a valueDefault property for ItemValue object instantiation. |
@@ -1,98 +0,127 @@ | ||
import { IItemValue, IItemValueDefaults } from "./IItemValue"; | ||
/** | ||
* A container to hold ItemValue objects, keyed by name. | ||
* Called when an item equals an interesting value. | ||
* | ||
* @template TValue Type of the item's value. | ||
* @param value Interesting value of an item. | ||
*/ | ||
export interface IItems { | ||
[i: string]: IItemValue; | ||
export declare type IValueCallback<TValue = any> = (value: TValue) => void; | ||
/** | ||
* Transforms an item's value. | ||
* | ||
* @template TValue Type of the item's value. | ||
* @param value Value of an item. | ||
* @returns Transformed value of the item. | ||
*/ | ||
export declare type IValueTransform = <TValue = any>(value: TValue) => TValue; | ||
/** | ||
* A mapping of item values to triggered callbacks. | ||
*/ | ||
export interface ITriggers { | ||
[i: string]: IValueCallback; | ||
[j: number]: IValueCallback; | ||
} | ||
/** | ||
* Settings to initialize a new instance of the IItemsHoldr interface. | ||
* Settings for item values, keyed by item key. | ||
*/ | ||
export interface IItemsHoldrSettings { | ||
export interface IItemValues { | ||
[i: string]: IItemSettings; | ||
} | ||
/** | ||
* Additional settings for storing an item. | ||
*/ | ||
export interface IItemSettings { | ||
/** | ||
* Initial settings for IItemValues to store. | ||
* Maximum value the item may equal if a number. | ||
*/ | ||
values?: IItemValueDefaults; | ||
maximum?: number; | ||
/** | ||
* Whether new items are allowed to be added (by default, true). | ||
* Callback for when the value reaches the maximum value. | ||
*/ | ||
allowNewItems?: boolean; | ||
onMaximum?: IValueCallback<number>; | ||
/** | ||
* Whether values should be saved immediately upon being set. | ||
* Minimum value the item may equal if a number. | ||
*/ | ||
autoSave?: boolean; | ||
minimum?: number; | ||
/** | ||
* A localStorage object to use instead of the global localStorage. | ||
* Callback for when the value reaches the minimum value. | ||
*/ | ||
localStorage?: any; | ||
onMinimum?: Function; | ||
/** | ||
* A prefix to add before IItemsValue keys | ||
* Maximum number to modulo the value against if a number. | ||
*/ | ||
prefix?: string; | ||
modularity?: number; | ||
/** | ||
* Default attributes for IItemValues. | ||
* Callback for when the value reaches modularity. | ||
*/ | ||
defaults?: IItemValueDefaults; | ||
} | ||
/** | ||
* A versatile container to store and manipulate values in localStorage. | ||
*/ | ||
export interface IItemsHoldr { | ||
onModular?: IValueCallback<number>; | ||
/** | ||
* @returns The values contained within, keyed by their keys. | ||
* A mapping of values to callbacks that should be triggered when value | ||
* is equal to them. | ||
*/ | ||
getValues(): { | ||
[i: string]: IItemValue; | ||
}; | ||
triggers?: ITriggers; | ||
/** | ||
* @returns Default attributes for values. | ||
* A default initial value to store, if value isn't provided. | ||
*/ | ||
getDefaults(): IItemValueDefaults; | ||
valueDefault?: any; | ||
} | ||
/** | ||
* Full export of stored items. | ||
*/ | ||
export interface IExportedItems { | ||
[i: string]: string; | ||
} | ||
/** | ||
* Settings to initialize a new instance of the IItemsHoldr interface. | ||
*/ | ||
export interface IItemsHoldrSettings { | ||
/** | ||
* @returns A reference to localStorage or a replacment object. | ||
* Whether values should be saved immediately upon being set. | ||
*/ | ||
getLocalStorage(): Storage; | ||
autoSave?: boolean; | ||
/** | ||
* @returns Whether this should save changes to localStorage automatically. | ||
* Default attributes for item values. | ||
*/ | ||
getAutoSave(): boolean; | ||
defaults?: IItemSettings; | ||
/** | ||
* @returns The prefix to store thigns under in localStorage. | ||
* Prefix to add before keys in storage. | ||
*/ | ||
getPrefix(): string; | ||
prefix?: string; | ||
/** | ||
* @returns String keys for each of the stored IItemValues. | ||
* Storage object to use instead of the global localStorage. | ||
*/ | ||
getKeys(): string[]; | ||
storage?: Storage; | ||
/** | ||
* @returns All String keys of items. | ||
* Initial settings for item values to store. | ||
*/ | ||
getItemKeys(): string[]; | ||
values?: IItemValues; | ||
} | ||
/** | ||
* A versatile container to store and manipulate values in localStorage. | ||
*/ | ||
export interface IItemsHoldr { | ||
/** | ||
* @param key The key for a known value. | ||
* @returns The known value of a key, assuming that key exists. | ||
* How many items are being stored. | ||
*/ | ||
getItem(key: string): any; | ||
readonly length: number; | ||
/** | ||
* @param key The key for a known value. | ||
* @returns The settings for that particular key. | ||
* Gets the key at an index. | ||
* | ||
* @param index An index for a key. | ||
* @returns The indexed key. | ||
*/ | ||
getObject(key: string): any; | ||
key(index: number): string; | ||
/** | ||
* @param key The key for a potentially known value. | ||
* @returns Whether there is a value under that key. | ||
* Creates a new item with settings. | ||
* | ||
* @param key Unique key to store the item under. | ||
* @param settings Any additional settings for the item. | ||
*/ | ||
hasKey(key: string): boolean; | ||
addItem(key: string, settings?: IItemSettings): void; | ||
/** | ||
* @returns A mapping of key names to the actual values of all objects being stored. | ||
*/ | ||
exportItems(): any; | ||
/** | ||
* Adds a new key & value pair to by linking to a newly created ItemValue. | ||
* Gets a value under a key. | ||
* | ||
* @param key The key to reference by new ItemValue by. | ||
* @param settings The settings for the new ItemValue. | ||
* @returns The newly created ItemValue. | ||
* @param key Key of an item. | ||
* @returns The known value of a key, assuming that key exists. | ||
*/ | ||
addItem(key: string, settings?: any): IItemValue; | ||
getItem(key: string): any; | ||
/** | ||
@@ -105,51 +134,55 @@ * Clears a value from the listing. | ||
/** | ||
* Completely clears all values from the ItemsHoldr. | ||
*/ | ||
clear(): void; | ||
/** | ||
* Sets the value for the ItemValue under the given key. | ||
* Sets the value for an item under the given key. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param value The new value for the ItemValue. | ||
* @param key Key of an item. | ||
* @param value The new value for the item. | ||
*/ | ||
setItem(key: string, value: any): void; | ||
/** | ||
* Increases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Increases the value of an item as a number or string. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to increase by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to increase by (by default, 1). | ||
*/ | ||
increase(key: string, amount?: number | string): void; | ||
/** | ||
* Increases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Decreases the value of an item as a number. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to increase by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to increase by (by default, 1). | ||
*/ | ||
decrease(key: string, amount?: number): void; | ||
/** | ||
* Toggles whether a value is true or false. | ||
* Toggles whether an item is true or false. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param key Key of an item. | ||
*/ | ||
toggle(key: string): void; | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* Gets whether an item exists under the key. | ||
* | ||
* @param key Key of an ItemValue. | ||
* @param key The key for a potentially known value. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
checkExistence(key: string): void; | ||
hasKey(key: string): boolean; | ||
/** | ||
* Manually saves an item's value to localStorage, ignoring the autoSave flag. | ||
* Gets a summary of keys and their values. | ||
* | ||
* @param key The key of the item to save. | ||
* @returns A mapping of keys to their stored values. | ||
*/ | ||
exportItems(): IExportedItems; | ||
/** | ||
* Completely clears all items. | ||
*/ | ||
clear(): void; | ||
/** | ||
* Manually saves an item's value to storage, ignoring autoSave settings. | ||
* | ||
* @param key Key of an item to save. | ||
*/ | ||
saveItem(key: string): void; | ||
/** | ||
* Manually saves all values to localStorage, ignoring the autoSave flag. | ||
* Manually saves all items to storage, ignoring autoSave settings. | ||
*/ | ||
saveAll(): void; | ||
} |
@@ -1,115 +0,148 @@ | ||
import { IItemValue, IItemValueDefaults } from "./IItemValue"; | ||
/** | ||
* Called when an item equals an interesting value. | ||
* | ||
* @template TValue Type of the item's value. | ||
* @param value Interesting value of an item. | ||
*/ | ||
export type IValueCallback<TValue = any> = (value: TValue) => void; | ||
/** | ||
* A container to hold ItemValue objects, keyed by name. | ||
* Transforms an item's value. | ||
* | ||
* @template TValue Type of the item's value. | ||
* @param value Value of an item. | ||
* @returns Transformed value of the item. | ||
*/ | ||
export interface IItems { | ||
[i: string]: IItemValue; | ||
export type IValueTransform = <TValue = any>(value: TValue) => TValue; | ||
/** | ||
* A mapping of item values to triggered callbacks. | ||
*/ | ||
export interface ITriggers { | ||
[i: string]: IValueCallback; | ||
[j: number]: IValueCallback; | ||
} | ||
/** | ||
* Settings to initialize a new instance of the IItemsHoldr interface. | ||
* Settings for item values, keyed by item key. | ||
*/ | ||
export interface IItemsHoldrSettings { | ||
/** | ||
* Initial settings for IItemValues to store. | ||
*/ | ||
values?: IItemValueDefaults; | ||
export interface IItemValues { | ||
[i: string]: IItemSettings; | ||
} | ||
/** | ||
* Additional settings for storing an item. | ||
*/ | ||
export interface IItemSettings { | ||
/** | ||
* Whether new items are allowed to be added (by default, true). | ||
* Maximum value the item may equal if a number. | ||
*/ | ||
allowNewItems?: boolean; | ||
maximum?: number; | ||
/** | ||
* Whether values should be saved immediately upon being set. | ||
* Callback for when the value reaches the maximum value. | ||
*/ | ||
autoSave?: boolean; | ||
onMaximum?: IValueCallback<number>; | ||
/** | ||
* A localStorage object to use instead of the global localStorage. | ||
* Minimum value the item may equal if a number. | ||
*/ | ||
localStorage?: any; | ||
minimum?: number; | ||
/** | ||
* A prefix to add before IItemsValue keys | ||
* Callback for when the value reaches the minimum value. | ||
*/ | ||
prefix?: string; | ||
onMinimum?: Function; | ||
/** | ||
* Default attributes for IItemValues. | ||
* Maximum number to modulo the value against if a number. | ||
*/ | ||
defaults?: IItemValueDefaults; | ||
} | ||
modularity?: number; | ||
/** | ||
* A versatile container to store and manipulate values in localStorage. | ||
*/ | ||
export interface IItemsHoldr { | ||
/** | ||
* @returns The values contained within, keyed by their keys. | ||
* Callback for when the value reaches modularity. | ||
*/ | ||
getValues(): { [i: string]: IItemValue }; | ||
onModular?: IValueCallback<number>; | ||
/** | ||
* @returns Default attributes for values. | ||
* A mapping of values to callbacks that should be triggered when value | ||
* is equal to them. | ||
*/ | ||
getDefaults(): IItemValueDefaults; | ||
triggers?: ITriggers; | ||
/** | ||
* @returns A reference to localStorage or a replacment object. | ||
* A default initial value to store, if value isn't provided. | ||
*/ | ||
getLocalStorage(): Storage; | ||
valueDefault?: any; | ||
} | ||
/** | ||
* Full export of stored items. | ||
*/ | ||
export interface IExportedItems { | ||
[i: string]: string; | ||
} | ||
/** | ||
* Settings to initialize a new instance of the IItemsHoldr interface. | ||
*/ | ||
export interface IItemsHoldrSettings { | ||
/** | ||
* @returns Whether this should save changes to localStorage automatically. | ||
* Whether values should be saved immediately upon being set. | ||
*/ | ||
getAutoSave(): boolean; | ||
autoSave?: boolean; | ||
/** | ||
* @returns The prefix to store thigns under in localStorage. | ||
* Default attributes for item values. | ||
*/ | ||
getPrefix(): string; | ||
defaults?: IItemSettings; | ||
/** | ||
* @returns String keys for each of the stored IItemValues. | ||
* Prefix to add before keys in storage. | ||
*/ | ||
getKeys(): string[]; | ||
prefix?: string; | ||
/** | ||
* @returns All String keys of items. | ||
* Storage object to use instead of the global localStorage. | ||
*/ | ||
getItemKeys(): string[]; | ||
storage?: Storage; | ||
/** | ||
* @param key The key for a known value. | ||
* @returns The known value of a key, assuming that key exists. | ||
* Initial settings for item values to store. | ||
*/ | ||
getItem(key: string): any; | ||
values?: IItemValues; | ||
} | ||
/** | ||
* A versatile container to store and manipulate values in localStorage. | ||
*/ | ||
export interface IItemsHoldr { | ||
/** | ||
* @param key The key for a known value. | ||
* @returns The settings for that particular key. | ||
* How many items are being stored. | ||
*/ | ||
getObject(key: string): any; | ||
readonly length: number; | ||
/** | ||
* @param key The key for a potentially known value. | ||
* @returns Whether there is a value under that key. | ||
* Gets the key at an index. | ||
* | ||
* @param index An index for a key. | ||
* @returns The indexed key. | ||
*/ | ||
hasKey(key: string): boolean; | ||
key(index: number): string; | ||
/** | ||
* @returns A mapping of key names to the actual values of all objects being stored. | ||
* Creates a new item with settings. | ||
* | ||
* @param key Unique key to store the item under. | ||
* @param settings Any additional settings for the item. | ||
*/ | ||
exportItems(): any; | ||
addItem(key: string, settings?: IItemSettings): void; | ||
/** | ||
* Adds a new key & value pair to by linking to a newly created ItemValue. | ||
* Gets a value under a key. | ||
* | ||
* @param key The key to reference by new ItemValue by. | ||
* @param settings The settings for the new ItemValue. | ||
* @returns The newly created ItemValue. | ||
* @param key Key of an item. | ||
* @returns The known value of a key, assuming that key exists. | ||
*/ | ||
addItem(key: string, settings?: any): IItemValue; | ||
getItem(key: string): any; | ||
@@ -124,11 +157,6 @@ /** | ||
/** | ||
* Completely clears all values from the ItemsHoldr. | ||
*/ | ||
clear(): void; | ||
/** | ||
* Sets the value for the ItemValue under the given key. | ||
* Sets the value for an item under the given key. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param value The new value for the ItemValue. | ||
* @param key Key of an item. | ||
* @param value The new value for the item. | ||
*/ | ||
@@ -138,7 +166,6 @@ setItem(key: string, value: any): void; | ||
/** | ||
* Increases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Increases the value of an item as a number or string. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to increase by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to increase by (by default, 1). | ||
*/ | ||
@@ -148,7 +175,6 @@ increase(key: string, amount?: number | string): void; | ||
/** | ||
* Increases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Decreases the value of an item as a number. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to increase by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to increase by (by default, 1). | ||
*/ | ||
@@ -158,5 +184,5 @@ decrease(key: string, amount?: number): void; | ||
/** | ||
* Toggles whether a value is true or false. | ||
* Toggles whether an item is true or false. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param key Key of an item. | ||
*/ | ||
@@ -166,20 +192,32 @@ toggle(key: string): void; | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* Gets whether an item exists under the key. | ||
* | ||
* @param key Key of an ItemValue. | ||
* @param key The key for a potentially known value. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
checkExistence(key: string): void; | ||
hasKey(key: string): boolean; | ||
/** | ||
* Manually saves an item's value to localStorage, ignoring the autoSave flag. | ||
* Gets a summary of keys and their values. | ||
* | ||
* @param key The key of the item to save. | ||
* @returns A mapping of keys to their stored values. | ||
*/ | ||
exportItems(): IExportedItems; | ||
/** | ||
* Completely clears all items. | ||
*/ | ||
clear(): void; | ||
/** | ||
* Manually saves an item's value to storage, ignoring autoSave settings. | ||
* | ||
* @param key Key of an item to save. | ||
*/ | ||
saveItem(key: string): void; | ||
/** | ||
* Manually saves all values to localStorage, ignoring the autoSave flag. | ||
* Manually saves all items to storage, ignoring autoSave settings. | ||
*/ | ||
saveAll(): void; | ||
} |
@@ -1,6 +0,4 @@ | ||
export * from "./createPlaceholderStorage"; | ||
export * from "./createStorage"; | ||
export * from "./IItemsHoldr"; | ||
export * from "./IItemValue"; | ||
export * from "./ItemsHoldr"; | ||
export * from "./ItemValue"; | ||
export * from "./proliferate"; |
@@ -1,2 +0,2 @@ | ||
define(["require", "exports", "./createPlaceholderStorage", "./ItemsHoldr", "./ItemValue", "./proliferate"], function (require, exports, createPlaceholderStorage_1, ItemsHoldr_1, ItemValue_1, proliferate_1) { | ||
define(["require", "exports", "./createStorage", "./ItemsHoldr", "./proliferate"], function (require, exports, createStorage_1, ItemsHoldr_1, proliferate_1) { | ||
"use strict"; | ||
@@ -7,6 +7,5 @@ function __export(m) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(createPlaceholderStorage_1); | ||
__export(createStorage_1); | ||
__export(ItemsHoldr_1); | ||
__export(ItemValue_1); | ||
__export(proliferate_1); | ||
}); |
@@ -1,6 +0,4 @@ | ||
export * from "./createPlaceholderStorage"; | ||
export * from "./createStorage"; | ||
export * from "./IItemsHoldr"; | ||
export * from "./IItemValue"; | ||
export * from "./ItemsHoldr"; | ||
export * from "./ItemValue"; | ||
export * from "./proliferate"; |
@@ -1,3 +0,2 @@ | ||
import { IItemsHoldr, IItemsHoldrSettings } from "./IItemsHoldr"; | ||
import { IItemValue } from "./IItemValue"; | ||
import { IExportedItems, IItemSettings, IItemsHoldr, IItemsHoldrSettings } from "./IItemsHoldr"; | ||
/** | ||
@@ -13,29 +12,29 @@ * A versatile container to store and manipulate values in localStorage, and | ||
/** | ||
* Default attributes for ItemValues. | ||
* A prefix to store things under in storage. | ||
*/ | ||
private readonly defaults; | ||
private readonly prefix; | ||
/** | ||
* A reference to localStorage or a replacement object. | ||
*/ | ||
private readonly localStorage; | ||
private readonly storage; | ||
/** | ||
* A prefix to store things under in localStorage. | ||
* Settings for item values, keyed by item key. | ||
*/ | ||
private readonly prefix; | ||
private readonly values; | ||
/** | ||
* Whether new items are allowed to be created using setItem. | ||
* Settings to create item containers. | ||
*/ | ||
private readonly allowNewItems; | ||
private readonly containerSettings; | ||
/** | ||
* The ItemValues being stored, keyed by name. | ||
* Whether this should save changes to localStorage automatically. | ||
*/ | ||
private items; | ||
private readonly autoSave; | ||
/** | ||
* A listing of all the String keys for the stored items. | ||
* All keys for stored items. | ||
*/ | ||
private itemKeys; | ||
/** | ||
* Whether this should save changes to localStorage automatically. | ||
* The items being stored, keyed by name. | ||
*/ | ||
private autoSave; | ||
private items; | ||
/** | ||
@@ -48,2 +47,6 @@ * Initializes a new instance of the ItemsHoldr class. | ||
/** | ||
* How many items are being stored. | ||
*/ | ||
readonly length: number; | ||
/** | ||
* Gets the key at an index. | ||
@@ -56,48 +59,11 @@ * | ||
/** | ||
* Gets the contained values. | ||
* Creates a new item with settings. | ||
* | ||
* @returns The values contained within, keyed by their keys. | ||
* @param key Unique key to store the item under. | ||
* @param settings Any additional settings for the item. | ||
*/ | ||
getValues(): { | ||
[i: string]: IItemValue; | ||
}; | ||
addItem(key: string, settings?: IItemSettings): void; | ||
/** | ||
* Gets the default attributes for values. | ||
* Gets the value under a key. | ||
* | ||
* @returns Default attributes for values. | ||
*/ | ||
getDefaults(): any; | ||
/** | ||
* Gets the reference to localStorage or its placeholder. | ||
* | ||
* @returns A reference to localStorage or its placeholder. | ||
*/ | ||
getLocalStorage(): Storage; | ||
/** | ||
* Gets whether this should save changes to localStorage automatically. | ||
* | ||
* @returns Whether this should save changes to localStorage automatically. | ||
*/ | ||
getAutoSave(): boolean; | ||
/** | ||
* Gets the prefix for localStorage keys. | ||
* | ||
* @returns The prefix to store keys under in localStorage. | ||
*/ | ||
getPrefix(): string; | ||
/** | ||
* Gets all keys for all items. | ||
* | ||
* @returns String keys for each of the stored ItemValues. | ||
*/ | ||
getKeys(): string[]; | ||
/** | ||
* Gets all stored keys of items. | ||
* | ||
* @returns All keys of items. | ||
*/ | ||
getItemKeys(): string[]; | ||
/** | ||
* Gets the value for a known key. | ||
* | ||
* @param key The key for a known value. | ||
@@ -108,30 +74,2 @@ * @returns The known value of a key, assuming that key exists. | ||
/** | ||
* Gets the value for a potentially unknown key. | ||
* | ||
* @param key The key for a potentially unknown value. | ||
* @returns The settings for that particular key. | ||
*/ | ||
getObject(key: string): any; | ||
/** | ||
* Checks whether a key exists. | ||
* | ||
* @param key The key for a potentially known value. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
hasKey(key: string): boolean; | ||
/** | ||
* Maps key names to their values. | ||
* | ||
* @returns A mapping of key names to the actual values of all objects being stored. | ||
*/ | ||
exportItems(): any; | ||
/** | ||
* Adds a new key & value pair to by linking to a newly created ItemValue. | ||
* | ||
* @param key The key to reference by new ItemValue by. | ||
* @param settings The settings for the new ItemValue. | ||
* @returns The newly created ItemValue. | ||
*/ | ||
addItem(key: string, settings?: any): IItemValue; | ||
/** | ||
* Clears a value from the listing, and removes its element from the | ||
@@ -144,49 +82,47 @@ * container (if they both exist). | ||
/** | ||
* Completely clears all values from the ItemsHoldr, removing their | ||
* elements from the container (if they both exist) as well. | ||
*/ | ||
clear(): void; | ||
/** | ||
* Sets the value for the ItemValue under the given key, then updates the ItemValue | ||
* (including the ItemValue's element and localStorage, if needed). | ||
* Sets the value for an item under the given key. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param value The new value for the ItemValue. | ||
* @param key Key of an item. | ||
* @param value The new value for the item. | ||
*/ | ||
setItem(key: string, value: any): void; | ||
/** | ||
* Increases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Increases the value of an item as a number or string. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to increase by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to increase by (by default, 1). | ||
*/ | ||
increase(key: string, amount?: number | string): void; | ||
/** | ||
* Decreases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Decreases the value of an item as a number | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to decrease by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to decrease by (by default, 1). | ||
*/ | ||
decrease(key: string, amount?: number): void; | ||
/** | ||
* Toggles whether a value is true or false. | ||
* Toggles whether an item is true or false. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param key Key of an item. | ||
*/ | ||
toggle(key: string): void; | ||
/** | ||
* Toggles this.autoSave. | ||
* Gets whether an item exists under the key. | ||
* | ||
* @param key Key of an item. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
toggleAutoSave(): void; | ||
hasKey(key: string): boolean; | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* Gets a summary of keys and their values. | ||
* | ||
* @param key | ||
* @returns A mapping of key to their stored values. | ||
*/ | ||
checkExistence(key: string): void; | ||
exportItems(): IExportedItems; | ||
/** | ||
* Manually saves an item's value to localStorage, ignoring the autoSave flag. | ||
* Completely clears all items. | ||
*/ | ||
clear(): void; | ||
/** | ||
* Manually saves an item's value to storage, ignoring autoSave settings. | ||
* | ||
@@ -197,5 +133,12 @@ * @param key The key of the item to save. | ||
/** | ||
* Manually saves all values to localStorage, ignoring the autoSave flag. | ||
* Manually saves all items to storage, ignoring autoSave settings. | ||
*/ | ||
saveAll(): void; | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* | ||
* @param key | ||
*/ | ||
private checkExistence(key); | ||
} |
@@ -1,2 +0,2 @@ | ||
define(["require", "exports", "./createPlaceholderStorage", "./ItemValue"], function (require, exports, createPlaceholderStorage_1, ItemValue_1) { | ||
define(["require", "exports", "./createStorage", "./ItemContainer"], function (require, exports, createStorage_1, ItemContainer_1) { | ||
"use strict"; | ||
@@ -18,17 +18,32 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
this.autoSave = !!settings.autoSave; | ||
this.items = {}; | ||
this.itemKeys = []; | ||
this.prefix = settings.prefix || ""; | ||
this.allowNewItems = settings.allowNewItems === undefined | ||
? true : settings.allowNewItems; | ||
if (settings.localStorage) { | ||
this.localStorage = settings.localStorage; | ||
this.values = this.settings.values || {}; | ||
if (settings.storage) { | ||
this.storage = settings.storage; | ||
} | ||
else if (typeof localStorage === "undefined") { | ||
this.localStorage = createPlaceholderStorage_1.createPlaceholderStorage(); | ||
this.storage = createStorage_1.createStorage(); | ||
} | ||
else { | ||
this.localStorage = localStorage; | ||
this.storage = localStorage; | ||
} | ||
this.defaults = settings.defaults || {}; | ||
this.clear(); | ||
this.containerSettings = { | ||
autoSave: this.autoSave, | ||
defaults: this.settings.defaults || {}, | ||
prefix: this.prefix, | ||
storage: this.storage, | ||
}; | ||
} | ||
Object.defineProperty(ItemsHoldr.prototype, "length", { | ||
/** | ||
* How many items are being stored. | ||
*/ | ||
get: function () { | ||
return this.itemKeys.length; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
@@ -44,60 +59,15 @@ * Gets the key at an index. | ||
/** | ||
* Gets the contained values. | ||
* Creates a new item with settings. | ||
* | ||
* @returns The values contained within, keyed by their keys. | ||
* @param key Unique key to store the item under. | ||
* @param settings Any additional settings for the item. | ||
*/ | ||
ItemsHoldr.prototype.getValues = function () { | ||
return this.items; | ||
ItemsHoldr.prototype.addItem = function (key, settings) { | ||
if (settings === void 0) { settings = {}; } | ||
this.items[key] = new ItemContainer_1.ItemContainer(this.containerSettings, key, settings); | ||
this.itemKeys.push(key); | ||
}; | ||
/** | ||
* Gets the default attributes for values. | ||
* Gets the value under a key. | ||
* | ||
* @returns Default attributes for values. | ||
*/ | ||
ItemsHoldr.prototype.getDefaults = function () { | ||
return this.defaults; | ||
}; | ||
/** | ||
* Gets the reference to localStorage or its placeholder. | ||
* | ||
* @returns A reference to localStorage or its placeholder. | ||
*/ | ||
ItemsHoldr.prototype.getLocalStorage = function () { | ||
return this.localStorage; | ||
}; | ||
/** | ||
* Gets whether this should save changes to localStorage automatically. | ||
* | ||
* @returns Whether this should save changes to localStorage automatically. | ||
*/ | ||
ItemsHoldr.prototype.getAutoSave = function () { | ||
return this.autoSave; | ||
}; | ||
/** | ||
* Gets the prefix for localStorage keys. | ||
* | ||
* @returns The prefix to store keys under in localStorage. | ||
*/ | ||
ItemsHoldr.prototype.getPrefix = function () { | ||
return this.prefix; | ||
}; | ||
/** | ||
* Gets all keys for all items. | ||
* | ||
* @returns String keys for each of the stored ItemValues. | ||
*/ | ||
ItemsHoldr.prototype.getKeys = function () { | ||
return Object.keys(this.items); | ||
}; | ||
/** | ||
* Gets all stored keys of items. | ||
* | ||
* @returns All keys of items. | ||
*/ | ||
ItemsHoldr.prototype.getItemKeys = function () { | ||
return this.itemKeys; | ||
}; | ||
/** | ||
* Gets the value for a known key. | ||
* | ||
* @param key The key for a known value. | ||
@@ -111,45 +81,2 @@ * @returns The known value of a key, assuming that key exists. | ||
/** | ||
* Gets the value for a potentially unknown key. | ||
* | ||
* @param key The key for a potentially unknown value. | ||
* @returns The settings for that particular key. | ||
*/ | ||
ItemsHoldr.prototype.getObject = function (key) { | ||
return this.items[key]; | ||
}; | ||
/** | ||
* Checks whether a key exists. | ||
* | ||
* @param key The key for a potentially known value. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
ItemsHoldr.prototype.hasKey = function (key) { | ||
return this.items.hasOwnProperty(key); | ||
}; | ||
/** | ||
* Maps key names to their values. | ||
* | ||
* @returns A mapping of key names to the actual values of all objects being stored. | ||
*/ | ||
ItemsHoldr.prototype.exportItems = function () { | ||
var output = {}; | ||
for (var i in this.items) { | ||
output[i] = this.items[i].getValue(); | ||
} | ||
return output; | ||
}; | ||
/** | ||
* Adds a new key & value pair to by linking to a newly created ItemValue. | ||
* | ||
* @param key The key to reference by new ItemValue by. | ||
* @param settings The settings for the new ItemValue. | ||
* @returns The newly created ItemValue. | ||
*/ | ||
ItemsHoldr.prototype.addItem = function (key, settings) { | ||
if (settings === void 0) { settings = {}; } | ||
this.items[key] = new ItemValue_1.ItemValue(this, key, settings); | ||
this.itemKeys.push(key); | ||
return this.items[key]; | ||
}; | ||
/** | ||
* Clears a value from the listing, and removes its element from the | ||
@@ -161,3 +88,3 @@ * container (if they both exist). | ||
ItemsHoldr.prototype.removeItem = function (key) { | ||
if (!this.items.hasOwnProperty(key)) { | ||
if (!{}.hasOwnProperty.call(this.items, key)) { | ||
return; | ||
@@ -167,26 +94,12 @@ } | ||
delete this.items[key]; | ||
delete this.localStorage[this.prefix + key]; | ||
}; | ||
/** | ||
* Completely clears all values from the ItemsHoldr, removing their | ||
* elements from the container (if they both exist) as well. | ||
*/ | ||
ItemsHoldr.prototype.clear = function () { | ||
this.items = {}; | ||
this.itemKeys = []; | ||
if (!this.settings.values) { | ||
return; | ||
this.storage.removeItem(this.prefix + key); | ||
if ({}.hasOwnProperty.call(this.values, key)) { | ||
this.addItem(key, this.values[key]); | ||
} | ||
for (var key in this.settings.values) { | ||
if (this.settings.values.hasOwnProperty(key)) { | ||
this.addItem(key, this.settings.values[key]); | ||
} | ||
} | ||
}; | ||
/** | ||
* Sets the value for the ItemValue under the given key, then updates the ItemValue | ||
* (including the ItemValue's element and localStorage, if needed). | ||
* Sets the value for an item under the given key. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param value The new value for the ItemValue. | ||
* @param key Key of an item. | ||
* @param value The new value for the item. | ||
*/ | ||
@@ -198,7 +111,6 @@ ItemsHoldr.prototype.setItem = function (key, value) { | ||
/** | ||
* Increases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Increases the value of an item as a number or string. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to increase by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to increase by (by default, 1). | ||
*/ | ||
@@ -213,7 +125,6 @@ ItemsHoldr.prototype.increase = function (key, amount) { | ||
/** | ||
* Decreases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Decreases the value of an item as a number | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to decrease by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to decrease by (by default, 1). | ||
*/ | ||
@@ -227,5 +138,5 @@ ItemsHoldr.prototype.decrease = function (key, amount) { | ||
/** | ||
* Toggles whether a value is true or false. | ||
* Toggles whether an item is true or false. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param key Key of an item. | ||
*/ | ||
@@ -238,24 +149,41 @@ ItemsHoldr.prototype.toggle = function (key) { | ||
/** | ||
* Toggles this.autoSave. | ||
* Gets whether an item exists under the key. | ||
* | ||
* @param key Key of an item. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
ItemsHoldr.prototype.toggleAutoSave = function () { | ||
this.autoSave = !this.autoSave; | ||
ItemsHoldr.prototype.hasKey = function (key) { | ||
return {}.hasOwnProperty.call(this.items, key); | ||
}; | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* Gets a summary of keys and their values. | ||
* | ||
* @param key | ||
* @returns A mapping of key to their stored values. | ||
*/ | ||
ItemsHoldr.prototype.checkExistence = function (key) { | ||
if (this.items.hasOwnProperty(key)) { | ||
return; | ||
ItemsHoldr.prototype.exportItems = function () { | ||
var output = {}; | ||
for (var _i = 0, _a = this.itemKeys; _i < _a.length; _i++) { | ||
var itemKey = _a[_i]; | ||
output[itemKey] = this.items[itemKey].getValue(); | ||
} | ||
if (!this.allowNewItems) { | ||
throw new Error("Unknown key given to ItemsHoldr: '" + key + "'."); | ||
return output; | ||
}; | ||
/** | ||
* Completely clears all items. | ||
*/ | ||
ItemsHoldr.prototype.clear = function () { | ||
for (var _i = 0, _a = this.itemKeys; _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
this.storage.removeItem(this.prefix + key); | ||
} | ||
this.addItem(key); | ||
this.items = {}; | ||
this.itemKeys = []; | ||
for (var key in this.values) { | ||
if ({}.hasOwnProperty.call(this.values, key)) { | ||
this.addItem(key, this.values[key]); | ||
} | ||
} | ||
}; | ||
/** | ||
* Manually saves an item's value to localStorage, ignoring the autoSave flag. | ||
* Manually saves an item's value to storage, ignoring autoSave settings. | ||
* | ||
@@ -265,15 +193,26 @@ * @param key The key of the item to save. | ||
ItemsHoldr.prototype.saveItem = function (key) { | ||
if (!this.items.hasOwnProperty(key)) { | ||
if (!{}.hasOwnProperty.call(this.items, key)) { | ||
throw new Error("Unknown key given to ItemsHoldr: '" + key + "'."); | ||
} | ||
this.items[key].updateLocalStorage(true); | ||
this.items[key].updateStorage(true); | ||
}; | ||
/** | ||
* Manually saves all values to localStorage, ignoring the autoSave flag. | ||
* Manually saves all items to storage, ignoring autoSave settings. | ||
*/ | ||
ItemsHoldr.prototype.saveAll = function () { | ||
for (var key in this.items) { | ||
this.items[key].updateLocalStorage(true); | ||
this.items[key].updateStorage(true); | ||
} | ||
}; | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* | ||
* @param key | ||
*/ | ||
ItemsHoldr.prototype.checkExistence = function (key) { | ||
if (!{}.hasOwnProperty.call(this.items, key)) { | ||
this.addItem(key, this.values[key]); | ||
} | ||
}; | ||
return ItemsHoldr; | ||
@@ -280,0 +219,0 @@ }()); |
@@ -1,7 +0,13 @@ | ||
import { createPlaceholderStorage } from "./createPlaceholderStorage"; | ||
import { IItems, IItemsHoldr, IItemsHoldrSettings } from "./IItemsHoldr"; | ||
import { IItemValue, IItemValueDefaults } from "./IItemValue"; | ||
import { ItemValue } from "./ItemValue"; | ||
import { createStorage } from "./createStorage"; | ||
import { IExportedItems, IItemSettings, IItemsHoldr, IItemsHoldrSettings, IItemValues } from "./IItemsHoldr"; | ||
import { IItemContainerSettings, ItemContainer } from "./ItemContainer"; | ||
/** | ||
* Item containers, keyed by item name. | ||
*/ | ||
interface IItems { | ||
[i: string]: ItemContainer; | ||
} | ||
/** | ||
* A versatile container to store and manipulate values in localStorage, and | ||
@@ -17,5 +23,5 @@ * optionally keep an updated HTML container showing these values. | ||
/** | ||
* Default attributes for ItemValues. | ||
* A prefix to store things under in storage. | ||
*/ | ||
private readonly defaults: IItemValueDefaults; | ||
private readonly prefix: string; | ||
@@ -25,21 +31,21 @@ /** | ||
*/ | ||
private readonly localStorage: Storage; | ||
private readonly storage: Storage; | ||
/** | ||
* A prefix to store things under in localStorage. | ||
* Settings for item values, keyed by item key. | ||
*/ | ||
private readonly prefix: string; | ||
private readonly values: IItemValues; | ||
/** | ||
* Whether new items are allowed to be created using setItem. | ||
* Settings to create item containers. | ||
*/ | ||
private readonly allowNewItems: boolean; | ||
private readonly containerSettings: IItemContainerSettings; | ||
/** | ||
* The ItemValues being stored, keyed by name. | ||
* Whether this should save changes to localStorage automatically. | ||
*/ | ||
private items: IItems; | ||
private readonly autoSave: boolean; | ||
/** | ||
* A listing of all the String keys for the stored items. | ||
* All keys for stored items. | ||
*/ | ||
@@ -49,5 +55,5 @@ private itemKeys: string[]; | ||
/** | ||
* Whether this should save changes to localStorage automatically. | ||
* The items being stored, keyed by name. | ||
*/ | ||
private autoSave: boolean; | ||
private items: IItems; | ||
@@ -62,18 +68,28 @@ /** | ||
this.autoSave = !!settings.autoSave; | ||
this.items = {}; | ||
this.itemKeys = []; | ||
this.prefix = settings.prefix || ""; | ||
this.values = this.settings.values || {}; | ||
this.allowNewItems = settings.allowNewItems === undefined | ||
? true : settings.allowNewItems; | ||
if (settings.localStorage) { | ||
this.localStorage = settings.localStorage; | ||
if (settings.storage) { | ||
this.storage = settings.storage; | ||
} else if (typeof localStorage === "undefined") { // tslint:disable-line strict-type-predicates | ||
this.localStorage = createPlaceholderStorage(); | ||
this.storage = createStorage(); | ||
} else { | ||
this.localStorage = localStorage; | ||
this.storage = localStorage; | ||
} | ||
this.defaults = settings.defaults || {}; | ||
this.containerSettings = { | ||
autoSave: this.autoSave, | ||
defaults: this.settings.defaults || {}, | ||
prefix: this.prefix, | ||
storage: this.storage, | ||
}; | ||
} | ||
this.clear(); | ||
/** | ||
* How many items are being stored. | ||
*/ | ||
public get length(): number { | ||
return this.itemKeys.length; | ||
} | ||
@@ -92,67 +108,15 @@ | ||
/** | ||
* Gets the contained values. | ||
* Creates a new item with settings. | ||
* | ||
* @returns The values contained within, keyed by their keys. | ||
* @param key Unique key to store the item under. | ||
* @param settings Any additional settings for the item. | ||
*/ | ||
public getValues(): { [i: string]: IItemValue } { | ||
return this.items; | ||
public addItem(key: string, settings: IItemSettings = {}): void { | ||
this.items[key] = new ItemContainer(this.containerSettings, key, settings); | ||
this.itemKeys.push(key); | ||
} | ||
/** | ||
* Gets the default attributes for values. | ||
* Gets the value under a key. | ||
* | ||
* @returns Default attributes for values. | ||
*/ | ||
public getDefaults(): any { | ||
return this.defaults; | ||
} | ||
/** | ||
* Gets the reference to localStorage or its placeholder. | ||
* | ||
* @returns A reference to localStorage or its placeholder. | ||
*/ | ||
public getLocalStorage(): Storage { | ||
return this.localStorage; | ||
} | ||
/** | ||
* Gets whether this should save changes to localStorage automatically. | ||
* | ||
* @returns Whether this should save changes to localStorage automatically. | ||
*/ | ||
public getAutoSave(): boolean { | ||
return this.autoSave; | ||
} | ||
/** | ||
* Gets the prefix for localStorage keys. | ||
* | ||
* @returns The prefix to store keys under in localStorage. | ||
*/ | ||
public getPrefix(): string { | ||
return this.prefix; | ||
} | ||
/** | ||
* Gets all keys for all items. | ||
* | ||
* @returns String keys for each of the stored ItemValues. | ||
*/ | ||
public getKeys(): string[] { | ||
return Object.keys(this.items); | ||
} | ||
/** | ||
* Gets all stored keys of items. | ||
* | ||
* @returns All keys of items. | ||
*/ | ||
public getItemKeys(): string[] { | ||
return this.itemKeys; | ||
} | ||
/** | ||
* Gets the value for a known key. | ||
* | ||
* @param key The key for a known value. | ||
@@ -168,50 +132,2 @@ * @returns The known value of a key, assuming that key exists. | ||
/** | ||
* Gets the value for a potentially unknown key. | ||
* | ||
* @param key The key for a potentially unknown value. | ||
* @returns The settings for that particular key. | ||
*/ | ||
public getObject(key: string): any { | ||
return this.items[key]; | ||
} | ||
/** | ||
* Checks whether a key exists. | ||
* | ||
* @param key The key for a potentially known value. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
public hasKey(key: string): boolean { | ||
return this.items.hasOwnProperty(key); | ||
} | ||
/** | ||
* Maps key names to their values. | ||
* | ||
* @returns A mapping of key names to the actual values of all objects being stored. | ||
*/ | ||
public exportItems(): any { | ||
const output: any = {}; | ||
for (const i in this.items) { | ||
output[i] = this.items[i].getValue(); | ||
} | ||
return output; | ||
} | ||
/** | ||
* Adds a new key & value pair to by linking to a newly created ItemValue. | ||
* | ||
* @param key The key to reference by new ItemValue by. | ||
* @param settings The settings for the new ItemValue. | ||
* @returns The newly created ItemValue. | ||
*/ | ||
public addItem(key: string, settings: any = {}): IItemValue { | ||
this.items[key] = new ItemValue(this, key, settings); | ||
this.itemKeys.push(key); | ||
return this.items[key]; | ||
} | ||
/** | ||
* Clears a value from the listing, and removes its element from the | ||
@@ -223,3 +139,3 @@ * container (if they both exist). | ||
public removeItem(key: string): void { | ||
if (!this.items.hasOwnProperty(key)) { | ||
if (!{}.hasOwnProperty.call(this.items, key)) { | ||
return; | ||
@@ -231,30 +147,14 @@ } | ||
delete this.items[key]; | ||
delete this.localStorage[this.prefix + key]; | ||
} | ||
this.storage.removeItem(this.prefix + key); | ||
/** | ||
* Completely clears all values from the ItemsHoldr, removing their | ||
* elements from the container (if they both exist) as well. | ||
*/ | ||
public clear(): void { | ||
this.items = {}; | ||
this.itemKeys = []; | ||
if (!this.settings.values) { | ||
return; | ||
if ({}.hasOwnProperty.call(this.values, key)) { | ||
this.addItem(key, this.values[key]); | ||
} | ||
for (const key in this.settings.values) { | ||
if (this.settings.values.hasOwnProperty(key)) { | ||
this.addItem(key, this.settings.values[key]); | ||
} | ||
} | ||
} | ||
/** | ||
* Sets the value for the ItemValue under the given key, then updates the ItemValue | ||
* (including the ItemValue's element and localStorage, if needed). | ||
* Sets the value for an item under the given key. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param value The new value for the ItemValue. | ||
* @param key Key of an item. | ||
* @param value The new value for the item. | ||
*/ | ||
@@ -268,7 +168,6 @@ public setItem(key: string, value: any): void { | ||
/** | ||
* Increases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Increases the value of an item as a number or string. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to increase by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to increase by (by default, 1). | ||
*/ | ||
@@ -285,7 +184,6 @@ public increase(key: string, amount: number | string = 1): void { | ||
/** | ||
* Decreases the value for the ItemValue under the given key, via addition for | ||
* Numbers or concatenation for Strings. | ||
* Decreases the value of an item as a number | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param amount The amount to decrease by (by default, 1). | ||
* @param key Key of an item. | ||
* @param amount Amount to decrease by (by default, 1). | ||
*/ | ||
@@ -301,5 +199,5 @@ public decrease(key: string, amount: number = 1): void { | ||
/** | ||
* Toggles whether a value is true or false. | ||
* Toggles whether an item is true or false. | ||
* | ||
* @param key The key of the ItemValue. | ||
* @param key Key of an item. | ||
*/ | ||
@@ -309,3 +207,3 @@ public toggle(key: string): void { | ||
const value: any = this.items[key].getValue() ? false : true; | ||
const value = this.items[key].getValue() ? false : true; | ||
@@ -316,28 +214,46 @@ this.items[key].setValue(value); | ||
/** | ||
* Toggles this.autoSave. | ||
* Gets whether an item exists under the key. | ||
* | ||
* @param key Key of an item. | ||
* @returns Whether there is a value under that key. | ||
*/ | ||
public toggleAutoSave(): void { | ||
this.autoSave = !this.autoSave; | ||
public hasKey(key: string): boolean { | ||
return {}.hasOwnProperty.call(this.items, key); | ||
} | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* Gets a summary of keys and their values. | ||
* | ||
* @param key | ||
* @returns A mapping of key to their stored values. | ||
*/ | ||
public checkExistence(key: string): void { | ||
if (this.items.hasOwnProperty(key)) { | ||
return; | ||
public exportItems(): IExportedItems { | ||
const output: any = {}; | ||
for (const itemKey of this.itemKeys) { | ||
output[itemKey] = this.items[itemKey].getValue(); | ||
} | ||
if (!this.allowNewItems) { | ||
throw new Error(`Unknown key given to ItemsHoldr: '${key}'.`); | ||
return output; | ||
} | ||
/** | ||
* Completely clears all items. | ||
*/ | ||
public clear(): void { | ||
for (const key of this.itemKeys) { | ||
this.storage.removeItem(this.prefix + key); | ||
} | ||
this.addItem(key); | ||
this.items = {}; | ||
this.itemKeys = []; | ||
for (const key in this.values) { | ||
if ({}.hasOwnProperty.call(this.values, key)) { | ||
this.addItem(key, this.values[key]); | ||
} | ||
} | ||
} | ||
/** | ||
* Manually saves an item's value to localStorage, ignoring the autoSave flag. | ||
* Manually saves an item's value to storage, ignoring autoSave settings. | ||
* | ||
@@ -347,17 +263,29 @@ * @param key The key of the item to save. | ||
public saveItem(key: string): void { | ||
if (!this.items.hasOwnProperty(key)) { | ||
if (!{}.hasOwnProperty.call(this.items, key)) { | ||
throw new Error(`Unknown key given to ItemsHoldr: '${key}'.`); | ||
} | ||
this.items[key].updateLocalStorage(true); | ||
this.items[key].updateStorage(true); | ||
} | ||
/** | ||
* Manually saves all values to localStorage, ignoring the autoSave flag. | ||
* Manually saves all items to storage, ignoring autoSave settings. | ||
*/ | ||
public saveAll(): void { | ||
for (const key in this.items) { | ||
this.items[key].updateLocalStorage(true); | ||
this.items[key].updateStorage(true); | ||
} | ||
} | ||
/** | ||
* Ensures a key exists in values. If it doesn't, and new values are | ||
* allowed, it creates it; otherwise, it throws an Error. | ||
* | ||
* @param key | ||
*/ | ||
private checkExistence(key: string): void { | ||
if (!{}.hasOwnProperty.call(this.items, key)) { | ||
this.addItem(key, this.values[key]); | ||
} | ||
} | ||
} |
@@ -7,6 +7,5 @@ /** | ||
* @param donor An object whose members are copied to recipient. | ||
* @param noOverride If recipient properties may be overriden (by | ||
* default, false). | ||
* @param noOverride Whether recipient properties may be overriden (by default, false). | ||
* @returns The recipient, which should have the donor proliferated onto it. | ||
*/ | ||
export declare const proliferate: (recipient: any, donor: any, noOverride?: boolean | undefined) => any; |
@@ -10,4 +10,3 @@ define(["require", "exports"], function (require, exports) { | ||
* @param donor An object whose members are copied to recipient. | ||
* @param noOverride If recipient properties may be overriden (by | ||
* default, false). | ||
* @param noOverride Whether recipient properties may be overriden (by default, false). | ||
* @returns The recipient, which should have the donor proliferated onto it. | ||
@@ -14,0 +13,0 @@ */ |
@@ -1,2 +0,1 @@ | ||
/** | ||
@@ -8,4 +7,3 @@ * Proliferates all members of the donor to the recipient recursively, as | ||
* @param donor An object whose members are copied to recipient. | ||
* @param noOverride If recipient properties may be overriden (by | ||
* default, false). | ||
* @param noOverride Whether recipient properties may be overriden (by default, false). | ||
* @returns The recipient, which should have the donor proliferated onto it. | ||
@@ -12,0 +10,0 @@ */ |
@@ -5,2 +5,3 @@ { | ||
"experimentalDecorators": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react", | ||
@@ -7,0 +8,0 @@ "lib": ["dom", "es2015.collection", "es2015.promise", "es5"], |
{ | ||
"extends": "./node_modules/shenanigans-manager/setup/tslint.json", | ||
"linterOptions": { | ||
"exclude": [ | ||
"./node_modules/**/*" | ||
] | ||
}, | ||
"rules": { | ||
"ban-types": false, | ||
"no-any": false, | ||
"no-dynamic-delete": false, | ||
"no-unsafe-any": false, | ||
@@ -7,0 +13,0 @@ "strict-boolean-expressions": false |
@@ -10,3 +10,3 @@ const glob = require("glob"); | ||
{ | ||
entry: `./src/${package.shenanigans.name}.js`, | ||
entry: `./src/index.js`, | ||
name: package.shenanigans.name, | ||
@@ -45,5 +45,4 @@ sources: [ | ||
// multiple entries? | ||
module.exports = { | ||
entry, // IDictionary<string> | ||
entry, | ||
externals, | ||
@@ -50,0 +49,0 @@ output: { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
895689
8395
556
21
62
4