danholibraryjs 1.5.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -2
- package/README.md +12 -304
- package/Time.xlsx +0 -0
- package/dist/Classes/{Event.d.ts → Events/Event.d.ts} +9 -8
- package/dist/Classes/{Event.js → Events/Event.js} +17 -9
- package/dist/Classes/{EventCollection.d.ts → Events/EventCollection.d.ts} +10 -10
- package/dist/Classes/{EventCollection.js → Events/EventCollection.js} +28 -29
- package/dist/Classes/{EventEmitter.d.ts → Events/EventEmitter.d.ts} +33 -7
- package/dist/Classes/{EventEmitter.js → Events/EventEmitter.js} +33 -3
- package/dist/Classes/Events/index.d.ts +3 -0
- package/dist/Classes/Events/index.js +19 -0
- package/dist/Classes/Time/Date.d.ts +147 -0
- package/dist/Classes/Time/Date.js +238 -0
- package/dist/Classes/Time/Time.d.ts +65 -0
- package/dist/Classes/Time/Time.js +117 -0
- package/dist/Classes/Time/TimeProperties.d.ts +3 -0
- package/dist/{Interfaces/BaseEventInterface.js → Classes/Time/TimeProperties.js} +0 -0
- package/dist/Classes/Time/TimeSpan.d.ts +123 -0
- package/dist/Classes/Time/TimeSpan.js +179 -0
- package/dist/Classes/Time/index.d.ts +4 -0
- package/dist/Classes/Time/index.js +20 -0
- package/dist/Classes/index.d.ts +2 -3
- package/dist/Classes/index.js +7 -4
- package/dist/Classes/store.d.ts +79 -0
- package/dist/Classes/store.js +85 -0
- package/dist/Extensions/Array.d.ts +31 -0
- package/dist/Extensions/Array.js +26 -0
- package/dist/Extensions/Map.d.ts +38 -0
- package/dist/Extensions/Map.js +31 -0
- package/dist/Extensions/Object.d.ts +16 -0
- package/dist/Extensions/Object.js +8 -0
- package/dist/Extensions/String.d.ts +26 -0
- package/dist/Extensions/String.js +17 -0
- package/dist/Extensions/index.d.ts +29 -0
- package/dist/Extensions/index.js +71 -0
- package/dist/Functions/GetCSSProperty.d.ts +15 -0
- package/dist/Functions/GetCSSProperty.js +26 -0
- package/dist/Functions/HTMLEvent.d.ts +6 -0
- package/dist/Functions/HTMLEvent.js +6 -0
- package/dist/Functions/SetNavigationSelected.js +2 -0
- package/dist/Functions/index.d.ts +1 -0
- package/dist/Functions/index.js +6 -1
- package/dist/Interfaces/ElementOptions.d.ts +12 -15
- package/dist/Interfaces/IReplacement.d.ts +1 -1
- package/dist/Interfaces/index.d.ts +0 -1
- package/dist/Interfaces/index.js +5 -2
- package/dist/Types/BetterTypes.d.ts +9 -0
- package/dist/{Interfaces/IHTMLEvent.js → Types/BetterTypes.js} +0 -0
- package/dist/Types/Date.d.ts +6 -0
- package/dist/Types/{EventHandler.js → Date.js} +0 -0
- package/dist/Types/Events.d.ts +10 -0
- package/dist/Types/{IElement.js → Events.js} +0 -0
- package/dist/Types/PropertiesWith.d.ts +13 -0
- package/dist/Types/{StringRegex.js → PropertiesWith.js} +0 -0
- package/dist/Types/TransformTypes.d.ts +13 -0
- package/dist/Types/TransformTypes.js +2 -0
- package/dist/Types/index.d.ts +31 -3
- package/dist/Types/index.js +10 -4
- package/dist/index.d.ts +5 -5
- package/dist/index.js +19 -10
- package/docs/Classes.md +488 -0
- package/docs/Extensions.md +146 -0
- package/docs/Functions.md +53 -0
- package/docs/Interfaces.md +34 -0
- package/docs/Types.md +137 -0
- package/docs/index.md +29 -0
- package/package.json +22 -21
- package/src/Classes/{Event.ts → Events/Event.ts} +19 -14
- package/src/Classes/Events/EventCollection.ts +109 -0
- package/src/Classes/{EventEmitter.ts → Events/EventEmitter.ts} +37 -11
- package/src/Classes/Events/index.ts +3 -0
- package/src/Classes/Time/Date.ts +264 -0
- package/src/Classes/Time/Time.ts +134 -0
- package/src/Classes/Time/TimeProperties.ts +3 -0
- package/src/Classes/Time/TimeSpan.ts +195 -0
- package/src/Classes/Time/index.ts +4 -0
- package/src/Classes/index.ts +2 -3
- package/src/Classes/store.ts +95 -0
- package/src/Extensions/Array.ts +57 -0
- package/src/Extensions/Map.ts +73 -0
- package/src/Extensions/Object.ts +25 -0
- package/src/Extensions/String.ts +43 -0
- package/src/Extensions/index.ts +83 -0
- package/src/Functions/GetCSSProperty.ts +27 -0
- package/src/Functions/HTMLEvent.ts +6 -0
- package/src/Functions/SetNavigationSelected.ts +1 -0
- package/src/Functions/index.ts +2 -1
- package/src/Interfaces/ElementOptions.ts +18 -14
- package/src/Interfaces/IReplacement.ts +1 -1
- package/src/Interfaces/index.ts +1 -2
- package/src/Types/BetterTypes.ts +10 -0
- package/src/Types/Date.ts +7 -0
- package/src/Types/Events.ts +15 -0
- package/src/Types/PropertiesWith.ts +14 -0
- package/src/Types/TransformTypes.ts +18 -0
- package/src/Types/index.ts +36 -3
- package/src/index.ts +5 -6
- package/tsconfig.json +99 -7
- package/dist/Extensions.d.ts +0 -85
- package/dist/Extensions.js +0 -84
- package/dist/Interfaces/BaseEventInterface.d.ts +0 -4
- package/dist/Interfaces/IHTMLEvent.d.ts +0 -4
- package/dist/Types/EventHandler.d.ts +0 -7
- package/dist/Types/IElement.d.ts +0 -9
- package/dist/Types/StringRegex.d.ts +0 -2
- package/src/Classes/EventCollection.ts +0 -116
- package/src/Extensions.ts +0 -185
- package/src/Interfaces/BaseEventInterface.ts +0 -4
- package/src/Types/EventHandler.ts +0 -12
- package/src/Types/IElement.ts +0 -9
- package/src/Types/StringRegex.ts +0 -2
- package/test.js +0 -20
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,102 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
+
"lib": ["ESNext", "DOM"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
|
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
|
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
|
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
+
|
|
26
|
+
/* Modules */
|
|
27
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
28
|
+
"rootDir": "./src", /* Specify the root folder within your source files. */
|
|
29
|
+
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
30
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
31
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
32
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
33
|
+
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
|
|
34
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
35
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
36
|
+
"resolveJsonModule": true, /* Enable importing .json files */
|
|
37
|
+
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
|
38
|
+
|
|
39
|
+
/* JavaScript Support */
|
|
40
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
|
|
41
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
42
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
|
|
43
|
+
|
|
44
|
+
/* Emit */
|
|
45
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
46
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
47
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
48
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
49
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
|
|
50
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
51
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
52
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
53
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
54
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
|
|
55
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
56
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
57
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
58
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
59
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
60
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
61
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
62
|
+
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
|
63
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
|
64
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
65
|
+
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
|
66
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
67
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
68
|
+
|
|
69
|
+
/* Interop Constraints */
|
|
70
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
71
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
72
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
|
|
73
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
74
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
75
|
+
|
|
76
|
+
/* Type Checking */
|
|
77
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
78
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
|
|
79
|
+
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
|
|
80
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
81
|
+
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
|
|
82
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
83
|
+
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
|
|
84
|
+
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
|
|
85
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
86
|
+
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
|
|
87
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
|
|
88
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
89
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
90
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
91
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
92
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
93
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
|
|
94
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
95
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
96
|
+
|
|
97
|
+
/* Completeness */
|
|
98
|
+
"skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
99
|
+
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
|
|
100
|
+
"watch": true,
|
|
101
|
+
},
|
|
10
102
|
}
|
package/dist/Extensions.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import ElementOptions from "./Interfaces/ElementOptions";
|
|
2
|
-
import IReplacement from "./Interfaces/IReplacement";
|
|
3
|
-
declare global {
|
|
4
|
-
interface Document {
|
|
5
|
-
/**
|
|
6
|
-
* Creates an element like Document#createElement, however with construction options to assign values in construction instead of after construction.
|
|
7
|
-
* @param tagName HTMLElement tag name
|
|
8
|
-
* @param options Construction options, instead of assigning values after construction
|
|
9
|
-
*/
|
|
10
|
-
createProperElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementOptions): HTMLElementTagNameMap[K];
|
|
11
|
-
}
|
|
12
|
-
interface HTMLCollection {
|
|
13
|
-
/**
|
|
14
|
-
* Converts HTMLCollection to Element[]
|
|
15
|
-
*/
|
|
16
|
-
array(): Element[];
|
|
17
|
-
}
|
|
18
|
-
interface Array<T> {
|
|
19
|
-
/**
|
|
20
|
-
* Pushes items to array and returns self with new items
|
|
21
|
-
* @param items Items to add to array
|
|
22
|
-
*/
|
|
23
|
-
add(...items: Array<T>): this;
|
|
24
|
-
/**
|
|
25
|
-
* Removes item from array and returns self without item
|
|
26
|
-
* @param item Item to remove
|
|
27
|
-
*/
|
|
28
|
-
remove(item: T): this;
|
|
29
|
-
/**
|
|
30
|
-
* Returns a random element from array
|
|
31
|
-
*/
|
|
32
|
-
random(): T;
|
|
33
|
-
}
|
|
34
|
-
interface Map<K, V> {
|
|
35
|
-
/**
|
|
36
|
-
* Converts into Array<[Key, Value]>
|
|
37
|
-
*/
|
|
38
|
-
array(): [K, V][];
|
|
39
|
-
/**
|
|
40
|
-
* Maps values into new types of generics
|
|
41
|
-
* @param callback Callbacking function to map values
|
|
42
|
-
*/
|
|
43
|
-
map<EK, EV>(callback: (value: V, key?: K, index?: number, map?: this) => [EK, EV]): Map<EK, EV>;
|
|
44
|
-
/**
|
|
45
|
-
* Returns array of "accepted" values. Criteria defined in callback param
|
|
46
|
-
* @param callback Callbacking function to filter away unwanted values
|
|
47
|
-
*/
|
|
48
|
-
filter(callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean): Map<K, V>;
|
|
49
|
-
/**
|
|
50
|
-
* Returns array of keys
|
|
51
|
-
*/
|
|
52
|
-
keyArr(): Array<K>;
|
|
53
|
-
/**
|
|
54
|
-
* Returns array of values
|
|
55
|
-
*/
|
|
56
|
-
valueArr(): Array<V>;
|
|
57
|
-
/**
|
|
58
|
-
* Returns first [key, value] match to callback param
|
|
59
|
-
* @param callback Callbacking function to find KeyValuePair
|
|
60
|
-
*/
|
|
61
|
-
find(callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean): [K, V];
|
|
62
|
-
/**
|
|
63
|
-
* Whether or not map includes a value. Returns true if it does, false if not ¯\_(ツ)_/¯
|
|
64
|
-
* @param value Value that may be includded in map
|
|
65
|
-
* @param fromIndex Start looking for value from specific index+. Default: 0
|
|
66
|
-
*/
|
|
67
|
-
includes(value: V, fromIndex?: number): boolean;
|
|
68
|
-
}
|
|
69
|
-
interface String {
|
|
70
|
-
/**
|
|
71
|
-
* Uppercases first letter of string
|
|
72
|
-
*/
|
|
73
|
-
toPascalCase(): string;
|
|
74
|
-
/**
|
|
75
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '_')
|
|
76
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
77
|
-
*/
|
|
78
|
-
toSnakeCase(replaceOptions?: IReplacement): string;
|
|
79
|
-
/**
|
|
80
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '-')
|
|
81
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
82
|
-
*/
|
|
83
|
-
toKebabCase(replaceOptions?: IReplacement): string;
|
|
84
|
-
}
|
|
85
|
-
}
|
package/dist/Extensions.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
Document.prototype.createProperElement = function (tagName, options) {
|
|
4
|
-
let baseElement = document.createElement(tagName);
|
|
5
|
-
if (!options)
|
|
6
|
-
return baseElement;
|
|
7
|
-
if (options.classes) {
|
|
8
|
-
baseElement.classList.add(...options.classes);
|
|
9
|
-
}
|
|
10
|
-
if (options.attributes) {
|
|
11
|
-
options.attributes.forEach(([attribute, value]) => baseElement.setAttribute(attribute, value));
|
|
12
|
-
}
|
|
13
|
-
if (options.children) {
|
|
14
|
-
baseElement.append(...[].concat(options.children));
|
|
15
|
-
}
|
|
16
|
-
if (options.events) {
|
|
17
|
-
options.events.forEach(({ name, handler }) => (baseElement.addEventListener(name, handler)));
|
|
18
|
-
}
|
|
19
|
-
return baseElement;
|
|
20
|
-
};
|
|
21
|
-
HTMLCollection.prototype.array = function () {
|
|
22
|
-
let result = new Array();
|
|
23
|
-
for (let i = 0; i < this.length; i++) {
|
|
24
|
-
result.push(this.item(i));
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
Array.prototype.add = function (...items) {
|
|
29
|
-
this.push(...items);
|
|
30
|
-
return this;
|
|
31
|
-
};
|
|
32
|
-
Array.prototype.remove = function (item) {
|
|
33
|
-
const itemInArray = this.includes(item) ? item : this.find(i => i == item);
|
|
34
|
-
if (!itemInArray)
|
|
35
|
-
throw new Error(`item is not in array!`);
|
|
36
|
-
const itemIndex = this.indexOf(itemInArray);
|
|
37
|
-
this.splice(itemIndex, 1);
|
|
38
|
-
return this;
|
|
39
|
-
};
|
|
40
|
-
Array.prototype.random = function () {
|
|
41
|
-
const randomIndex = Math.round(Math.random() * this.length);
|
|
42
|
-
return this[randomIndex];
|
|
43
|
-
};
|
|
44
|
-
Map.prototype.array = function () {
|
|
45
|
-
let result = new Array();
|
|
46
|
-
for (const kvp of this) {
|
|
47
|
-
result.push(kvp);
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
Map.prototype.map = function (callback) {
|
|
52
|
-
return this.array()
|
|
53
|
-
.map(([k, v], i) => callback(v, k, i, this))
|
|
54
|
-
.reduce((map, [key, value]) => map.set(key, value), new Map());
|
|
55
|
-
};
|
|
56
|
-
Map.prototype.filter = function (callback) {
|
|
57
|
-
return this.array()
|
|
58
|
-
.filter(([k, v], i) => callback(v, k, i, this))
|
|
59
|
-
.reduce((map, [key, value]) => map.set(key, value), new Map());
|
|
60
|
-
};
|
|
61
|
-
Map.prototype.keyArr = function () {
|
|
62
|
-
return this.array().map(([k]) => k);
|
|
63
|
-
};
|
|
64
|
-
Map.prototype.valueArr = function () {
|
|
65
|
-
return this.array().map(([_, v]) => v);
|
|
66
|
-
};
|
|
67
|
-
Map.prototype.find = function (callback) {
|
|
68
|
-
return this.array().find(([k, v], i) => callback(v, k, i, this));
|
|
69
|
-
};
|
|
70
|
-
Map.prototype.includes = function (item, fromIndex) {
|
|
71
|
-
return this.valueArr().includes(item, fromIndex);
|
|
72
|
-
};
|
|
73
|
-
String.prototype.toPascalCase = function () {
|
|
74
|
-
return this.substring(0, 1).toUpperCase() + this.substring(1);
|
|
75
|
-
};
|
|
76
|
-
function spaceReplacer(self, replacer, replacement) {
|
|
77
|
-
return self.replace(new RegExp(`${typeof replacer == 'string' ? replacer : replacer.source}+`), replacement);
|
|
78
|
-
}
|
|
79
|
-
String.prototype.toSnakeCase = function (replaceOptions = { replacer: ' ', replacement: '_' }) {
|
|
80
|
-
return spaceReplacer(this, replaceOptions.replacer, replaceOptions.replacement);
|
|
81
|
-
};
|
|
82
|
-
String.prototype.toKebabCase = function (replaceOptions = { replacer: ' ', replacement: '-' }) {
|
|
83
|
-
return spaceReplacer(this, replaceOptions.replacer, replaceOptions.replacement);
|
|
84
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import BaseEvent from "../Interfaces/BaseEventInterface";
|
|
2
|
-
/**
|
|
3
|
-
* Eventhandler type for:
|
|
4
|
-
* @see EventCollection
|
|
5
|
-
*/
|
|
6
|
-
export declare type EventHandler<Events extends BaseEvent, Event extends keyof Events, ReturnType = any> = (args: Events[Event]) => ReturnType;
|
|
7
|
-
export default EventHandler;
|
package/dist/Types/IElement.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Used for HTMLElement.append in ElementOptions, Document.createProperElement.
|
|
3
|
-
* IElement accepts HTML Elements or HTMl-like strings.
|
|
4
|
-
*
|
|
5
|
-
* @see HTMLElement.append
|
|
6
|
-
* @see Document.createProperElement
|
|
7
|
-
*/
|
|
8
|
-
export declare type IElement = HTMLElement | string;
|
|
9
|
-
export default IElement;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import BaseEvent from "../Interfaces/BaseEventInterface";
|
|
2
|
-
import EventHandler from "../Types/EventHandler";
|
|
3
|
-
import Event from './Event';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Collection of Events from @see EventEmitter
|
|
7
|
-
* @borrows EventHandler
|
|
8
|
-
* @borrows Event
|
|
9
|
-
*/
|
|
10
|
-
export class EventCollection<Events extends BaseEvent> {
|
|
11
|
-
constructor(events?: Map<keyof Events, EventHandler<Events, keyof Events>[]>) {
|
|
12
|
-
this._events = !events ?
|
|
13
|
-
new Map<keyof Events, Event<Events>>() :
|
|
14
|
-
events.array().reduce((result, [event, handlers]) =>
|
|
15
|
-
result.set(event, new Event<Events>(event, ...handlers)),
|
|
16
|
-
new Map<keyof Events, Event<Events>>());
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**Amount of events stored*/
|
|
20
|
-
public get size() {
|
|
21
|
-
return this._events.size;
|
|
22
|
-
}
|
|
23
|
-
/**@private Internal event collection*/
|
|
24
|
-
private _events = new Map<keyof Events, Event<Events>>();
|
|
25
|
-
/**@private limit of events*/
|
|
26
|
-
private _limit = 0;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns true if event is in collection
|
|
30
|
-
* @param event Event name
|
|
31
|
-
* @returns true if event is in collection
|
|
32
|
-
*/
|
|
33
|
-
public has(event: keyof Events): boolean {
|
|
34
|
-
return this._events.has(event);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns event matching event parameter
|
|
38
|
-
* @param event Event name
|
|
39
|
-
* @returns Event
|
|
40
|
-
*/
|
|
41
|
-
public get<T = any>(event: keyof Events): Event<Events> {
|
|
42
|
-
return this._events.get(event);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Adds handler to event collection with name as key
|
|
46
|
-
* @param name Event name
|
|
47
|
-
* @param handler Handler for event
|
|
48
|
-
* @returns this
|
|
49
|
-
*/
|
|
50
|
-
public add(name: keyof Events, handler: EventHandler<Events, keyof Events>, once = false): this {
|
|
51
|
-
if (this._limit > 0 && this._limit + 1 > this._events.size) {
|
|
52
|
-
throw new Error(`Listener limit, ${this._limit}, reached!`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const event = this.has(name) && this.get(name);
|
|
56
|
-
|
|
57
|
-
if (once) this._events.set(name, event ? event.once(handler) : new Event<Events>(name).once(handler))
|
|
58
|
-
else this._events.set(name, event ? event.on(handler) : new Event(name, handler));
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* @summary clear(): Clears all events
|
|
63
|
-
* @summary clear("all", myEventHandler): Removes myEventHandler from all events that have it
|
|
64
|
-
* @summary clear("myEvent"): Clears all handlers tied to "myEvent"
|
|
65
|
-
* @summary clear("myEvent", myEventHandler): Removes myEventHandler from "myEvent"
|
|
66
|
-
*
|
|
67
|
-
* @param name Event name | "all"
|
|
68
|
-
* @param handler Specific handler to remove. If left blank, all handlers in name will be removed
|
|
69
|
-
* @returns this
|
|
70
|
-
*/
|
|
71
|
-
public clear(name: keyof Events | "all" = 'all', handler?: EventHandler<Events, keyof Events>): this {
|
|
72
|
-
//clear(): Clears all events
|
|
73
|
-
if ((name as string).toLowerCase() == 'all' && handler == null) this._events.clear();
|
|
74
|
-
|
|
75
|
-
//clear("all", myEventHandler): Removes the "myEventHandler" handler from all events
|
|
76
|
-
else if ((name as string).toLowerCase() == 'all' && handler) this._events = (() => {
|
|
77
|
-
const eventNames = this._events.array().map(([name, event]) => event.includes(handler) && name);
|
|
78
|
-
this._events.forEach((event, name) =>
|
|
79
|
-
eventNames.includes(name) &&
|
|
80
|
-
this._events.set(name, event.off(handler)
|
|
81
|
-
));
|
|
82
|
-
|
|
83
|
-
return this._events;
|
|
84
|
-
})();
|
|
85
|
-
|
|
86
|
-
//clear("myEvent"): Deletes myEvent from this._events
|
|
87
|
-
else if ((name as string).toLowerCase() != "all" && handler == null) this._events.delete(name as keyof Events);
|
|
88
|
-
|
|
89
|
-
//clear("myEvent", myEventHandler): Removes the "myEventsHandler" handler from "myEvent"
|
|
90
|
-
else if ((name as string).toLowerCase() != 'all' && handler) this._events.set(name as keyof Events, this.get(name as keyof Events).off(handler));
|
|
91
|
-
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public emit<Event extends keyof Events>(name: Event, args: Events[Event]) {
|
|
96
|
-
return this.get(name).emit(args);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Limits how many events to accept using EventEmitter#on or EventEmitter#once
|
|
101
|
-
* @param limit Limit of events to keep
|
|
102
|
-
* @returns this with the new limit
|
|
103
|
-
*
|
|
104
|
-
* @throws Unknown event, if event name isn't recognized
|
|
105
|
-
*/
|
|
106
|
-
public limit<Event extends keyof Events>(event: 'all' | Event, limit: number) {
|
|
107
|
-
if (limit <= 0) return;
|
|
108
|
-
|
|
109
|
-
if (event == 'all') this._limit = limit;
|
|
110
|
-
else if (this.has(event)) this.get(event).limit = limit;
|
|
111
|
-
else throw new Error(`Unknown event, ${event}!`);
|
|
112
|
-
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
export default EventCollection;
|
package/src/Extensions.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import ElementOptions from "./Interfaces/ElementOptions";
|
|
2
|
-
import IReplacement from "./Interfaces/IReplacement";
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
interface Document {
|
|
6
|
-
/**
|
|
7
|
-
* Creates an element like Document#createElement, however with construction options to assign values in construction instead of after construction.
|
|
8
|
-
* @param tagName HTMLElement tag name
|
|
9
|
-
* @param options Construction options, instead of assigning values after construction
|
|
10
|
-
*/
|
|
11
|
-
createProperElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementOptions): HTMLElementTagNameMap[K]
|
|
12
|
-
}
|
|
13
|
-
interface HTMLCollection {
|
|
14
|
-
/**
|
|
15
|
-
* Converts HTMLCollection to Element[]
|
|
16
|
-
*/
|
|
17
|
-
array(): Element[]
|
|
18
|
-
}
|
|
19
|
-
interface Array<T> {
|
|
20
|
-
/**
|
|
21
|
-
* Pushes items to array and returns self with new items
|
|
22
|
-
* @param items Items to add to array
|
|
23
|
-
*/
|
|
24
|
-
add(...items: Array<T>): this
|
|
25
|
-
/**
|
|
26
|
-
* Removes item from array and returns self without item
|
|
27
|
-
* @param item Item to remove
|
|
28
|
-
*/
|
|
29
|
-
remove(item: T): this
|
|
30
|
-
/**
|
|
31
|
-
* Returns a random element from array
|
|
32
|
-
*/
|
|
33
|
-
random(): T
|
|
34
|
-
}
|
|
35
|
-
interface Map<K, V> {
|
|
36
|
-
/**
|
|
37
|
-
* Converts into Array<[Key, Value]>
|
|
38
|
-
*/
|
|
39
|
-
array(): [K, V][]
|
|
40
|
-
/**
|
|
41
|
-
* Maps values into new types of generics
|
|
42
|
-
* @param callback Callbacking function to map values
|
|
43
|
-
*/
|
|
44
|
-
map<EK, EV>(callback: (value: V, key?: K, index?: number, map?: this) => [EK, EV]): Map<EK, EV>
|
|
45
|
-
/**
|
|
46
|
-
* Returns array of "accepted" values. Criteria defined in callback param
|
|
47
|
-
* @param callback Callbacking function to filter away unwanted values
|
|
48
|
-
*/
|
|
49
|
-
filter(callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean): Map<K, V>
|
|
50
|
-
/**
|
|
51
|
-
* Returns array of keys
|
|
52
|
-
*/
|
|
53
|
-
keyArr(): Array<K>
|
|
54
|
-
/**
|
|
55
|
-
* Returns array of values
|
|
56
|
-
*/
|
|
57
|
-
valueArr(): Array<V>
|
|
58
|
-
/**
|
|
59
|
-
* Returns first [key, value] match to callback param
|
|
60
|
-
* @param callback Callbacking function to find KeyValuePair
|
|
61
|
-
*/
|
|
62
|
-
find(callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean): [K, V]
|
|
63
|
-
/**
|
|
64
|
-
* Whether or not map includes a value. Returns true if it does, false if not ¯\_(ツ)_/¯
|
|
65
|
-
* @param value Value that may be includded in map
|
|
66
|
-
* @param fromIndex Start looking for value from specific index+. Default: 0
|
|
67
|
-
*/
|
|
68
|
-
includes(value: V, fromIndex?: number): boolean
|
|
69
|
-
}
|
|
70
|
-
interface String {
|
|
71
|
-
/**
|
|
72
|
-
* Uppercases first letter of string
|
|
73
|
-
*/
|
|
74
|
-
toPascalCase(): string
|
|
75
|
-
/**
|
|
76
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '_')
|
|
77
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
78
|
-
*/
|
|
79
|
-
toSnakeCase(replaceOptions?: IReplacement): string
|
|
80
|
-
/**
|
|
81
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '-')
|
|
82
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
83
|
-
*/
|
|
84
|
-
toKebabCase(replaceOptions?: IReplacement): string
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
Document.prototype.createProperElement = function<K extends keyof HTMLElementTagNameMap>(this: Document, tagName: K, options?: ElementOptions) {
|
|
89
|
-
let baseElement = document.createElement(tagName);
|
|
90
|
-
if (!options) return baseElement;
|
|
91
|
-
|
|
92
|
-
if (options.classes) {
|
|
93
|
-
baseElement.classList.add(...options.classes);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (options.attributes) {
|
|
97
|
-
options.attributes.forEach(([attribute, value]) => baseElement.setAttribute(attribute, value));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (options.children) {
|
|
101
|
-
baseElement.append(...[].concat(options.children));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (options.events) {
|
|
105
|
-
options.events.forEach(({ name, handler }) => (
|
|
106
|
-
baseElement.addEventListener(name, handler)
|
|
107
|
-
))
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return baseElement;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
HTMLCollection.prototype.array = function(this: HTMLCollection) {
|
|
114
|
-
let result = new Array<Element>();
|
|
115
|
-
|
|
116
|
-
for (let i = 0; i < this.length; i++) {
|
|
117
|
-
result.push(this.item(i));
|
|
118
|
-
}
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
Array.prototype.add = function<T>(this: Array<T>, ...items: Array<T>) {
|
|
123
|
-
this.push(...items);
|
|
124
|
-
return this;
|
|
125
|
-
}
|
|
126
|
-
Array.prototype.remove = function<T>(this: Array<T>, item: T): Array<T> {
|
|
127
|
-
const itemInArray = this.includes(item) ? item : this.find(i => i == item);
|
|
128
|
-
if (!itemInArray) throw new Error(`item is not in array!`);
|
|
129
|
-
|
|
130
|
-
const itemIndex = this.indexOf(itemInArray);
|
|
131
|
-
this.splice(itemIndex, 1);
|
|
132
|
-
return this;
|
|
133
|
-
}
|
|
134
|
-
Array.prototype.random = function<T>(this: Array<T>): T {
|
|
135
|
-
const randomIndex = Math.round(Math.random() * this.length);
|
|
136
|
-
return this[randomIndex];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
Map.prototype.array = function<K, V>(this: Map<K, V>): [K, V][] {
|
|
140
|
-
let result = new Array<[K, V]>();
|
|
141
|
-
for (const kvp of this) {
|
|
142
|
-
result.push(kvp);
|
|
143
|
-
}
|
|
144
|
-
return result;
|
|
145
|
-
}
|
|
146
|
-
Map.prototype.map = function<K, V, EK, EV>(this: Map<K, V>, callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => [EK, EV]): Map<EK, EV> {
|
|
147
|
-
return this.array()
|
|
148
|
-
.map(([k, v], i) => callback(v, k, i, this))
|
|
149
|
-
.reduce((map, [key, value]) =>
|
|
150
|
-
map.set(key, value),
|
|
151
|
-
new Map<EK, EV>())
|
|
152
|
-
}
|
|
153
|
-
Map.prototype.filter = function<K, V>(this: Map<K, V>, callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean): Map<K, V> {
|
|
154
|
-
return this.array()
|
|
155
|
-
.filter(([k, v], i) => callback(v, k, i, this))
|
|
156
|
-
.reduce((map, [key, value]) =>
|
|
157
|
-
map.set(key, value),
|
|
158
|
-
new Map<K, V>())
|
|
159
|
-
}
|
|
160
|
-
Map.prototype.keyArr = function<K, V>(this: Map<K, V>): K[] {
|
|
161
|
-
return this.array().map(([k]) => k);
|
|
162
|
-
}
|
|
163
|
-
Map.prototype.valueArr = function<K, V>(this: Map<K, V>): V[] {
|
|
164
|
-
return this.array().map(([_, v]) => v);
|
|
165
|
-
}
|
|
166
|
-
Map.prototype.find = function<K, V>(this: Map<K, V>, callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean) {
|
|
167
|
-
return this.array().find(([k, v], i) => callback(v, k, i, this));
|
|
168
|
-
}
|
|
169
|
-
Map.prototype.includes = function<K, V>(this: Map<K, V>, item: V, fromIndex?: number) {
|
|
170
|
-
return this.valueArr().includes(item, fromIndex);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
String.prototype.toPascalCase = function(this: string) {
|
|
174
|
-
return this.substring(0, 1).toUpperCase() + this.substring(1);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function spaceReplacer(self: string, replacer: string | RegExp, replacement: string) {
|
|
178
|
-
return self.replace(new RegExp(`${typeof replacer == 'string' ? replacer : replacer.source}+`), replacement);
|
|
179
|
-
}
|
|
180
|
-
String.prototype.toSnakeCase = function(this: string, replaceOptions: IReplacement = { replacer: ' ', replacement: '_' }) {
|
|
181
|
-
return spaceReplacer(this, replaceOptions.replacer, replaceOptions.replacement)
|
|
182
|
-
}
|
|
183
|
-
String.prototype.toKebabCase = function(this: string, replaceOptions: IReplacement = { replacer: ' ', replacement: '-' }) {
|
|
184
|
-
return spaceReplacer(this, replaceOptions.replacer, replaceOptions.replacement);
|
|
185
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import BaseEvent from "../Interfaces/BaseEventInterface";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Eventhandler type for:
|
|
5
|
-
* @see EventCollection
|
|
6
|
-
*/
|
|
7
|
-
export type EventHandler<
|
|
8
|
-
Events extends BaseEvent,
|
|
9
|
-
Event extends keyof Events,
|
|
10
|
-
ReturnType = any
|
|
11
|
-
> = (args: Events[Event]) => ReturnType;
|
|
12
|
-
export default EventHandler;
|
package/src/Types/IElement.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Used for HTMLElement.append in ElementOptions, Document.createProperElement.
|
|
3
|
-
* IElement accepts HTML Elements or HTMl-like strings.
|
|
4
|
-
*
|
|
5
|
-
* @see HTMLElement.append
|
|
6
|
-
* @see Document.createProperElement
|
|
7
|
-
*/
|
|
8
|
-
export type IElement = HTMLElement | string;
|
|
9
|
-
export default IElement
|
package/src/Types/StringRegex.ts
DELETED