@akadenia/helpers 1.7.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/date.d.ts +2 -1
- package/dist/date.js +18 -12
- package/dist/object.js +6 -6
- package/dist/text.d.ts +1 -1
- package/dist/text.js +10 -10
- package/package.json +9 -9
package/dist/date.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare function parseDate(date: string | Date): Date;
|
|
|
39
39
|
*
|
|
40
40
|
* @function
|
|
41
41
|
* @param {string | Date} date - The date string that needs to be formatted
|
|
42
|
+
* @param {boolean} appendTime - A boolean to determine if the time should be appended to the date
|
|
42
43
|
* @returns {string} - A string representing the date in the short ordinal date
|
|
43
44
|
*/
|
|
44
|
-
export declare function getShortOrdinalDate(date: string | Date): string;
|
|
45
|
+
export declare function getShortOrdinalDate(date: string | Date, appendTime?: boolean): string;
|
package/dist/date.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.formatDateTime = exports.getDateString = exports.getReadableDate = exports.getReadableDateTime = void 0;
|
|
4
|
+
exports.parseDate = parseDate;
|
|
5
|
+
exports.getShortOrdinalDate = getShortOrdinalDate;
|
|
4
6
|
/**
|
|
5
7
|
*
|
|
6
8
|
* @function
|
|
@@ -47,27 +49,27 @@ exports.formatDateTime = formatDateTime;
|
|
|
47
49
|
function parseDate(date) {
|
|
48
50
|
const outputDate = typeof date === "string" ? new Date(date) : date;
|
|
49
51
|
if (isNaN(outputDate.getTime())) {
|
|
50
|
-
throw new Error(`Cannot parse
|
|
52
|
+
throw new Error(`Cannot parse date: ${JSON.stringify(date)}`);
|
|
51
53
|
}
|
|
52
54
|
return outputDate;
|
|
53
55
|
}
|
|
54
|
-
exports.parseDate = parseDate;
|
|
55
56
|
/**
|
|
56
57
|
*
|
|
57
58
|
* @function
|
|
58
59
|
* @param {string | Date} date - The date string that needs to be formatted
|
|
60
|
+
* @param {boolean} appendTime - A boolean to determine if the time should be appended to the date
|
|
59
61
|
* @returns {string} - A string representing the date in the short ordinal date
|
|
60
62
|
*/
|
|
61
|
-
function getShortOrdinalDate(date) {
|
|
63
|
+
function getShortOrdinalDate(date, appendTime) {
|
|
62
64
|
var _a;
|
|
63
65
|
const newDate = parseDate(date);
|
|
64
|
-
const day = newDate.
|
|
66
|
+
const day = newDate.getUTCDate();
|
|
65
67
|
const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
66
|
-
const monthIndex = newDate.
|
|
67
|
-
const year = newDate.
|
|
68
|
-
const hours = newDate.
|
|
69
|
-
const minutes = newDate.
|
|
70
|
-
const seconds = newDate.
|
|
68
|
+
const monthIndex = newDate.getUTCMonth();
|
|
69
|
+
const year = newDate.getUTCFullYear();
|
|
70
|
+
const hours = newDate.getUTCHours().toString().padStart(2, "0");
|
|
71
|
+
const minutes = newDate.getUTCMinutes().toString().padStart(2, "0");
|
|
72
|
+
const seconds = newDate.getUTCSeconds().toString().padStart(2, "0");
|
|
71
73
|
const ordinalEndings = ["th", "st", "nd", "rd"];
|
|
72
74
|
let suffix = ordinalEndings[0];
|
|
73
75
|
if (day <= 3 && day > 0) {
|
|
@@ -77,6 +79,10 @@ function getShortOrdinalDate(date) {
|
|
|
77
79
|
// Determine the ordinal endings based on the last digit of the day
|
|
78
80
|
suffix = (_a = ordinalEndings[day % 10]) !== null && _a !== void 0 ? _a : suffix;
|
|
79
81
|
}
|
|
80
|
-
|
|
82
|
+
if (appendTime) {
|
|
83
|
+
return `${monthNames[monthIndex]} ${day}${suffix} ${year} ${hours}:${minutes}:${seconds}`;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return `${monthNames[monthIndex]} ${day}${suffix} ${year}`;
|
|
87
|
+
}
|
|
81
88
|
}
|
|
82
|
-
exports.getShortOrdinalDate = getShortOrdinalDate;
|
package/dist/object.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.findEntry = exports.objectPropHasValue = exports.parseCookie = exports.isPureObject = void 0;
|
|
4
|
+
exports.filterObjectsByProperty = filterObjectsByProperty;
|
|
5
|
+
exports.containsSubObject = containsSubObject;
|
|
6
|
+
exports.findObjectBySubObject = findObjectBySubObject;
|
|
7
|
+
exports.filterObjectsBySubObject = filterObjectsBySubObject;
|
|
8
|
+
exports.convertArrayToMap = convertArrayToMap;
|
|
4
9
|
/**
|
|
5
10
|
*
|
|
6
11
|
* @function
|
|
@@ -39,7 +44,6 @@ function filterObjectsByProperty(array, propertyName, propertyValue) {
|
|
|
39
44
|
const predicate = (obj) => Object.getOwnPropertyDescriptor(obj, propertyName) && obj[propertyName] === propertyValue;
|
|
40
45
|
return array.filter(predicate);
|
|
41
46
|
}
|
|
42
|
-
exports.filterObjectsByProperty = filterObjectsByProperty;
|
|
43
47
|
/**
|
|
44
48
|
* Checks if the main object contains the sub object.
|
|
45
49
|
* @template T extends Record<string, any> - The type of the main object.
|
|
@@ -58,7 +62,6 @@ function containsSubObject(mainObject, subObject) {
|
|
|
58
62
|
}
|
|
59
63
|
return true;
|
|
60
64
|
}
|
|
61
|
-
exports.containsSubObject = containsSubObject;
|
|
62
65
|
/**
|
|
63
66
|
* Finds the object containing the given sub object in the array.
|
|
64
67
|
* @template T extends Record<string, any> - The type of objects in the array.
|
|
@@ -70,7 +73,6 @@ function findObjectBySubObject(array, subObject) {
|
|
|
70
73
|
const predicate = (obj) => containsSubObject(obj, subObject);
|
|
71
74
|
return array.find(predicate) || null;
|
|
72
75
|
}
|
|
73
|
-
exports.findObjectBySubObject = findObjectBySubObject;
|
|
74
76
|
/**
|
|
75
77
|
* Filters an array of objects based on the objects containing the given sub object
|
|
76
78
|
* @template T extends Record<string, any>
|
|
@@ -82,7 +84,6 @@ function filterObjectsBySubObject(array, subObject) {
|
|
|
82
84
|
const predicate = (obj) => containsSubObject(obj, subObject);
|
|
83
85
|
return array.filter(predicate);
|
|
84
86
|
}
|
|
85
|
-
exports.filterObjectsBySubObject = filterObjectsBySubObject;
|
|
86
87
|
/**
|
|
87
88
|
* Checks if the object has the key with the value.
|
|
88
89
|
* @param {Object} object - The object to check
|
|
@@ -120,4 +121,3 @@ function convertArrayToMap(arrayData, keyProp) {
|
|
|
120
121
|
}, dataAsObject);
|
|
121
122
|
return dataAsObject;
|
|
122
123
|
}
|
|
123
|
-
exports.convertArrayToMap = convertArrayToMap;
|
package/dist/text.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @param {"toSnakeCase" | "toCamelCase"} type - The type of casing the string, object, or array of objects should be converted to (snake_case or camelCase)
|
|
6
6
|
* @returns {T} - A new string, object, or array of objects in the specified casing
|
|
7
7
|
*/
|
|
8
|
-
export declare const convertKeyCasing: <T extends string | Object | Object
|
|
8
|
+
export declare const convertKeyCasing: <T extends string | Object | Array<Object>>(input: T, type: "toSnakeCase" | "toCamelCase") => T;
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
11
|
* @function
|
package/dist/text.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.abbreviateNumber = exports.
|
|
3
|
+
exports.abbreviateNumber = exports.isValidEmail = exports.enforceCharacterLimit = exports.capitalizeText = exports.handleNullDisplay = exports.convertCamelToSnakeCase = exports.convertSnakeToCamelCase = exports.pluralizeOnCondition = exports.replaceUnderscoreWithSpaces = exports.replaceSpacesWithUnderscore = exports.fileNameFromPath = exports.truncateText = exports.formatPosition = exports.uuidv4 = exports.convertKeyCasing = void 0;
|
|
4
|
+
exports.convertCamelToKebabCase = convertCamelToKebabCase;
|
|
5
|
+
exports.convertKebabToCamelCase = convertKebabToCamelCase;
|
|
6
|
+
exports.generateAcronym = generateAcronym;
|
|
7
|
+
exports.isAcronym = isAcronym;
|
|
8
|
+
exports.acronymToKebabCase = acronymToKebabCase;
|
|
9
|
+
exports.generateIDFromWord = generateIDFromWord;
|
|
10
|
+
exports.generateWordFromId = generateWordFromId;
|
|
11
|
+
exports.generateSlugFromWordsWithID = generateSlugFromWordsWithID;
|
|
12
|
+
exports.extractIDfromSlug = extractIDfromSlug;
|
|
4
13
|
const _1 = require("./");
|
|
5
14
|
// Internal Helper Functions At The Top
|
|
6
15
|
/**
|
|
@@ -142,7 +151,6 @@ exports.convertCamelToSnakeCase = convertCamelToSnakeCase;
|
|
|
142
151
|
function convertCamelToKebabCase(word) {
|
|
143
152
|
return word.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
144
153
|
}
|
|
145
|
-
exports.convertCamelToKebabCase = convertCamelToKebabCase;
|
|
146
154
|
/**
|
|
147
155
|
* Convert kebab case to camel case
|
|
148
156
|
* @function
|
|
@@ -155,7 +163,6 @@ function convertKebabToCamelCase(word) {
|
|
|
155
163
|
.map((token) => (0, exports.capitalizeText)(token))
|
|
156
164
|
.join("");
|
|
157
165
|
}
|
|
158
|
-
exports.convertKebabToCamelCase = convertKebabToCamelCase;
|
|
159
166
|
/**
|
|
160
167
|
* Generate acronym from text
|
|
161
168
|
* @param term term to be converted to an acronym
|
|
@@ -167,7 +174,6 @@ function generateAcronym(term) {
|
|
|
167
174
|
.map((word) => word[0])
|
|
168
175
|
.join("");
|
|
169
176
|
}
|
|
170
|
-
exports.generateAcronym = generateAcronym;
|
|
171
177
|
/**
|
|
172
178
|
* Validate if a word is acronym
|
|
173
179
|
* @function
|
|
@@ -177,7 +183,6 @@ exports.generateAcronym = generateAcronym;
|
|
|
177
183
|
function isAcronym(word) {
|
|
178
184
|
return word.toUpperCase() === word;
|
|
179
185
|
}
|
|
180
|
-
exports.isAcronym = isAcronym;
|
|
181
186
|
/**
|
|
182
187
|
* Convert acronym to kebab case
|
|
183
188
|
* @function
|
|
@@ -193,7 +198,6 @@ function acronymToKebabCase(word) {
|
|
|
193
198
|
.map((token) => token.toLowerCase())
|
|
194
199
|
.join("-");
|
|
195
200
|
}
|
|
196
|
-
exports.acronymToKebabCase = acronymToKebabCase;
|
|
197
201
|
/**
|
|
198
202
|
* @function
|
|
199
203
|
* @param value The string to be displayed
|
|
@@ -253,7 +257,6 @@ function generateIDFromWord(text) {
|
|
|
253
257
|
.map((word) => word.toLowerCase())
|
|
254
258
|
.join("-");
|
|
255
259
|
}
|
|
256
|
-
exports.generateIDFromWord = generateIDFromWord;
|
|
257
260
|
/**
|
|
258
261
|
* Get the word from the generated ID
|
|
259
262
|
* @function
|
|
@@ -265,7 +268,6 @@ function generateWordFromId(id, customList = {}) {
|
|
|
265
268
|
var _a;
|
|
266
269
|
return (_a = customList[id]) !== null && _a !== void 0 ? _a : id.split("-").map(exports.capitalizeText).join(" ");
|
|
267
270
|
}
|
|
268
|
-
exports.generateWordFromId = generateWordFromId;
|
|
269
271
|
/**
|
|
270
272
|
* Get the slug from words
|
|
271
273
|
* @function
|
|
@@ -278,7 +280,6 @@ function generateSlugFromWordsWithID(id, ...words) {
|
|
|
278
280
|
allWords = allWords.map((word) => encodeURIComponent(word.toLocaleLowerCase()));
|
|
279
281
|
return allWords.join("-");
|
|
280
282
|
}
|
|
281
|
-
exports.generateSlugFromWordsWithID = generateSlugFromWordsWithID;
|
|
282
283
|
/**
|
|
283
284
|
* Extracts the id from the slug
|
|
284
285
|
* @function
|
|
@@ -291,7 +292,6 @@ function extractIDfromSlug(slug) {
|
|
|
291
292
|
}
|
|
292
293
|
return slug.split("-").pop();
|
|
293
294
|
}
|
|
294
|
-
exports.extractIDfromSlug = extractIDfromSlug;
|
|
295
295
|
/**
|
|
296
296
|
* Abbreviate number
|
|
297
297
|
* @function
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akadenia/helpers",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Akadenia helpers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,20 +30,20 @@
|
|
|
30
30
|
"bugs": {
|
|
31
31
|
"url": "https://github.com/akadenia/AkadeniaHelpers/issues"
|
|
32
32
|
},
|
|
33
|
-
"homepage": "https://
|
|
33
|
+
"homepage": "https://akadenia.com/packages/akadenia-helpers",
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@commitlint/cli": "^18.6.1",
|
|
36
|
-
"@commitlint/config-conventional": "^18.6.
|
|
36
|
+
"@commitlint/config-conventional": "^18.6.3",
|
|
37
37
|
"@jest/globals": "^29.7.0",
|
|
38
38
|
"@semantic-release/changelog": "^6.0.3",
|
|
39
39
|
"@semantic-release/exec": "^6.0.3",
|
|
40
|
-
"@types/node": "^18.
|
|
41
|
-
"husky": "^9.
|
|
40
|
+
"@types/node": "^18.19.54",
|
|
41
|
+
"husky": "^9.1.6",
|
|
42
42
|
"jest": "^29.7.0",
|
|
43
|
-
"jsdoc-to-markdown": "^8.0.
|
|
44
|
-
"prettier": "^3.
|
|
43
|
+
"jsdoc-to-markdown": "^8.0.3",
|
|
44
|
+
"prettier": "^3.3.3",
|
|
45
45
|
"semantic-release": "22.0.12",
|
|
46
|
-
"ts-jest": "^29.
|
|
47
|
-
"typescript": "^5.
|
|
46
|
+
"ts-jest": "^29.2.5",
|
|
47
|
+
"typescript": "^5.6.2"
|
|
48
48
|
}
|
|
49
49
|
}
|