@akadenia/helpers 1.5.0 → 1.7.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 +27 -7
- package/dist/text.d.ts +7 -0
- package/dist/text.js +23 -1
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -29,8 +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(
|
|
33
|
-
- [`TextHelpers.generateSlugFromWords(id,words)`](#
|
|
32
|
+
- [`TextHelpers.generateWordFromId(word)`](#texthelpersgeneratewordfromidword)
|
|
33
|
+
- [`TextHelpers.generateSlugFromWords(id, ...words)`](#texthelpersgenerateslugfromwordsid-words)
|
|
34
|
+
- [`TextHelpers.extractIDfromSlug(slug)`](#texthelpersextractidfromslugslug)
|
|
35
|
+
- [`TextHelpers.abbreviateNumber(number)`](#texthelpersabbreviatenumbernumber)
|
|
34
36
|
- [ObjectHelpers](#objecthelpers)
|
|
35
37
|
- [`ObjectHelpers.isPureObject(any)`](#objecthelpersispureobjectany)
|
|
36
38
|
- [`ObjectHelpers.parseCookie(str)`](#objecthelpersparsecookiestr)
|
|
@@ -38,13 +40,15 @@
|
|
|
38
40
|
- [`ObjectHelpers.containsSubObject(mainObject, subObject)`](#objecthelperscontainssubobjectmainobject-subobject)
|
|
39
41
|
- [`ObjectHelpers.findObjectBySubObject(array, subObject)`](#objecthelpersfindobjectbysubobjectarray-subobject)
|
|
40
42
|
- [`ObjectHelpers.filterObjectsBySubObject(array, subObject)`](#objecthelpersfilterobjectsbysubobjectarray-subobject)
|
|
41
|
-
- [`ObjectHelpers.objectPropHasValue({object, key, value)}`](#
|
|
43
|
+
- [`ObjectHelpers.objectPropHasValue({object, key, value)}`](#objecthelpersobjectprophasvalueobject-key-value)
|
|
42
44
|
- [`ObjectHelpers.findEntry(array, predicate)`](#objecthelpersfindentryarray-predicate)
|
|
43
45
|
- [GenericHelpers](#generichelpers)
|
|
44
46
|
- [`GenericHelpers.delay(ms)`](#generichelpersdelayms)
|
|
45
47
|
- [`GenericHelpers.getPreferredUriScheme(host)`](#generichelpersgetpreferredurischemehost)
|
|
46
48
|
- [FileHelpers](#filehelpers)
|
|
47
49
|
- [`FileHelpers.checkFileExtension(filePath, validExtensions)`](#filehelperscheckfileextensionfilepath-validextensions)
|
|
50
|
+
- [Contributing to this package](#contributing-to-this-package)
|
|
51
|
+
- [License](#license)
|
|
48
52
|
|
|
49
53
|
# DateHelpers
|
|
50
54
|
|
|
@@ -261,7 +265,6 @@ Arguments
|
|
|
261
265
|
|--|--|--|--|
|
|
262
266
|
|`data`|`string`|The word that is being validated as acronym|
|
|
263
267
|
|
|
264
|
-
|
|
265
268
|
## `TextHelpers.acronymToKebabCase(data)`
|
|
266
269
|
|
|
267
270
|
Convert acronym to kebab case
|
|
@@ -272,7 +275,6 @@ Arguments
|
|
|
272
275
|
|--|--|--|--|
|
|
273
276
|
|`data`|`string`|The acronym to be converted to kebab case|
|
|
274
277
|
|
|
275
|
-
|
|
276
278
|
## `TextHelpers.handleNullDisplay(value, defaultValue="N/A")`
|
|
277
279
|
|
|
278
280
|
Returns the input string or the default string if the input value is null or undefined.
|
|
@@ -324,7 +326,7 @@ Arguments
|
|
|
324
326
|
## `TextHelpers.generateSlugFromWords(id, ...words)`
|
|
325
327
|
|
|
326
328
|
Get the slug from words
|
|
327
|
-
Returns the slug from the words
|
|
329
|
+
Returns the slug from the words and it will be url path safe
|
|
328
330
|
|
|
329
331
|
Arguments
|
|
330
332
|
|Name|Type|Required|Description|
|
|
@@ -343,6 +345,22 @@ Arguments
|
|
|
343
345
|
|--|--|--|--|
|
|
344
346
|
|`slug`|`string`|`true`|The slug associated with the id|
|
|
345
347
|
|
|
348
|
+
## `TextHelpers.abbreviateNumber(number)`
|
|
349
|
+
|
|
350
|
+
Returns the string representation of the abbreviated number, rounded to two decimal places.
|
|
351
|
+
|
|
352
|
+
Arguments
|
|
353
|
+
|Name|Type|Required|Description|
|
|
354
|
+
|--|--|--|--|
|
|
355
|
+
|`number`|`number`|`true`|The number to be abbreviated|
|
|
356
|
+
|
|
357
|
+
Examples
|
|
358
|
+
- Numbers below 1,000 are displayed without abbreviation
|
|
359
|
+
- Numbers between 1,000 and 1,000,000 are displayed in thousands (e.g. 1.23K)
|
|
360
|
+
- Numbers between 1,000,000 and 1,000,000,000 are displayed in millions (e.g. 1.23M)
|
|
361
|
+
- Numbers above 1,000,000,000 are displayed in billions (e.g. 1.23B)
|
|
362
|
+
|
|
363
|
+
Note: If the input `number` is null or undefined, the function returns null.
|
|
346
364
|
|
|
347
365
|
# ObjectHelpers
|
|
348
366
|
|
|
@@ -425,7 +443,9 @@ Arguments
|
|
|
425
443
|
|--|--|--|--|
|
|
426
444
|
|`array`|`T[]`|`true`|An array of objects to be filtered|
|
|
427
445
|
|`array`|`Partial<T>`|`true`|The sub-object to be searched for in the array|
|
|
446
|
+
|
|
428
447
|
## `ObjectHelpers.objectPropHasValue({object, key, value)}`
|
|
448
|
+
|
|
429
449
|
Checks if the object has the key with the value.
|
|
430
450
|
|
|
431
451
|
Arguments
|
|
@@ -436,6 +456,7 @@ Arguments
|
|
|
436
456
|
|`value`|`any`|`true`|The value to check|
|
|
437
457
|
|
|
438
458
|
## `ObjectHelpers.findEntry(array, predicate)`
|
|
459
|
+
|
|
439
460
|
Finds the first entry in the array that satisfies the predicate.
|
|
440
461
|
|
|
441
462
|
Arguments
|
|
@@ -480,7 +501,6 @@ Arguments
|
|
|
480
501
|
|`filePath`|`string`|`true`|The file path to check|
|
|
481
502
|
|`validExtensions`|`string[]`|`true`|The valid extensions|
|
|
482
503
|
|
|
483
|
-
|
|
484
504
|
## Contributing to this package
|
|
485
505
|
|
|
486
506
|
This package follows the commitlint and conventional commits standards. As such the commit messages should follow the following format:
|
package/dist/text.d.ts
CHANGED
|
@@ -165,3 +165,10 @@ export declare function generateSlugFromWordsWithID(id: string, ...words: string
|
|
|
165
165
|
* @returns The id from the slug
|
|
166
166
|
*/
|
|
167
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.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;
|
|
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
|
/**
|
|
@@ -292,3 +292,25 @@ function extractIDfromSlug(slug) {
|
|
|
292
292
|
return slug.split("-").pop();
|
|
293
293
|
}
|
|
294
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(2).replace(/\.00$/, "") + symbol;
|
|
313
|
+
}
|
|
314
|
+
return number.toString();
|
|
315
|
+
};
|
|
316
|
+
exports.abbreviateNumber = abbreviateNumber;
|