nhb-toolbox 2.3.4 → 2.3.7

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.
@@ -8,8 +8,8 @@ export declare const convertIntoFormData: <T extends object>(data: T) => FormDat
8
8
  /**
9
9
  * * Check if a formdata object is empty.
10
10
  *
11
- * @param obj FormData to check.
12
- * @returns Whether the formdata is empty.
11
+ * @param data FormData to check.
12
+ * @returns Boolean (`true`/`false`) Whether the formdata is empty.
13
13
  */
14
14
  export declare const isEmptyFormData: (data: FormData) => boolean;
15
15
  //# sourceMappingURL=convert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/form/convert.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,QAAQ,CAAC,KAAG,QAY/D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,SAAU,QAAQ,KAAG,OAOhD,CAAC"}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/form/convert.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,QAAQ,CAAC,KAAG,QAY/D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,SAAU,QAAQ,KAAG,OAQhD,CAAC"}
@@ -24,13 +24,13 @@ exports.convertIntoFormData = convertIntoFormData;
24
24
  /**
25
25
  * * Check if a formdata object is empty.
26
26
  *
27
- * @param obj FormData to check.
28
- * @returns Whether the formdata is empty.
27
+ * @param data FormData to check.
28
+ * @returns Boolean (`true`/`false`) Whether the formdata is empty.
29
29
  */
30
30
  const isEmptyFormData = (data) => {
31
31
  if ('entries' in data && typeof data.entries === 'function') {
32
32
  return Array.from(data.entries()).length === 0;
33
33
  }
34
- throw new Error('`FormData.entries()` is not supported in this environment.');
34
+ throw new Error('`FormData.entries()` is not supported in this environment!');
35
35
  };
36
36
  exports.isEmptyFormData = isEmptyFormData;
@@ -1,4 +1,4 @@
1
- import type { DecimalOptions, RandomNumberOptions } from './types';
1
+ import type { ConvertedDecimal, DecimalOptions, RandomNumberOptions } from './types';
2
2
  /**
3
3
  * * Utility to generate a random number between a given range.
4
4
  * * If no options are provided, it will generate a random number between `0` and `100` (inclusive).
@@ -11,11 +11,11 @@ export declare const getRandomNumber: (options?: RandomNumberOptions) => number;
11
11
  /**
12
12
  * * Utility to round a number to given decimal places.
13
13
  *
14
- * @param num - Number to round.
14
+ * @param input - Number or `stringified` number to round.
15
15
  * @param options - Options for rounding behavior, including decimal places and return type.
16
- * @returns Converted number (as a `number`) or string (if `isString` is `true`).
16
+ * @returns Converted number as `number` (default) or `string` (if `isString` is `true`).
17
17
  */
18
- export declare const convertToDecimal: (num: number, options?: DecimalOptions) => number | string;
18
+ export declare const convertToDecimal: <T extends boolean | undefined = false>(input: number | `${number}`, options?: DecimalOptions<T>) => ConvertedDecimal<T>;
19
19
  /**
20
20
  * * Calculates the HCF/GCD of multiple numbers.
21
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/number/basics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAAc,mBAAmB,KAAG,MA+C/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,QACvB,MAAM,YACD,cAAc,KACtB,MAAM,GAAG,MAQX,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,EAAE,KAAG,MAQnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,EAAE,KAAG,MAQnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,MAAM,UAAW,MAAM,KAAG,OAEtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,OAErC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,UAAW,MAAM,cAAc,MAAM,KAAG,OAE9D,CAAC"}
1
+ {"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/number/basics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAAc,mBAAmB,KAAG,MA+C/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO,GAAG,SAAS,iBACtD,MAAM,GAAG,GAAG,MAAM,EAAE,YACjB,cAAc,CAAC,CAAC,CAAC,KACzB,gBAAgB,CAAC,CAAC,CAcpB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,EAAE,KAAG,MAQnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,EAAE,KAAG,MAQnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,MAAM,UAAW,MAAM,KAAG,OAEtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,OAErC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,UAAW,MAAM,cAAc,MAAM,KAAG,OAE9D,CAAC"}
@@ -47,16 +47,22 @@ exports.getRandomNumber = getRandomNumber;
47
47
  /**
48
48
  * * Utility to round a number to given decimal places.
49
49
  *
50
- * @param num - Number to round.
50
+ * @param input - Number or `stringified` number to round.
51
51
  * @param options - Options for rounding behavior, including decimal places and return type.
52
- * @returns Converted number (as a `number`) or string (if `isString` is `true`).
52
+ * @returns Converted number as `number` (default) or `string` (if `isString` is `true`).
53
53
  */
54
- const convertToDecimal = (num, options) => {
54
+ const convertToDecimal = (input, options) => {
55
55
  const { decimalPlaces = 2, isString = false } = options || {};
56
- if (isString) {
57
- return num.toFixed(decimalPlaces);
56
+ let number;
57
+ if (typeof input === 'number') {
58
+ number = input;
58
59
  }
59
- return parseFloat(num.toFixed(decimalPlaces));
60
+ else {
61
+ number = Number(input);
62
+ }
63
+ return isString ?
64
+ number.toFixed(decimalPlaces)
65
+ : Number(number.toFixed(decimalPlaces));
60
66
  };
61
67
  exports.convertToDecimal = convertToDecimal;
62
68
  /**
@@ -10,12 +10,14 @@ export interface RandomNumberOptions {
10
10
  includeMax?: boolean;
11
11
  }
12
12
  /** - Decimal options for converting to decimal */
13
- export interface DecimalOptions {
13
+ export interface DecimalOptions<T extends boolean | undefined = false> {
14
14
  /** Number of decimal places to round to. Defaults to `2`. */
15
15
  decimalPlaces?: number;
16
16
  /** If the return value is in `string` or `number`. Defaults to `false`. */
17
- isString?: boolean;
17
+ isString?: T;
18
18
  }
19
+ /** - Converted decimal type either `number` or `string`. */
20
+ export type ConvertedDecimal<T> = T extends true ? string : number;
19
21
  /** - Type of numbers to generate */
20
22
  export type NumberType = 'any' | 'natural' | 'odd' | 'even' | 'prime' | 'random';
21
23
  /** - Output format for the generated numbers */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/number/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IACnC,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC9B,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,QAAQ,CAAC,EA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GACnB,KAAK,GACL,SAAS,GACT,KAAK,GACL,MAAM,GACN,OAAO,GACP,QAAQ,CAAC;AAEZ,gDAAgD;AAChD,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEvC,kDAAkD;AAClD,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,KAAK,CAAE,SAAQ,mBAAmB;IACzE,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,KAAK,CAAC,EAAE,CAAC,CAAC;CACV;AAED,4DAA4D;AAC5D,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,KAAK,IACxC,CAAC,SAAS,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const LOWERCASE: string[];
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/string/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,EAAE,MAAM,EAiIpB,CAAC"}
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOWERCASE = void 0;
4
+ exports.LOWERCASE = [
5
+ // Conjunctions
6
+ 'and',
7
+ 'but',
8
+ 'or',
9
+ 'nor',
10
+ 'for',
11
+ 'so',
12
+ 'yet',
13
+ 'after',
14
+ 'although',
15
+ 'as',
16
+ 'because',
17
+ 'before',
18
+ 'even',
19
+ 'if',
20
+ 'once',
21
+ 'since',
22
+ 'than',
23
+ 'that',
24
+ 'though',
25
+ 'unless',
26
+ 'until',
27
+ 'when',
28
+ 'whenever',
29
+ 'where',
30
+ 'whereas',
31
+ 'wherever',
32
+ 'whether',
33
+ 'while',
34
+ // Prepositions
35
+ 'about',
36
+ 'above',
37
+ 'across',
38
+ 'after',
39
+ 'against',
40
+ 'along',
41
+ 'among',
42
+ 'around',
43
+ 'as',
44
+ 'at',
45
+ 'before',
46
+ 'behind',
47
+ 'below',
48
+ 'beneath',
49
+ 'beside',
50
+ 'between',
51
+ 'beyond',
52
+ 'but',
53
+ 'by',
54
+ 'concerning',
55
+ 'considering',
56
+ 'despite',
57
+ 'down',
58
+ 'during',
59
+ 'except',
60
+ 'following',
61
+ 'for',
62
+ 'from',
63
+ 'in',
64
+ 'inside',
65
+ 'into',
66
+ 'like',
67
+ 'minus',
68
+ 'near',
69
+ 'of',
70
+ 'off',
71
+ 'on',
72
+ 'onto',
73
+ 'opposite',
74
+ 'out',
75
+ 'outside',
76
+ 'over',
77
+ 'past',
78
+ 'per',
79
+ 'plus',
80
+ 'regarding',
81
+ 'round',
82
+ 'save',
83
+ 'since',
84
+ 'than',
85
+ 'through',
86
+ 'throughout',
87
+ 'till',
88
+ 'to',
89
+ 'toward',
90
+ 'towards',
91
+ 'under',
92
+ 'underneath',
93
+ 'unlike',
94
+ 'until',
95
+ 'up',
96
+ 'upon',
97
+ 'versus',
98
+ 'via',
99
+ 'with',
100
+ 'within',
101
+ 'without',
102
+ // Articles
103
+ 'a',
104
+ 'an',
105
+ 'the',
106
+ // Auxiliary Verbs
107
+ 'am',
108
+ 'are',
109
+ 'be',
110
+ 'been',
111
+ 'being',
112
+ 'can',
113
+ 'could',
114
+ 'do',
115
+ 'does',
116
+ 'did',
117
+ 'had',
118
+ 'has',
119
+ 'have',
120
+ 'is',
121
+ 'may',
122
+ 'might',
123
+ 'must',
124
+ 'shall',
125
+ 'should',
126
+ 'was',
127
+ 'were',
128
+ 'will',
129
+ 'would',
130
+ ];
@@ -1,11 +1,29 @@
1
+ import type { CaseFormat } from './types';
1
2
  /**
2
- * * Converts a string to `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Title Case`.
3
+ * Converts a string to a specified case format such as `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Title Case`, `lowercase`, or `UPPERCASE`.
3
4
  *
4
- * @param string - The input string to be converted. Words should be separated by **non-alphanumeric characters** (e.g., spaces, hyphens, underscores, dots, slashes, etc.).
5
- * @param format - The format to convert the string to (`'camelCase'`, `'snake_case'`, `'kebab-case'`, `PascalCase`, or `Title Case`).
5
+ * This function handles non-alphanumeric characters (e.g., spaces, hyphens, underscores, dots, slashes) as word delimiters. For `Title Case`, prepositions, articles, conjunctions, and auxiliary verbs are not capitalized unless they appear at the start of the title.
6
+ * You can also convert the string to `lowercase` or `UPPERCASE`, but it's recommended to use default string methods like `string.toLowerCase()` and `string.toUpperCase()` for these cases.
7
+ *
8
+ * @param string The input string to be converted. The string should have words separated by non-alphanumeric characters (e.g., spaces, hyphens, underscores, etc.).
9
+ * @param format The format to convert the string to. The available formats are:
10
+ * - `'camelCase'`: Converts to camelCase (e.g., `myVariableName`).
11
+ * - `'snake_case'`: Converts to snake_case (e.g., `my_variable_name`).
12
+ * - `'kebab-case'`: Converts to kebab-case (e.g., `my-variable-name`).
13
+ * - `'PascalCase'`: Converts to PascalCase (e.g., `MyVariableName`).
14
+ * - `'Title Case'`: Converts to Title Case (e.g., `My Variable Name`), where certain words like `prepositions, articles, conjunctions and auxiliary verbs` are not capitalized unless at the start.
15
+ * - `'lowercase'`: Converts the string to all lowercase characters.
16
+ * - `'UPPERCASE'`: Converts the string to all uppercase characters.
6
17
  * @returns The formatted string in the specified case format.
18
+ * @example
19
+ * convertStringCase('my-example_string', 'camelCase'); // returns 'myExampleString'
20
+ * convertStringCase('my-example_string', 'snake_case'); // returns 'my_example_string'
21
+ * convertStringCase('my-example_string', 'kebab-case'); // returns 'my-example-string'
22
+ * convertStringCase('my example string', 'Title Case'); // returns 'My Example String'
23
+ * convertStringCase('my example string', 'lowercase'); // returns 'my example string'
24
+ * convertStringCase('my example string', 'UPPERCASE'); // returns 'MY EXAMPLE STRING'
7
25
  */
8
- export declare function convertStringCase(string: string, format: 'camelCase' | 'snake_case' | 'kebab-case' | 'PascalCase' | 'Title Case'): string;
26
+ export declare function convertStringCase(string: string, format: CaseFormat): string;
9
27
  /**
10
28
  * Replaces all occurrences of a string or pattern in the given input string.
11
29
  *
@@ -1 +1 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/string/convert.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,EACd,MAAM,EACH,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,YAAY,GACb,MAAM,CAyCR;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,UACvB,MAAM,QACP,MAAM,GAAG,MAAM,WACZ,MAAM,KACb,MAgBF,CAAC"}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/string/convert.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CA6E5E;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,UACvB,MAAM,QACP,MAAM,GAAG,MAAM,WACZ,MAAM,KACb,MAgBF,CAAC"}
@@ -1,22 +1,61 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceAllInString = void 0;
4
+ exports.convertStringCase = convertStringCase;
5
+ const constants_1 = require("./constants");
2
6
  /**
3
- * * Converts a string to `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Title Case`.
7
+ * Converts a string to a specified case format such as `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Title Case`, `lowercase`, or `UPPERCASE`.
8
+ *
9
+ * This function handles non-alphanumeric characters (e.g., spaces, hyphens, underscores, dots, slashes) as word delimiters. For `Title Case`, prepositions, articles, conjunctions, and auxiliary verbs are not capitalized unless they appear at the start of the title.
10
+ * You can also convert the string to `lowercase` or `UPPERCASE`, but it's recommended to use default string methods like `string.toLowerCase()` and `string.toUpperCase()` for these cases.
4
11
  *
5
- * @param string - The input string to be converted. Words should be separated by **non-alphanumeric characters** (e.g., spaces, hyphens, underscores, dots, slashes, etc.).
6
- * @param format - The format to convert the string to (`'camelCase'`, `'snake_case'`, `'kebab-case'`, `PascalCase`, or `Title Case`).
12
+ * @param string The input string to be converted. The string should have words separated by non-alphanumeric characters (e.g., spaces, hyphens, underscores, etc.).
13
+ * @param format The format to convert the string to. The available formats are:
14
+ * - `'camelCase'`: Converts to camelCase (e.g., `myVariableName`).
15
+ * - `'snake_case'`: Converts to snake_case (e.g., `my_variable_name`).
16
+ * - `'kebab-case'`: Converts to kebab-case (e.g., `my-variable-name`).
17
+ * - `'PascalCase'`: Converts to PascalCase (e.g., `MyVariableName`).
18
+ * - `'Title Case'`: Converts to Title Case (e.g., `My Variable Name`), where certain words like `prepositions, articles, conjunctions and auxiliary verbs` are not capitalized unless at the start.
19
+ * - `'lowercase'`: Converts the string to all lowercase characters.
20
+ * - `'UPPERCASE'`: Converts the string to all uppercase characters.
7
21
  * @returns The formatted string in the specified case format.
22
+ * @example
23
+ * convertStringCase('my-example_string', 'camelCase'); // returns 'myExampleString'
24
+ * convertStringCase('my-example_string', 'snake_case'); // returns 'my_example_string'
25
+ * convertStringCase('my-example_string', 'kebab-case'); // returns 'my-example-string'
26
+ * convertStringCase('my example string', 'Title Case'); // returns 'My Example String'
27
+ * convertStringCase('my example string', 'lowercase'); // returns 'my example string'
28
+ * convertStringCase('my example string', 'UPPERCASE'); // returns 'MY EXAMPLE STRING'
8
29
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.replaceAllInString = void 0;
11
- exports.convertStringCase = convertStringCase;
12
30
  function convertStringCase(string, format) {
13
31
  if (!string || typeof string !== 'string')
14
32
  return '';
33
+ const start = string.match(/^[^\d\w\s]+/)?.[0] || '';
34
+ const end = string.match(/[^\d\w\s]+$/)?.[0] || '';
35
+ const core = string.replace(/^[^\d\w\s]+|[^\w\s]+$/g, '').trim();
36
+ const titleCase = core
37
+ .split(/\s+/g)
38
+ .map((part) => {
39
+ const startSymbol = part.match(/^[^\d\w\s]+/)?.[0] || ''; // Capture leading symbols
40
+ const endSymbol = part.match(/[^\d\w\s]+$/)?.[0] || ''; // Capture trailing symbols
41
+ const coreWord = part.replace(/^[^\d\w\s]+|[^\d\w\s]+$/g, ''); // Remove them for processing
42
+ if (constants_1.LOWERCASE.includes(coreWord.toLowerCase())) {
43
+ return startSymbol + coreWord.toLowerCase() + endSymbol;
44
+ }
45
+ return (startSymbol +
46
+ coreWord.charAt(0).toUpperCase() +
47
+ coreWord.slice(1) +
48
+ endSymbol);
49
+ })
50
+ .join(' ');
15
51
  const formattedString = string.replace(/[^a-zA-Z0-9]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''));
16
52
  if (!formattedString)
17
53
  return '';
18
54
  switch (format) {
19
55
  case 'camelCase':
56
+ // return formattedString.replace(/[A-Z]/g, (letter, index) =>
57
+ // index === 0 ? letter.toUpperCase() : letter.toLowerCase(),
58
+ // );
20
59
  return (formattedString.charAt(0).toLowerCase() +
21
60
  formattedString.slice(1));
22
61
  case 'snake_case':
@@ -27,7 +66,14 @@ function convertStringCase(string, format) {
27
66
  return (formattedString.charAt(0).toUpperCase() +
28
67
  formattedString.slice(1));
29
68
  case 'Title Case':
30
- return formattedString.replace(/[A-Z]/g, (letter, index) => index === 0 ? letter.toUpperCase() : ` ${letter.toUpperCase()}`);
69
+ return (start +
70
+ titleCase.charAt(0).toUpperCase() +
71
+ titleCase.slice(1) +
72
+ end);
73
+ case 'lowercase':
74
+ return start + core.toLowerCase() + end;
75
+ case 'UPPERCASE':
76
+ return start + core.toUpperCase() + end;
31
77
  default:
32
78
  return formattedString;
33
79
  }
@@ -33,5 +33,7 @@ export interface AnagramOptions {
33
33
  /** Whether to lookup in the dictionary. Default is `false`. */
34
34
  validWords?: boolean;
35
35
  }
36
+ /** - Case formats for converting a string */
37
+ export type CaseFormat = 'camelCase' | 'snake_case' | 'kebab-case' | 'PascalCase' | 'Title Case' | 'UPPERCASE' | 'lowercase';
36
38
  export {};
37
39
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IACjC,iGAAiG;IACjG,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kFAAkF;IAClF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qFAAqF;IACrF,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,mDAAmD;AACnD,KAAK,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,aAAa,SAAS,OAAO,IACnE,CAAC,SAAS,GAAG,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GACvC,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE,GAC7D,UAAU,CAAC,CAAC,CAAC,CAAC;AAEjB,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,iBAAiB,IACzE,CAAC,CAAC,eAAe,CAAC,SAAS,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,GAC5C,CAAC,CAAC,qBAAqB,CAAC,SAAS,IAAI,GACtC,eAAe,CACd,CAAC,CAAC,eAAe,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EACnD,CAAC,CAAC,eAAe,CAAC,SAAS,OAAO,GAAG,CAAC,CAAC,eAAe,CAAC,GAAG,IAAI,CAC9D,GACA,CAAC,CAAC,eAAe,CAAC,SAAS,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,GAChD,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5B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AC,GAC5C,CAAC,CAAC,qBAAqB,CAAC,SAAS,IAAI,GACtC,eAAe,CACd,CAAC,CAAC,eAAe,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EACnD,CAAC,CAAC,eAAe,CAAC,SAAS,OAAO,GAAG,CAAC,CAAC,eAAe,CAAC,GAAG,IAAI,CAC9D,GACA,CAAC,CAAC,eAAe,CAAC,SAAS,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,GAChD,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5B,iDAAiD;AACjD,MAAM,WAAW,eAAe;IAC/B,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,gFAAgF;IAChF,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC;CACtC;AAED,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC9B,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,6CAA6C;AAC7C,MAAM,MAAM,UAAU,GACnB,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "2.3.4",
3
+ "version": "2.3.7",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions for everyday development needs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",