@akadenia/helpers 1.4.0 → 1.5.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 CHANGED
@@ -30,6 +30,7 @@
30
30
  - [`TextHelpers.isValidEmail(email)`](#texthelpersisvalidemailemail)
31
31
  - [`TextHelpers.generateIdFromWord(word)`](#texthelpersgenerateidfromwordword)
32
32
  - [`TextHelpers.generateWordFromId(id)`](#texthelpersgeneratewordfromidid)
33
+ - [`TextHelpers.generateSlugFromWords(id,words)`](#texthelpersgenerateslugfromwordsidwords)
33
34
  - [ObjectHelpers](#objecthelpers)
34
35
  - [`ObjectHelpers.isPureObject(any)`](#objecthelpersispureobjectany)
35
36
  - [`ObjectHelpers.parseCookie(str)`](#objecthelpersparsecookiestr)
@@ -302,7 +303,7 @@ Arguments
302
303
  ## `TextHelpers.generateIdFromWord(word)`
303
304
 
304
305
  Generate ID from word
305
- The generated ID from the word
306
+ Returns the generated ID from the word
306
307
 
307
308
  Arguments
308
309
  |Name|Type|Required|Description|
@@ -312,14 +313,36 @@ Arguments
312
313
  ## `TextHelpers.generateWordFromId(word)`
313
314
 
314
315
  Get the word from the generated ID
315
- The word that is got from the id
316
+ Returns the word that is got from the id
316
317
 
317
318
  Arguments
318
319
  |Name|Type|Required|Description|
319
320
  |--|--|--|--|
320
- |`word`|`string`|`true`|The id that is needed to get the word from|
321
+ |`words`|`string`|`true`|The id that is needed to get the word from|
321
322
  |`customList`|`Record<string, string>`|`false`|The custom lists that has the id with the custom list of words|
322
323
 
324
+ ## `TextHelpers.generateSlugFromWords(id, ...words)`
325
+
326
+ Get the slug from words
327
+ Returns the slug from the words and it will be url path safe
328
+
329
+ Arguments
330
+ |Name|Type|Required|Description|
331
+ |--|--|--|--|
332
+ |`id`|`string`|`true`|The id that is needed to be concatenated with the slug|
333
+ |`words`|`string[]`|`true`|The words that will be in the slug|
334
+
335
+ ## `TextHelpers.extractIDfromSlug(slug)`
336
+
337
+ Extracts the id from the slug
338
+ Returns the id from the slug
339
+ Throws error if the string is empty, null or undefined
340
+
341
+ Arguments
342
+ |Name|Type|Required|Description|
343
+ |--|--|--|--|
344
+ |`slug`|`string`|`true`|The slug associated with the id|
345
+
323
346
 
324
347
  # ObjectHelpers
325
348
 
package/dist/index.d.ts CHANGED
@@ -1,27 +1,7 @@
1
- import { convertCamelToSnakeCase, convertSnakeToCamelCase, fileNameFromPath, formatPosition, handleNullDisplay, pluralizeOnCondition, replaceSpacesWithUnderscore, replaceUnderscoreWithSpaces, truncateText, uuidv4, enforceCharacterLimit, capitalizeText, generateIDFromWord, generateWordFromId, convertCamelToKebabCase, convertKebabToCamelCase, isAcronym, acronymToKebabCase } from "./text";
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
- isAcronym: typeof isAcronym;
23
- acronymToKebabCase: typeof acronymToKebabCase;
24
- generateIDFromWord: typeof generateIDFromWord;
25
- generateWordFromId: typeof generateWordFromId;
26
- };
27
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 text_1 = require("./text");
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,24 +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
- isAcronym: text_1.isAcronym,
54
- acronymToKebabCase: text_1.acronymToKebabCase,
55
- generateIDFromWord: text_1.generateIDFromWord,
56
- generateWordFromId: text_1.generateWordFromId,
57
- };
58
- exports.TextHelpers = TextHelpers;
package/dist/text.d.ts CHANGED
@@ -150,3 +150,18 @@ 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;
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.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,29 @@ 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akadenia/helpers",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Akadenia helpers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",