danholibraryjs 1.3.0 → 1.7.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} +14 -11
- package/dist/Classes/{Event.js → Events/Event.js} +16 -6
- package/dist/Classes/{EventCollection.d.ts → Events/EventCollection.d.ts} +10 -9
- package/dist/Classes/{EventCollection.js → Events/EventCollection.js} +27 -28
- package/dist/Classes/{EventEmitter.d.ts → Events/EventEmitter.d.ts} +11 -8
- package/dist/Classes/{EventEmitter.js → Events/EventEmitter.js} +7 -1
- 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/{Types/EventHandler.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 -2
- package/dist/Classes/index.js +7 -3
- 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 +11 -0
- package/dist/Functions/HTMLEvent.js +14 -0
- package/dist/Functions/SetNavigationSelected.js +2 -0
- package/dist/Functions/index.d.ts +2 -0
- package/dist/Functions/index.js +7 -1
- package/dist/Interfaces/ElementOptions.d.ts +12 -18
- package/dist/Interfaces/IReplacement.d.ts +3 -2
- package/dist/Interfaces/index.js +5 -1
- package/dist/Types/BetterTypes.d.ts +9 -0
- package/dist/Types/{IElement.js → BetterTypes.js} +0 -0
- package/dist/Types/Date.d.ts +6 -0
- package/dist/Types/{StringRegex.js → Date.js} +0 -0
- package/dist/Types/Events.d.ts +10 -0
- package/dist/Types/Events.js +2 -0
- package/dist/Types/PropertiesWith.d.ts +13 -0
- package/dist/Types/PropertiesWith.js +2 -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 -9
- package/dist/index.js +19 -8
- package/docs/Classes.md +455 -0
- package/docs/Extensions.md +146 -0
- package/docs/Functions.md +53 -0
- package/docs/Interfaces.md +34 -0
- package/docs/Types.md +129 -0
- package/docs/index.md +29 -0
- package/package.json +22 -21
- package/src/Classes/{Event.ts → Events/Event.ts} +31 -20
- package/src/Classes/Events/EventCollection.ts +109 -0
- package/src/Classes/{EventEmitter.ts → Events/EventEmitter.ts} +16 -13
- 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 -2
- 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 +13 -0
- package/src/Functions/SetNavigationSelected.ts +1 -0
- package/src/Functions/index.ts +3 -1
- package/src/Interfaces/ElementOptions.ts +18 -16
- package/src/Interfaces/IReplacement.ts +4 -3
- 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 -13
- package/tsconfig.json +99 -7
- package/dist/Extensions.d.ts +0 -81
- package/dist/Extensions.js +0 -80
- package/dist/Types/EventHandler.d.ts +0 -6
- package/dist/Types/IElement.d.ts +0 -9
- package/dist/Types/StringRegex.d.ts +0 -2
- package/src/Classes/EventCollection.ts +0 -115
- package/src/Extensions.ts +0 -179
- package/src/Types/EventHandler.ts +0 -6
- package/src/Types/IElement.ts +0 -9
- package/src/Types/StringRegex.ts +0 -2
package/dist/Extensions.d.ts
DELETED
|
@@ -1,81 +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
|
-
interface Map<K, V> {
|
|
31
|
-
/**
|
|
32
|
-
* Converts into Array<[Key, Value]>
|
|
33
|
-
*/
|
|
34
|
-
array(): [K, V][];
|
|
35
|
-
/**
|
|
36
|
-
* Maps values into new types of generics
|
|
37
|
-
* @param callback Callbacking function to map values
|
|
38
|
-
*/
|
|
39
|
-
map<EK, EV>(callback: (value: V, key?: K, index?: number, map?: this) => [EK, EV]): Map<EK, EV>;
|
|
40
|
-
/**
|
|
41
|
-
* Returns array of "accepted" values. Criteria defined in callback param
|
|
42
|
-
* @param callback Callbacking function to filter away unwanted values
|
|
43
|
-
*/
|
|
44
|
-
filter(callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean): Map<K, V>;
|
|
45
|
-
/**
|
|
46
|
-
* Returns array of keys
|
|
47
|
-
*/
|
|
48
|
-
keyArr(): Array<K>;
|
|
49
|
-
/**
|
|
50
|
-
* Returns array of values
|
|
51
|
-
*/
|
|
52
|
-
valueArr(): Array<V>;
|
|
53
|
-
/**
|
|
54
|
-
* Returns first [key, value] match to callback param
|
|
55
|
-
* @param callback Callbacking function to find KeyValuePair
|
|
56
|
-
*/
|
|
57
|
-
find(callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean): [K, V];
|
|
58
|
-
/**
|
|
59
|
-
* Whether or not map includes a value. Returns true if it does, false if not ¯\_(ツ)_/¯
|
|
60
|
-
* @param value Value that may be includded in map
|
|
61
|
-
* @param fromIndex Start looking for value from specific index+. Default: 0
|
|
62
|
-
*/
|
|
63
|
-
includes(value: V, fromIndex?: number): boolean;
|
|
64
|
-
}
|
|
65
|
-
interface String {
|
|
66
|
-
/**
|
|
67
|
-
* Uppercases first letter of string
|
|
68
|
-
*/
|
|
69
|
-
toPascalCase(): string;
|
|
70
|
-
/**
|
|
71
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '_')
|
|
72
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
73
|
-
*/
|
|
74
|
-
toSnakeCase(replaceOptions?: IReplacement): 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
|
-
toKebabCase(replaceOptions?: IReplacement): string;
|
|
80
|
-
}
|
|
81
|
-
}
|
package/dist/Extensions.js
DELETED
|
@@ -1,80 +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(...options.children);
|
|
15
|
-
}
|
|
16
|
-
if (options.events) {
|
|
17
|
-
options.events.forEach(({ name, handlers }) => (handlers.forEach(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
|
-
Map.prototype.array = function () {
|
|
41
|
-
let result = new Array();
|
|
42
|
-
for (const kvp of this) {
|
|
43
|
-
result.push(kvp);
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
};
|
|
47
|
-
Map.prototype.map = function (callback) {
|
|
48
|
-
return this.array()
|
|
49
|
-
.map(([k, v], i) => callback(v, k, i, this))
|
|
50
|
-
.reduce((map, [key, value]) => map.set(key, value), new Map());
|
|
51
|
-
};
|
|
52
|
-
Map.prototype.filter = function (callback) {
|
|
53
|
-
return this.array()
|
|
54
|
-
.filter(([k, v], i) => callback(v, k, i, this))
|
|
55
|
-
.reduce((map, [key, value]) => map.set(key, value), new Map());
|
|
56
|
-
};
|
|
57
|
-
Map.prototype.keyArr = function () {
|
|
58
|
-
return this.array().map(([k]) => k);
|
|
59
|
-
};
|
|
60
|
-
Map.prototype.valueArr = function () {
|
|
61
|
-
return this.array().map(([_, v]) => v);
|
|
62
|
-
};
|
|
63
|
-
Map.prototype.find = function (callback) {
|
|
64
|
-
return this.array().find(([k, v], i) => callback(v, k, i, this));
|
|
65
|
-
};
|
|
66
|
-
Map.prototype.includes = function (item, fromIndex) {
|
|
67
|
-
return this.valueArr().includes(item, fromIndex);
|
|
68
|
-
};
|
|
69
|
-
String.prototype.toPascalCase = function () {
|
|
70
|
-
return this.substring(0, 1).toUpperCase() + this.substring(1);
|
|
71
|
-
};
|
|
72
|
-
function spaceReplacer(self, replacer, replacement) {
|
|
73
|
-
return self.replace(new RegExp(`${typeof replacer == 'string' ? replacer : replacer.source}+`), replacement);
|
|
74
|
-
}
|
|
75
|
-
String.prototype.toSnakeCase = function (replaceOptions = { replacer: ' ', replacement: '_' }) {
|
|
76
|
-
return spaceReplacer(this, replaceOptions.replacer, replaceOptions.replacement);
|
|
77
|
-
};
|
|
78
|
-
String.prototype.toKebabCase = function (replaceOptions = { replacer: ' ', replacement: '-' }) {
|
|
79
|
-
return spaceReplacer(this, replaceOptions.replacer, replaceOptions.replacement);
|
|
80
|
-
};
|
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,115 +0,0 @@
|
|
|
1
|
-
import EventHandler from "../Types/EventHandler";
|
|
2
|
-
import Event from './Event';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Collection of Events from @see EventEmitter
|
|
6
|
-
* @borrows EventHandler
|
|
7
|
-
* @borrows Event
|
|
8
|
-
*/
|
|
9
|
-
export class EventCollection {
|
|
10
|
-
constructor(events?: Map<string, EventHandler[]>) {
|
|
11
|
-
this._events = !events ?
|
|
12
|
-
new Map<string, Event>() :
|
|
13
|
-
events.array().reduce((result, [event, handlers]) =>
|
|
14
|
-
result.set(event, new Event(event, ...handlers)),
|
|
15
|
-
new Map<string, Event>());
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**Amount of events stored*/
|
|
19
|
-
public get size() {
|
|
20
|
-
return this._events.size;
|
|
21
|
-
}
|
|
22
|
-
/**@private Internal event collection*/
|
|
23
|
-
private _events = new Map<string, Event>();
|
|
24
|
-
/**@private limit of events*/
|
|
25
|
-
private _limit = 0;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Returns true if event is in collection
|
|
29
|
-
* @param event Event name
|
|
30
|
-
* @returns true if event is in collection
|
|
31
|
-
*/
|
|
32
|
-
public has(event: string): boolean {
|
|
33
|
-
return this._events.has(event);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Returns event matching event parameter
|
|
37
|
-
* @param event Event name
|
|
38
|
-
* @returns Event
|
|
39
|
-
*/
|
|
40
|
-
public get<T = any>(event: string): Event<T> {
|
|
41
|
-
return this._events.get(event);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Adds handler to event collection with name as key
|
|
45
|
-
* @param name Event name
|
|
46
|
-
* @param handler Handler for event
|
|
47
|
-
* @returns this
|
|
48
|
-
*/
|
|
49
|
-
public add(name: string, handler: EventHandler, once = false): this {
|
|
50
|
-
if (this._limit > 0 && this._limit + 1 > this._events.size) {
|
|
51
|
-
throw new Error(`Listener limit, ${this._limit}, reached!`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const event = this.has(name) && this.get(name);
|
|
55
|
-
|
|
56
|
-
if (once) this._events.set(name, event ? event.once(handler) : new Event(name).once(handler))
|
|
57
|
-
else this._events.set(name, event ? event.on(handler) : new Event(name, handler));
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @summary clear(): Clears all events
|
|
62
|
-
* @summary clear("all", myEventHandler): Removes myEventHandler from all events that have it
|
|
63
|
-
* @summary clear("myEvent"): Clears all handlers tied to "myEvent"
|
|
64
|
-
* @summary clear("myEvent", myEventHandler): Removes myEventHandler from "myEvent"
|
|
65
|
-
*
|
|
66
|
-
* @param name Event name | "all"
|
|
67
|
-
* @param handler Specific handler to remove. If left blank, all handlers in name will be removed
|
|
68
|
-
* @returns this
|
|
69
|
-
*/
|
|
70
|
-
public clear(name: string | "all" = 'all', handler?: EventHandler): this {
|
|
71
|
-
//clear(): Clears all events
|
|
72
|
-
if (name.toLowerCase() == 'all' && handler == null) this._events.clear();
|
|
73
|
-
|
|
74
|
-
//clear("all", myEventHandler): Removes the "myEventHandler" handler from all events
|
|
75
|
-
else if (name.toLowerCase() == 'all' && handler) this._events = (() => {
|
|
76
|
-
const eventNames = this._events.array().map(([name, event]) => event.includes(handler) && name);
|
|
77
|
-
this._events.forEach((event, name) =>
|
|
78
|
-
eventNames.includes(name) &&
|
|
79
|
-
this._events.set(name, event.off(handler)
|
|
80
|
-
));
|
|
81
|
-
|
|
82
|
-
return this._events;
|
|
83
|
-
})();
|
|
84
|
-
|
|
85
|
-
//clear("myEvent"): Deletes myEvent from this._events
|
|
86
|
-
else if (name.toLowerCase() != "all" && handler == null) this._events.delete(name);
|
|
87
|
-
|
|
88
|
-
//clear("myEvent", myEventHandler): Removes the "myEventsHandler" handler from "myEvent"
|
|
89
|
-
else if (name.toLowerCase() != 'all' && handler) this._events.set(name, this.get(name).off(handler));
|
|
90
|
-
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public emit(name: string, ...args: any[]) {
|
|
95
|
-
return this.get(name).emit(...args);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Limits how many events to accept using EventEmitter#on or EventEmitter#once
|
|
100
|
-
* @param limit Limit of events to keep
|
|
101
|
-
* @returns this with the new limit
|
|
102
|
-
*
|
|
103
|
-
* @throws Unknown event, if event name isn't recognized
|
|
104
|
-
*/
|
|
105
|
-
public limit(event: 'all' | string, limit: number) {
|
|
106
|
-
if (limit <= 0) return;
|
|
107
|
-
|
|
108
|
-
if (event == 'all') this._limit = limit;
|
|
109
|
-
else if (this.has(event)) this.get(event).limit = limit;
|
|
110
|
-
else throw new Error(`Unknown event, ${event}!`);
|
|
111
|
-
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
export default EventCollection;
|
package/src/Extensions.ts
DELETED
|
@@ -1,179 +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
|
-
interface Map<K, V> {
|
|
32
|
-
/**
|
|
33
|
-
* Converts into Array<[Key, Value]>
|
|
34
|
-
*/
|
|
35
|
-
array(): [K, V][]
|
|
36
|
-
/**
|
|
37
|
-
* Maps values into new types of generics
|
|
38
|
-
* @param callback Callbacking function to map values
|
|
39
|
-
*/
|
|
40
|
-
map<EK, EV>(callback: (value: V, key?: K, index?: number, map?: this) => [EK, EV]): Map<EK, EV>
|
|
41
|
-
/**
|
|
42
|
-
* Returns array of "accepted" values. Criteria defined in callback param
|
|
43
|
-
* @param callback Callbacking function to filter away unwanted values
|
|
44
|
-
*/
|
|
45
|
-
filter(callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean): Map<K, V>
|
|
46
|
-
/**
|
|
47
|
-
* Returns array of keys
|
|
48
|
-
*/
|
|
49
|
-
keyArr(): Array<K>
|
|
50
|
-
/**
|
|
51
|
-
* Returns array of values
|
|
52
|
-
*/
|
|
53
|
-
valueArr(): Array<V>
|
|
54
|
-
/**
|
|
55
|
-
* Returns first [key, value] match to callback param
|
|
56
|
-
* @param callback Callbacking function to find KeyValuePair
|
|
57
|
-
*/
|
|
58
|
-
find(callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean): [K, V]
|
|
59
|
-
/**
|
|
60
|
-
* Whether or not map includes a value. Returns true if it does, false if not ¯\_(ツ)_/¯
|
|
61
|
-
* @param value Value that may be includded in map
|
|
62
|
-
* @param fromIndex Start looking for value from specific index+. Default: 0
|
|
63
|
-
*/
|
|
64
|
-
includes(value: V, fromIndex?: number): boolean
|
|
65
|
-
}
|
|
66
|
-
interface String {
|
|
67
|
-
/**
|
|
68
|
-
* Uppercases first letter of string
|
|
69
|
-
*/
|
|
70
|
-
toPascalCase(): string
|
|
71
|
-
/**
|
|
72
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '_')
|
|
73
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
74
|
-
*/
|
|
75
|
-
toSnakeCase(replaceOptions?: IReplacement): string
|
|
76
|
-
/**
|
|
77
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '-')
|
|
78
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
79
|
-
*/
|
|
80
|
-
toKebabCase(replaceOptions?: IReplacement): string
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
Document.prototype.createProperElement = function<K extends keyof HTMLElementTagNameMap>(this: Document, tagName: K, options?: ElementOptions) {
|
|
85
|
-
let baseElement = document.createElement(tagName);
|
|
86
|
-
if (!options) return baseElement;
|
|
87
|
-
|
|
88
|
-
if (options.classes) {
|
|
89
|
-
baseElement.classList.add(...options.classes);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (options.attributes) {
|
|
93
|
-
options.attributes.forEach(([attribute, value]) => baseElement.setAttribute(attribute, value));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (options.children) {
|
|
97
|
-
baseElement.append(...options.children);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (options.events) {
|
|
101
|
-
options.events.forEach(({ name, handlers }) => (
|
|
102
|
-
handlers.forEach(handler => (
|
|
103
|
-
baseElement.addEventListener(name, handler)
|
|
104
|
-
))
|
|
105
|
-
))
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return baseElement;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
HTMLCollection.prototype.array = function(this: HTMLCollection) {
|
|
112
|
-
let result = new Array<Element>();
|
|
113
|
-
|
|
114
|
-
for (let i = 0; i < this.length; i++) {
|
|
115
|
-
result.push(this.item(i));
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
Array.prototype.add = function<T>(this: Array<T>, ...items: Array<T>) {
|
|
121
|
-
this.push(...items);
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
Array.prototype.remove = function<T>(this: Array<T>, item: T): Array<T> {
|
|
125
|
-
const itemInArray = this.includes(item) ? item : this.find(i => i == item);
|
|
126
|
-
if (!itemInArray) throw new Error(`item is not in array!`);
|
|
127
|
-
|
|
128
|
-
const itemIndex = this.indexOf(itemInArray);
|
|
129
|
-
this.splice(itemIndex, 1);
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
Map.prototype.array = function<K, V>(this: Map<K, V>): [K, V][] {
|
|
134
|
-
let result = new Array<[K, V]>();
|
|
135
|
-
for (const kvp of this) {
|
|
136
|
-
result.push(kvp);
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
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> {
|
|
141
|
-
return this.array()
|
|
142
|
-
.map(([k, v], i) => callback(v, k, i, this))
|
|
143
|
-
.reduce((map, [key, value]) =>
|
|
144
|
-
map.set(key, value),
|
|
145
|
-
new Map<EK, EV>())
|
|
146
|
-
}
|
|
147
|
-
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> {
|
|
148
|
-
return this.array()
|
|
149
|
-
.filter(([k, v], i) => callback(v, k, i, this))
|
|
150
|
-
.reduce((map, [key, value]) =>
|
|
151
|
-
map.set(key, value),
|
|
152
|
-
new Map<K, V>())
|
|
153
|
-
}
|
|
154
|
-
Map.prototype.keyArr = function<K, V>(this: Map<K, V>): K[] {
|
|
155
|
-
return this.array().map(([k]) => k);
|
|
156
|
-
}
|
|
157
|
-
Map.prototype.valueArr = function<K, V>(this: Map<K, V>): V[] {
|
|
158
|
-
return this.array().map(([_, v]) => v);
|
|
159
|
-
}
|
|
160
|
-
Map.prototype.find = function<K, V>(this: Map<K, V>, callback: (value: V, key?: K, index?: number, map?: Map<K, V>) => boolean) {
|
|
161
|
-
return this.array().find(([k, v], i) => callback(v, k, i, this));
|
|
162
|
-
}
|
|
163
|
-
Map.prototype.includes = function<K, V>(this: Map<K, V>, item: V, fromIndex?: number) {
|
|
164
|
-
return this.valueArr().includes(item, fromIndex);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
String.prototype.toPascalCase = function(this: string) {
|
|
168
|
-
return this.substring(0, 1).toUpperCase() + this.substring(1);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function spaceReplacer(self: string, replacer: string | RegExp, replacement: string) {
|
|
172
|
-
return self.replace(new RegExp(`${typeof replacer == 'string' ? replacer : replacer.source}+`), replacement);
|
|
173
|
-
}
|
|
174
|
-
String.prototype.toSnakeCase = function(this: string, replaceOptions: IReplacement = { replacer: ' ', replacement: '_' }) {
|
|
175
|
-
return spaceReplacer(this, replaceOptions.replacer, replaceOptions.replacement)
|
|
176
|
-
}
|
|
177
|
-
String.prototype.toKebabCase = function(this: string, replaceOptions: IReplacement = { replacer: ' ', replacement: '-' }) {
|
|
178
|
-
return spaceReplacer(this, replaceOptions.replacer, replaceOptions.replacement);
|
|
179
|
-
}
|
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