danholibraryjs 1.11.0 → 2.0.1
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/README.md +0 -1
- package/_package.github-release.json +6 -0
- package/_package.npm-release.json +6 -0
- package/dist/Classes/DanhoLogger.d.ts +23 -0
- package/dist/Classes/DanhoLogger.js +65 -0
- package/dist/Classes/Events/Event.d.ts +66 -66
- package/dist/Classes/Events/Event.js +114 -114
- package/dist/Classes/Events/EventCollection.d.ts +57 -57
- package/dist/Classes/Events/EventCollection.js +109 -109
- package/dist/Classes/Events/EventEmitter.d.ts +74 -74
- package/dist/Classes/Events/EventEmitter.js +97 -97
- package/dist/Classes/Events/index.d.ts +3 -3
- package/dist/Classes/Events/index.js +19 -19
- package/dist/Classes/Time/Date.d.ts +148 -147
- package/dist/Classes/Time/Date.js +241 -238
- package/dist/Classes/Time/Time.d.ts +66 -65
- package/dist/Classes/Time/Time.js +120 -117
- package/dist/Classes/Time/TimeProperties.d.ts +3 -3
- package/dist/Classes/Time/TimeProperties.js +2 -2
- package/dist/Classes/Time/TimeSpan.d.ts +123 -123
- package/dist/Classes/Time/TimeSpan.js +179 -179
- package/dist/Classes/Time/index.d.ts +4 -4
- package/dist/Classes/Time/index.js +20 -20
- package/dist/Classes/index.d.ts +4 -3
- package/dist/Classes/index.js +20 -19
- package/dist/Classes/store.d.ts +75 -75
- package/dist/Classes/store.js +84 -84
- package/dist/Extensions/Array/array.extension.d.ts +42 -0
- package/dist/Extensions/Array/array.extension.js +57 -0
- package/dist/Extensions/Array/crud.extension.d.ts +24 -0
- package/dist/Extensions/Array/crud.extension.js +28 -0
- package/dist/Extensions/Array/index.d.ts +6 -0
- package/dist/Extensions/Array/index.js +22 -0
- package/dist/Extensions/Array/loop.extension.d.ts +18 -0
- package/dist/Extensions/Array/loop.extension.js +23 -0
- package/dist/Extensions/Array/random.extension.d.ts +23 -0
- package/dist/Extensions/Array/random.extension.js +35 -0
- package/dist/Extensions/Array/sort.extension.d.ts +27 -0
- package/dist/Extensions/Array/sort.extension.js +31 -0
- package/dist/Extensions/Array/string.extension.d.ts +13 -0
- package/dist/Extensions/Array/string.extension.js +14 -0
- package/dist/Extensions/Function.d.ts +29 -14
- package/dist/Extensions/Function.js +23 -10
- package/dist/Extensions/Map.d.ts +54 -54
- package/dist/Extensions/Map.js +42 -42
- package/dist/Extensions/Number.d.ts +13 -0
- package/dist/Extensions/Number.js +40 -0
- package/dist/Extensions/Object/arrays.extension.d.ts +17 -0
- package/dist/Extensions/Object/arrays.extension.js +13 -0
- package/dist/Extensions/Object/booleans.extension.d.ts +18 -0
- package/dist/Extensions/Object/booleans.extension.js +37 -0
- package/dist/Extensions/Object/extracts.extension.d.ts +38 -0
- package/dist/Extensions/Object/extracts.extension.js +72 -0
- package/dist/Extensions/Object/index.d.ts +4 -49
- package/dist/Extensions/Object/index.js +20 -38
- package/dist/Extensions/Object/properties.d.ts +28 -28
- package/dist/Extensions/Object/properties.extension.d.ts +33 -0
- package/dist/Extensions/Object/properties.extension.js +21 -0
- package/dist/Extensions/Object/properties.js +20 -20
- package/dist/Extensions/String/case.extension.d.ts +12 -0
- package/dist/Extensions/String/case.extension.js +55 -0
- package/dist/Extensions/String/index.d.ts +1 -0
- package/dist/{Functions → Extensions/String}/index.js +17 -21
- package/dist/Extensions/index.d.ts +6 -17
- package/dist/Extensions/index.js +22 -30
- package/dist/Interfaces/ElementOptions.d.ts +15 -15
- package/dist/Interfaces/ElementOptions.js +2 -2
- package/dist/Interfaces/IReplacement.d.ts +12 -12
- package/dist/Interfaces/IReplacement.js +2 -2
- package/dist/Interfaces/index.d.ts +2 -2
- package/dist/Interfaces/index.js +18 -18
- package/dist/Types/Able.d.ts +16 -0
- package/dist/Types/Able.js +2 -0
- package/dist/Types/Array.d.ts +6 -0
- package/dist/Types/Array.js +2 -0
- package/dist/Types/BetterTypes.d.ts +9 -9
- package/dist/Types/BetterTypes.js +2 -2
- package/dist/Types/C#.d.ts +8 -0
- package/dist/Types/C#.js +2 -0
- package/dist/Types/Date.d.ts +6 -6
- package/dist/Types/Date.js +2 -2
- package/dist/Types/Events.d.ts +10 -10
- package/dist/Types/Events.js +2 -2
- package/dist/Types/Function.d.ts +5 -0
- package/dist/Types/Function.js +2 -0
- package/dist/Types/Object.d.ts +4 -0
- package/dist/Types/Object.js +2 -0
- package/dist/Types/PropertiesWith.d.ts +34 -13
- package/dist/Types/PropertiesWith.js +2 -2
- package/dist/Types/String.d.ts +1 -0
- package/dist/Types/String.js +2 -0
- package/dist/Types/TransformTypes.d.ts +22 -16
- package/dist/Types/TransformTypes.js +2 -2
- package/dist/Types/index.d.ts +24 -65
- package/dist/Types/index.js +27 -21
- package/dist/Utils/{ApiUtil → ApiUtils}/ApiTypes.d.ts +15 -15
- package/dist/Utils/{ApiUtil → ApiUtils}/ApiTypes.js +15 -15
- package/dist/Utils/{ApiUtil → ApiUtils}/RequestUtil.d.ts +19 -19
- package/dist/Utils/{ApiUtil → ApiUtils}/RequestUtil.js +73 -73
- package/dist/Utils/{ApiUtil → ApiUtils}/index.d.ts +20 -20
- package/dist/Utils/{ApiUtil → ApiUtils}/index.js +33 -33
- package/dist/Utils/ColorUtils.d.ts +11 -0
- package/dist/Utils/ColorUtils.js +93 -0
- package/dist/Utils/{FormUtil.d.ts → FormUtils.d.ts} +6 -6
- package/dist/Utils/{FormUtil.js → FormUtils.js} +35 -35
- package/dist/Utils/NumberUtils.d.ts +1 -0
- package/dist/Utils/NumberUtils.js +7 -0
- package/dist/Utils/PatcherUtils.d.ts +6 -0
- package/dist/Utils/PatcherUtils.js +80 -0
- package/dist/Utils/StringUtils.d.ts +3 -0
- package/dist/Utils/StringUtils.js +47 -0
- package/dist/Utils/TimeUtils/debounce.util.d.ts +22 -0
- package/dist/Utils/TimeUtils/debounce.util.js +78 -0
- package/dist/Utils/TimeUtils/functions.util.d.ts +4 -0
- package/dist/Utils/TimeUtils/functions.util.js +21 -0
- package/dist/Utils/TimeUtils/index.d.ts +15 -0
- package/dist/Utils/TimeUtils/index.js +34 -0
- package/dist/Utils/TimeUtils/throttle.util.d.ts +15 -0
- package/dist/Utils/TimeUtils/throttle.util.js +43 -0
- package/dist/Utils/index.d.ts +7 -2
- package/dist/Utils/index.js +23 -18
- package/dist/index.d.ts +4 -5
- package/dist/index.js +20 -21
- package/docs/Classes.md +78 -3
- package/docs/Extensions.md +219 -78
- package/docs/Types.md +202 -58
- package/docs/index.md +0 -1
- package/package.json +4 -2
- package/src/Classes/DanhoLogger.ts +78 -0
- package/src/Classes/Events/Event.ts +96 -96
- package/src/Classes/Events/EventCollection.ts +90 -90
- package/src/Classes/Events/EventEmitter.ts +68 -68
- package/src/Classes/Time/Date.ts +219 -216
- package/src/Classes/Time/Time.ts +109 -104
- package/src/Classes/Time/TimeSpan.ts +171 -171
- package/src/Classes/index.ts +1 -0
- package/src/Classes/store.ts +22 -22
- package/src/Extensions/Array/array.extension.ts +103 -0
- package/src/Extensions/Array/crud.extension.ts +46 -0
- package/src/Extensions/Array/index.ts +6 -0
- package/src/Extensions/Array/loop.extension.ts +38 -0
- package/src/Extensions/Array/random.extension.ts +56 -0
- package/src/Extensions/Array/sort.extension.ts +52 -0
- package/src/Extensions/Array/string.extension.ts +22 -0
- package/src/Extensions/Function.ts +37 -10
- package/src/Extensions/Map.ts +56 -56
- package/src/Extensions/Number.ts +50 -0
- package/src/Extensions/Object/arrays.extension.ts +27 -0
- package/src/Extensions/Object/booleans.extension.ts +46 -0
- package/src/Extensions/Object/extracts.extension.ts +102 -0
- package/src/Extensions/Object/index.ts +4 -82
- package/src/Extensions/Object/properties.extension.ts +59 -0
- package/src/Extensions/Object/properties.ts +36 -36
- package/src/Extensions/String/case.extension.ts +95 -0
- package/src/Extensions/String/index.ts +1 -0
- package/src/Extensions/index.ts +3 -21
- package/src/Interfaces/ElementOptions.ts +7 -7
- package/src/Interfaces/IReplacement.ts +2 -2
- package/src/Types/Able.ts +22 -0
- package/src/Types/Array.ts +7 -0
- package/src/Types/C#.ts +9 -0
- package/src/Types/Date.ts +1 -1
- package/src/Types/Events.ts +12 -12
- package/src/Types/Function.ts +10 -0
- package/src/Types/Object.ts +4 -0
- package/src/Types/PropertiesWith.ts +35 -4
- package/src/Types/String.ts +1 -0
- package/src/Types/TransformTypes.ts +21 -13
- package/src/Types/index.ts +7 -69
- package/src/Utils/{ApiUtil → ApiUtils}/ApiTypes.ts +2 -1
- package/src/Utils/{ApiUtil → ApiUtils}/index.ts +1 -1
- package/src/Utils/ColorUtils.ts +102 -0
- package/src/Utils/{FormUtil.ts → FormUtils.ts} +2 -2
- package/src/Utils/NumberUtils.ts +3 -0
- package/src/Utils/PatcherUtils.ts +111 -0
- package/src/Utils/StringUtils.ts +44 -0
- package/src/Utils/TimeUtils/debounce.util.ts +85 -0
- package/src/Utils/TimeUtils/functions.util.ts +18 -0
- package/src/Utils/TimeUtils/index.ts +9 -0
- package/src/Utils/TimeUtils/throttle.util.ts +44 -0
- package/src/Utils/index.ts +8 -2
- package/src/index.ts +0 -1
- package/dist/Extensions/Array.d.ts +0 -52
- package/dist/Extensions/Array.js +0 -51
- package/dist/Extensions/Document.d.ts +0 -27
- package/dist/Extensions/Document.js +0 -32
- package/dist/Extensions/String.d.ts +0 -36
- package/dist/Extensions/String.js +0 -25
- package/dist/Functions/CopyToClipboard.d.ts +0 -7
- package/dist/Functions/CopyToClipboard.js +0 -15
- package/dist/Functions/GetCSSProperty.d.ts +0 -15
- package/dist/Functions/GetCSSProperty.js +0 -26
- package/dist/Functions/GetNestedProperty.d.ts +0 -9
- package/dist/Functions/GetNestedProperty.js +0 -23
- package/dist/Functions/HTMLEvent.d.ts +0 -11
- package/dist/Functions/HTMLEvent.js +0 -14
- package/dist/Functions/SetNavigationSelected.d.ts +0 -9
- package/dist/Functions/SetNavigationSelected.js +0 -25
- package/dist/Functions/index.d.ts +0 -5
- package/docs/Functions.md +0 -61
- package/src/Extensions/Array.ts +0 -95
- package/src/Extensions/Document.ts +0 -58
- package/src/Extensions/String.ts +0 -54
- package/src/Functions/CopyToClipboard.ts +0 -10
- package/src/Functions/GetCSSProperty.ts +0 -27
- package/src/Functions/GetNestedProperty.ts +0 -29
- package/src/Functions/HTMLEvent.ts +0 -13
- package/src/Functions/SetNavigationSelected.ts +0 -19
- package/src/Functions/index.ts +0 -5
- /package/src/Utils/{ApiUtil → ApiUtils}/RequestUtil.ts +0 -0
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export type UpdateFinder<T> = (item: T, index: number, self: Array<T>) => boolean;
|
|
2
|
-
declare global {
|
|
3
|
-
interface Array<T> {
|
|
4
|
-
/**
|
|
5
|
-
* Pushes items to array and returns self with new items
|
|
6
|
-
* @param items Items to add to array
|
|
7
|
-
*/
|
|
8
|
-
add(...items: Array<T>): this;
|
|
9
|
-
/**
|
|
10
|
-
* Update an item in array
|
|
11
|
-
* @param old The old value or index to update
|
|
12
|
-
* @param updated Updated value
|
|
13
|
-
*/
|
|
14
|
-
update(old: T | number | UpdateFinder<T>, updated: T): T;
|
|
15
|
-
/**
|
|
16
|
-
* Removes item from array and returns self without item
|
|
17
|
-
* @param item Item or index to remove
|
|
18
|
-
*/
|
|
19
|
-
remove(item: T | number): this;
|
|
20
|
-
/**
|
|
21
|
-
* Returns a random element from array
|
|
22
|
-
*/
|
|
23
|
-
random(): T;
|
|
24
|
-
/**
|
|
25
|
-
* Returns item matching index. If negative number, subtracts number from length
|
|
26
|
-
* @param i Index of item
|
|
27
|
-
*/
|
|
28
|
-
index(i: number): T;
|
|
29
|
-
/**
|
|
30
|
-
* For every x in array, execute callback
|
|
31
|
-
* @param every i.e every 2nd item in array
|
|
32
|
-
* @param callback Function to execute
|
|
33
|
-
* @returns Array of results
|
|
34
|
-
*/
|
|
35
|
-
nth<U>(every: number, callback: (item: T, index: number, collection: Array<T>, self: this) => U): Array<U>;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
declare function add<T>(this: Array<T>, ...items: Array<T>): T[];
|
|
39
|
-
declare function update<T>(this: Array<T>, old: T | number | UpdateFinder<T>, updated: T): T;
|
|
40
|
-
declare function remove<T>(this: Array<T>, value: T | number): Array<T>;
|
|
41
|
-
declare function random<T>(this: Array<T>): T;
|
|
42
|
-
declare function index<T>(this: Array<T>, i: number): T;
|
|
43
|
-
declare function nth<T, U>(this: Array<T>, every: number, callback: (item: T, index: number, collection: Array<T>, self: Array<T>) => U): Array<U>;
|
|
44
|
-
export declare const ArrayExtensions: {
|
|
45
|
-
add: typeof add;
|
|
46
|
-
update: typeof update;
|
|
47
|
-
remove: typeof remove;
|
|
48
|
-
random: typeof random;
|
|
49
|
-
index: typeof index;
|
|
50
|
-
nth: typeof nth;
|
|
51
|
-
};
|
|
52
|
-
export {};
|
package/dist/Extensions/Array.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArrayExtensions = void 0;
|
|
4
|
-
function add(...items) {
|
|
5
|
-
this.push(...items);
|
|
6
|
-
return this;
|
|
7
|
-
}
|
|
8
|
-
Array.prototype.add = add;
|
|
9
|
-
function update(old, updated) {
|
|
10
|
-
const item = typeof old === 'number' ? this[old]
|
|
11
|
-
: typeof old === 'function' ? this.find(old)
|
|
12
|
-
: old;
|
|
13
|
-
if (!item)
|
|
14
|
-
throw new Error('Old was not found in array!');
|
|
15
|
-
const index = this.indexOf(item);
|
|
16
|
-
return this[index] = updated;
|
|
17
|
-
}
|
|
18
|
-
Array.prototype.update = update;
|
|
19
|
-
function remove(value) {
|
|
20
|
-
const index = typeof value === 'number' ? value : this.indexOf(value);
|
|
21
|
-
if (index > -1)
|
|
22
|
-
this.splice(index, 1);
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
Array.prototype.remove = remove;
|
|
26
|
-
function random() {
|
|
27
|
-
const randomIndex = Math.round(Math.random() * this.length);
|
|
28
|
-
return this[randomIndex];
|
|
29
|
-
}
|
|
30
|
-
Array.prototype.random = random;
|
|
31
|
-
function index(i) {
|
|
32
|
-
return this[i < 0 ? this.length + i : i];
|
|
33
|
-
}
|
|
34
|
-
Array.prototype.index = index;
|
|
35
|
-
function nth(every, callback) {
|
|
36
|
-
const result = new Array();
|
|
37
|
-
let collection = new Array();
|
|
38
|
-
for (let i = 0; i < this.length; i++) {
|
|
39
|
-
collection.push(this[i]);
|
|
40
|
-
if (i % every === 0) {
|
|
41
|
-
result.push(callback(this[i], i, collection, this));
|
|
42
|
-
collection = new Array();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
Array.prototype.nth = nth;
|
|
48
|
-
exports.ArrayExtensions = {
|
|
49
|
-
add, update, remove,
|
|
50
|
-
random, index, nth
|
|
51
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { IElement } from "../Types";
|
|
2
|
-
declare global {
|
|
3
|
-
interface Document {
|
|
4
|
-
/**
|
|
5
|
-
* Creates an element like Document#createElement, however with construction options to assign values in construction instead of after construction.
|
|
6
|
-
* @param tagName HTMLElement tag name
|
|
7
|
-
* @param options Construction options, instead of assigning values after construction
|
|
8
|
-
* @param children Child elements
|
|
9
|
-
*/
|
|
10
|
-
createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]>, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
|
|
11
|
-
createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
|
|
12
|
-
createElementFromString<K extends keyof HTMLElementTagNameMap>(html: string, parentTag?: K): HTMLElementTagNameMap[K];
|
|
13
|
-
}
|
|
14
|
-
interface HTMLCollection {
|
|
15
|
-
/**
|
|
16
|
-
* Converts HTMLCollection to Element[]
|
|
17
|
-
*/
|
|
18
|
-
array(): Element[];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
declare function createElement<Tag extends keyof HTMLElementTagNameMap>(this: Document, tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]> | string, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
|
|
22
|
-
declare function createElementFromString<Tag extends keyof HTMLElementTagNameMap>(this: Document, html: string, tag?: Tag): HTMLElementTagNameMap[Tag];
|
|
23
|
-
export declare const DocumentExtensions: {
|
|
24
|
-
createElement: typeof createElement;
|
|
25
|
-
createElementFromString: typeof createElementFromString;
|
|
26
|
-
};
|
|
27
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DocumentExtensions = void 0;
|
|
4
|
-
function createElement(tagName, options, ...children) {
|
|
5
|
-
const element = Object.assign(document.createElement(tagName), typeof options === 'string' ? {} : options);
|
|
6
|
-
children ??= typeof options === 'string' ? [options] : [];
|
|
7
|
-
typeof options === 'string' && children.unshift(options);
|
|
8
|
-
if (!children.length)
|
|
9
|
-
return element;
|
|
10
|
-
else if (typeof children === 'string')
|
|
11
|
-
element.innerHTML = children;
|
|
12
|
-
else if (children instanceof Array)
|
|
13
|
-
children.forEach(child => (typeof child === 'string' ?
|
|
14
|
-
element.innerHTML += child :
|
|
15
|
-
element.appendChild(child)));
|
|
16
|
-
else
|
|
17
|
-
element.appendChild(children);
|
|
18
|
-
return element;
|
|
19
|
-
}
|
|
20
|
-
Document.prototype.createProperElement = createElement;
|
|
21
|
-
function createElementFromString(html, tag) {
|
|
22
|
-
if (!html.startsWith(`<${tag}`))
|
|
23
|
-
html = `<${tag}>${html}</${tag}>`;
|
|
24
|
-
return new DOMParser().parseFromString(html, 'text/html').body.firstElementChild;
|
|
25
|
-
}
|
|
26
|
-
Document.prototype.createElementFromString = createElementFromString;
|
|
27
|
-
HTMLCollection.prototype.array = function () {
|
|
28
|
-
return Array.from(this);
|
|
29
|
-
};
|
|
30
|
-
exports.DocumentExtensions = {
|
|
31
|
-
createElement, createElementFromString
|
|
32
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import IReplacement from "../Interfaces/IReplacement";
|
|
2
|
-
declare global {
|
|
3
|
-
interface String {
|
|
4
|
-
/**
|
|
5
|
-
* Uppercases first letter of string
|
|
6
|
-
*/
|
|
7
|
-
toPascalCase(): string;
|
|
8
|
-
/**
|
|
9
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '_')
|
|
10
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
11
|
-
*/
|
|
12
|
-
toSnakeCase(replaceOptions?: IReplacement): string;
|
|
13
|
-
/**
|
|
14
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '-')
|
|
15
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
16
|
-
*/
|
|
17
|
-
toKebabCase(replaceOptions?: IReplacement): string;
|
|
18
|
-
/**
|
|
19
|
-
* String.substring but accepting negative numbers to cut from length
|
|
20
|
-
* @param start Start of string. 0 indexed, if negative number, subtracts number from length
|
|
21
|
-
* @param end End of string. 0 indexed, if negative number, substracts number from length
|
|
22
|
-
*/
|
|
23
|
-
clip(start: number, end?: number): string;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
declare function toPascalCase(this: string): string;
|
|
27
|
-
declare function toSnakeCase(this: string, replaceOptions: IReplacement): string;
|
|
28
|
-
declare function toKebabCase(this: string, replaceOptions: IReplacement): string;
|
|
29
|
-
declare function clip(this: string, start: number, end?: number): string;
|
|
30
|
-
export declare const StringExtensions: {
|
|
31
|
-
toPascalCase: typeof toPascalCase;
|
|
32
|
-
toSnakeCase: typeof toSnakeCase;
|
|
33
|
-
toKebabCase: typeof toKebabCase;
|
|
34
|
-
clip: typeof clip;
|
|
35
|
-
};
|
|
36
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StringExtensions = void 0;
|
|
4
|
-
function toPascalCase() {
|
|
5
|
-
return this.substring(0, 1).toUpperCase() + this.substring(1);
|
|
6
|
-
}
|
|
7
|
-
String.prototype.toPascalCase = toPascalCase;
|
|
8
|
-
function spaceReplacer(self, replacer, replacement) {
|
|
9
|
-
return self.replace(new RegExp(`${typeof replacer == 'string' ? replacer : replacer.source}+`), replacement);
|
|
10
|
-
}
|
|
11
|
-
function toSnakeCase(replaceOptions) {
|
|
12
|
-
return spaceReplacer(this, replaceOptions.replacer || ' ', replaceOptions.replacement || '_');
|
|
13
|
-
}
|
|
14
|
-
String.prototype.toSnakeCase = toSnakeCase;
|
|
15
|
-
function toKebabCase(replaceOptions) {
|
|
16
|
-
return spaceReplacer(this, replaceOptions.replacer || ' ', replaceOptions.replacement || '-');
|
|
17
|
-
}
|
|
18
|
-
String.prototype.toKebabCase = toKebabCase;
|
|
19
|
-
function clip(start, end) {
|
|
20
|
-
return this.substring(start < 0 ? this.length - start : start, end && end < 0 ? this.length + end : end);
|
|
21
|
-
}
|
|
22
|
-
String.prototype.clip = clip;
|
|
23
|
-
exports.StringExtensions = {
|
|
24
|
-
toPascalCase, toSnakeCase, toKebabCase, clip
|
|
25
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copies value to clipboard and alerts a response, if response is defined
|
|
3
|
-
* @param value Value to clipboard
|
|
4
|
-
* @param response Alerts if response is given
|
|
5
|
-
*/
|
|
6
|
-
export declare function CopyToClipboard(value: string, response?: string): Promise<void>;
|
|
7
|
-
export default CopyToClipboard;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CopyToClipboard = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Copies value to clipboard and alerts a response, if response is defined
|
|
6
|
-
* @param value Value to clipboard
|
|
7
|
-
* @param response Alerts if response is given
|
|
8
|
-
*/
|
|
9
|
-
async function CopyToClipboard(value, response) {
|
|
10
|
-
await navigator.clipboard.writeText(value);
|
|
11
|
-
if (response)
|
|
12
|
-
alert(response);
|
|
13
|
-
}
|
|
14
|
-
exports.CopyToClipboard = CopyToClipboard;
|
|
15
|
-
exports.default = CopyToClipboard;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
type CSSReturnTypes = {
|
|
2
|
-
string: string;
|
|
3
|
-
number: number;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Gets the value of "property" in type "type" from query "query"
|
|
7
|
-
* Basically, you can get your --color-primary from :root
|
|
8
|
-
*
|
|
9
|
-
* @param property Name of the property to get
|
|
10
|
-
* @param type Type of the property to parse
|
|
11
|
-
* @param query Query to get the element that has the property
|
|
12
|
-
* @returns Property value converted to type
|
|
13
|
-
*/
|
|
14
|
-
export declare function GetCSSProperty<Type extends keyof CSSReturnTypes>(property: string, type: Type, query?: string): CSSReturnTypes[Type];
|
|
15
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetCSSProperty = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Gets the value of "property" in type "type" from query "query"
|
|
6
|
-
* Basically, you can get your --color-primary from :root
|
|
7
|
-
*
|
|
8
|
-
* @param property Name of the property to get
|
|
9
|
-
* @param type Type of the property to parse
|
|
10
|
-
* @param query Query to get the element that has the property
|
|
11
|
-
* @returns Property value converted to type
|
|
12
|
-
*/
|
|
13
|
-
function GetCSSProperty(property, type, query = ":root") {
|
|
14
|
-
const rootEl = document.querySelector(query);
|
|
15
|
-
if (!rootEl)
|
|
16
|
-
throw new Error(`${query} does not exist!`);
|
|
17
|
-
const rootStyles = getComputedStyle(rootEl);
|
|
18
|
-
const cssProp = rootStyles.getPropertyValue(property);
|
|
19
|
-
if (type === 'string')
|
|
20
|
-
return cssProp;
|
|
21
|
-
const numberValue = parseInt(cssProp);
|
|
22
|
-
if (isNaN(numberValue))
|
|
23
|
-
throw new Error(`${property} is not a number!: ${cssProp}`);
|
|
24
|
-
return numberValue;
|
|
25
|
-
}
|
|
26
|
-
exports.GetCSSProperty = GetCSSProperty;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type GetNestedProperty<Parent, Key extends string> = Key extends keyof Parent ? Parent[Key] : Key extends `${infer K}.${infer Rest}` ? K extends keyof Parent ? GetNestedProperty<Parent[K], Rest> : never : never;
|
|
2
|
-
/**
|
|
3
|
-
* Gets a nested property from an object
|
|
4
|
-
* @param parent Parent object to search
|
|
5
|
-
* @param key Key to search for. Can be nested with dot notation
|
|
6
|
-
* @returns Value of key or null if not found
|
|
7
|
-
*/
|
|
8
|
-
export declare function GetNestedProperty<Parent extends object, Key extends string>(parent: Parent, key: Key): GetNestedProperty<Parent, Key> | null;
|
|
9
|
-
export default GetNestedProperty;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetNestedProperty = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Gets a nested property from an object
|
|
6
|
-
* @param parent Parent object to search
|
|
7
|
-
* @param key Key to search for. Can be nested with dot notation
|
|
8
|
-
* @returns Value of key or null if not found
|
|
9
|
-
*/
|
|
10
|
-
function GetNestedProperty(parent, key) {
|
|
11
|
-
if (key in parent)
|
|
12
|
-
return parent[key];
|
|
13
|
-
for (const prop in parent) {
|
|
14
|
-
if (typeof parent[prop] === 'object') {
|
|
15
|
-
const result = GetNestedProperty(parent[prop], key);
|
|
16
|
-
if (result)
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
exports.GetNestedProperty = GetNestedProperty;
|
|
23
|
-
exports.default = GetNestedProperty;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create HTMLEvent object from function
|
|
3
|
-
* @param name Name of the event
|
|
4
|
-
* @param handler Handler for the event
|
|
5
|
-
* @returns Parameters as object
|
|
6
|
-
*/
|
|
7
|
-
export declare function HTMLEvent<Event extends keyof HTMLElementEventMap, ReturnType extends any>(name: Event, handler: (event: HTMLElementEventMap[Event]) => ReturnType): {
|
|
8
|
-
name: Event;
|
|
9
|
-
handler: (event: HTMLElementEventMap[Event]) => ReturnType;
|
|
10
|
-
};
|
|
11
|
-
export default HTMLEvent;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HTMLEvent = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Create HTMLEvent object from function
|
|
6
|
-
* @param name Name of the event
|
|
7
|
-
* @param handler Handler for the event
|
|
8
|
-
* @returns Parameters as object
|
|
9
|
-
*/
|
|
10
|
-
function HTMLEvent(name, handler) {
|
|
11
|
-
return { name, handler };
|
|
12
|
-
}
|
|
13
|
-
exports.HTMLEvent = HTMLEvent;
|
|
14
|
-
exports.default = HTMLEvent;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Appends classes to header's "a" elements, when navigation to "a"'s page is selected
|
|
3
|
-
* @param query The query selector for Document.querySelector
|
|
4
|
-
* @param currentPageClasses Class(es) to append header's "a" elements
|
|
5
|
-
*
|
|
6
|
-
* @borrows Document.querySelector
|
|
7
|
-
*/
|
|
8
|
-
export declare function SetNavigationSelected(query: string, ...currentPageClasses: string[]): void;
|
|
9
|
-
export default SetNavigationSelected;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SetNavigationSelected = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Appends classes to header's "a" elements, when navigation to "a"'s page is selected
|
|
6
|
-
* @param query The query selector for Document.querySelector
|
|
7
|
-
* @param currentPageClasses Class(es) to append header's "a" elements
|
|
8
|
-
*
|
|
9
|
-
* @borrows Document.querySelector
|
|
10
|
-
*/
|
|
11
|
-
function SetNavigationSelected(query, ...currentPageClasses) {
|
|
12
|
-
const header = document.querySelector(query);
|
|
13
|
-
if (!header)
|
|
14
|
-
throw { message: `Couldn't find header from query, ${query}` };
|
|
15
|
-
const children = header.children.array().filter(c => c.tagName === 'a');
|
|
16
|
-
const currentPage = document.location.href;
|
|
17
|
-
children.forEach(gc => {
|
|
18
|
-
if (gc.href != currentPage)
|
|
19
|
-
gc.classList.remove(...currentPageClasses);
|
|
20
|
-
else
|
|
21
|
-
gc.classList.add(...currentPageClasses);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
exports.SetNavigationSelected = SetNavigationSelected;
|
|
25
|
-
exports.default = SetNavigationSelected;
|
package/docs/Functions.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# [DanhoLibraryJS](../README.md)
|
|
2
|
-
|
|
3
|
-
## Functions
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
/**
|
|
7
|
-
* Copies value to clipboard and alerts a response, if response is defined
|
|
8
|
-
* @param value Value to clipboard
|
|
9
|
-
* @param response Alerts if response is given
|
|
10
|
-
*/
|
|
11
|
-
async function CopyToClipboard(value: string, response?: string): Promise<void>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Gets the value of "property" in type "type" from query "query"
|
|
15
|
-
* Basically, you can get your --color-primary from :root
|
|
16
|
-
*
|
|
17
|
-
* @param property Name of the property to get
|
|
18
|
-
* @param type Type of the property to parse
|
|
19
|
-
* @param query Query to get the element that has the property
|
|
20
|
-
* @returns Property value converted to type
|
|
21
|
-
*/
|
|
22
|
-
function GetCSSProperty<Type extends keyof CSSReturnTypes>(property: string, type: Type, query = ":root"): CSSReturnTypes[Type];
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Gets a nested property from an object
|
|
26
|
-
* @param parent Parent object to search
|
|
27
|
-
* @param key Key to search for. Can be nested with dot notation
|
|
28
|
-
* @returns Value of key or null if not found
|
|
29
|
-
*/
|
|
30
|
-
function GetNestedProperty<Parent, Key extends string>(parent: Parent, key: Key): GetNestedProperty<Parent, Key> | null;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Create HTMLEvent object from function
|
|
34
|
-
* @param name Name of the event
|
|
35
|
-
* @param handler Handler for the event
|
|
36
|
-
* @returns Parameters as object
|
|
37
|
-
*/
|
|
38
|
-
function HTMLEvent<
|
|
39
|
-
Event extends keyof HTMLElementEventMap,
|
|
40
|
-
ReturnType extends any
|
|
41
|
-
>(name: Event, handler: (event: HTMLElementEventMap[Event]) => ReturnType): {
|
|
42
|
-
name: Event,
|
|
43
|
-
handler: (event: HTMLElementEventMap[Event]) => ReturnType
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Appends classes to header's "a" elements, when navigation to "a"'s page is selected
|
|
48
|
-
* @param query The query selector for Document.querySelector
|
|
49
|
-
* @param currentPageClasses Class(es) to append header's "a" elements
|
|
50
|
-
*
|
|
51
|
-
* @borrows Document.querySelector
|
|
52
|
-
*/
|
|
53
|
-
function SetNavigationSelected(query: string, ...currentPageClasses: Array<string>): void;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Converts input into milliseconds
|
|
57
|
-
* @param input Input to convert to ms. 1s | 2m | 3h | 1M | 60000
|
|
58
|
-
* @returns Millisecond value of input
|
|
59
|
-
*/
|
|
60
|
-
function ms(input: TimeDelay): number
|
|
61
|
-
```
|
package/src/Extensions/Array.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
export type UpdateFinder<T> = (item: T, index: number, self: Array<T>) => boolean
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
interface Array<T> {
|
|
5
|
-
/**
|
|
6
|
-
* Pushes items to array and returns self with new items
|
|
7
|
-
* @param items Items to add to array
|
|
8
|
-
*/
|
|
9
|
-
add(...items: Array<T>): this
|
|
10
|
-
/**
|
|
11
|
-
* Update an item in array
|
|
12
|
-
* @param old The old value or index to update
|
|
13
|
-
* @param updated Updated value
|
|
14
|
-
*/
|
|
15
|
-
update(old: T | number | UpdateFinder<T>, updated: T): T
|
|
16
|
-
/**
|
|
17
|
-
* Removes item from array and returns self without item
|
|
18
|
-
* @param item Item or index to remove
|
|
19
|
-
*/
|
|
20
|
-
remove(item: T | number): this
|
|
21
|
-
/**
|
|
22
|
-
* Returns a random element from array
|
|
23
|
-
*/
|
|
24
|
-
random(): T
|
|
25
|
-
/**
|
|
26
|
-
* Returns item matching index. If negative number, subtracts number from length
|
|
27
|
-
* @param i Index of item
|
|
28
|
-
*/
|
|
29
|
-
index(i: number): T,
|
|
30
|
-
/**
|
|
31
|
-
* For every x in array, execute callback
|
|
32
|
-
* @param every i.e every 2nd item in array
|
|
33
|
-
* @param callback Function to execute
|
|
34
|
-
* @returns Array of results
|
|
35
|
-
*/
|
|
36
|
-
nth<U>(every: number, callback: (item: T, index: number, collection: Array<T>, self: this) => U): Array<U>
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function add<T>(this: Array<T>, ...items: Array<T>) {
|
|
41
|
-
this.push(...items);
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
Array.prototype.add = add;
|
|
45
|
-
|
|
46
|
-
function update<T>(this: Array<T>, old: T | number | UpdateFinder<T>, updated: T) {
|
|
47
|
-
const item = typeof old === 'number' ? this[old]
|
|
48
|
-
: typeof old === 'function' ? this.find(old as UpdateFinder<T>)
|
|
49
|
-
: old;
|
|
50
|
-
if (!item) throw new Error('Old was not found in array!');
|
|
51
|
-
|
|
52
|
-
const index = this.indexOf(item);
|
|
53
|
-
return this[index] = updated;
|
|
54
|
-
}
|
|
55
|
-
Array.prototype.update = update;
|
|
56
|
-
|
|
57
|
-
function remove<T>(this: Array<T>, value: T | number): Array<T> {
|
|
58
|
-
const index = typeof value === 'number' ? value : this.indexOf(value);
|
|
59
|
-
if (index > -1) this.splice(index, 1);
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
Array.prototype.remove = remove;
|
|
63
|
-
|
|
64
|
-
function random<T>(this: Array<T>): T {
|
|
65
|
-
const randomIndex = Math.round(Math.random() * this.length);
|
|
66
|
-
return this[randomIndex];
|
|
67
|
-
}
|
|
68
|
-
Array.prototype.random = random;
|
|
69
|
-
|
|
70
|
-
function index<T>(this: Array<T>, i: number): T {
|
|
71
|
-
return this[i < 0 ? this.length + i : i];
|
|
72
|
-
}
|
|
73
|
-
Array.prototype.index = index;
|
|
74
|
-
|
|
75
|
-
function nth<T, U>(this: Array<T>, every: number, callback: (item: T, index: number, collection: Array<T>, self: Array<T>) => U): Array<U> {
|
|
76
|
-
const result = new Array<U>();
|
|
77
|
-
let collection = new Array<T>();
|
|
78
|
-
|
|
79
|
-
for (let i = 0; i < this.length; i++) {
|
|
80
|
-
collection.push(this[i]);
|
|
81
|
-
|
|
82
|
-
if (i % every === 0) {
|
|
83
|
-
result.push(callback(this[i], i, collection, this));
|
|
84
|
-
collection = new Array<T>();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
Array.prototype.nth = nth;
|
|
91
|
-
|
|
92
|
-
export const ArrayExtensions = {
|
|
93
|
-
add, update, remove,
|
|
94
|
-
random, index, nth
|
|
95
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { IElement } from "../Types";
|
|
2
|
-
|
|
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
|
-
* @param children Child elements
|
|
10
|
-
*/
|
|
11
|
-
createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]>, ...children: Array<IElement>): HTMLElementTagNameMap[Tag]
|
|
12
|
-
createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, ...children: Array<IElement>): HTMLElementTagNameMap[Tag]
|
|
13
|
-
createElementFromString<K extends keyof HTMLElementTagNameMap>(html: string, parentTag?: K): HTMLElementTagNameMap[K]
|
|
14
|
-
}
|
|
15
|
-
interface HTMLCollection {
|
|
16
|
-
/**
|
|
17
|
-
* Converts HTMLCollection to Element[]
|
|
18
|
-
*/
|
|
19
|
-
array(): Element[]
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function createElement<Tag extends keyof HTMLElementTagNameMap>(
|
|
24
|
-
this: Document, tagName: Tag,
|
|
25
|
-
options?: Partial<HTMLElementTagNameMap[Tag]> | string,
|
|
26
|
-
...children: Array<IElement>
|
|
27
|
-
): HTMLElementTagNameMap[Tag] {
|
|
28
|
-
|
|
29
|
-
const element = Object.assign(document.createElement(tagName), typeof options === 'string' ? {} : options);
|
|
30
|
-
children ??= typeof options === 'string' ? [options] as Array<IElement> : [];
|
|
31
|
-
typeof options === 'string' && children.unshift(options);
|
|
32
|
-
|
|
33
|
-
if (!children.length) return element;
|
|
34
|
-
else if (typeof children === 'string') element.innerHTML = children;
|
|
35
|
-
else if (children instanceof Array) children.forEach(child => (
|
|
36
|
-
typeof child === 'string' ?
|
|
37
|
-
element.innerHTML += child :
|
|
38
|
-
element.appendChild(child)
|
|
39
|
-
));
|
|
40
|
-
else element.appendChild(children);
|
|
41
|
-
return element;
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
Document.prototype.createProperElement = createElement;
|
|
45
|
-
|
|
46
|
-
function createElementFromString<Tag extends keyof HTMLElementTagNameMap>(this: Document, html: string, tag?: Tag): HTMLElementTagNameMap[Tag] {
|
|
47
|
-
if (!html.startsWith(`<${tag}`)) html = `<${tag}>${html}</${tag}>`;
|
|
48
|
-
return new DOMParser().parseFromString(html, 'text/html').body.firstElementChild as HTMLElementTagNameMap[Tag];
|
|
49
|
-
}
|
|
50
|
-
Document.prototype.createElementFromString = createElementFromString;
|
|
51
|
-
|
|
52
|
-
HTMLCollection.prototype.array = function(this: HTMLCollection) {
|
|
53
|
-
return Array.from(this);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const DocumentExtensions = {
|
|
57
|
-
createElement, createElementFromString
|
|
58
|
-
};
|