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
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { TransformType } from "../../Types";
|
|
2
|
+
import DanhoDate, { DanhoDateConstructor } from "./Date";
|
|
3
|
+
import TimeProperties from "./TimeProperties";
|
|
4
|
+
/**
|
|
5
|
+
* What properties to include when using TimeSpan.toString(format: TimeSpanFormat): string
|
|
6
|
+
*/
|
|
7
|
+
export declare type TimeSpanFormat = Partial<TransformType<TimeProperties<true>, number, boolean>>;
|
|
8
|
+
/**
|
|
9
|
+
* Timespan between 2 dates.
|
|
10
|
+
* @borrows TimeSpanValue
|
|
11
|
+
* @borrows Time
|
|
12
|
+
* @borrows TimeProperties
|
|
13
|
+
*/
|
|
14
|
+
export declare class TimeSpan implements TimeProperties<true> {
|
|
15
|
+
constructor(from: DanhoDateConstructor, to?: DanhoDateConstructor);
|
|
16
|
+
/**
|
|
17
|
+
* Which of the dates in constructor had the highest getTime()
|
|
18
|
+
*/
|
|
19
|
+
private _highest;
|
|
20
|
+
/**
|
|
21
|
+
* Which of the dates in constructor had the lowest getTime()
|
|
22
|
+
*/
|
|
23
|
+
private _lowest;
|
|
24
|
+
/**
|
|
25
|
+
* The time difference between highest and lowest
|
|
26
|
+
* @returns Time difference in ms between this._highest and this._lowest
|
|
27
|
+
*/
|
|
28
|
+
private _getTimeDifference;
|
|
29
|
+
/**
|
|
30
|
+
* Reduces ms into provided timeDifference
|
|
31
|
+
* @param ms Millisecond value to reduce
|
|
32
|
+
* @param timeDifference Time difference in ms that for each timeDifference in ms, add 1 to result
|
|
33
|
+
* @returns How many times timeDifference fits in ms
|
|
34
|
+
*/
|
|
35
|
+
private _reduceTime;
|
|
36
|
+
/**
|
|
37
|
+
* Total years between dates
|
|
38
|
+
*/
|
|
39
|
+
years: number;
|
|
40
|
+
/**
|
|
41
|
+
* Total months between dates
|
|
42
|
+
*/
|
|
43
|
+
months: number;
|
|
44
|
+
/**
|
|
45
|
+
* Total weeks between dates
|
|
46
|
+
*/
|
|
47
|
+
weeks: number;
|
|
48
|
+
/**
|
|
49
|
+
* Total days between dates
|
|
50
|
+
*/
|
|
51
|
+
days: number;
|
|
52
|
+
/**
|
|
53
|
+
* Total hours between dates
|
|
54
|
+
*/
|
|
55
|
+
hours: number;
|
|
56
|
+
/**
|
|
57
|
+
* Total minutes between dates
|
|
58
|
+
*/
|
|
59
|
+
minutes: number;
|
|
60
|
+
/**
|
|
61
|
+
* Total seconds between dates
|
|
62
|
+
*/
|
|
63
|
+
seconds: number;
|
|
64
|
+
/**
|
|
65
|
+
* Total milliseconds between dates
|
|
66
|
+
*/
|
|
67
|
+
milliseconds: number;
|
|
68
|
+
/**
|
|
69
|
+
* Get the total unit time between the two dates
|
|
70
|
+
* @param unit Time unit in milliseconds
|
|
71
|
+
* @returns How many times that unit fits in total ms between the two dates
|
|
72
|
+
*/
|
|
73
|
+
private _getTotalUnit;
|
|
74
|
+
/**
|
|
75
|
+
* Get the maximum amount of months between the two dates
|
|
76
|
+
* @returns Number of max amount of months that are between the two dates
|
|
77
|
+
*/
|
|
78
|
+
getTotalMonths(): number;
|
|
79
|
+
/**
|
|
80
|
+
* Get the maximum amount of weeks between the two dates
|
|
81
|
+
* @returns Number of max amount of weeks that are between the two dates
|
|
82
|
+
*/
|
|
83
|
+
getTotalWeeks(): number;
|
|
84
|
+
/**
|
|
85
|
+
* Get the maximum amount of days between the two dates
|
|
86
|
+
* @returns Number of max amount of days that are between the two dates
|
|
87
|
+
*/
|
|
88
|
+
getTotalDays(): number;
|
|
89
|
+
/**
|
|
90
|
+
* Get the maximum amount of hours between the two dates
|
|
91
|
+
* @returns Number of max amount of hours that are between the two dates
|
|
92
|
+
*/
|
|
93
|
+
getTotalHours(): number;
|
|
94
|
+
/**
|
|
95
|
+
* Get the maximum amount of minutes between the two dates
|
|
96
|
+
* @returns Number of max amount of minutes that are between the two dates
|
|
97
|
+
*/
|
|
98
|
+
getTotalMinutes(): number;
|
|
99
|
+
/**
|
|
100
|
+
* Get the maximum amount of seconds between the two dates
|
|
101
|
+
* @returns Number of max amount of seconds that are between the two dates
|
|
102
|
+
*/
|
|
103
|
+
getTotalSeconds(): number;
|
|
104
|
+
/**
|
|
105
|
+
* Get the maximum amount of milliseconds between the two dates
|
|
106
|
+
* @returns Number of max amount of milliseconds that are between the two dates
|
|
107
|
+
*/
|
|
108
|
+
getTotalMilliseconds(): number;
|
|
109
|
+
/**
|
|
110
|
+
* Start date of timespan
|
|
111
|
+
*/
|
|
112
|
+
from: DanhoDate;
|
|
113
|
+
/**
|
|
114
|
+
* End date of timespan
|
|
115
|
+
*/
|
|
116
|
+
to: DanhoDate;
|
|
117
|
+
/**
|
|
118
|
+
* Timespan is in the past
|
|
119
|
+
*/
|
|
120
|
+
pastTense: boolean;
|
|
121
|
+
toString(format?: TimeSpanFormat): string;
|
|
122
|
+
}
|
|
123
|
+
export default TimeSpan;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TimeSpan = void 0;
|
|
7
|
+
const Date_1 = __importDefault(require("./Date"));
|
|
8
|
+
const Time_1 = __importDefault(require("./Time"));
|
|
9
|
+
/**
|
|
10
|
+
* Timespan between 2 dates.
|
|
11
|
+
* @borrows TimeSpanValue
|
|
12
|
+
* @borrows Time
|
|
13
|
+
* @borrows TimeProperties
|
|
14
|
+
*/
|
|
15
|
+
class TimeSpan {
|
|
16
|
+
constructor(from, to = Date.now()) {
|
|
17
|
+
//General properties
|
|
18
|
+
this.from = new Date_1.default(from);
|
|
19
|
+
this.to = new Date_1.default(to);
|
|
20
|
+
//Ensure from < to
|
|
21
|
+
this._highest = this.from.time > this.to.time ? this.from : this.to;
|
|
22
|
+
this._lowest = this.from == this._highest ? this.to : this.from;
|
|
23
|
+
this.pastTense = this._highest !== this.to;
|
|
24
|
+
this._highest = new Date_1.default(this._highest.time + Time_1.default.millisecond);
|
|
25
|
+
let timeDifference = this._getTimeDifference();
|
|
26
|
+
//Calculate time difference between from & to and set to object properties
|
|
27
|
+
[this.years, timeDifference] = this._reduceTime(Time_1.default.year, timeDifference);
|
|
28
|
+
[this.months, timeDifference] = this._reduceTime(Time_1.default.month, timeDifference);
|
|
29
|
+
[this.weeks, timeDifference] = this._reduceTime(Time_1.default.week, timeDifference);
|
|
30
|
+
[this.days, timeDifference] = this._reduceTime(Time_1.default.day, timeDifference);
|
|
31
|
+
[this.hours, timeDifference] = this._reduceTime(Time_1.default.hour, timeDifference);
|
|
32
|
+
[this.minutes, timeDifference] = this._reduceTime(Time_1.default.minute, timeDifference);
|
|
33
|
+
[this.seconds, timeDifference] = this._reduceTime(Time_1.default.second, timeDifference);
|
|
34
|
+
[this.milliseconds, timeDifference] = this._reduceTime(Time_1.default.millisecond, timeDifference);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Which of the dates in constructor had the highest getTime()
|
|
38
|
+
*/
|
|
39
|
+
_highest;
|
|
40
|
+
/**
|
|
41
|
+
* Which of the dates in constructor had the lowest getTime()
|
|
42
|
+
*/
|
|
43
|
+
_lowest;
|
|
44
|
+
/**
|
|
45
|
+
* The time difference between highest and lowest
|
|
46
|
+
* @returns Time difference in ms between this._highest and this._lowest
|
|
47
|
+
*/
|
|
48
|
+
_getTimeDifference() {
|
|
49
|
+
return Math.round(this._highest.time - this._lowest.time);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reduces ms into provided timeDifference
|
|
53
|
+
* @param ms Millisecond value to reduce
|
|
54
|
+
* @param timeDifference Time difference in ms that for each timeDifference in ms, add 1 to result
|
|
55
|
+
* @returns How many times timeDifference fits in ms
|
|
56
|
+
*/
|
|
57
|
+
_reduceTime(ms, timeDifference) {
|
|
58
|
+
let result = 0;
|
|
59
|
+
while (timeDifference > ms) {
|
|
60
|
+
timeDifference -= ms;
|
|
61
|
+
result++;
|
|
62
|
+
}
|
|
63
|
+
return [result, timeDifference];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Total years between dates
|
|
67
|
+
*/
|
|
68
|
+
years;
|
|
69
|
+
/**
|
|
70
|
+
* Total months between dates
|
|
71
|
+
*/
|
|
72
|
+
months;
|
|
73
|
+
/**
|
|
74
|
+
* Total weeks between dates
|
|
75
|
+
*/
|
|
76
|
+
weeks;
|
|
77
|
+
/**
|
|
78
|
+
* Total days between dates
|
|
79
|
+
*/
|
|
80
|
+
days;
|
|
81
|
+
/**
|
|
82
|
+
* Total hours between dates
|
|
83
|
+
*/
|
|
84
|
+
hours;
|
|
85
|
+
/**
|
|
86
|
+
* Total minutes between dates
|
|
87
|
+
*/
|
|
88
|
+
minutes;
|
|
89
|
+
/**
|
|
90
|
+
* Total seconds between dates
|
|
91
|
+
*/
|
|
92
|
+
seconds;
|
|
93
|
+
/**
|
|
94
|
+
* Total milliseconds between dates
|
|
95
|
+
*/
|
|
96
|
+
milliseconds;
|
|
97
|
+
/**
|
|
98
|
+
* Get the total unit time between the two dates
|
|
99
|
+
* @param unit Time unit in milliseconds
|
|
100
|
+
* @returns How many times that unit fits in total ms between the two dates
|
|
101
|
+
*/
|
|
102
|
+
_getTotalUnit(unit) {
|
|
103
|
+
return this._reduceTime(unit, this._getTimeDifference())[0];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the maximum amount of months between the two dates
|
|
107
|
+
* @returns Number of max amount of months that are between the two dates
|
|
108
|
+
*/
|
|
109
|
+
getTotalMonths() {
|
|
110
|
+
return this._getTotalUnit(Time_1.default.month);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get the maximum amount of weeks between the two dates
|
|
114
|
+
* @returns Number of max amount of weeks that are between the two dates
|
|
115
|
+
*/
|
|
116
|
+
getTotalWeeks() {
|
|
117
|
+
return this._getTotalUnit(Time_1.default.week);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the maximum amount of days between the two dates
|
|
121
|
+
* @returns Number of max amount of days that are between the two dates
|
|
122
|
+
*/
|
|
123
|
+
getTotalDays() {
|
|
124
|
+
return this._getTotalUnit(Time_1.default.day);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get the maximum amount of hours between the two dates
|
|
128
|
+
* @returns Number of max amount of hours that are between the two dates
|
|
129
|
+
*/
|
|
130
|
+
getTotalHours() {
|
|
131
|
+
return this._getTotalUnit(Time_1.default.hour);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get the maximum amount of minutes between the two dates
|
|
135
|
+
* @returns Number of max amount of minutes that are between the two dates
|
|
136
|
+
*/
|
|
137
|
+
getTotalMinutes() {
|
|
138
|
+
return this._getTotalUnit(Time_1.default.minute);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get the maximum amount of seconds between the two dates
|
|
142
|
+
* @returns Number of max amount of seconds that are between the two dates
|
|
143
|
+
*/
|
|
144
|
+
getTotalSeconds() {
|
|
145
|
+
return this._getTotalUnit(Time_1.default.second);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get the maximum amount of milliseconds between the two dates
|
|
149
|
+
* @returns Number of max amount of milliseconds that are between the two dates
|
|
150
|
+
*/
|
|
151
|
+
getTotalMilliseconds() {
|
|
152
|
+
return this._getTotalUnit(Time_1.default.millisecond);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Start date of timespan
|
|
156
|
+
*/
|
|
157
|
+
from;
|
|
158
|
+
/**
|
|
159
|
+
* End date of timespan
|
|
160
|
+
*/
|
|
161
|
+
to;
|
|
162
|
+
/**
|
|
163
|
+
* Timespan is in the past
|
|
164
|
+
*/
|
|
165
|
+
pastTense;
|
|
166
|
+
toString(format) {
|
|
167
|
+
//console.log(`${this.years}Y ${this.months}M ${this.weeks}w ${this.days}d ${this.hours}h ${this.minutes}m ${this.seconds}s ${this.milliseconds}ms`);
|
|
168
|
+
const times = [this.years, this.months, this.weeks, this.days, this.hours, this.minutes, this.seconds, this.milliseconds];
|
|
169
|
+
const timeMsg = ["year", "month", "week", "day", "hour", "minute", "second", "millisecond"];
|
|
170
|
+
const result = times.reduce((result, time, i) => (
|
|
171
|
+
// If time is above 0, format is provided, a property matches current property and said property is true, append addition else return result
|
|
172
|
+
time > 0 && (format ? timeMsg[i] in format && format[timeMsg[i]] === true : true) ?
|
|
173
|
+
`${result}${times[i]} ${timeMsg[i]}${times[i] != 1 ? 's' : ''}, ` :
|
|
174
|
+
result), '');
|
|
175
|
+
return result.length > 2 && result.substring(0, result.length - 2) || '';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.TimeSpan = TimeSpan;
|
|
179
|
+
exports.default = TimeSpan;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Date"), exports);
|
|
18
|
+
__exportStar(require("./Time"), exports);
|
|
19
|
+
__exportStar(require("./TimeProperties"), exports);
|
|
20
|
+
__exportStar(require("./TimeSpan"), exports);
|
package/dist/Classes/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './Events';
|
|
2
|
+
export * from './Time';
|
package/dist/Classes/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -10,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./
|
|
14
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./Events"), exports);
|
|
18
|
+
__exportStar(require("./Time"), exports);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
declare type UpdateFinder<T> = (item: T, index: number, self: Array<T>) => boolean;
|
|
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
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
Array.prototype.add = function (...items) {
|
|
4
|
+
this.push(...items);
|
|
5
|
+
return this;
|
|
6
|
+
};
|
|
7
|
+
Array.prototype.update = function (old, updated) {
|
|
8
|
+
const item = typeof old === 'number' ? this[old] : typeof old === 'function' ? this.find(old) : old;
|
|
9
|
+
if (!item)
|
|
10
|
+
throw new Error('Old was not found in array!');
|
|
11
|
+
const index = this.indexOf(item);
|
|
12
|
+
return this[index] = updated;
|
|
13
|
+
};
|
|
14
|
+
Array.prototype.remove = function (value) {
|
|
15
|
+
const index = typeof value === 'number' ? value : this.indexOf(value);
|
|
16
|
+
if (index > -1)
|
|
17
|
+
this.splice(index, 1);
|
|
18
|
+
return this;
|
|
19
|
+
};
|
|
20
|
+
Array.prototype.random = function () {
|
|
21
|
+
const randomIndex = Math.round(Math.random() * this.length);
|
|
22
|
+
return this[randomIndex];
|
|
23
|
+
};
|
|
24
|
+
Array.prototype.index = function (i) {
|
|
25
|
+
return this[i < 0 ? this.length + i : i];
|
|
26
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
declare global {
|
|
3
|
+
interface Map<K, V> {
|
|
4
|
+
/**
|
|
5
|
+
* Converts into Array<[Key, Value]>
|
|
6
|
+
*/
|
|
7
|
+
array(): Array<[K, V]>;
|
|
8
|
+
/**
|
|
9
|
+
* Maps values into new types of generics
|
|
10
|
+
* @param callback Callbacking function to map values
|
|
11
|
+
*/
|
|
12
|
+
map<EK, EV>(callback: (value: V, key: K, index: number, self: this) => [EK, EV]): Map<EK, EV>;
|
|
13
|
+
/**
|
|
14
|
+
* Returns array of "accepted" values. Criteria defined in callback param
|
|
15
|
+
* @param callback Callbacking function to filter away unwanted values
|
|
16
|
+
*/
|
|
17
|
+
filter(callback: (value: V, key: K, index: number, self: this) => boolean): Map<K, V>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns array of keys
|
|
20
|
+
*/
|
|
21
|
+
keyArr(): Array<K>;
|
|
22
|
+
/**
|
|
23
|
+
* Returns array of values
|
|
24
|
+
*/
|
|
25
|
+
valueArr(): Array<V>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns first [key, value] match to callback param. Returns undefined if nothing found
|
|
28
|
+
* @param callback Callbacking function to find KeyValuePair
|
|
29
|
+
*/
|
|
30
|
+
find(callback: (value: V, key: K, index: number, self: this) => boolean): [K, V] | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Whether or not map includes a value. Returns true if it does, false if not ¯\_(ツ)_/¯
|
|
33
|
+
* @param value Value that may be includded in map
|
|
34
|
+
* @param fromIndex Start looking for value from specific index+. Default: 0
|
|
35
|
+
*/
|
|
36
|
+
includes(value: V, fromIndex?: number): boolean;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
Map.prototype.array = function () {
|
|
4
|
+
let result = new Array();
|
|
5
|
+
for (const kvp of this) {
|
|
6
|
+
result.push(kvp);
|
|
7
|
+
}
|
|
8
|
+
return result;
|
|
9
|
+
};
|
|
10
|
+
Map.prototype.map = function (callback) {
|
|
11
|
+
return this.array()
|
|
12
|
+
.map(([k, v], i) => callback(v, k, i, this))
|
|
13
|
+
.reduce((map, [key, value]) => map.set(key, value), new Map());
|
|
14
|
+
};
|
|
15
|
+
Map.prototype.filter = function (callback) {
|
|
16
|
+
return this.array()
|
|
17
|
+
.filter(([k, v], i) => callback(v, k, i, this))
|
|
18
|
+
.reduce((map, [key, value]) => map.set(key, value), new Map());
|
|
19
|
+
};
|
|
20
|
+
Map.prototype.keyArr = function () {
|
|
21
|
+
return this.array().map(([k]) => k);
|
|
22
|
+
};
|
|
23
|
+
Map.prototype.valueArr = function () {
|
|
24
|
+
return this.array().map(([_, v]) => v);
|
|
25
|
+
};
|
|
26
|
+
Map.prototype.find = function (callback) {
|
|
27
|
+
return this.array().find(([k, v], i) => callback(v, k, i, this));
|
|
28
|
+
};
|
|
29
|
+
Map.prototype.includes = function (item, fromIndex) {
|
|
30
|
+
return this.valueArr().includes(item, fromIndex);
|
|
31
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ValueOf } from "../Types";
|
|
2
|
+
export {};
|
|
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 = {}>(from: From): Array<[keyof From, ValueOf<From>]>;
|
|
10
|
+
/**
|
|
11
|
+
* Destructures object into array of property keys
|
|
12
|
+
* @param from Object to destruct
|
|
13
|
+
*/
|
|
14
|
+
keysOf<From = {}>(from: From): Array<keyof From>;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import IReplacement from "../Interfaces/IReplacement";
|
|
2
|
+
export {};
|
|
3
|
+
declare global {
|
|
4
|
+
interface String {
|
|
5
|
+
/**
|
|
6
|
+
* Uppercases first letter of string
|
|
7
|
+
*/
|
|
8
|
+
toPascalCase(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Replaces "replacer" (default: ' ') with "replacement" (default: '_')
|
|
11
|
+
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
12
|
+
*/
|
|
13
|
+
toSnakeCase(replaceOptions?: IReplacement): string;
|
|
14
|
+
/**
|
|
15
|
+
* Replaces "replacer" (default: ' ') with "replacement" (default: '-')
|
|
16
|
+
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
17
|
+
*/
|
|
18
|
+
toKebabCase(replaceOptions?: IReplacement): string;
|
|
19
|
+
/**
|
|
20
|
+
* String.substring but accepting negative numbers to cut from length
|
|
21
|
+
* @param start Start of string. 0 indexed, if negative number, subtracts number from length
|
|
22
|
+
* @param end End of string. 0 indexed, if negative number, substracts number from length
|
|
23
|
+
*/
|
|
24
|
+
clip(start: number, end?: number): string;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
String.prototype.toPascalCase = function () {
|
|
4
|
+
return this.substring(0, 1).toUpperCase() + this.substring(1);
|
|
5
|
+
};
|
|
6
|
+
function spaceReplacer(self, replacer, replacement) {
|
|
7
|
+
return self.replace(new RegExp(`${typeof replacer == 'string' ? replacer : replacer.source}+`), replacement);
|
|
8
|
+
}
|
|
9
|
+
String.prototype.toSnakeCase = function (replaceOptions) {
|
|
10
|
+
return spaceReplacer(this, replaceOptions.replacer || ' ', replaceOptions.replacement || '_');
|
|
11
|
+
};
|
|
12
|
+
String.prototype.toKebabCase = function (replaceOptions) {
|
|
13
|
+
return spaceReplacer(this, replaceOptions.replacer || ' ', replaceOptions.replacement || '-');
|
|
14
|
+
};
|
|
15
|
+
String.prototype.clip = function (start, end) {
|
|
16
|
+
return this.substring(start < 0 ? this.length - start : start, end && end < 0 ? this.length + end : end);
|
|
17
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import ElementOptions from "../Interfaces/ElementOptions";
|
|
2
|
+
import { IElement } from "../Types";
|
|
3
|
+
export * from './Array';
|
|
4
|
+
export * from './Map';
|
|
5
|
+
export * from './Object';
|
|
6
|
+
export * from './String';
|
|
7
|
+
declare global {
|
|
8
|
+
interface BooleanConstructor {
|
|
9
|
+
/**
|
|
10
|
+
* Parses string to boolean. Will only return true if value === "true" otherwise false
|
|
11
|
+
*/
|
|
12
|
+
parseBoolean(value: string): boolean;
|
|
13
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Array"), exports);
|
|
18
|
+
__exportStar(require("./Map"), exports);
|
|
19
|
+
__exportStar(require("./Object"), exports);
|
|
20
|
+
__exportStar(require("./String"), exports);
|
|
21
|
+
Boolean.parseBoolean = function (value) {
|
|
22
|
+
return value === "true";
|
|
23
|
+
};
|
|
24
|
+
try {
|
|
25
|
+
Document.prototype.createProperElement = function (tagName, options, ...children) {
|
|
26
|
+
let baseElement = document.createElement(tagName);
|
|
27
|
+
if (!options)
|
|
28
|
+
return baseElement;
|
|
29
|
+
const { id, class: className, dataset, ...rest } = options;
|
|
30
|
+
if (id)
|
|
31
|
+
baseElement.id = id;
|
|
32
|
+
if (className) {
|
|
33
|
+
const classNames = Array.isArray(className) ? className : [className];
|
|
34
|
+
classNames.forEach(className => baseElement.classList.add(className));
|
|
35
|
+
}
|
|
36
|
+
children ?? options.children;
|
|
37
|
+
if (children) {
|
|
38
|
+
const childrenElements = Array.isArray(children) ? children : [children];
|
|
39
|
+
childrenElements.forEach(child => baseElement.append(child));
|
|
40
|
+
}
|
|
41
|
+
if (dataset)
|
|
42
|
+
Object.entries(dataset).forEach(([key, value]) => baseElement.dataset[key] = value);
|
|
43
|
+
for (const optionKey in rest) {
|
|
44
|
+
const optionValue = rest[optionKey];
|
|
45
|
+
if (optionValue === undefined)
|
|
46
|
+
continue;
|
|
47
|
+
if (typeof optionValue === 'function') {
|
|
48
|
+
baseElement.addEventListener(optionKey.substring(2), rest[optionKey]);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
baseElement.setAttribute(optionKey, optionValue.toString());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return baseElement;
|
|
55
|
+
};
|
|
56
|
+
Document.prototype.createFromHtml = function (html, parentTag) {
|
|
57
|
+
return new DOMParser().parseFromString(html, 'text/html').body.firstChild;
|
|
58
|
+
};
|
|
59
|
+
HTMLCollection.prototype.array = function () {
|
|
60
|
+
let result = new Array();
|
|
61
|
+
for (let i = 0; i < this.length; i++) {
|
|
62
|
+
const item = this.item(i);
|
|
63
|
+
if (item !== null)
|
|
64
|
+
result.push(item);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Used in node.js
|
|
71
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare 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 {};
|