danholibraryjs 1.8.0 → 1.10.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/dist/Classes/Events/Event.js +1 -1
- package/dist/Classes/Events/EventCollection.js +1 -1
- package/dist/Classes/Events/EventEmitter.d.ts +4 -4
- package/dist/Classes/Time/Date.d.ts +5 -5
- package/dist/Classes/Time/Time.d.ts +3 -3
- package/dist/Classes/Time/TimeProperties.d.ts +2 -2
- package/dist/Classes/Time/TimeSpan.d.ts +1 -1
- package/dist/Classes/index.d.ts +1 -0
- package/dist/Classes/index.js +1 -0
- package/dist/Classes/store.d.ts +1 -1
- package/dist/Classes/store.js +0 -1
- package/dist/Extensions/Array.d.ts +8 -1
- package/dist/Extensions/Array.js +47 -10
- package/dist/Extensions/Document.d.ts +27 -0
- package/dist/Extensions/Document.js +32 -0
- package/dist/Extensions/Function.d.ts +14 -0
- package/dist/Extensions/Function.js +10 -0
- package/dist/Extensions/Map.d.ts +17 -1
- package/dist/Extensions/Map.js +24 -13
- package/dist/Extensions/Object/index.d.ts +49 -0
- package/dist/Extensions/Object/index.js +38 -0
- package/dist/Extensions/Object/properties.d.ts +28 -0
- package/dist/Extensions/Object/properties.js +20 -0
- package/dist/Extensions/String.d.ts +11 -1
- package/dist/Extensions/String.js +15 -7
- package/dist/Extensions/index.d.ts +5 -17
- package/dist/Extensions/index.js +8 -49
- package/dist/Functions/GetCSSProperty.d.ts +1 -1
- package/dist/Functions/GetNestedProperty.d.ts +9 -0
- package/dist/Functions/GetNestedProperty.js +23 -0
- package/dist/Functions/index.d.ts +1 -0
- package/dist/Functions/index.js +1 -0
- package/dist/Interfaces/ElementOptions.d.ts +4 -4
- package/dist/Types/BetterTypes.d.ts +3 -3
- package/dist/Types/Date.d.ts +6 -6
- package/dist/Types/Events.d.ts +2 -2
- package/dist/Types/PropertiesWith.d.ts +2 -2
- package/dist/Types/TransformTypes.d.ts +2 -2
- package/dist/Types/index.d.ts +21 -6
- package/docs/Extensions.md +7 -0
- package/docs/Functions.md +8 -0
- package/docs/Types.md +23 -18
- package/package.json +6 -3
- package/src/Classes/Events/Event.ts +1 -1
- package/src/Classes/Events/EventCollection.ts +1 -1
- package/src/Classes/Events/EventEmitter.ts +16 -5
- package/src/Classes/index.ts +2 -1
- package/src/Classes/store.ts +11 -8
- package/src/Extensions/Array.ts +49 -11
- package/src/Extensions/Document.ts +58 -0
- package/src/Extensions/Function.ts +18 -0
- package/src/Extensions/Map.ts +24 -9
- package/src/Extensions/Object/index.ts +82 -0
- package/src/Extensions/Object/properties.ts +51 -0
- package/src/Extensions/String.ts +17 -6
- package/src/Extensions/index.ts +7 -66
- package/src/Functions/GetNestedProperty.ts +29 -0
- package/src/Functions/index.ts +1 -0
- package/src/Interfaces/ElementOptions.ts +2 -2
- package/src/Types/index.ts +27 -2
- package/tsconfig.json +2 -2
- package/Time.xlsx +0 -0
- package/dist/Extensions/Object.d.ts +0 -16
- package/dist/Extensions/Object.js +0 -8
- package/src/Extensions/Object.ts +0 -25
package/.gitattributes
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
# Auto detect text files and perform LF normalization
|
|
2
|
-
* text=auto
|
|
1
|
+
# Auto detect text files and perform LF normalization
|
|
2
|
+
* text=auto
|
|
@@ -53,7 +53,7 @@ class Event {
|
|
|
53
53
|
*/
|
|
54
54
|
on(listener, prepend = false) {
|
|
55
55
|
if (this.limit > 0 && this._listeners.length + 1 > this.limit) {
|
|
56
|
-
throw new Error(`Event limit, ${this.limit}, reached for event ${this.name}!`);
|
|
56
|
+
throw new Error(`Event limit, ${this.limit}, reached for event ${this.name.toString()}!`);
|
|
57
57
|
}
|
|
58
58
|
if (prepend)
|
|
59
59
|
this._listeners = [listener, ...this._listeners];
|
|
@@ -99,7 +99,7 @@ class EventCollection {
|
|
|
99
99
|
}
|
|
100
100
|
const event = this.get(eventName);
|
|
101
101
|
if (!event)
|
|
102
|
-
throw new Error(`Unknown event, ${eventName}!`);
|
|
102
|
+
throw new Error(`Unknown event, ${eventName.toString()}!`);
|
|
103
103
|
event.limit = limit;
|
|
104
104
|
this._events.set(eventName, event);
|
|
105
105
|
return this;
|
|
@@ -40,21 +40,21 @@ export declare class EventEmitter<Events extends BaseEvent<string, Array<any>>>
|
|
|
40
40
|
* @param listener Callback function to run, when event occurs
|
|
41
41
|
* @returns this
|
|
42
42
|
*/
|
|
43
|
-
on<Return extends any, Event extends keyof Events>(event: Event, listener: EventHandler<Events, Event, Return>):
|
|
43
|
+
on<Return extends any, Event extends keyof Events>(event: Event, listener: EventHandler<Events, Event, Return>): EventEmitter<Events>;
|
|
44
44
|
/**
|
|
45
45
|
* Adds listener to event collection, and runs listener once when event is emitted
|
|
46
46
|
* @param event Event to handle
|
|
47
47
|
* @param listener Callback function to run, when event occurs
|
|
48
48
|
* @returns this
|
|
49
49
|
*/
|
|
50
|
-
once<Return extends any, Event extends keyof Events>(event: Event, listener: EventHandler<Events, Event, Return>):
|
|
50
|
+
once<Return extends any, Event extends keyof Events>(event: Event, listener: EventHandler<Events, Event, Return>): EventEmitter<Events>;
|
|
51
51
|
/**
|
|
52
52
|
* Removes listener(s) from event
|
|
53
53
|
* @param event Event to get collection of listeners | "all"
|
|
54
54
|
* @param listener If left null, removes all listeners tied to event, else only removes listener from event
|
|
55
55
|
* @returns this
|
|
56
56
|
*/
|
|
57
|
-
off<Return extends any, Event extends keyof Events>(event?: Event | 'all', listener?: EventHandler<Events, Event, Return>):
|
|
57
|
+
off<Return extends any, Event extends keyof Events>(event?: Event | 'all', listener?: EventHandler<Events, Event, Return>): EventEmitter<Events>;
|
|
58
58
|
/**
|
|
59
59
|
* Emits event and runs all listeners tied to event
|
|
60
60
|
* @param event Event to emit
|
|
@@ -69,6 +69,6 @@ export declare class EventEmitter<Events extends BaseEvent<string, Array<any>>>
|
|
|
69
69
|
* @param limit Limit of events to keep. If you want to limit amount of events saved, use 'all'.
|
|
70
70
|
* @returns this with the new limit
|
|
71
71
|
*/
|
|
72
|
-
limit<Event extends keyof Events>(event: 'all' | Event, limit: number):
|
|
72
|
+
limit<Event extends keyof Events>(event: 'all' | Event, limit: number): EventEmitter<Events>;
|
|
73
73
|
}
|
|
74
74
|
export default EventEmitter;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { BetterOmit, PartialExcept, LongMonth, LongDay, ShortDay, ShortMonth } from "../../Types";
|
|
2
2
|
import TimeProperties from "./TimeProperties";
|
|
3
3
|
import TimeSpan, { TimeSpanFormat } from "./TimeSpan";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
type Data = PartialExcept<BetterOmit<TimeProperties<true>, 'weeks'>, 'years' | 'months'>;
|
|
5
|
+
type Double = `${number}${number}`;
|
|
6
|
+
type Quadruple = `${Double}${Double}`;
|
|
7
|
+
type DateFormat = `${Double}/${Double}/${Quadruple}`;
|
|
8
8
|
/**
|
|
9
9
|
* Type used to construct DanhoDate.
|
|
10
10
|
* @Data Partial TimeProperties except years & months
|
|
11
11
|
* @DateFormat string as dd/MM/yyyy
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type DanhoDateConstructor = Data | DateFormat | number | Date;
|
|
14
14
|
declare class DanhoDate {
|
|
15
15
|
/**
|
|
16
16
|
* Returns the value of the current irl time
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { LongMonth } from "../../Types/Date";
|
|
2
2
|
/** '2s' or 2000 */
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
3
|
+
export type TimeUnit = 'ms' | 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'y';
|
|
4
|
+
export type TimeString = `${number}${TimeUnit}`;
|
|
5
|
+
export type TimeDelay = number | TimeString;
|
|
6
6
|
export declare const ValidTime: RegExp;
|
|
7
7
|
/**
|
|
8
8
|
* Converts input into milliseconds
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
type TimeKeys = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
|
|
2
|
+
export type TimeProperties<Plural extends boolean = false> = Record<Plural extends true ? `${TimeKeys}s` : TimeKeys, number>;
|
|
3
3
|
export default TimeProperties;
|
|
@@ -4,7 +4,7 @@ import TimeProperties from "./TimeProperties";
|
|
|
4
4
|
/**
|
|
5
5
|
* What properties to include when using TimeSpan.toString(format: TimeSpanFormat): string
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type TimeSpanFormat = Partial<TransformType<TimeProperties<true>, number, boolean>>;
|
|
8
8
|
/**
|
|
9
9
|
* Timespan between 2 dates.
|
|
10
10
|
* @borrows TimeSpanValue
|
package/dist/Classes/index.d.ts
CHANGED
package/dist/Classes/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Events"), exports);
|
|
18
18
|
__exportStar(require("./Time"), exports);
|
|
19
|
+
__exportStar(require("./store"), exports);
|
package/dist/Classes/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Arrayable } from "../Types";
|
|
2
2
|
import { EventEmitter } from "./Events";
|
|
3
|
-
export
|
|
3
|
+
export type Reducer<State, Types extends Record<string, any[]>, Action extends keyof Types> = (state: State, ...args: Types[Action]) => State;
|
|
4
4
|
/**
|
|
5
5
|
* EventEmitter, but it stores state and handles state change with reducers
|
|
6
6
|
*
|
package/dist/Classes/store.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
|
|
2
|
+
type UpdateFinder<T> = (item: T, index: number, self: Array<T>) => boolean;
|
|
3
3
|
declare global {
|
|
4
4
|
interface Array<T> {
|
|
5
5
|
/**
|
|
@@ -27,5 +27,12 @@ declare global {
|
|
|
27
27
|
* @param i Index of item
|
|
28
28
|
*/
|
|
29
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: (collection: Array<T>, index: number, self: this) => U): Array<U>;
|
|
30
37
|
}
|
|
31
38
|
}
|
package/dist/Extensions/Array.js
CHANGED
|
@@ -1,26 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.ArrayExtensions = void 0;
|
|
4
|
+
function add(...items) {
|
|
4
5
|
this.push(...items);
|
|
5
6
|
return this;
|
|
6
|
-
}
|
|
7
|
-
Array.prototype.
|
|
8
|
-
|
|
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;
|
|
9
13
|
if (!item)
|
|
10
14
|
throw new Error('Old was not found in array!');
|
|
11
15
|
const index = this.indexOf(item);
|
|
12
16
|
return this[index] = updated;
|
|
13
|
-
}
|
|
14
|
-
Array.prototype.
|
|
17
|
+
}
|
|
18
|
+
Array.prototype.update = update;
|
|
19
|
+
function remove(value) {
|
|
15
20
|
const index = typeof value === 'number' ? value : this.indexOf(value);
|
|
16
21
|
if (index > -1)
|
|
17
22
|
this.splice(index, 1);
|
|
18
23
|
return this;
|
|
19
|
-
}
|
|
20
|
-
Array.prototype.
|
|
24
|
+
}
|
|
25
|
+
Array.prototype.remove = remove;
|
|
26
|
+
function random() {
|
|
21
27
|
const randomIndex = Math.round(Math.random() * this.length);
|
|
22
28
|
return this[randomIndex];
|
|
23
|
-
}
|
|
24
|
-
Array.prototype.
|
|
29
|
+
}
|
|
30
|
+
Array.prototype.random = random;
|
|
31
|
+
function index(i) {
|
|
25
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
|
+
};
|
|
52
|
+
Array.prototype.nth = function (every, callback) {
|
|
53
|
+
const result = new Array();
|
|
54
|
+
let collection = new Array();
|
|
55
|
+
for (let i = 0; i < this.length; i++) {
|
|
56
|
+
collection.push(this[i]);
|
|
57
|
+
if (i % every === 0) {
|
|
58
|
+
result.push(callback(collection, i, this));
|
|
59
|
+
collection = new Array();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
26
63
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Function {
|
|
3
|
+
/**
|
|
4
|
+
* Checks if obj is a function
|
|
5
|
+
* @param obj Object to check
|
|
6
|
+
*/
|
|
7
|
+
is(obj: any): obj is Function;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare function is(obj: any): obj is Function;
|
|
11
|
+
export declare const FunctionExtensions: {
|
|
12
|
+
is: typeof is;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
package/dist/Extensions/Map.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {};
|
|
2
1
|
declare global {
|
|
3
2
|
interface Map<K, V> {
|
|
4
3
|
/**
|
|
@@ -36,3 +35,20 @@ declare global {
|
|
|
36
35
|
includes(value: V, fromIndex?: number): boolean;
|
|
37
36
|
}
|
|
38
37
|
}
|
|
38
|
+
declare function array<K, V>(this: Map<K, V>): Array<[K, V]>;
|
|
39
|
+
declare function map<K, V, EK, EV>(this: Map<K, V>, callback: (value: V, key: K, index: number, map: Map<K, V>) => [EK, EV]): Map<EK, EV>;
|
|
40
|
+
declare function filter<K, V>(this: Map<K, V>, callback: (value: V, key: K, index: number, map: Map<K, V>) => boolean): Map<K, V>;
|
|
41
|
+
declare function keyArr<K, V>(this: Map<K, V>): Array<K>;
|
|
42
|
+
declare function valueArr<K, V>(this: Map<K, V>): Array<V>;
|
|
43
|
+
declare function find<K, V>(this: Map<K, V>, callback: (value: V, key: K, index: number, map: Map<K, V>) => boolean): [K, V] | undefined;
|
|
44
|
+
declare function includes<K, V>(this: Map<K, V>, item: V, fromIndex?: number): boolean;
|
|
45
|
+
export declare const MapExtensions: {
|
|
46
|
+
array: typeof array;
|
|
47
|
+
map: typeof map;
|
|
48
|
+
filter: typeof filter;
|
|
49
|
+
keyArr: typeof keyArr;
|
|
50
|
+
valueArr: typeof valueArr;
|
|
51
|
+
find: typeof find;
|
|
52
|
+
includes: typeof includes;
|
|
53
|
+
};
|
|
54
|
+
export {};
|
package/dist/Extensions/Map.js
CHANGED
|
@@ -1,31 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.MapExtensions = void 0;
|
|
4
|
+
function array() {
|
|
4
5
|
let result = new Array();
|
|
5
6
|
for (const kvp of this) {
|
|
6
7
|
result.push(kvp);
|
|
7
8
|
}
|
|
8
9
|
return result;
|
|
9
|
-
}
|
|
10
|
-
Map.prototype.
|
|
10
|
+
}
|
|
11
|
+
Map.prototype.array = array;
|
|
12
|
+
function map(callback) {
|
|
11
13
|
return this.array()
|
|
12
14
|
.map(([k, v], i) => callback(v, k, i, this))
|
|
13
15
|
.reduce((map, [key, value]) => map.set(key, value), new Map());
|
|
14
|
-
}
|
|
15
|
-
Map.prototype.
|
|
16
|
+
}
|
|
17
|
+
Map.prototype.map = map;
|
|
18
|
+
function filter(callback) {
|
|
16
19
|
return this.array()
|
|
17
20
|
.filter(([k, v], i) => callback(v, k, i, this))
|
|
18
21
|
.reduce((map, [key, value]) => map.set(key, value), new Map());
|
|
19
|
-
}
|
|
20
|
-
Map.prototype.
|
|
22
|
+
}
|
|
23
|
+
Map.prototype.filter = filter;
|
|
24
|
+
function keyArr() {
|
|
21
25
|
return this.array().map(([k]) => k);
|
|
22
|
-
}
|
|
23
|
-
Map.prototype.
|
|
26
|
+
}
|
|
27
|
+
Map.prototype.keyArr = keyArr;
|
|
28
|
+
function valueArr() {
|
|
24
29
|
return this.array().map(([_, v]) => v);
|
|
25
|
-
}
|
|
26
|
-
Map.prototype.
|
|
30
|
+
}
|
|
31
|
+
Map.prototype.valueArr = valueArr;
|
|
32
|
+
function find(callback) {
|
|
27
33
|
return this.array().find(([k, v], i) => callback(v, k, i, this));
|
|
28
|
-
}
|
|
29
|
-
Map.prototype.
|
|
34
|
+
}
|
|
35
|
+
Map.prototype.find = find;
|
|
36
|
+
function includes(item, fromIndex) {
|
|
30
37
|
return this.valueArr().includes(item, fromIndex);
|
|
38
|
+
}
|
|
39
|
+
Map.prototype.includes = includes;
|
|
40
|
+
exports.MapExtensions = {
|
|
41
|
+
array, map, filter, keyArr, valueArr, find, includes
|
|
31
42
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ValueOf } from "../../Types";
|
|
2
|
+
import { Properties } from "./properties";
|
|
3
|
+
declare global {
|
|
4
|
+
interface ObjectConstructor {
|
|
5
|
+
/**
|
|
6
|
+
* Destructures object into array of [property, value]
|
|
7
|
+
* @param from Object to destruct
|
|
8
|
+
*/
|
|
9
|
+
array<From extends {} = {}>(from: From): Array<[keyof From, ValueOf<From>]>;
|
|
10
|
+
/**
|
|
11
|
+
* Omits properties from object, but for some reason the correct term is "extract"
|
|
12
|
+
* @param from Object to extract properties from
|
|
13
|
+
* @param props Properties to extract/Omit
|
|
14
|
+
*/
|
|
15
|
+
extract<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Omit<From, Props>;
|
|
16
|
+
/**
|
|
17
|
+
* Pick properties from object, but for some reason the correct term is "exclude"
|
|
18
|
+
* @param from Object to exclude properties from
|
|
19
|
+
* @param props Properties to exclude/pick
|
|
20
|
+
*/
|
|
21
|
+
exclude<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props>;
|
|
22
|
+
/**
|
|
23
|
+
* Returns true if object is empty
|
|
24
|
+
* @param obj Object to check
|
|
25
|
+
*/
|
|
26
|
+
isNullOrUndefined(obj: any): obj is null | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Destructures object into array of property keys
|
|
29
|
+
* @param from Object to destruct
|
|
30
|
+
*/
|
|
31
|
+
keysOf<From extends {} = {}>(from: From): Array<keyof From>;
|
|
32
|
+
omit<From extends {}, Exclude extends keyof From>(from: From, ...exclude: Exclude[]): Omit<From, Exclude>;
|
|
33
|
+
properties: Properties;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
declare function array<From extends {} = {}>(this: object, from: From): Array<[keyof From, ValueOf<From>]>;
|
|
37
|
+
declare function extract<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Omit<From, Props>;
|
|
38
|
+
declare function exclude<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props>;
|
|
39
|
+
declare function isNullOrUndefined(obj: any): obj is null | undefined;
|
|
40
|
+
declare function keysOf<From extends {} = {}>(this: object, from: From): Array<keyof From>;
|
|
41
|
+
export declare const ObjectExtensions: {
|
|
42
|
+
properties: Properties;
|
|
43
|
+
array: typeof array;
|
|
44
|
+
extract: typeof extract;
|
|
45
|
+
exclude: typeof exclude;
|
|
46
|
+
isNullOrUndefined: typeof isNullOrUndefined;
|
|
47
|
+
keysOf: typeof keysOf;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectExtensions = void 0;
|
|
4
|
+
const properties_1 = require("./properties");
|
|
5
|
+
function array(from) {
|
|
6
|
+
return Object.keysOf(from).map(prop => [prop, from[prop]]);
|
|
7
|
+
}
|
|
8
|
+
Object.array = array;
|
|
9
|
+
function extract(from, ...props) {
|
|
10
|
+
// If props are Array<keyof From>, Array<Partial<From>>, or Array<keyof From | Partial<From>>, ensure _props as Array<keyof From>
|
|
11
|
+
const _props = props.map(prop => typeof prop === "object" ? Object.keysOf(prop) : prop).flat();
|
|
12
|
+
_props.forEach(prop => delete from[prop]);
|
|
13
|
+
return from;
|
|
14
|
+
}
|
|
15
|
+
Object.extract = extract;
|
|
16
|
+
function exclude(from, ...props) {
|
|
17
|
+
// If props are Array<keyof From>, Array<Partial<From>>, or Array<keyof From | Partial<From>>, ensure _props as Array<keyof From>
|
|
18
|
+
const _props = props.map(prop => typeof prop === "object" ? Object.keysOf(prop) : prop).flat();
|
|
19
|
+
return Object.keysOf(from).reduce((result, prop) => {
|
|
20
|
+
if (_props.includes(prop))
|
|
21
|
+
delete result[prop];
|
|
22
|
+
return result;
|
|
23
|
+
}, from);
|
|
24
|
+
}
|
|
25
|
+
Object.exclude = exclude;
|
|
26
|
+
function isNullOrUndefined(obj) {
|
|
27
|
+
return obj === null || obj === undefined;
|
|
28
|
+
}
|
|
29
|
+
Object.isNullOrUndefined = isNullOrUndefined;
|
|
30
|
+
function keysOf(from) {
|
|
31
|
+
return Object.keys(from);
|
|
32
|
+
}
|
|
33
|
+
Object.keysOf = keysOf;
|
|
34
|
+
Object.properties = properties_1.properties;
|
|
35
|
+
exports.ObjectExtensions = {
|
|
36
|
+
properties: properties_1.properties,
|
|
37
|
+
array, extract, exclude, isNullOrUndefined, keysOf,
|
|
38
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PropertiesWith, If } from '../../Types';
|
|
2
|
+
type PrimitiveMap = {
|
|
3
|
+
string: string;
|
|
4
|
+
number: number;
|
|
5
|
+
boolean: boolean;
|
|
6
|
+
undefined: undefined;
|
|
7
|
+
null: null;
|
|
8
|
+
object: object;
|
|
9
|
+
function: Function;
|
|
10
|
+
any: any;
|
|
11
|
+
Date: Date;
|
|
12
|
+
RegExp: RegExp;
|
|
13
|
+
Promise: Promise<any>;
|
|
14
|
+
Array: Array<any>;
|
|
15
|
+
Map: Map<any, any>;
|
|
16
|
+
Set: Set<any>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Object with getPrimitiveTypes<Source, AllowFunctions extends boolean>(
|
|
20
|
+
* source: Source,
|
|
21
|
+
* allowFunctions: AllowFunctions = false
|
|
22
|
+
* ): Object with properties from source that matches primitive type
|
|
23
|
+
*/
|
|
24
|
+
export type Properties = {
|
|
25
|
+
[Key in keyof PrimitiveMap as `get${Capitalize<Key>}s`]: <Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions) => If<AllowFunctions, PropertiesWith<PrimitiveMap[Key] | ((...args: any[]) => PrimitiveMap[Key]), Source>, PropertiesWith<PrimitiveMap[Key], Source>>;
|
|
26
|
+
};
|
|
27
|
+
export declare const properties: Properties;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.properties = void 0;
|
|
4
|
+
const String_1 = require("../String");
|
|
5
|
+
exports.properties = [
|
|
6
|
+
'string', 'number', 'boolean', 'undefined', 'null',
|
|
7
|
+
'object', 'function', 'any',
|
|
8
|
+
'Date', 'RegExp', 'Promise', 'Array', 'Map', 'Set'
|
|
9
|
+
].reduce((result, primitive) => {
|
|
10
|
+
result[`get${String_1.StringExtensions.toPascalCase.bind(primitive)()}s`] = function (source, withFunctions = false) {
|
|
11
|
+
return Object.keysOf(source).reduce((result, key) => {
|
|
12
|
+
if (source[key].constructor.name === primitive ||
|
|
13
|
+
(withFunctions && typeof source[key] === 'function' && source[key]).constructor.name === primitive) {
|
|
14
|
+
result[key] = source[key];
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}, {});
|
|
18
|
+
};
|
|
19
|
+
return result;
|
|
20
|
+
}, {});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import IReplacement from "../Interfaces/IReplacement";
|
|
2
|
-
export {};
|
|
3
2
|
declare global {
|
|
4
3
|
interface String {
|
|
5
4
|
/**
|
|
@@ -24,3 +23,14 @@ declare global {
|
|
|
24
23
|
clip(start: number, end?: number): string;
|
|
25
24
|
}
|
|
26
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,17 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.StringExtensions = void 0;
|
|
4
|
+
function toPascalCase() {
|
|
4
5
|
return this.substring(0, 1).toUpperCase() + this.substring(1);
|
|
5
|
-
}
|
|
6
|
+
}
|
|
7
|
+
String.prototype.toPascalCase = toPascalCase;
|
|
6
8
|
function spaceReplacer(self, replacer, replacement) {
|
|
7
9
|
return self.replace(new RegExp(`${typeof replacer == 'string' ? replacer : replacer.source}+`), replacement);
|
|
8
10
|
}
|
|
9
|
-
|
|
11
|
+
function toSnakeCase(replaceOptions) {
|
|
10
12
|
return spaceReplacer(this, replaceOptions.replacer || ' ', replaceOptions.replacement || '_');
|
|
11
|
-
}
|
|
12
|
-
String.prototype.
|
|
13
|
+
}
|
|
14
|
+
String.prototype.toSnakeCase = toSnakeCase;
|
|
15
|
+
function toKebabCase(replaceOptions) {
|
|
13
16
|
return spaceReplacer(this, replaceOptions.replacer || ' ', replaceOptions.replacement || '-');
|
|
14
|
-
}
|
|
15
|
-
String.prototype.
|
|
17
|
+
}
|
|
18
|
+
String.prototype.toKebabCase = toKebabCase;
|
|
19
|
+
function clip(start, end) {
|
|
16
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
|
|
17
25
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import ElementOptions from "../Interfaces/ElementOptions";
|
|
2
|
-
import { IElement } from "../Types";
|
|
3
1
|
export * from './Array';
|
|
2
|
+
export * from './Document';
|
|
4
3
|
export * from './Map';
|
|
5
4
|
export * from './Object';
|
|
6
5
|
export * from './String';
|
|
@@ -11,19 +10,8 @@ declare global {
|
|
|
11
10
|
*/
|
|
12
11
|
parseBoolean(value: string): boolean;
|
|
13
12
|
}
|
|
14
|
-
interface Document {
|
|
15
|
-
/**
|
|
16
|
-
* Creates an element like Document#createElement, however with construction options to assign values in construction instead of after construction.
|
|
17
|
-
* @param tagName HTMLElement tag name
|
|
18
|
-
* @param options Construction options, instead of assigning values after construction
|
|
19
|
-
*/
|
|
20
|
-
createProperElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementOptions, ...children: Array<IElement>): HTMLElementTagNameMap[K];
|
|
21
|
-
createFromHtml<K extends keyof HTMLElementTagNameMap>(html: string, parentTag?: K): HTMLElementTagNameMap[K];
|
|
22
|
-
}
|
|
23
|
-
interface HTMLCollection {
|
|
24
|
-
/**
|
|
25
|
-
* Converts HTMLCollection to Element[]
|
|
26
|
-
*/
|
|
27
|
-
array(): Element[];
|
|
28
|
-
}
|
|
29
13
|
}
|
|
14
|
+
declare function parseBoolean(value: string): boolean;
|
|
15
|
+
export declare const BooleanExtensions: {
|
|
16
|
+
parseBoolean: typeof parseBoolean;
|
|
17
|
+
};
|