@akadenia/helpers 1.7.0 → 1.7.2
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/README.MD +10 -2
- 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 +36 -13
- package/package.json +9 -9
package/README.MD
CHANGED
|
@@ -392,8 +392,9 @@ Filter an array of objects based on a specific property and its corresponding va
|
|
|
392
392
|
Returns an array containing all objects that have the specified property with the given value.
|
|
393
393
|
|
|
394
394
|
Template
|
|
395
|
+
```typescript
|
|
395
396
|
T extends Record<string, any>
|
|
396
|
-
|
|
397
|
+
```
|
|
397
398
|
Arguments
|
|
398
399
|
|Name|Type|Required|Description|
|
|
399
400
|
|--|--|--|--|
|
|
@@ -407,7 +408,9 @@ It compares the key-value pairs of the sub-object with the corresponding key-val
|
|
|
407
408
|
Returns true If all key-value pairs in the sub-object are found in the main object; otherwise, it returns false.
|
|
408
409
|
|
|
409
410
|
Template
|
|
411
|
+
```typescript
|
|
410
412
|
T extends Record<string, any>
|
|
413
|
+
```
|
|
411
414
|
|
|
412
415
|
Arguments
|
|
413
416
|
|Name|Type|Required|Description|
|
|
@@ -422,7 +425,9 @@ Returns the first object found in the array that contains the sub-object or null
|
|
|
422
425
|
if no match is found.
|
|
423
426
|
|
|
424
427
|
Template
|
|
428
|
+
```typescript
|
|
425
429
|
T extends Record<string, any>
|
|
430
|
+
```
|
|
426
431
|
|
|
427
432
|
Arguments
|
|
428
433
|
|Name|Type|Required|Description|
|
|
@@ -436,7 +441,9 @@ Filters an array of objects based on the presence of a specific sub-object withi
|
|
|
436
441
|
Returns an array containing all objects from the input array that contain the specified sub-object.
|
|
437
442
|
|
|
438
443
|
Template
|
|
444
|
+
```typescript
|
|
439
445
|
T extends Record<string, any>
|
|
446
|
+
```
|
|
440
447
|
|
|
441
448
|
Arguments
|
|
442
449
|
|Name|Type|Required|Description|
|
|
@@ -522,7 +529,8 @@ Common types according to [commitlint-config-conventional (based on the Angular
|
|
|
522
529
|
- revert
|
|
523
530
|
- style
|
|
524
531
|
- test
|
|
525
|
-
|
|
532
|
+
|
|
533
|
+
if you introduce a breaking change, please add BREAKING CHANGE in the pull request description
|
|
526
534
|
|
|
527
535
|
## License
|
|
528
536
|
|
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
|
|
@@ -236,9 +240,32 @@ exports.enforceCharacterLimit = enforceCharacterLimit;
|
|
|
236
240
|
* @returns The boolean value when the condition is met
|
|
237
241
|
*/
|
|
238
242
|
const isValidEmail = (email) => {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
243
|
+
// First check for null/undefined
|
|
244
|
+
if (!email) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
// Check if the email has an @ symbol and the length of the email tokens is exactly 2
|
|
248
|
+
const parts = email.split("@");
|
|
249
|
+
if (parts.length !== 2) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
const [local, domain] = parts;
|
|
253
|
+
// Check local part rules
|
|
254
|
+
if (!local || local.length === 0) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
if (local.startsWith(".") || local.endsWith(".")) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
if (local.includes("..")) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._+-]*$/.test(local)) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
// Check domain part rules
|
|
267
|
+
const domainRegex = /^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/;
|
|
268
|
+
return domainRegex.test(domain);
|
|
242
269
|
};
|
|
243
270
|
exports.isValidEmail = isValidEmail;
|
|
244
271
|
/**
|
|
@@ -253,7 +280,6 @@ function generateIDFromWord(text) {
|
|
|
253
280
|
.map((word) => word.toLowerCase())
|
|
254
281
|
.join("-");
|
|
255
282
|
}
|
|
256
|
-
exports.generateIDFromWord = generateIDFromWord;
|
|
257
283
|
/**
|
|
258
284
|
* Get the word from the generated ID
|
|
259
285
|
* @function
|
|
@@ -265,7 +291,6 @@ function generateWordFromId(id, customList = {}) {
|
|
|
265
291
|
var _a;
|
|
266
292
|
return (_a = customList[id]) !== null && _a !== void 0 ? _a : id.split("-").map(exports.capitalizeText).join(" ");
|
|
267
293
|
}
|
|
268
|
-
exports.generateWordFromId = generateWordFromId;
|
|
269
294
|
/**
|
|
270
295
|
* Get the slug from words
|
|
271
296
|
* @function
|
|
@@ -278,7 +303,6 @@ function generateSlugFromWordsWithID(id, ...words) {
|
|
|
278
303
|
allWords = allWords.map((word) => encodeURIComponent(word.toLocaleLowerCase()));
|
|
279
304
|
return allWords.join("-");
|
|
280
305
|
}
|
|
281
|
-
exports.generateSlugFromWordsWithID = generateSlugFromWordsWithID;
|
|
282
306
|
/**
|
|
283
307
|
* Extracts the id from the slug
|
|
284
308
|
* @function
|
|
@@ -291,7 +315,6 @@ function extractIDfromSlug(slug) {
|
|
|
291
315
|
}
|
|
292
316
|
return slug.split("-").pop();
|
|
293
317
|
}
|
|
294
|
-
exports.extractIDfromSlug = extractIDfromSlug;
|
|
295
318
|
/**
|
|
296
319
|
* Abbreviate number
|
|
297
320
|
* @function
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akadenia/helpers",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
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
|
}
|