nhb-toolbox 4.14.6 → 4.14.8

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/CHANGELOG.md CHANGED
@@ -6,9 +6,10 @@ All notable changes to the package will be documented here.
6
6
 
7
7
  ---
8
8
 
9
- ## [4.14.4-6] - 2025-08-13 - 2025-08-14
9
+ ## [4.14.4-8] - 2025-08-13 - 2025-08-14
10
10
 
11
11
  - **Updated** internal logic of `convertStringCase` utility, added new `options` parameter.
12
+ - **Fixed** multiple internal issues and JSDoc; Optimized internal logic.
12
13
 
13
14
  ## [4.14.1-3] - 2025-08-11 - 2025-08-12
14
15
 
@@ -20,7 +20,7 @@ const constants_1 = require("./constants");
20
20
  * - `'Title Case'` → Title Case (e.g., `My Variable Name`)
21
21
  * - `'lowercase'` → all lowercase [ It is recommended to use built-in string method `string.toLowerCase()` ]
22
22
  * - `'UPPERCASE'` → all uppercase [ It is recommended to use built-in string method `string.toUpperCase()` ]
23
- * @param options - Optional configuration settings.
23
+ * @param options - Optional configuration options for more control.
24
24
  *
25
25
  * @returns The converted string, with leading/trailing punctuation preserved.
26
26
  *
@@ -92,7 +92,7 @@ function convertStringCase(value, format, options) {
92
92
  const core = value
93
93
  .replace(/^[^\p{L}\p{N}\s]+|[^\p{L}\p{N}\s]+$/gu, '')
94
94
  .trim();
95
- const lower = (s) => s.toLowerCase();
95
+ const lowerCase = (s) => s.toLowerCase();
96
96
  const isAcronym = (s) => s.length >= 2 && /^[\p{Lu}]+$/u.test(s);
97
97
  const capitalize = (s) => s.length === 0 ?
98
98
  ''
@@ -121,49 +121,57 @@ function convertStringCase(value, format, options) {
121
121
  const smallSet = new Set(constants_1.LOWERCASE);
122
122
  switch (format) {
123
123
  case 'camelCase': {
124
- const firstToken = tokens[0];
125
- const first = lower(firstToken);
126
- const rest = tokens
124
+ const middle = tokens
127
125
  .slice(1)
128
- .map((t) => {
129
- if (preserveAcronyms && isAcronym(t)) {
130
- return t; // preserve acronym as-is
126
+ .map((token) => {
127
+ if (preserveAcronyms && isAcronym(token)) {
128
+ return token; // preserve acronym as-is
131
129
  }
132
- return capitalize(t);
130
+ return capitalize(token);
133
131
  })
134
132
  .join('');
135
- return start.concat(first.concat(rest), end);
133
+ return start.concat(lowerCase(tokens[0]).concat(middle), end);
136
134
  }
137
135
  case 'PascalCase': {
138
136
  const body = tokens
139
- .map((t) => {
140
- if (preserveAcronyms && isAcronym(t))
141
- return t;
142
- return capitalize(t);
137
+ .map((token) => {
138
+ if (preserveAcronyms && isAcronym(token))
139
+ return token;
140
+ return capitalize(token);
143
141
  })
144
142
  .join('');
145
143
  return start.concat(body, end);
146
144
  }
147
145
  case 'snake_case': {
148
- const body = tokens.map((t) => lower(t)).join('_');
146
+ const body = tokens.map((token) => lowerCase(token)).join('_');
149
147
  return start.concat(body, end);
150
148
  }
151
149
  case 'kebab-case': {
152
- const body = tokens.map((t) => lower(t)).join('-');
150
+ const body = tokens.map((token) => lowerCase(token)).join('-');
153
151
  return start.concat(body, end);
154
152
  }
155
153
  case 'Title Case': {
156
154
  const title = tokens
157
- .map((t, i, arr) => {
158
- const tlc = t.toLowerCase();
155
+ .map((token, idx, self) => {
156
+ const tokenLower = token.toLowerCase();
159
157
  // keep small words lowercase unless first or last
160
- if (i !== 0 && i !== arr.length - 1 && smallSet.has(tlc)) {
161
- return tlc;
158
+ if (idx !== 0 &&
159
+ idx !== self.length - 1 &&
160
+ smallSet.has(tokenLower)) {
161
+ return tokenLower;
162
162
  }
163
- if (preserveAcronyms && isAcronym(t)) {
164
- return t;
163
+ // If preserveAcronyms is enabled, preserve acronym-like subparts inside hyphenated tokens.
164
+ // Example: "XML-HTTP" -> ["XML","HTTP"] -> preserved -> "XML-HTTP"
165
+ if (preserveAcronyms && token.includes('-')) {
166
+ return token
167
+ .split('-')
168
+ .map((sub) => isAcronym(sub) ? sub : capitalize(sub))
169
+ .join('-');
165
170
  }
166
- return capitalize(t);
171
+ if (preserveAcronyms && isAcronym(token)) {
172
+ return token.split('-');
173
+ }
174
+ return capitalize(token);
167
175
  })
168
176
  .join(' ');
169
177
  return start.concat(title, end);
@@ -17,7 +17,7 @@ import type { CaseFormat, StringCaseOptions } from './types';
17
17
  * - `'Title Case'` → Title Case (e.g., `My Variable Name`)
18
18
  * - `'lowercase'` → all lowercase [ It is recommended to use built-in string method `string.toLowerCase()` ]
19
19
  * - `'UPPERCASE'` → all uppercase [ It is recommended to use built-in string method `string.toUpperCase()` ]
20
- * @param options - Optional configuration settings.
20
+ * @param options - Optional configuration options for more control.
21
21
  *
22
22
  * @returns The converted string, with leading/trailing punctuation preserved.
23
23
  *
@@ -1 +1 @@
1
- {"version":3,"file":"case.d.ts","sourceRoot":"","sources":["../../../src/string/case.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE,iBAAiB,GACzB,MAAM,CA2HR"}
1
+ {"version":3,"file":"case.d.ts","sourceRoot":"","sources":["../../../src/string/case.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE,iBAAiB,GACzB,MAAM,CAsIR"}
@@ -31,7 +31,7 @@ export interface AnagramOptions {
31
31
  }
32
32
  /** - Case formats for converting a string */
33
33
  export type CaseFormat = 'camelCase' | 'snake_case' | 'kebab-case' | 'PascalCase' | 'Title Case' | 'UPPERCASE' | 'lowercase';
34
- /** * Options for convertStringCase. */
34
+ /** * Options for `convertStringCase`. */
35
35
  export interface StringCaseOptions {
36
36
  /**
37
37
  * Preserve acronym-like tokens (tokens that are ALL UPPERCASE with length >= 2)
@@ -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,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;AAEf,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IACjC;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,EAAE,OAAO,C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CAAyC;AACzC,MAAM,WAAW,iBAAiB;IACjC;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC3B,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC"}
@@ -17,7 +17,7 @@ import { LOWERCASE } from './constants.js';
17
17
  * - `'Title Case'` → Title Case (e.g., `My Variable Name`)
18
18
  * - `'lowercase'` → all lowercase [ It is recommended to use built-in string method `string.toLowerCase()` ]
19
19
  * - `'UPPERCASE'` → all uppercase [ It is recommended to use built-in string method `string.toUpperCase()` ]
20
- * @param options - Optional configuration settings.
20
+ * @param options - Optional configuration options for more control.
21
21
  *
22
22
  * @returns The converted string, with leading/trailing punctuation preserved.
23
23
  *
@@ -89,7 +89,7 @@ export function convertStringCase(value, format, options) {
89
89
  const core = value
90
90
  .replace(/^[^\p{L}\p{N}\s]+|[^\p{L}\p{N}\s]+$/gu, '')
91
91
  .trim();
92
- const lower = (s) => s.toLowerCase();
92
+ const lowerCase = (s) => s.toLowerCase();
93
93
  const isAcronym = (s) => s.length >= 2 && /^[\p{Lu}]+$/u.test(s);
94
94
  const capitalize = (s) => s.length === 0 ?
95
95
  ''
@@ -118,49 +118,57 @@ export function convertStringCase(value, format, options) {
118
118
  const smallSet = new Set(LOWERCASE);
119
119
  switch (format) {
120
120
  case 'camelCase': {
121
- const firstToken = tokens[0];
122
- const first = lower(firstToken);
123
- const rest = tokens
121
+ const middle = tokens
124
122
  .slice(1)
125
- .map((t) => {
126
- if (preserveAcronyms && isAcronym(t)) {
127
- return t; // preserve acronym as-is
123
+ .map((token) => {
124
+ if (preserveAcronyms && isAcronym(token)) {
125
+ return token; // preserve acronym as-is
128
126
  }
129
- return capitalize(t);
127
+ return capitalize(token);
130
128
  })
131
129
  .join('');
132
- return start.concat(first.concat(rest), end);
130
+ return start.concat(lowerCase(tokens[0]).concat(middle), end);
133
131
  }
134
132
  case 'PascalCase': {
135
133
  const body = tokens
136
- .map((t) => {
137
- if (preserveAcronyms && isAcronym(t))
138
- return t;
139
- return capitalize(t);
134
+ .map((token) => {
135
+ if (preserveAcronyms && isAcronym(token))
136
+ return token;
137
+ return capitalize(token);
140
138
  })
141
139
  .join('');
142
140
  return start.concat(body, end);
143
141
  }
144
142
  case 'snake_case': {
145
- const body = tokens.map((t) => lower(t)).join('_');
143
+ const body = tokens.map((token) => lowerCase(token)).join('_');
146
144
  return start.concat(body, end);
147
145
  }
148
146
  case 'kebab-case': {
149
- const body = tokens.map((t) => lower(t)).join('-');
147
+ const body = tokens.map((token) => lowerCase(token)).join('-');
150
148
  return start.concat(body, end);
151
149
  }
152
150
  case 'Title Case': {
153
151
  const title = tokens
154
- .map((t, i, arr) => {
155
- const tlc = t.toLowerCase();
152
+ .map((token, idx, self) => {
153
+ const tokenLower = token.toLowerCase();
156
154
  // keep small words lowercase unless first or last
157
- if (i !== 0 && i !== arr.length - 1 && smallSet.has(tlc)) {
158
- return tlc;
155
+ if (idx !== 0 &&
156
+ idx !== self.length - 1 &&
157
+ smallSet.has(tokenLower)) {
158
+ return tokenLower;
159
159
  }
160
- if (preserveAcronyms && isAcronym(t)) {
161
- return t;
160
+ // If preserveAcronyms is enabled, preserve acronym-like subparts inside hyphenated tokens.
161
+ // Example: "XML-HTTP" -> ["XML","HTTP"] -> preserved -> "XML-HTTP"
162
+ if (preserveAcronyms && token.includes('-')) {
163
+ return token
164
+ .split('-')
165
+ .map((sub) => isAcronym(sub) ? sub : capitalize(sub))
166
+ .join('-');
162
167
  }
163
- return capitalize(t);
168
+ if (preserveAcronyms && isAcronym(token)) {
169
+ return token.split('-');
170
+ }
171
+ return capitalize(token);
164
172
  })
165
173
  .join(' ');
166
174
  return start.concat(title, end);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.14.6",
3
+ "version": "4.14.8",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",