@alextheman/utility 1.11.4 → 1.11.6
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/dist/index.cjs +34 -34
- package/dist/index.js +34 -34
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,30 +20,30 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
addDaysToDate: () =>
|
|
24
|
-
appendSemicolon: () =>
|
|
25
|
-
convertFileToBase64: () =>
|
|
26
|
-
formatDateAndTime: () =>
|
|
27
|
-
getRandomNumber: () =>
|
|
28
|
-
isLeapYear: () =>
|
|
29
|
-
isMonthlyMultiple: () =>
|
|
30
|
-
isSameDate: () =>
|
|
31
|
-
randomiseArray: () =>
|
|
23
|
+
addDaysToDate: () => addDaysToDate_default,
|
|
24
|
+
appendSemicolon: () => appendSemicolon_default,
|
|
25
|
+
convertFileToBase64: () => convertFileToBase64_default,
|
|
26
|
+
formatDateAndTime: () => formatDateAndTime_default,
|
|
27
|
+
getRandomNumber: () => getRandomNumber_default,
|
|
28
|
+
isLeapYear: () => isLeapYear_default,
|
|
29
|
+
isMonthlyMultiple: () => isMonthlyMultiple_default,
|
|
30
|
+
isSameDate: () => isSameDate_default,
|
|
31
|
+
randomiseArray: () => randomiseArray_default,
|
|
32
32
|
range: () => range_default,
|
|
33
33
|
truncate: () => truncate_default,
|
|
34
34
|
wait: () => wait_default
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
|
-
// src/
|
|
38
|
+
// src/addDaysToDate.ts
|
|
39
39
|
function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement = 1) {
|
|
40
40
|
const newDate = currentDate;
|
|
41
41
|
newDate.setDate(newDate.getDate() + dayIncrement);
|
|
42
42
|
return newDate;
|
|
43
43
|
}
|
|
44
|
-
var
|
|
44
|
+
var addDaysToDate_default = addDaysToDate;
|
|
45
45
|
|
|
46
|
-
// src/
|
|
46
|
+
// src/appendSemicolon.ts
|
|
47
47
|
function appendSemicolon(stringToAppendTo) {
|
|
48
48
|
if (stringToAppendTo.includes("\n")) {
|
|
49
49
|
throw new Error("MULTIPLE_LINE_ERROR");
|
|
@@ -54,9 +54,9 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
54
54
|
}
|
|
55
55
|
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
56
56
|
}
|
|
57
|
-
var
|
|
57
|
+
var appendSemicolon_default = appendSemicolon;
|
|
58
58
|
|
|
59
|
-
// src/
|
|
59
|
+
// src/convertFileToBase64.ts
|
|
60
60
|
function convertFileToBase64(file) {
|
|
61
61
|
return new Promise((resolve, reject) => {
|
|
62
62
|
const reader = new FileReader();
|
|
@@ -73,51 +73,51 @@ function convertFileToBase64(file) {
|
|
|
73
73
|
};
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
var
|
|
76
|
+
var convertFileToBase64_default = convertFileToBase64;
|
|
77
77
|
|
|
78
|
-
// src/
|
|
78
|
+
// src/isSameDate.ts
|
|
79
79
|
function isSameDate(firstDate, secondDate) {
|
|
80
80
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
|
|
81
81
|
}
|
|
82
|
-
var
|
|
82
|
+
var isSameDate_default = isSameDate;
|
|
83
83
|
|
|
84
|
-
// src/
|
|
84
|
+
// src/formatDateAndTime.ts
|
|
85
85
|
function formatDateAndTime(inputDate) {
|
|
86
|
-
const yesterday =
|
|
86
|
+
const yesterday = addDaysToDate_default(/* @__PURE__ */ new Date(), -1);
|
|
87
87
|
const today = /* @__PURE__ */ new Date();
|
|
88
88
|
const inputTime = `${inputDate.getHours().toString().padStart(2, "0")}:${inputDate.getMinutes().toString().padStart(2, "0")}`;
|
|
89
|
-
if (
|
|
89
|
+
if (isSameDate_default(inputDate, yesterday)) {
|
|
90
90
|
return `Yesterday at ${inputTime}`;
|
|
91
91
|
}
|
|
92
|
-
if (
|
|
92
|
+
if (isSameDate_default(inputDate, today)) {
|
|
93
93
|
return `Today at ${inputTime}`;
|
|
94
94
|
}
|
|
95
95
|
const formattedInputDay = inputDate.getDate().toString().padStart(2, "0");
|
|
96
96
|
const formattedInputMonth = (inputDate.getMonth() + 1).toString().padStart(2, "0");
|
|
97
|
-
const formattedInputYear = inputDate.getFullYear().toString()
|
|
97
|
+
const formattedInputYear = inputDate.getFullYear().toString();
|
|
98
98
|
return `${formattedInputDay}/${formattedInputMonth}/${formattedInputYear}, ${inputTime}`;
|
|
99
99
|
}
|
|
100
|
-
var
|
|
100
|
+
var formatDateAndTime_default = formatDateAndTime;
|
|
101
101
|
|
|
102
|
-
// src/
|
|
102
|
+
// src/getRandomNumber.ts
|
|
103
103
|
function getRandomNumber(lowerBound, upperBound) {
|
|
104
104
|
if (lowerBound % 1 !== 0 || upperBound % 1 !== 0) {
|
|
105
105
|
throw new Error("NON_INTEGER_INPUTS");
|
|
106
106
|
}
|
|
107
107
|
return Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);
|
|
108
108
|
}
|
|
109
|
-
var
|
|
109
|
+
var getRandomNumber_default = getRandomNumber;
|
|
110
110
|
|
|
111
|
-
// src/
|
|
111
|
+
// src/isLeapYear.ts
|
|
112
112
|
function isLeapYear(year) {
|
|
113
113
|
if (year % 1 !== 0) {
|
|
114
114
|
throw new Error("NON_INTEGER_INPUT");
|
|
115
115
|
}
|
|
116
116
|
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
117
117
|
}
|
|
118
|
-
var
|
|
118
|
+
var isLeapYear_default = isLeapYear;
|
|
119
119
|
|
|
120
|
-
// src/
|
|
120
|
+
// src/isMonthlyMultiple.ts
|
|
121
121
|
function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
122
122
|
if ([3, 5, 8, 10].includes(firstDate.getMonth())) {
|
|
123
123
|
return firstDate.getDate() === 30 && secondDate.getDate() === 31;
|
|
@@ -126,7 +126,7 @@ function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
|
126
126
|
}
|
|
127
127
|
function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
128
128
|
if (firstDate.getMonth() === 1) {
|
|
129
|
-
if (!
|
|
129
|
+
if (!isLeapYear_default(firstDate.getFullYear()) && firstDate.getDate() === 28) {
|
|
130
130
|
return [28, 29, 30, 31].includes(secondDate.getDate());
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -134,7 +134,7 @@ function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
|
134
134
|
}
|
|
135
135
|
function leapYearFebruaryChecks(firstDate, secondDate) {
|
|
136
136
|
if (firstDate.getMonth() === 1) {
|
|
137
|
-
if (
|
|
137
|
+
if (isLeapYear_default(firstDate.getFullYear()) && firstDate.getDate() === 29) {
|
|
138
138
|
return [29, 30, 31].includes(secondDate.getDate());
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -152,19 +152,19 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
152
152
|
}
|
|
153
153
|
return firstDate.getDate() === secondDate.getDate();
|
|
154
154
|
}
|
|
155
|
-
var
|
|
155
|
+
var isMonthlyMultiple_default = isMonthlyMultiple;
|
|
156
156
|
|
|
157
|
-
// src/
|
|
157
|
+
// src/randomiseArray.ts
|
|
158
158
|
function randomiseArray(array) {
|
|
159
159
|
const mutableArray = [...array];
|
|
160
160
|
const outputArray = [];
|
|
161
161
|
do {
|
|
162
|
-
const indexToRemove =
|
|
162
|
+
const indexToRemove = getRandomNumber_default(0, mutableArray.length - 1);
|
|
163
163
|
outputArray.push(mutableArray.splice(indexToRemove, 1)[0]);
|
|
164
164
|
} while (mutableArray.length > 0);
|
|
165
165
|
return outputArray;
|
|
166
166
|
}
|
|
167
|
-
var
|
|
167
|
+
var randomiseArray_default = randomiseArray;
|
|
168
168
|
|
|
169
169
|
// src/range.ts
|
|
170
170
|
function range(start, stop, step = 1) {
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/addDaysToDate.ts
|
|
2
2
|
function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement = 1) {
|
|
3
3
|
const newDate = currentDate;
|
|
4
4
|
newDate.setDate(newDate.getDate() + dayIncrement);
|
|
5
5
|
return newDate;
|
|
6
6
|
}
|
|
7
|
-
var
|
|
7
|
+
var addDaysToDate_default = addDaysToDate;
|
|
8
8
|
|
|
9
|
-
// src/
|
|
9
|
+
// src/appendSemicolon.ts
|
|
10
10
|
function appendSemicolon(stringToAppendTo) {
|
|
11
11
|
if (stringToAppendTo.includes("\n")) {
|
|
12
12
|
throw new Error("MULTIPLE_LINE_ERROR");
|
|
@@ -17,9 +17,9 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
17
17
|
}
|
|
18
18
|
return stringWithNoTrailingWhitespace[stringWithNoTrailingWhitespace.length - 1] === ";" ? stringWithNoTrailingWhitespace : `${stringWithNoTrailingWhitespace};`;
|
|
19
19
|
}
|
|
20
|
-
var
|
|
20
|
+
var appendSemicolon_default = appendSemicolon;
|
|
21
21
|
|
|
22
|
-
// src/
|
|
22
|
+
// src/convertFileToBase64.ts
|
|
23
23
|
function convertFileToBase64(file) {
|
|
24
24
|
return new Promise((resolve, reject) => {
|
|
25
25
|
const reader = new FileReader();
|
|
@@ -36,51 +36,51 @@ function convertFileToBase64(file) {
|
|
|
36
36
|
};
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
var
|
|
39
|
+
var convertFileToBase64_default = convertFileToBase64;
|
|
40
40
|
|
|
41
|
-
// src/
|
|
41
|
+
// src/isSameDate.ts
|
|
42
42
|
function isSameDate(firstDate, secondDate) {
|
|
43
43
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
|
|
44
44
|
}
|
|
45
|
-
var
|
|
45
|
+
var isSameDate_default = isSameDate;
|
|
46
46
|
|
|
47
|
-
// src/
|
|
47
|
+
// src/formatDateAndTime.ts
|
|
48
48
|
function formatDateAndTime(inputDate) {
|
|
49
|
-
const yesterday =
|
|
49
|
+
const yesterday = addDaysToDate_default(/* @__PURE__ */ new Date(), -1);
|
|
50
50
|
const today = /* @__PURE__ */ new Date();
|
|
51
51
|
const inputTime = `${inputDate.getHours().toString().padStart(2, "0")}:${inputDate.getMinutes().toString().padStart(2, "0")}`;
|
|
52
|
-
if (
|
|
52
|
+
if (isSameDate_default(inputDate, yesterday)) {
|
|
53
53
|
return `Yesterday at ${inputTime}`;
|
|
54
54
|
}
|
|
55
|
-
if (
|
|
55
|
+
if (isSameDate_default(inputDate, today)) {
|
|
56
56
|
return `Today at ${inputTime}`;
|
|
57
57
|
}
|
|
58
58
|
const formattedInputDay = inputDate.getDate().toString().padStart(2, "0");
|
|
59
59
|
const formattedInputMonth = (inputDate.getMonth() + 1).toString().padStart(2, "0");
|
|
60
|
-
const formattedInputYear = inputDate.getFullYear().toString()
|
|
60
|
+
const formattedInputYear = inputDate.getFullYear().toString();
|
|
61
61
|
return `${formattedInputDay}/${formattedInputMonth}/${formattedInputYear}, ${inputTime}`;
|
|
62
62
|
}
|
|
63
|
-
var
|
|
63
|
+
var formatDateAndTime_default = formatDateAndTime;
|
|
64
64
|
|
|
65
|
-
// src/
|
|
65
|
+
// src/getRandomNumber.ts
|
|
66
66
|
function getRandomNumber(lowerBound, upperBound) {
|
|
67
67
|
if (lowerBound % 1 !== 0 || upperBound % 1 !== 0) {
|
|
68
68
|
throw new Error("NON_INTEGER_INPUTS");
|
|
69
69
|
}
|
|
70
70
|
return Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);
|
|
71
71
|
}
|
|
72
|
-
var
|
|
72
|
+
var getRandomNumber_default = getRandomNumber;
|
|
73
73
|
|
|
74
|
-
// src/
|
|
74
|
+
// src/isLeapYear.ts
|
|
75
75
|
function isLeapYear(year) {
|
|
76
76
|
if (year % 1 !== 0) {
|
|
77
77
|
throw new Error("NON_INTEGER_INPUT");
|
|
78
78
|
}
|
|
79
79
|
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
80
80
|
}
|
|
81
|
-
var
|
|
81
|
+
var isLeapYear_default = isLeapYear;
|
|
82
82
|
|
|
83
|
-
// src/
|
|
83
|
+
// src/isMonthlyMultiple.ts
|
|
84
84
|
function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
85
85
|
if ([3, 5, 8, 10].includes(firstDate.getMonth())) {
|
|
86
86
|
return firstDate.getDate() === 30 && secondDate.getDate() === 31;
|
|
@@ -89,7 +89,7 @@ function endOfMonthChecksButNotFebruary(firstDate, secondDate) {
|
|
|
89
89
|
}
|
|
90
90
|
function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
91
91
|
if (firstDate.getMonth() === 1) {
|
|
92
|
-
if (!
|
|
92
|
+
if (!isLeapYear_default(firstDate.getFullYear()) && firstDate.getDate() === 28) {
|
|
93
93
|
return [28, 29, 30, 31].includes(secondDate.getDate());
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -97,7 +97,7 @@ function nonLeapYearFebruaryChecks(firstDate, secondDate) {
|
|
|
97
97
|
}
|
|
98
98
|
function leapYearFebruaryChecks(firstDate, secondDate) {
|
|
99
99
|
if (firstDate.getMonth() === 1) {
|
|
100
|
-
if (
|
|
100
|
+
if (isLeapYear_default(firstDate.getFullYear()) && firstDate.getDate() === 29) {
|
|
101
101
|
return [29, 30, 31].includes(secondDate.getDate());
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -115,19 +115,19 @@ function isMonthlyMultiple(firstDate, secondDate) {
|
|
|
115
115
|
}
|
|
116
116
|
return firstDate.getDate() === secondDate.getDate();
|
|
117
117
|
}
|
|
118
|
-
var
|
|
118
|
+
var isMonthlyMultiple_default = isMonthlyMultiple;
|
|
119
119
|
|
|
120
|
-
// src/
|
|
120
|
+
// src/randomiseArray.ts
|
|
121
121
|
function randomiseArray(array) {
|
|
122
122
|
const mutableArray = [...array];
|
|
123
123
|
const outputArray = [];
|
|
124
124
|
do {
|
|
125
|
-
const indexToRemove =
|
|
125
|
+
const indexToRemove = getRandomNumber_default(0, mutableArray.length - 1);
|
|
126
126
|
outputArray.push(mutableArray.splice(indexToRemove, 1)[0]);
|
|
127
127
|
} while (mutableArray.length > 0);
|
|
128
128
|
return outputArray;
|
|
129
129
|
}
|
|
130
|
-
var
|
|
130
|
+
var randomiseArray_default = randomiseArray;
|
|
131
131
|
|
|
132
132
|
// src/range.ts
|
|
133
133
|
function range(start, stop, step = 1) {
|
|
@@ -169,15 +169,15 @@ function wait(seconds) {
|
|
|
169
169
|
}
|
|
170
170
|
var wait_default = wait;
|
|
171
171
|
export {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
172
|
+
addDaysToDate_default as addDaysToDate,
|
|
173
|
+
appendSemicolon_default as appendSemicolon,
|
|
174
|
+
convertFileToBase64_default as convertFileToBase64,
|
|
175
|
+
formatDateAndTime_default as formatDateAndTime,
|
|
176
|
+
getRandomNumber_default as getRandomNumber,
|
|
177
|
+
isLeapYear_default as isLeapYear,
|
|
178
|
+
isMonthlyMultiple_default as isMonthlyMultiple,
|
|
179
|
+
isSameDate_default as isSameDate,
|
|
180
|
+
randomiseArray_default as randomiseArray,
|
|
181
181
|
range_default as range,
|
|
182
182
|
truncate_default as truncate,
|
|
183
183
|
wait_default as wait
|