@akadenia/helpers 1.7.3 → 1.8.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/README.MD +829 -364
- package/dist/object.d.ts +7 -0
- package/dist/object.js +14 -1
- package/dist/text.d.ts +7 -0
- package/dist/text.js +30 -1
- package/package.json +1 -1
package/dist/object.d.ts
CHANGED
|
@@ -74,3 +74,10 @@ export declare const findEntry: <EntryType>(array: EntryType[], predicate: (item
|
|
|
74
74
|
export declare function convertArrayToMap<T extends object>(arrayData: T[], keyProp: keyof T): {
|
|
75
75
|
[key: string]: T;
|
|
76
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Converts object keys from camelCase to kebab-case
|
|
79
|
+
* @template T extends Record<string, any> - The type of the object
|
|
80
|
+
* @param {T | undefined} obj - The object to convert
|
|
81
|
+
* @returns {Record<string, any> | undefined} - The object with kebab-case keys or undefined
|
|
82
|
+
*/
|
|
83
|
+
export declare const convertObjectKeysToKebabCase: <T extends Record<string, any>>(obj: T | undefined) => Record<string, any> | undefined;
|
package/dist/object.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findEntry = exports.objectPropHasValue = exports.parseCookie = exports.isPureObject = void 0;
|
|
3
|
+
exports.convertObjectKeysToKebabCase = exports.findEntry = exports.objectPropHasValue = exports.parseCookie = exports.isPureObject = void 0;
|
|
4
4
|
exports.filterObjectsByProperty = filterObjectsByProperty;
|
|
5
5
|
exports.containsSubObject = containsSubObject;
|
|
6
6
|
exports.findObjectBySubObject = findObjectBySubObject;
|
|
7
7
|
exports.filterObjectsBySubObject = filterObjectsBySubObject;
|
|
8
8
|
exports.convertArrayToMap = convertArrayToMap;
|
|
9
|
+
const text_1 = require("./text");
|
|
9
10
|
/**
|
|
10
11
|
*
|
|
11
12
|
* @function
|
|
@@ -121,3 +122,15 @@ function convertArrayToMap(arrayData, keyProp) {
|
|
|
121
122
|
}, dataAsObject);
|
|
122
123
|
return dataAsObject;
|
|
123
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Converts object keys from camelCase to kebab-case
|
|
127
|
+
* @template T extends Record<string, any> - The type of the object
|
|
128
|
+
* @param {T | undefined} obj - The object to convert
|
|
129
|
+
* @returns {Record<string, any> | undefined} - The object with kebab-case keys or undefined
|
|
130
|
+
*/
|
|
131
|
+
const convertObjectKeysToKebabCase = (obj) => {
|
|
132
|
+
if (!obj)
|
|
133
|
+
return undefined;
|
|
134
|
+
return Object.entries(obj).reduce((acc, [key, value]) => (Object.assign(Object.assign({}, acc), { [(0, text_1.convertCamelToKebabCase)(key)]: value })), {});
|
|
135
|
+
};
|
|
136
|
+
exports.convertObjectKeysToKebabCase = convertObjectKeysToKebabCase;
|
package/dist/text.d.ts
CHANGED
|
@@ -82,6 +82,13 @@ export declare function convertCamelToKebabCase(word: string): string;
|
|
|
82
82
|
* @returns {string} - The word returned as camel case
|
|
83
83
|
*/
|
|
84
84
|
export declare function convertKebabToCamelCase(word: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Convert camel case to readable text
|
|
87
|
+
* @function
|
|
88
|
+
* @param {string} name - The name to be converted to readable text
|
|
89
|
+
* @returns {string} - The readable text
|
|
90
|
+
*/
|
|
91
|
+
export declare function convertCamelCaseToReadableText(name: string): string;
|
|
85
92
|
/**
|
|
86
93
|
* Generate acronym from text
|
|
87
94
|
* @param term term to be converted to an acronym
|
package/dist/text.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
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
4
|
exports.convertCamelToKebabCase = convertCamelToKebabCase;
|
|
5
5
|
exports.convertKebabToCamelCase = convertKebabToCamelCase;
|
|
6
|
+
exports.convertCamelCaseToReadableText = convertCamelCaseToReadableText;
|
|
6
7
|
exports.generateAcronym = generateAcronym;
|
|
7
8
|
exports.isAcronym = isAcronym;
|
|
8
9
|
exports.acronymToKebabCase = acronymToKebabCase;
|
|
@@ -121,7 +122,22 @@ exports.replaceUnderscoreWithSpaces = replaceUnderscoreWithSpaces;
|
|
|
121
122
|
* @returns {string} - The word with "s" added to the end if the condition is true
|
|
122
123
|
*/
|
|
123
124
|
const pluralizeOnCondition = (word, condition) => {
|
|
124
|
-
|
|
125
|
+
if (!condition)
|
|
126
|
+
return word;
|
|
127
|
+
const lowerCasedWord = word.toLowerCase();
|
|
128
|
+
// Handle words ending with 'y' (e.g., 'library' -> 'libraries')
|
|
129
|
+
if (lowerCasedWord.endsWith("y")) {
|
|
130
|
+
return `${word.slice(0, -1)}ies`;
|
|
131
|
+
}
|
|
132
|
+
// Handle words ending with 's', 'sh', or 'ch' (e.g., 'class' -> 'classes')
|
|
133
|
+
if (lowerCasedWord.endsWith("s") ||
|
|
134
|
+
lowerCasedWord.endsWith("sh") ||
|
|
135
|
+
lowerCasedWord.endsWith("ch") ||
|
|
136
|
+
lowerCasedWord.endsWith("x")) {
|
|
137
|
+
return `${word}es`;
|
|
138
|
+
}
|
|
139
|
+
// Default pluralization by adding 's'
|
|
140
|
+
return `${word}s`;
|
|
125
141
|
};
|
|
126
142
|
exports.pluralizeOnCondition = pluralizeOnCondition;
|
|
127
143
|
/**
|
|
@@ -163,6 +179,19 @@ function convertKebabToCamelCase(word) {
|
|
|
163
179
|
.map((token) => (0, exports.capitalizeText)(token))
|
|
164
180
|
.join("");
|
|
165
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Convert camel case to readable text
|
|
184
|
+
* @function
|
|
185
|
+
* @param {string} name - The name to be converted to readable text
|
|
186
|
+
* @returns {string} - The readable text
|
|
187
|
+
*/
|
|
188
|
+
function convertCamelCaseToReadableText(name) {
|
|
189
|
+
return name
|
|
190
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
|
|
191
|
+
.replace(/([a-z\d])([A-Z])/g, "$1 $2")
|
|
192
|
+
.replace(/^./, (c) => c.toUpperCase())
|
|
193
|
+
.trim();
|
|
194
|
+
}
|
|
166
195
|
/**
|
|
167
196
|
* Generate acronym from text
|
|
168
197
|
* @param term term to be converted to an acronym
|