nhb-toolbox 0.9.0 → 0.9.1

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,4 +8,11 @@ import type { CapitalizeOptions } from './types';
8
8
  * @returns Capitalized string.
9
9
  */
10
10
  export declare const capitalizeString: (string: string, options?: CapitalizeOptions) => string;
11
+ /**
12
+ * Utility to truncate a string to a specified length.
13
+ * @param string The string to truncate.
14
+ * @param maxLength The maximum length of the truncated string.
15
+ * @returns Truncated string;
16
+ */
17
+ export declare const truncateString: (string: string, maxLength: number) => string;
11
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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,YACJ,iBAAiB,KACzB,MA4CF,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,YACJ,iBAAiB,KACzB,MA0CF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,WAAY,MAAM,aAAa,MAAM,KAAG,MAYlE,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.capitalizeString = void 0;
3
+ exports.truncateString = 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
6
  * Handles surrounding symbols like quotes or parentheses.
@@ -10,9 +10,7 @@ exports.capitalizeString = void 0;
10
10
  * @returns Capitalized string.
11
11
  */
12
12
  const capitalizeString = (string, options) => {
13
- if (typeof string !== 'string' || !string.trim())
14
- return '';
15
- if (!string)
13
+ if (typeof string !== 'string' || !string)
16
14
  return '';
17
15
  const trimmedString = string.trim();
18
16
  if (!trimmedString)
@@ -42,3 +40,22 @@ const capitalizeString = (string, options) => {
42
40
  : trimmedString.slice(1));
43
41
  };
44
42
  exports.capitalizeString = capitalizeString;
43
+ /**
44
+ * Utility to truncate a string to a specified length.
45
+ * @param string The string to truncate.
46
+ * @param maxLength The maximum length of the truncated string.
47
+ * @returns Truncated string;
48
+ */
49
+ const truncateString = (string, maxLength) => {
50
+ if (typeof string !== 'string' || !string)
51
+ return '';
52
+ const trimmedString = string.trim();
53
+ if (!trimmedString)
54
+ return '';
55
+ if (!trimmedString)
56
+ return '';
57
+ if (trimmedString.length <= maxLength)
58
+ return trimmedString;
59
+ return trimmedString.slice(0, maxLength).concat('...');
60
+ };
61
+ exports.truncateString = truncateString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
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",