diff --git a/.gitignore b/.gitignore index a545ce5..e39c473 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ +docs/** lib/** +src/**/*.css +src/**/*.d.ts src/**/*.js* +~src/main.js test/**/*.js -test/index.html -test/utils/** -!test/utils/mocks.ts +test/**/*.d.ts node_modules/ npm-debug.log diff --git a/README.md b/README.md index c1726e2..31df924 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Hookups for extensible triggered mod events. + ## Build Process ModAttachr uses [Gulp](http://gulpjs.com/) to automate building, which requires [Node.js](http://node.js.org). diff --git a/package.json b/package.json index fba24b2..8db873b 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,9 @@ }, "license": "MIT", "dependencies": { - "itemsholdr": "^0.5.2" + "itemsholdr": "^0.5.3" }, "devDependencies": { - "gulp-shenanigans": "^0.5.15" + "gulp-shenanigans": "^0.5.20" } } diff --git a/shenanigans.json b/shenanigans.json index 6d755a2..a85ec99 100644 --- a/shenanigans.json +++ b/shenanigans.json @@ -1,10 +1,10 @@ { "dependencies": { - "ItemsHoldr": "^0.5.2" + "ItemsHoldr": "^0.5.3" }, "package": { "description": "Hookups for extensible triggered mod events.", "name": "ModAttachr", - "version": "0.5.1" + "version": "0.5.2" } } diff --git a/src/IModAttachr.ts b/src/IModAttachr.ts index 31c6965..4a4600f 100644 --- a/src/IModAttachr.ts +++ b/src/IModAttachr.ts @@ -1,4 +1,4 @@ -/// +import { IItemsHoldr } from "itemsholdr/lib/IItemsHoldr"; /** * General schema for a mod, including its name, events with callbacks, @@ -69,7 +69,7 @@ export interface IModAttachrSettings { /** * A ItemsHoldr to store mod status locally. */ - ItemsHoldr?: ItemsHoldr.IItemsHoldr; + ItemsHoldr?: IItemsHoldr; /** * Whether there should be a ItemsHoldr created if one isn't given. @@ -110,7 +110,7 @@ export interface IModAttachr { /** * @returns The ItemsHoldr if storeLocally is true (by default, undefined). */ - getItemsHolder(): ItemsHoldr.IItemsHoldr; + getItemsHolder(): IItemsHoldr | undefined; /** * @returns The default scope used to apply mods from, if not this ModAttachr. diff --git a/src/ModAttachr.ts b/src/ModAttachr.ts index f705495..4d53802 100644 --- a/src/ModAttachr.ts +++ b/src/ModAttachr.ts @@ -1,4 +1,5 @@ -/// +import { IItemsHoldr } from "itemsholdr/lib/IItemsHoldr"; +import { ItemsHoldr } from "itemsholdr/lib/ItemsHoldr"; import { ICallbackRegister, IEventCallback, IEventsRegister, IMod, IModAttachr, IModAttachrSettings, IMods @@ -21,7 +22,7 @@ export class ModAttachr implements IModAttachr { /** * A ItemsHoldr object that may be used to store mod status. */ - private ItemsHolder: ItemsHoldr.IItemsHoldr; + private ItemsHolder?: IItemsHoldr; /** * A default scope to apply mod events from, if not this ModAttachr. @@ -48,7 +49,7 @@ export class ModAttachr implements IModAttachr { this.ItemsHolder = settings.ItemsHoldr; } else if (settings.storeLocally) { // If one isn't provided by storeLocally is still true, make one - this.ItemsHolder = new ItemsHoldr.ItemsHoldr(); + this.ItemsHolder = new ItemsHoldr(); } if (settings.mods) { @@ -88,7 +89,7 @@ export class ModAttachr implements IModAttachr { /** * @returns The ItemsHoldr if storeLocally is true (by default, undefined). */ - public getItemsHolder(): ItemsHoldr.IItemsHoldr { + public getItemsHolder(): IItemsHoldr | undefined { return this.ItemsHolder; } diff --git a/test/ModAttachr/_.ts b/test/ModAttachr/_.ts index 2174339..c1cb46d 100644 --- a/test/ModAttachr/_.ts +++ b/test/ModAttachr/_.ts @@ -1,10 +1,3 @@ -/// -/// -/// - import { mochaLoader } from "../main"; -import { mocks } from "../utils/mocks"; -mochaLoader.it("_", (): void => { - chai.expect(() => mocks.mockModAttachr()).to.not.throw(); -}); +mochaLoader.it("_", (): void => { }); diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..5ba42b5 --- /dev/null +++ b/test/index.html @@ -0,0 +1,40 @@ + + + + + ModAttachr Tests + + + + + +
+ + + + + + + + + + + + + + + + + + diff --git a/test/main.ts b/test/main.ts index 7f68c53..78686f4 100644 --- a/test/main.ts +++ b/test/main.ts @@ -2,11 +2,27 @@ import { MochaLoader } from "./utils/MochaLoader"; -declare var require: any; -declare var testPaths: any; +declare var requirejs: any; +declare var testDependencies: string[]; +declare var testPaths: string[]; export const mochaLoader: MochaLoader = new MochaLoader(mocha); +/** + * Informs RequireJS of the file location for a test dependency. + * + * @param testDependencies Modules depended upon for tests. + */ +function redirectTestDependencies(dependencies: string[]): void { + for (const dependency of dependencies) { + requirejs.config({ + paths: { + [dependency.toLowerCase() + "/lib"]: `../node_modules/${dependency.toLowerCase()}/src` + } + }); + } +} + /** * Recursively loads test paths under mocha loader. * @@ -23,17 +39,21 @@ function loadTestPaths(loadingPaths: string[], i: number, onComplete: () => void } mochaLoader.setTestPath(loadingPaths[i]); - require( + requirejs( [loadingPaths[i]], (): void => { loadTestPaths(loadingPaths, i + 1, onComplete); }); } -loadTestPaths( - testPaths, - 0, - (): void => { - mochaLoader.describeTests(); - mochaLoader.run(); - }); +((): void => { + redirectTestDependencies(testDependencies); + + loadTestPaths( + testPaths, + 0, + (): void => { + mochaLoader.describeTests(); + mochaLoader.run(); + }); +})(); diff --git a/test/tsconfig.json b/test/tsconfig.json index 96c911b..b93b9ed 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,13 +1,19 @@ { "compilerOptions": { - "declaration": false, + "declaration": true, "module": "amd", + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noFallthroughCasesInSwitch": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "outDir": "..", + "rootDir": "..", + "strictNullChecks": true, "target": "es3" }, - "files": [ - "main.ts", - "utils/mocks.ts", - "utils/MochaLoader.ts", - "ModAttachr/_.ts" + "include": [ + "./**/*.ts" ] -} \ No newline at end of file +} diff --git a/test/utils/MochaLoader.ts b/test/utils/MochaLoader.ts new file mode 100644 index 0000000..68ca90d --- /dev/null +++ b/test/utils/MochaLoader.ts @@ -0,0 +1,124 @@ +/* This file was auto-generated by gulp-shenanigans */ +/// +/// + +/** + * Grouping of mocha describe() tests. + */ +interface ITestHierarchy { + /** + * Hierarchical children within this describe() group. + */ + children: { + [i: string]: ITestHierarchy; + }; + + /** + * Tests run in this describe(). + */ + tests: { + [i: string]: (done: Function) => void; + }; +} + +/** + * Combines mocha tests into their describe() groups. + */ +export class MochaLoader { + /** + * The underlying mocha instance. + */ + private mocha: Mocha; + + /** + * Root grouping of test hierarchies. + */ + private testHierarchy: ITestHierarchy = { + children: {}, + tests: {} + }; + + /** + * Mocha describe() path for the next test to be added. + */ + private currentTestPath: string[]; + + /** + * Initializes a new instance of the MochaLoader class. + * + * @param mocha The underlying mocha instance. + */ + public constructor(mocha: Mocha) { + this.mocha = mocha; + this.mocha.setup("bdd"); + } + + /** + * Sets the current test path. + * + * @param rawPath A new current test path. + */ + public setTestPath(rawPath: string): void { + this.currentTestPath = rawPath.split("/"); + } + + /** + * Adds a new test under the current test path. + * + * @param testName The name of the test. + * @param test A new test. + */ + public it(testName: string, test: (done: Function) => void): void { + if (!this.currentTestPath) { + throw new Error(`No test path defined before adding test '${testName}'.`); + } + + let testHierarchy: ITestHierarchy = this.testHierarchy; + + for (const part of this.currentTestPath) { + if (!testHierarchy.children[part]) { + testHierarchy = testHierarchy.children[part] = { + children: {}, + tests: {} + }; + } else { + testHierarchy = testHierarchy.children[part]; + } + } + + testHierarchy.tests[testName] = test; + } + + /** + * Finalizes the tests' describe() hierarchy. + */ + public describeTests(): void { + this.describeTestHierarchy(this.testHierarchy); + } + + /** + * Runs tests using mocha. + */ + public run(): void { + this.mocha.run(); + } + + /** + * Recursively describes a test hierarchy and its children hierarchies. + * + * @param testHierarchy A test hierarchy to describe. + */ + private describeTestHierarchy(testHierarchy: ITestHierarchy): void { + for (const testName in testHierarchy.tests) { + if (testName in testHierarchy.tests) { + it(testName, testHierarchy.tests[testName]); + } + } + + for (const childName in testHierarchy.children) { + if (childName in testHierarchy.children) { + describe(childName, (): void => this.describeTestHierarchy(testHierarchy.children[childName])); + } + } + } +} diff --git a/test/utils/fakes.ts b/test/utils/fakes.ts new file mode 100644 index 0000000..cd4cf9a --- /dev/null +++ b/test/utils/fakes.ts @@ -0,0 +1,10 @@ +import { IModAttachr, IModAttachrSettings } from "../../src/IModAttachr"; +import { ModAttachr } from "../../src/ModAttachr"; + +/** + * @param settings Settings for the ModAttachr. + * @returns An ModAttachr instance. + */ +export function mockModAttachr(settings?: IModAttachrSettings): IModAttachr { + return new ModAttachr(settings); +} diff --git a/test/utils/mocks.ts b/test/utils/mocks.ts deleted file mode 100644 index b79131e..0000000 --- a/test/utils/mocks.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { IModAttachr, IModAttachrSettings } from "../../src/IModAttachr"; -import { ModAttachr } from "../../src/ModAttachr"; - -export const mocks = { - /** - * @param settings Settings for the ModAttachr. - * @returns An ModAttachr instance. - */ - mockModAttachr: (settings?: IModAttachrSettings): IModAttachr => { - return new ModAttachr(settings); - } -}; diff --git a/tsconfig.json b/tsconfig.json index f1dd816..266200b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,17 @@ { "compilerOptions": { - "module": "amd", - "target": "es3", - "noImplicitAny": true, "declaration": true, - "outDir": "dist" + "module": "amd", + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noFallthroughCasesInSwitch": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "strictNullChecks": true, + "target": "es3" }, - "files": [ - "src/IModAttachr.ts", - "src/ModAttachr.ts" + "include": [ + "./src/**/*.ts" ] -} \ No newline at end of file +} diff --git a/tslint.json b/tslint.json index 5c23448..326aeb4 100644 --- a/tslint.json +++ b/tslint.json @@ -15,7 +15,6 @@ "interface-name": [true, "always-prefix"], "jsdoc-format": true, "label-position": true, - "label-undefined": true, "max-line-length": [true, 140], "member-access": true, "member-ordering": [ @@ -38,9 +37,7 @@ "trace" ], "no-construct": true, - "no-constructor-vars": true, "no-debugger": true, - "no-duplicate-key": true, "no-duplicate-variable": true, "no-empty": true, "no-eval": true, @@ -50,14 +47,11 @@ "no-string-literal": true, "no-switch-case-fall-through": true, "no-trailing-whitespace": true, - "no-unreachable": true, "no-unsafe-finally": true, "no-unused-expression": true, - "no-unused-variable": true, "no-unused-new": true, "no-use-before-declare": true, "no-var-keyword": true, - "no-var-requires": true, "one-line": [ true, "check-catch", @@ -92,11 +86,6 @@ } ], "use-isnan": true, - "use-strict": [ - true, - "check-module", - "check-function" - ], "whitespace": [ true, "check-branch", diff --git a/typings/ItemsHoldr.d.ts b/typings/ItemsHoldr.d.ts deleted file mode 100644 index 38475be..0000000 --- a/typings/ItemsHoldr.d.ts +++ /dev/null @@ -1,777 +0,0 @@ -declare namespace ItemsHoldr { - /** - * A container to hold ItemValue objects, keyed by name. - */ - interface IItems { - [i: string]: IItemValue; - } - /** - * Settings to initialize a new instance of the IItemsHoldr interface. - */ - interface IItemsHoldrSettings { - /** - * Initial settings for IItemValues to store. - */ - values?: IItemValueDefaults; - /** - * Whether new items are allowed to be added (by default, true). - */ - allowNewItems?: boolean; - /** - * Whether values should be saved immediately upon being set. - */ - autoSave?: boolean; - /** - * Arguments to pass to triggered callback Functions. - */ - callbackArgs?: any[]; - /** - * A localStorage object to use instead of the global localStorage. - */ - localStorage?: any; - /** - * A prefix to add before IItemsValue keys - */ - prefix?: string; - /** - * Default attributes for IItemValues. - */ - defaults?: IItemValueDefaults; - /** - * Any hardcoded changes to element content. - */ - displayChanges?: { - [i: string]: string; - }; - /** - * Whether an HTML container should be created to house the IItemValue elements. - */ - doMakeContainer?: boolean; - /** - * Arguments to pass to create the container, if not the default div and className. - */ - containersArguments?: [string, any][]; - } - /** - * A versatile container to store and manipulate values in localStorage, and - * optionally keep an updated HTML container showing these values. - */ - interface IItemsHoldr { - /** - * @returns The values contained within, keyed by their keys. - */ - getValues(): { - [i: string]: IItemValue; - }; - /** - * @returns Default attributes for values. - */ - getDefaults(): IItemValueDefaults; - /** - * @returns A reference to localStorage or a replacment object. - */ - getLocalStorage(): Storage; - /** - * @returns Whether this should save changes to localStorage automatically. - */ - getAutoSave(): boolean; - /** - * @returns The prefix to store thigns under in localStorage. - */ - getPrefix(): string; - /** - * @returns The container HTML element, if it exists. - */ - getContainer(): HTMLElement; - /** - * @returns createElement arguments for HTML containers, outside-to-inside. - */ - getContainersArguments(): [string, any][]; - /** - * @returns Any hard-coded changes to element content. - */ - getDisplayChanges(): { - [i: string]: string; - }; - /** - * @returns Arguments to be passed to triggered event callbacks. - */ - getCallbackArgs(): any[]; - /** - * @returns String keys for each of the stored IItemValues. - */ - getKeys(): string[]; - /** - * @returns All String keys of items. - */ - getItemKeys(): string[]; - /** - * @param key The key for a known value. - * @returns The known value of a key, assuming that key exists. - */ - getItem(key: string): any; - /** - * @param key The key for a known value. - * @returns The settings for that particular key. - */ - getObject(key: string): any; - /** - * @param key The key for a potentially known value. - * @returns Whether there is a value under that key. - */ - hasKey(key: string): boolean; - /** - * @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 - * container (if they both exist). - * - * @param key The key of the element to remove. - */ - removeItem(key: string): void; - /** - * 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). - * - * @param key The key of the ItemValue. - * @param value The new value for the ItemValue. - */ - setItem(key: string, value: any): void; - /** - * Increases the value for the ItemValue under the given key, via addition for - * Numbers or concatenation for Strings. - * - * @param key The key of the ItemValue. - * @param amount The 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. - * - * @param key The key of the ItemValue. - * @param amount The amount to increase by (by default, 1). - */ - decrease(key: string, amount?: number): void; - /** - * Toggles whether a value is true or false. - * - * @param key The key of the ItemValue. - */ - 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. - * - * @param key - */ - checkExistence(key: string): void; - /** - * Manually saves an item's value to localStorage, ignoring the autoSave flag. - * - * @param key The key of the item to save. - */ - saveItem(key: string): void; - /** - * Manually saves all values to localStorage, ignoring the autoSave flag. - */ - saveAll(): void; - /** - * Hides the container Element by setting its visibility to hidden. - */ - hideContainer(): void; - /** - * Shows the container Element by setting its visibility to visible. - */ - displayContainer(): void; - /** - * Creates the container Element, which contains a child for each ItemValue that - * specifies hasElement to be true. - * - * @param containers An Array representing the Element to be created and the - * children between it and the contained ItemValues. - * Each contained Object has a String tag name as its - * first member, followed by any number of Objects to apply - * via createElement. - * @returns A newly created Element that can be used as a container. - */ - makeContainer(containers: [string, any][]): HTMLElement; - /** - * @returns Whether displayChanges has an entry for a particular value. - */ - hasDisplayChange(value: string): boolean; - /** - * @returns The displayChanges entry for a particular value. - */ - getDisplayChange(value: string): string; - /** - * Creates a new HTMLElement of the given type. For each Object given as - * arguments after, each member is proliferated onto the element. - * - * @param tag The type of the HTMLElement (by default, "div"). - * @param args Any number of Objects to be proliferated onto the - * new HTMLElement. - * @returns A newly created HTMLElement of the given tag. - */ - createElement(tag?: string, ...args: any[]): HTMLElement; - /** - * 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. - */ - proliferate(recipient: any, donor: any, noOverride?: boolean): any; - /** - * Identical to proliferate, but tailored for HTML elements because many - * element attributes don't play nicely with JavaScript Array standards. - * Looking at you, HTMLCollection! - * - * @param recipient An HTMLElement 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. - */ - proliferateElement(recipient: any, donor: any, noOverride?: boolean): any; - } - /** - * A mapping of ItemValue values to triggered callbacks. - */ - interface ITriggers { - [i: string]: Function; - [j: number]: Function; - } - /** - * A container of default values to pass to IItemValues, keyed by the - * IItemValue keys.m - */ - interface IItemValueDefaults { - [i: string]: IItemValueSettings; - } - /** - * Settings to initialize a new instance of the IItemValue interface. - */ - interface IItemValueSettings { - /** - * An initial value to store. - */ - value?: any; - /** - * A default initial value to store, if value isn't provided. - */ - valueDefault?: any; - /** - * Whether the value should be stored in the IItemHoldr's localStorage. - */ - storeLocally?: boolean; - /** - * A mapping of values to callbacks that should be triggered when value - * is equal to them. - */ - triggers?: ITriggers; - /** - * Whether an Element should be created and synced to the value. - */ - hasElement?: boolean; - /** - * An Element tag to use in creating the element, if hasElement is true. - */ - elementTag?: string; - /** - * A minimum value for the value to equal, if value is a number. - */ - minimum?: number; - /** - * A callback to call when the value reaches the minimum value. - */ - onMinimum?: Function; - /** - * A maximum value for the value to equal, if value is a number. - */ - maximum?: number; - /** - * A callback to call when the value reaches the maximum value. - */ - onMaximum?: Function; - /** - * A maximum number to modulo the value against, if value is a number. - */ - modularity?: number; - /** - * A callback to call when the value reaches modularity. - */ - onModular?: Function; - /** - * A Function to transform the value when it's being set. - */ - transformGet?: Function; - /** - * A Function to transform the value when it's being retrieved. - */ - transformSet?: Function; - } - /** - * Storage container for a single IItemsHoldr value. The value may have triggers - * assigned to value, modularity, and other triggers, as well as an HTML element. - */ - interface IItemValue { - /** - * @returns The value being stored, with a transformGet applied if one exists. - */ - getValue(): any; - /** - * Sets the value being stored, with a is a transformSet applied if one exists. - * Any attached triggers to the new value will be called. - * - * @param value The desired value to now store. - */ - setValue(value: any): void; - /** - * @returns The stored HTML element, if it exists. - */ - getElement(): HTMLElement; - /** - * General update Function to be run whenever the internal value is changed. - * It runs all the trigger, modular, etc. checks, updates the HTML element - * if there is one, and updates localStorage if needed. - */ - update(): void; - /** - * Stores a ItemValue's value in localStorage under the prefix plus its key. - * - * @param overrideAutoSave Whether the policy on saving should be ignored - * so saving happens regardless. By default, false. - */ - updateLocalStorage(overrideAutoSave?: boolean): void; - } - /** - * A versatile container to store and manipulate values in localStorage, and - * optionally keep an updated HTML container showing these values. - */ - class ItemsHoldr implements IItemsHoldr { - /** - * Settings used to construct this ItemsHoldr. - */ - private settings; - /** - * The ItemValues being stored, keyed by name. - */ - private items; - /** - * A listing of all the String keys for the stored items. - */ - private itemKeys; - /** - * Default attributes for ItemValues. - */ - private defaults; - /** - * A reference to localStorage or a replacement object. - */ - private localStorage; - /** - * A prefix to store things under in localStorage. - */ - private prefix; - /** - * Whether new items are allowed to be created using setItem. - */ - private allowNewItems; - /** - * Whether this should save changes to localStorage automatically. - */ - private autoSave; - /** - * A container element containing children for each value's element. - */ - private container; - /** - * An Array of elements as createElement arguments, outside-to-inside. - */ - private containersArguments; - /** - * Any hardcoded changes to element content, such as "INF" for Infinity. - */ - private displayChanges; - /** - * Arguments to be passed to triggered callback Functions. - */ - private callbackArgs; - /** - * Initializes a new instance of the ItemsHoldr class. - * - * @param settings Any optional custom settings. - */ - constructor(settings?: IItemsHoldrSettings); - /** - * @param index An index for a key. - * @returns The indexed key. - */ - key(index: number): string; - /** - * @returns The values contained within, keyed by their keys. - */ - getValues(): { - [i: string]: IItemValue; - }; - /** - * @returns {Mixed} Default attributes for values. - */ - getDefaults(): any; - /** - * @returns A reference to localStorage or a replacment object. - */ - getLocalStorage(): Storage; - /** - * @returns Whether this should save changes to localStorage automatically. - */ - getAutoSave(): boolean; - /** - * @returns The prefix to store thigns under in localStorage. - */ - getPrefix(): string; - /** - * @returns The container HTML element, if it exists. - */ - getContainer(): HTMLElement; - /** - * @returns createElement arguments for HTML containers, outside-to-inside. - */ - getContainersArguments(): [string, any][]; - /** - * @returns Any hard-coded changes to element content. - */ - getDisplayChanges(): { - [i: string]: string; - }; - /** - * @returns Arguments to be passed to triggered event callbacks. - */ - getCallbackArgs(): any[]; - /** - * @returns String keys for each of the stored ItemValues. - */ - getKeys(): string[]; - /** - * @returns All String keys of items. - */ - getItemKeys(): string[]; - /** - * @param key The key for a known value. - * @returns The known value of a key, assuming that key exists. - */ - getItem(key: string): any; - /** - * @param key The key for a known value. - * @returns The settings for that particular key. - */ - getObject(key: string): any; - /** - * @param key The key for a potentially known value. - * @returns Whether there is a value under that key. - */ - hasKey(key: string): boolean; - /** - * @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 - * container (if they both exist). - * - * @param key The key of the element to remove. - */ - removeItem(key: string): void; - /** - * 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). - * - * @param key The key of the ItemValue. - * @param value The new value for the ItemValue. - */ - setItem(key: string, value: any): void; - /** - * Increases the value for the ItemValue under the given key, via addition for - * Numbers or concatenation for Strings. - * - * @param key The key of the ItemValue. - * @param amount The 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. - * - * @param key The key of the ItemValue. - * @param amount The amount to decrease by (by default, 1). - */ - decrease(key: string, amount?: number): void; - /** - * Toggles whether a value is true or false. - * - * @param key The key of the ItemValue. - */ - toggle(key: string): void; - /** - * Toggles this.autoSave. - */ - toggleAutoSave(): 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 - */ - checkExistence(key: string): void; - /** - * Manually saves an item's value to localStorage, ignoring the autoSave flag. - * - * @param key The key of the item to save. - */ - saveItem(key: string): void; - /** - * Manually saves all values to localStorage, ignoring the autoSave flag. - */ - saveAll(): void; - /** - * Hides the container Element by setting its visibility to hidden. - */ - hideContainer(): void; - /** - * Shows the container Element by setting its visibility to visible. - */ - displayContainer(): void; - /** - * Creates the container Element, which contains a child for each ItemValue that - * specifies hasElement to be true. - * - * @param containers An Array representing the Element to be created and the - * children between it and the contained ItemValues. - * Each contained Object has a String tag name as its - * first member, followed by any number of Objects to apply - * via createElement. - * @returns A newly created Element that can be used as a container. - */ - makeContainer(containers: [string, any][]): HTMLElement; - /** - * @returns Whether displayChanges has an entry for a particular value. - */ - hasDisplayChange(value: string): boolean; - /** - * @returns The displayChanges entry for a particular value. - */ - getDisplayChange(value: string): string; - /** - * Creates a new HTMLElement of the given type. For each Object given as - * arguments after, each member is proliferated onto the element. - * - * @param tag The type of the HTMLElement (by default, "div"). - * @param args Any number of Objects to be proliferated onto the - * new HTMLElement. - * @returns A newly created HTMLElement of the given tag. - */ - createElement(tag?: string, ...args: any[]): HTMLElement; - /** - * 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. - */ - proliferate(recipient: any, donor: any, noOverride?: boolean): any; - /** - * Identical to proliferate, but tailored for HTML elements because many - * element attributes don't play nicely with JavaScript Array standards. - * Looking at you, HTMLCollection! - * - * @param recipient An HTMLElement 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. - */ - proliferateElement(recipient: any, donor: any, noOverride?: boolean): HTMLElement; - /** - * Creates an Object that can be used to create a new LocalStorage - * replacement, if the JavaScript environment doesn't have one. - * - * @returns {Object} - */ - private createPlaceholderStorage(); - /** - * Resets this.items to their default values and resets this.itemKeys. - */ - private resetItemsToDefaults(); - } - /** - * Storage container for a single ItemsHoldr value. The value may have triggers - * assigned to value, modularity, and other triggers, as well as an HTML element. - */ - class ItemValue implements IItemValue { - /** - * The container ItemsHoldr governing usage of this ItemsValue. - */ - private ItemsHolder; - /** - * The unique key identifying this ItemValue in the ItemsHoldr. - */ - private key; - /** - * A default initial value to store, if value isn't provided. - */ - private valueDefault; - /** - * Whether the value should be stored in the ItemHoldr's localStorage. - */ - private storeLocally; - /** - * A mapping of values to callbacks that should be triggered when value - * is equal to them. - */ - private triggers; - /** - * An HTML element whose second child's textContent is always set to that of the element. - */ - private element; - /** - * Whether an Element should be created and synced to the value. - */ - private hasElement; - /** - * An Element tag to use in creating the element, if hasElement is true. - */ - private elementTag; - /** - * A minimum value for the value to equal, if value is a number. - */ - private minimum; - /** - * A callback to call when the value reaches the minimum value. - */ - private onMinimum; - /** - * A maximum value for the value to equal, if value is a number. - */ - private maximum; - /** - * A callback to call when the value reaches the maximum value. - */ - private onMaximum; - /** - * A maximum number to modulo the value against, if value is a number. - */ - private modularity; - /** - * A callback to call when the value reaches modularity. - */ - private onModular; - /** - * A Function to transform the value when it's being set. - */ - private transformGet; - /** - * A Function to transform the value when it's being retrieved. - */ - private transformSet; - /** - * The value being stored. - */ - private value; - /** - * Creates a new ItemValue with the given key and settings. Defaults are given - * to the value via proliferate before the settings. - * - * @constructor - * @param ItemsHolder The container for this value. - * @param key The key to reference this new ItemValue by. - * @param settings Any optional custom settings. - */ - constructor(ItemsHolder: IItemsHoldr, key: string, settings?: any); - /** - * @returns The value being stored, with a transformGet applied if one exists. - */ - getValue(): any; - /** - * Sets the value being stored, with a is a transformSet applied if one exists. - * Any attached triggers to the new value will be called. - * - * @param value The desired value to now store. - */ - setValue(value: any): void; - /** - * @returns The stored HTML element, if it exists. - */ - getElement(): HTMLElement; - /** - * General update Function to be run whenever the internal value is changed. - * It runs all the trigger, modular, etc. checks, updates the HTML element - * if there is one, and updates localStorage if needed. - */ - update(): void; - /** - * Stores a ItemValue's value in localStorage under the prefix plus its key. - * - * @param [overrideAutoSave] Whether the policy on saving should be - * ignored (so saving happens regardless). By - * default, false. - */ - updateLocalStorage(overrideAutoSave?: boolean): void; - /** - * Checks if the current value should trigger a callback, and if so calls it. - */ - private checkTriggers(); - /** - * Checks if the current value is greater than the modularity (assuming - * modular is a non-zero Numbers), and if so, continuously reduces value and - * calls this.onModular. - */ - private checkModularity(); - /** - * Updates the ItemValue's element's second child to be the ItemValue's value. - */ - private updateElement(); - /** - * Retrieves a ItemValue's value from localStorage, making sure not to try to - * JSON.parse an undefined or null value. - * - * @returns {Mixed} - */ - private retrieveLocalStorage(); - } -} -declare var module: any;