@webdeveric/utils 1.0.0 โ†’ 1.1.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.
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.codePointLength = codePointLength;
4
+ /**
5
+ * Get the number of Unicode code points in `input`, unlike `string.length` which counts UTF-16 code units.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * codePointLength('hello'); // 5
10
+ * codePointLength('๐Ÿ˜€'); // 1
11
+ * '๐Ÿ˜€'.length; // 2
12
+ * ```
13
+ */
14
+ function codePointLength(input) {
15
+ return [...input].length;
16
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphemeLength = graphemeLength;
4
+ const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
5
+ /**
6
+ * Get the number of grapheme clusters (user-perceived characters) in `input`, unlike `string.length` which counts UTF-16 code units.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * graphemeLength('hello'); // 5
11
+ * graphemeLength('๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'); // 1
12
+ * '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'.length; // 11
13
+ * ```
14
+ */
15
+ function graphemeLength(input) {
16
+ let count = 0;
17
+ // eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/no-unused-vars
18
+ for (const _ of segmenter.segment(input)) {
19
+ count++;
20
+ }
21
+ return count;
22
+ }
package/dist/cjs/index.js CHANGED
@@ -26,6 +26,7 @@ __exportStar(require("./capitalize.js"), exports);
26
26
  __exportStar(require("./cartesian.js"), exports);
27
27
  __exportStar(require("./chunk.js"), exports);
28
28
  __exportStar(require("./clamp.js"), exports);
29
+ __exportStar(require("./codePointLength.js"), exports);
29
30
  __exportStar(require("./combinations.js"), exports);
30
31
  __exportStar(require("./comment.js"), exports);
31
32
  __exportStar(require("./compose.js"), exports);
@@ -56,6 +57,7 @@ __exportStar(require("./getPaths.js"), exports);
56
57
  __exportStar(require("./getRandomItem.js"), exports);
57
58
  __exportStar(require("./getSortedObject.js"), exports);
58
59
  __exportStar(require("./getType.js"), exports);
60
+ __exportStar(require("./graphemeLength.js"), exports);
59
61
  __exportStar(require("./has.js"), exports);
60
62
  __exportStar(require("./hasAdditionalProperties.js"), exports);
61
63
  __exportStar(require("./inRange.js"), exports);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Get the number of Unicode code points in `input`, unlike `string.length` which counts UTF-16 code units.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * codePointLength('hello'); // 5
7
+ * codePointLength('๐Ÿ˜€'); // 1
8
+ * '๐Ÿ˜€'.length; // 2
9
+ * ```
10
+ */
11
+ export function codePointLength(input) {
12
+ return [...input].length;
13
+ }
@@ -0,0 +1,19 @@
1
+ const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
2
+ /**
3
+ * Get the number of grapheme clusters (user-perceived characters) in `input`, unlike `string.length` which counts UTF-16 code units.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * graphemeLength('hello'); // 5
8
+ * graphemeLength('๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'); // 1
9
+ * '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'.length; // 11
10
+ * ```
11
+ */
12
+ export function graphemeLength(input) {
13
+ let count = 0;
14
+ // eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/no-unused-vars
15
+ for (const _ of segmenter.segment(input)) {
16
+ count++;
17
+ }
18
+ return count;
19
+ }
package/dist/mjs/index.js CHANGED
@@ -10,6 +10,7 @@ export * from './capitalize.js';
10
10
  export * from './cartesian.js';
11
11
  export * from './chunk.js';
12
12
  export * from './clamp.js';
13
+ export * from './codePointLength.js';
13
14
  export * from './combinations.js';
14
15
  export * from './comment.js';
15
16
  export * from './compose.js';
@@ -40,6 +41,7 @@ export * from './getPaths.js';
40
41
  export * from './getRandomItem.js';
41
42
  export * from './getSortedObject.js';
42
43
  export * from './getType.js';
44
+ export * from './graphemeLength.js';
43
45
  export * from './has.js';
44
46
  export * from './hasAdditionalProperties.js';
45
47
  export * from './inRange.js';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Get the number of Unicode code points in `input`, unlike `string.length` which counts UTF-16 code units.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * codePointLength('hello'); // 5
7
+ * codePointLength('๐Ÿ˜€'); // 1
8
+ * '๐Ÿ˜€'.length; // 2
9
+ * ```
10
+ */
11
+ export declare function codePointLength(input: string): number;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Get the number of grapheme clusters (user-perceived characters) in `input`, unlike `string.length` which counts UTF-16 code units.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * graphemeLength('hello'); // 5
7
+ * graphemeLength('๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'); // 1
8
+ * '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'.length; // 11
9
+ * ```
10
+ */
11
+ export declare function graphemeLength(input: string): number;
@@ -8,6 +8,7 @@ export * from './capitalize.js';
8
8
  export * from './cartesian.js';
9
9
  export * from './chunk.js';
10
10
  export * from './clamp.js';
11
+ export * from './codePointLength.js';
11
12
  export * from './combinations.js';
12
13
  export * from './comment.js';
13
14
  export * from './compose.js';
@@ -38,6 +39,7 @@ export * from './getPaths.js';
38
39
  export * from './getRandomItem.js';
39
40
  export * from './getSortedObject.js';
40
41
  export * from './getType.js';
42
+ export * from './graphemeLength.js';
41
43
  export * from './has.js';
42
44
  export * from './hasAdditionalProperties.js';
43
45
  export * from './inRange.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webdeveric/utils",
3
3
  "description": "Just another collection of utilities.",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -107,7 +107,7 @@
107
107
  "lint-staged": "^17.0.8",
108
108
  "prettier": "^3.9.5",
109
109
  "rimraf": "^6.1.3",
110
- "semantic-release": "^25.0.5",
110
+ "semantic-release": "^25.0.6",
111
111
  "typedoc": "^0.28.20",
112
112
  "validate-package-exports": "^1.2.1",
113
113
  "vitest": "^4.1.10"