@akadenia/helpers 1.4.1 → 1.6.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 +44 -8
- package/dist/index.d.ts +1 -22
- package/dist/index.js +2 -23
- package/dist/text.d.ts +22 -0
- package/dist/text.js +49 -1
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -29,7 +29,10 @@
|
|
|
29
29
|
- [`TextHelpers.enforceCharacterLimit({text, characterLimit, onCharacterLimit})`](#texthelpersenforcecharacterlimittext-characterlimit-oncharacterlimit)
|
|
30
30
|
- [`TextHelpers.isValidEmail(email)`](#texthelpersisvalidemailemail)
|
|
31
31
|
- [`TextHelpers.generateIdFromWord(word)`](#texthelpersgenerateidfromwordword)
|
|
32
|
-
- [`TextHelpers.generateWordFromId(
|
|
32
|
+
- [`TextHelpers.generateWordFromId(word)`](#texthelpersgeneratewordfromidword)
|
|
33
|
+
- [`TextHelpers.generateSlugFromWords(id, ...words)`](#texthelpersgenerateslugfromwordsid-words)
|
|
34
|
+
- [`TextHelpers.extractIDfromSlug(slug)`](#texthelpersextractidfromslugslug)
|
|
35
|
+
- [`TextHelpers.abbreviateNumber(number)`](#texthelpersabbreviatenumbernumber)
|
|
33
36
|
- [ObjectHelpers](#objecthelpers)
|
|
34
37
|
- [`ObjectHelpers.isPureObject(any)`](#objecthelpersispureobjectany)
|
|
35
38
|
- [`ObjectHelpers.parseCookie(str)`](#objecthelpersparsecookiestr)
|
|
@@ -37,13 +40,15 @@
|
|
|
37
40
|
- [`ObjectHelpers.containsSubObject(mainObject, subObject)`](#objecthelperscontainssubobjectmainobject-subobject)
|
|
38
41
|
- [`ObjectHelpers.findObjectBySubObject(array, subObject)`](#objecthelpersfindobjectbysubobjectarray-subobject)
|
|
39
42
|
- [`ObjectHelpers.filterObjectsBySubObject(array, subObject)`](#objecthelpersfilterobjectsbysubobjectarray-subobject)
|
|
40
|
-
- [`ObjectHelpers.objectPropHasValue({object, key, value)}`](#
|
|
43
|
+
- [`ObjectHelpers.objectPropHasValue({object, key, value)}`](#objecthelpersobjectprophasvalueobject-key-value)
|
|
41
44
|
- [`ObjectHelpers.findEntry(array, predicate)`](#objecthelpersfindentryarray-predicate)
|
|
42
45
|
- [GenericHelpers](#generichelpers)
|
|
43
46
|
- [`GenericHelpers.delay(ms)`](#generichelpersdelayms)
|
|
44
47
|
- [`GenericHelpers.getPreferredUriScheme(host)`](#generichelpersgetpreferredurischemehost)
|
|
45
48
|
- [FileHelpers](#filehelpers)
|
|
46
49
|
- [`FileHelpers.checkFileExtension(filePath, validExtensions)`](#filehelperscheckfileextensionfilepath-validextensions)
|
|
50
|
+
- [Contributing to this package](#contributing-to-this-package)
|
|
51
|
+
- [License](#license)
|
|
47
52
|
|
|
48
53
|
# DateHelpers
|
|
49
54
|
|
|
@@ -260,7 +265,6 @@ Arguments
|
|
|
260
265
|
|--|--|--|--|
|
|
261
266
|
|`data`|`string`|The word that is being validated as acronym|
|
|
262
267
|
|
|
263
|
-
|
|
264
268
|
## `TextHelpers.acronymToKebabCase(data)`
|
|
265
269
|
|
|
266
270
|
Convert acronym to kebab case
|
|
@@ -271,7 +275,6 @@ Arguments
|
|
|
271
275
|
|--|--|--|--|
|
|
272
276
|
|`data`|`string`|The acronym to be converted to kebab case|
|
|
273
277
|
|
|
274
|
-
|
|
275
278
|
## `TextHelpers.handleNullDisplay(value, defaultValue="N/A")`
|
|
276
279
|
|
|
277
280
|
Returns the input string or the default string if the input value is null or undefined.
|
|
@@ -302,7 +305,7 @@ Arguments
|
|
|
302
305
|
## `TextHelpers.generateIdFromWord(word)`
|
|
303
306
|
|
|
304
307
|
Generate ID from word
|
|
305
|
-
|
|
308
|
+
Returns the generated ID from the word
|
|
306
309
|
|
|
307
310
|
Arguments
|
|
308
311
|
|Name|Type|Required|Description|
|
|
@@ -312,14 +315,45 @@ Arguments
|
|
|
312
315
|
## `TextHelpers.generateWordFromId(word)`
|
|
313
316
|
|
|
314
317
|
Get the word from the generated ID
|
|
315
|
-
|
|
318
|
+
Returns the word that is got from the id
|
|
316
319
|
|
|
317
320
|
Arguments
|
|
318
321
|
|Name|Type|Required|Description|
|
|
319
322
|
|--|--|--|--|
|
|
320
|
-
|`
|
|
323
|
+
|`words`|`string`|`true`|The id that is needed to get the word from|
|
|
321
324
|
|`customList`|`Record<string, string>`|`false`|The custom lists that has the id with the custom list of words|
|
|
322
325
|
|
|
326
|
+
## `TextHelpers.generateSlugFromWords(id, ...words)`
|
|
327
|
+
|
|
328
|
+
Get the slug from words
|
|
329
|
+
Returns the slug from the words and it will be url path safe
|
|
330
|
+
|
|
331
|
+
Arguments
|
|
332
|
+
|Name|Type|Required|Description|
|
|
333
|
+
|--|--|--|--|
|
|
334
|
+
|`id`|`string`|`true`|The id that is needed to be concatenated with the slug|
|
|
335
|
+
|`words`|`string[]`|`true`|The words that will be in the slug|
|
|
336
|
+
|
|
337
|
+
## `TextHelpers.extractIDfromSlug(slug)`
|
|
338
|
+
|
|
339
|
+
Extracts the id from the slug
|
|
340
|
+
Returns the id from the slug
|
|
341
|
+
Throws error if the string is empty, null or undefined
|
|
342
|
+
|
|
343
|
+
Arguments
|
|
344
|
+
|Name|Type|Required|Description|
|
|
345
|
+
|--|--|--|--|
|
|
346
|
+
|`slug`|`string`|`true`|The slug associated with the id|
|
|
347
|
+
|
|
348
|
+
## `TextHelpers.abbreviateNumber(number)`
|
|
349
|
+
|
|
350
|
+
Abbreviate number
|
|
351
|
+
Returns the string representation of the abbreviated number
|
|
352
|
+
|
|
353
|
+
Arguments
|
|
354
|
+
|Name|Type|Required|Description|
|
|
355
|
+
|--|--|--|--|
|
|
356
|
+
|`number`|`number`|`true`|The number to be abbreviated|
|
|
323
357
|
|
|
324
358
|
# ObjectHelpers
|
|
325
359
|
|
|
@@ -402,7 +436,9 @@ Arguments
|
|
|
402
436
|
|--|--|--|--|
|
|
403
437
|
|`array`|`T[]`|`true`|An array of objects to be filtered|
|
|
404
438
|
|`array`|`Partial<T>`|`true`|The sub-object to be searched for in the array|
|
|
439
|
+
|
|
405
440
|
## `ObjectHelpers.objectPropHasValue({object, key, value)}`
|
|
441
|
+
|
|
406
442
|
Checks if the object has the key with the value.
|
|
407
443
|
|
|
408
444
|
Arguments
|
|
@@ -413,6 +449,7 @@ Arguments
|
|
|
413
449
|
|`value`|`any`|`true`|The value to check|
|
|
414
450
|
|
|
415
451
|
## `ObjectHelpers.findEntry(array, predicate)`
|
|
452
|
+
|
|
416
453
|
Finds the first entry in the array that satisfies the predicate.
|
|
417
454
|
|
|
418
455
|
Arguments
|
|
@@ -457,7 +494,6 @@ Arguments
|
|
|
457
494
|
|`filePath`|`string`|`true`|The file path to check|
|
|
458
495
|
|`validExtensions`|`string[]`|`true`|The valid extensions|
|
|
459
496
|
|
|
460
|
-
|
|
461
497
|
## Contributing to this package
|
|
462
498
|
|
|
463
499
|
This package follows the commitlint and conventional commits standards. As such the commit messages should follow the following format:
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as TextHelpers from "./text";
|
|
2
2
|
import * as DateHelpers from "./date";
|
|
3
3
|
import * as ObjectHelpers from "./object";
|
|
4
4
|
import * as MapHelpers from "./map";
|
|
5
5
|
import * as GenericHelpers from "./generic";
|
|
6
6
|
import * as FileHelpers from "./file";
|
|
7
|
-
declare const TextHelpers: {
|
|
8
|
-
convertCamelToSnakeCase: typeof convertCamelToSnakeCase;
|
|
9
|
-
convertSnakeToCamelCase: typeof convertSnakeToCamelCase;
|
|
10
|
-
fileNameFromPath: typeof fileNameFromPath;
|
|
11
|
-
formatPosition: typeof formatPosition;
|
|
12
|
-
handleNullDisplay: typeof handleNullDisplay;
|
|
13
|
-
pluralizeOnCondition: typeof pluralizeOnCondition;
|
|
14
|
-
replaceSpacesWithUnderscore: typeof replaceSpacesWithUnderscore;
|
|
15
|
-
replaceUnderscoreWithSpaces: typeof replaceUnderscoreWithSpaces;
|
|
16
|
-
truncateText: typeof truncateText;
|
|
17
|
-
uuidv4: typeof uuidv4;
|
|
18
|
-
enforceCharacterLimit: typeof enforceCharacterLimit;
|
|
19
|
-
capitalizeText: typeof capitalizeText;
|
|
20
|
-
convertCamelToKebabCase: typeof convertCamelToKebabCase;
|
|
21
|
-
convertKebabToCamelCase: typeof convertKebabToCamelCase;
|
|
22
|
-
generateAcronym: typeof generateAcronym;
|
|
23
|
-
isAcronym: typeof isAcronym;
|
|
24
|
-
acronymToKebabCase: typeof acronymToKebabCase;
|
|
25
|
-
generateIDFromWord: typeof generateIDFromWord;
|
|
26
|
-
generateWordFromId: typeof generateWordFromId;
|
|
27
|
-
};
|
|
28
7
|
export { ObjectHelpers, DateHelpers, MapHelpers, TextHelpers, GenericHelpers, FileHelpers };
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.FileHelpers = exports.GenericHelpers = exports.TextHelpers = exports.MapHelpers = exports.DateHelpers = exports.ObjectHelpers = void 0;
|
|
27
|
-
const
|
|
27
|
+
const TextHelpers = __importStar(require("./text"));
|
|
28
|
+
exports.TextHelpers = TextHelpers;
|
|
28
29
|
const DateHelpers = __importStar(require("./date"));
|
|
29
30
|
exports.DateHelpers = DateHelpers;
|
|
30
31
|
const ObjectHelpers = __importStar(require("./object"));
|
|
@@ -35,25 +36,3 @@ const GenericHelpers = __importStar(require("./generic"));
|
|
|
35
36
|
exports.GenericHelpers = GenericHelpers;
|
|
36
37
|
const FileHelpers = __importStar(require("./file"));
|
|
37
38
|
exports.FileHelpers = FileHelpers;
|
|
38
|
-
const TextHelpers = {
|
|
39
|
-
convertCamelToSnakeCase: text_1.convertCamelToSnakeCase,
|
|
40
|
-
convertSnakeToCamelCase: text_1.convertSnakeToCamelCase,
|
|
41
|
-
fileNameFromPath: text_1.fileNameFromPath,
|
|
42
|
-
formatPosition: text_1.formatPosition,
|
|
43
|
-
handleNullDisplay: text_1.handleNullDisplay,
|
|
44
|
-
pluralizeOnCondition: text_1.pluralizeOnCondition,
|
|
45
|
-
replaceSpacesWithUnderscore: text_1.replaceSpacesWithUnderscore,
|
|
46
|
-
replaceUnderscoreWithSpaces: text_1.replaceUnderscoreWithSpaces,
|
|
47
|
-
truncateText: text_1.truncateText,
|
|
48
|
-
uuidv4: text_1.uuidv4,
|
|
49
|
-
enforceCharacterLimit: text_1.enforceCharacterLimit,
|
|
50
|
-
capitalizeText: text_1.capitalizeText,
|
|
51
|
-
convertCamelToKebabCase: text_1.convertCamelToKebabCase,
|
|
52
|
-
convertKebabToCamelCase: text_1.convertKebabToCamelCase,
|
|
53
|
-
generateAcronym: text_1.generateAcronym,
|
|
54
|
-
isAcronym: text_1.isAcronym,
|
|
55
|
-
acronymToKebabCase: text_1.acronymToKebabCase,
|
|
56
|
-
generateIDFromWord: text_1.generateIDFromWord,
|
|
57
|
-
generateWordFromId: text_1.generateWordFromId,
|
|
58
|
-
};
|
|
59
|
-
exports.TextHelpers = TextHelpers;
|
package/dist/text.d.ts
CHANGED
|
@@ -150,3 +150,25 @@ export declare function generateIDFromWord(text: string): string;
|
|
|
150
150
|
* @returns The word that is got from the id
|
|
151
151
|
*/
|
|
152
152
|
export declare function generateWordFromId(id: string, customList?: Record<string, string>): string;
|
|
153
|
+
/**
|
|
154
|
+
* Get the slug from words
|
|
155
|
+
* @function
|
|
156
|
+
* @param id The id that will be in the slug
|
|
157
|
+
* @param words The words that will be in the slug
|
|
158
|
+
* @returns The slug from the words and it will be url path safe
|
|
159
|
+
*/
|
|
160
|
+
export declare function generateSlugFromWordsWithID(id: string, ...words: string[]): string;
|
|
161
|
+
/**
|
|
162
|
+
* Extracts the id from the slug
|
|
163
|
+
* @function
|
|
164
|
+
* @param slug The slug associated with the id
|
|
165
|
+
* @returns The id from the slug
|
|
166
|
+
*/
|
|
167
|
+
export declare function extractIDfromSlug(slug: string): string | undefined;
|
|
168
|
+
/**
|
|
169
|
+
* Abbreviate number
|
|
170
|
+
* @function
|
|
171
|
+
* @param number The number to be abbreviated
|
|
172
|
+
* @returns The string representation of the abbreviated number
|
|
173
|
+
*/
|
|
174
|
+
export declare const abbreviateNumber: (number: number | undefined | null) => string | null;
|
package/dist/text.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateWordFromId = exports.generateIDFromWord = exports.isValidEmail = exports.enforceCharacterLimit = exports.capitalizeText = exports.handleNullDisplay = exports.acronymToKebabCase = exports.isAcronym = exports.generateAcronym = exports.convertKebabToCamelCase = exports.convertCamelToKebabCase = exports.convertCamelToSnakeCase = exports.convertSnakeToCamelCase = exports.pluralizeOnCondition = exports.replaceUnderscoreWithSpaces = exports.replaceSpacesWithUnderscore = exports.fileNameFromPath = exports.truncateText = exports.formatPosition = exports.uuidv4 = exports.convertKeyCasing = void 0;
|
|
3
|
+
exports.abbreviateNumber = exports.extractIDfromSlug = exports.generateSlugFromWordsWithID = exports.generateWordFromId = exports.generateIDFromWord = exports.isValidEmail = exports.enforceCharacterLimit = exports.capitalizeText = exports.handleNullDisplay = exports.acronymToKebabCase = exports.isAcronym = exports.generateAcronym = exports.convertKebabToCamelCase = exports.convertCamelToKebabCase = exports.convertCamelToSnakeCase = exports.convertSnakeToCamelCase = exports.pluralizeOnCondition = exports.replaceUnderscoreWithSpaces = exports.replaceSpacesWithUnderscore = exports.fileNameFromPath = exports.truncateText = exports.formatPosition = exports.uuidv4 = exports.convertKeyCasing = void 0;
|
|
4
4
|
const _1 = require("./");
|
|
5
5
|
// Internal Helper Functions At The Top
|
|
6
6
|
/**
|
|
@@ -266,3 +266,51 @@ function generateWordFromId(id, customList = {}) {
|
|
|
266
266
|
return (_a = customList[id]) !== null && _a !== void 0 ? _a : id.split("-").map(exports.capitalizeText).join(" ");
|
|
267
267
|
}
|
|
268
268
|
exports.generateWordFromId = generateWordFromId;
|
|
269
|
+
/**
|
|
270
|
+
* Get the slug from words
|
|
271
|
+
* @function
|
|
272
|
+
* @param id The id that will be in the slug
|
|
273
|
+
* @param words The words that will be in the slug
|
|
274
|
+
* @returns The slug from the words and it will be url path safe
|
|
275
|
+
*/
|
|
276
|
+
function generateSlugFromWordsWithID(id, ...words) {
|
|
277
|
+
let allWords = [...words.map((word) => word.split(" ")).flat(), ...id.split(" ").flat()];
|
|
278
|
+
allWords = allWords.map((word) => encodeURIComponent(word.toLocaleLowerCase()));
|
|
279
|
+
return allWords.join("-");
|
|
280
|
+
}
|
|
281
|
+
exports.generateSlugFromWordsWithID = generateSlugFromWordsWithID;
|
|
282
|
+
/**
|
|
283
|
+
* Extracts the id from the slug
|
|
284
|
+
* @function
|
|
285
|
+
* @param slug The slug associated with the id
|
|
286
|
+
* @returns The id from the slug
|
|
287
|
+
*/
|
|
288
|
+
function extractIDfromSlug(slug) {
|
|
289
|
+
if (!slug) {
|
|
290
|
+
throw new Error("slug cannot be empty, null or undefined string");
|
|
291
|
+
}
|
|
292
|
+
return slug.split("-").pop();
|
|
293
|
+
}
|
|
294
|
+
exports.extractIDfromSlug = extractIDfromSlug;
|
|
295
|
+
/**
|
|
296
|
+
* Abbreviate number
|
|
297
|
+
* @function
|
|
298
|
+
* @param number The number to be abbreviated
|
|
299
|
+
* @returns The string representation of the abbreviated number
|
|
300
|
+
*/
|
|
301
|
+
const abbreviateNumber = (number) => {
|
|
302
|
+
const abbreviations = [
|
|
303
|
+
{ value: 1e9, symbol: "B" },
|
|
304
|
+
{ value: 1e6, symbol: "M" },
|
|
305
|
+
{ value: 1e3, symbol: "k" },
|
|
306
|
+
];
|
|
307
|
+
if (!number || isNaN(number))
|
|
308
|
+
return null;
|
|
309
|
+
const abbreviated = abbreviations.find(({ value }) => Math.abs(number) >= value);
|
|
310
|
+
if (abbreviated) {
|
|
311
|
+
const { value, symbol } = abbreviated;
|
|
312
|
+
return (number / value).toFixed(1).replace(/\.0$/, "") + symbol;
|
|
313
|
+
}
|
|
314
|
+
return number.toString();
|
|
315
|
+
};
|
|
316
|
+
exports.abbreviateNumber = abbreviateNumber;
|