nhb-toolbox 0.8.7 → 0.8.9

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/dist/index.js CHANGED
@@ -3,4 +3,3 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.capitalizeString = void 0;
4
4
  var string_1 = require("./string");
5
5
  Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return string_1.capitalizeString; } });
6
- //# sourceMappingURL=index.js.map
@@ -1,9 +1,11 @@
1
+ import type { CapitalizeOptions } from './types';
1
2
  /**
2
3
  * Utility to convert the first letter of any string to uppercase and the rest lowercase (unless specified).
4
+ * Handles surrounding symbols like quotes or parentheses.
5
+ *
3
6
  * @param string String to be capitalized.
4
- * @param capEach If true, capitalizes the first letter of each word (space separated). Defaults to `false`.
5
- * @param lowerRest If true, ensures that the rest of the string is lowercase. Defaults to `true`.
7
+ * @param options Options to customize the capitalization.
6
8
  * @returns Capitalized string.
7
9
  */
8
- export declare const capitalizeString: (string: string, capEach?: boolean, lowerRest?: boolean) => string;
10
+ export declare const capitalizeString: (string: string, options?: CapitalizeOptions) => string;
9
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,WACpB,MAAM,YACL,OAAO,cACL,OAAO,KAChB,MAyBF,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,WACpB,MAAM,YACL,iBAAiB,KAKxB,MA2CF,CAAC"}
@@ -3,35 +3,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.capitalizeString = void 0;
4
4
  /**
5
5
  * Utility to convert the first letter of any string to uppercase and the rest lowercase (unless specified).
6
+ * Handles surrounding symbols like quotes or parentheses.
7
+ *
6
8
  * @param string String to be capitalized.
7
- * @param capEach If true, capitalizes the first letter of each word (space separated). Defaults to `false`.
8
- * @param lowerRest If true, ensures that the rest of the string is lowercase. Defaults to `true`.
9
+ * @param options Options to customize the capitalization.
9
10
  * @returns Capitalized string.
10
11
  */
11
- const capitalizeString = (string, capEach = false, lowerRest = true) => {
12
+ const capitalizeString = (string, options = {
13
+ capitalizeAll: false,
14
+ capitalizeEachFirst: false,
15
+ lowerCaseRest: true,
16
+ }) => {
17
+ if (typeof string !== 'string' || !string.trim())
18
+ return '';
12
19
  if (!string)
13
20
  return '';
14
21
  const trimmedString = string.trim();
15
22
  if (!trimmedString)
16
23
  return '';
17
- if (capEach) {
24
+ const { capitalizeAll, capitalizeEachFirst, lowerCaseRest } = options;
25
+ if (capitalizeAll) {
26
+ return trimmedString.toUpperCase();
27
+ }
28
+ if (capitalizeEachFirst) {
18
29
  return trimmedString
19
- .split(' ')
20
- .map((word) => (0, exports.capitalizeString)(word, false, lowerRest))
30
+ .split(/\s+/)
31
+ .map((word) => (0, exports.capitalizeString)(word, { lowerCaseRest }))
21
32
  .join(' ');
22
33
  }
23
- else {
24
- if (lowerRest) {
25
- return trimmedString
26
- .charAt(0)
34
+ const matchArray = trimmedString.match(/^(\W*)(\w)(.*)$/);
35
+ if (matchArray && matchArray.length === 4) {
36
+ const [_, leadingSymbols, firstLetter, rest] = matchArray;
37
+ return (leadingSymbols +
38
+ firstLetter
27
39
  .toUpperCase()
28
- .concat(trimmedString.slice(1).toLowerCase());
29
- }
30
- return trimmedString
31
- .charAt(0)
32
- .toUpperCase()
33
- .concat(trimmedString.slice(1));
40
+ .concat(lowerCaseRest ? rest.toLowerCase() : rest));
34
41
  }
42
+ return trimmedString
43
+ .charAt(0)
44
+ .toUpperCase()
45
+ .concat(lowerCaseRest
46
+ ? trimmedString.slice(1).toLowerCase()
47
+ : trimmedString.slice(1));
35
48
  };
36
49
  exports.capitalizeString = capitalizeString;
37
- //# sourceMappingURL=index.js.map
@@ -1,2 +1,9 @@
1
- export type TCapitalize = (string: string, capEach?: boolean, lowerRest?: boolean) => string;
1
+ export interface CapitalizeOptions {
2
+ /** If true, capitalizes the first letter of each word (space separated). Defaults to `false` */
3
+ capitalizeEachFirst?: boolean;
4
+ /** If true, ensures that the whole string is capitalized. Defaults to `false` */
5
+ capitalizeAll?: boolean;
6
+ /** If true, ensures that the rest of the string is lowercase. Defaults to `true` */
7
+ lowerCaseRest?: boolean;
8
+ }
2
9
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO,KACf,MAAM,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IACjC,gGAAgG;IAChG,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,iFAAiF;IACjF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,oFAAoF;IACpF,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB"}
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1,2 +1 @@
1
1
  "use strict";
2
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,17 +1,9 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "0.8.7",
3
+ "version": "0.8.9",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions for everyday development needs.",
5
- "main": "./dist/index.cjs",
6
- "module": "./dist/index.mjs",
7
- "types": "./dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "import": "./dist/index.mjs",
11
- "require": "./dist/index.cjs"
12
- },
13
- "./package.json": "./package.json"
14
- },
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
15
7
  "publishConfig": {
16
8
  "access": "public"
17
9
  },
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA4C;AAAnC,0GAAA,gBAAgB,OAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACI,MAAM,gBAAgB,GAAG,CAC/B,MAAc,EACd,UAAmB,KAAK,EACxB,YAAqB,IAAI,EAChB,EAAE;IACX,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEvB,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAEpC,IAAI,CAAC,aAAa;QAAE,OAAO,EAAE,CAAC;IAE9B,IAAI,OAAO,EAAE,CAAC;QACb,OAAO,aAAa;aAClB,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,wBAAgB,EAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;aACvD,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;SAAM,CAAC;QACP,IAAI,SAAS,EAAE,CAAC;YACf,OAAO,aAAa;iBAClB,MAAM,CAAC,CAAC,CAAC;iBACT,WAAW,EAAE;iBACb,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,aAAa;aAClB,MAAM,CAAC,CAAC,CAAC;aACT,WAAW,EAAE;aACb,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;AACF,CAAC,CAAC;AA7BW,QAAA,gBAAgB,oBA6B3B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}