@webdeveric/utils 1.0.0 โ†’ 1.2.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
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.indent = indent;
4
+ const constants_js_1 = require("./constants.js");
5
+ /**
6
+ * Add `indent` before each line in `input`.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * indent('one\ntwo\nthree', ' '); // ' one\n two\n three'
11
+ * ```
12
+ */
13
+ function indent(input, indentation) {
14
+ return (indentation +
15
+ input.replaceAll(new RegExp(String.raw `(?<newLine>${constants_js_1.NEWLINE_RAW_PATTERN})`, 'g'), `$<newLine>${indentation}`));
16
+ }
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,8 +57,10 @@ __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);
63
+ __exportStar(require("./indent.js"), exports);
61
64
  __exportStar(require("./inRange.js"), exports);
62
65
  __exportStar(require("./isEmpty.js"), exports);
63
66
  __exportStar(require("./iterateForever.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
+ }
@@ -0,0 +1,13 @@
1
+ import { NEWLINE_RAW_PATTERN } from './constants.js';
2
+ /**
3
+ * Add `indent` before each line in `input`.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * indent('one\ntwo\nthree', ' '); // ' one\n two\n three'
8
+ * ```
9
+ */
10
+ export function indent(input, indentation) {
11
+ return (indentation +
12
+ input.replaceAll(new RegExp(String.raw `(?<newLine>${NEWLINE_RAW_PATTERN})`, 'g'), `$<newLine>${indentation}`));
13
+ }
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,8 +41,10 @@ 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';
47
+ export * from './indent.js';
45
48
  export * from './inRange.js';
46
49
  export * from './isEmpty.js';
47
50
  export * from './iterateForever.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;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Add `indent` before each line in `input`.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * indent('one\ntwo\nthree', ' '); // ' one\n two\n three'
7
+ * ```
8
+ */
9
+ export declare function indent(input: string, indentation: string): string;
@@ -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,8 +39,10 @@ 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';
45
+ export * from './indent.js';
43
46
  export * from './inRange.js';
44
47
  export * from './isEmpty.js';
45
48
  export * from './iterateForever.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.2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -66,7 +66,7 @@
66
66
  "url": "https://github.com/webdeveric/utils/issues"
67
67
  },
68
68
  "homepage": "https://github.com/webdeveric/utils/#readme",
69
- "packageManager": "pnpm@11.11.0+sha512.4463f65fd80ed80d69bc1d4bf163ee94f605c7380fc318bb5b2ebe15f8cd12d49c51a4d59e951b401e764d3b6ca751cbf51bc50ed7001a6bcb4935e684c34882",
69
+ "packageManager": "pnpm@11.15.0+sha512.266f8957a30d2be6e9468e5e66bcdedd35a794175f71b067ba8504d686cce1d0c0f429b33c323c3c569ad4891e667574a49ff71d1b89a22cc66f13c65818c578",
70
70
  "scripts": {
71
71
  "clean": "rimraf ./dist/ ./cache/ ./coverage/",
72
72
  "prebuild": "pnpm clean",
@@ -107,9 +107,9 @@
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.7",
111
111
  "typedoc": "^0.28.20",
112
- "validate-package-exports": "^1.2.1",
112
+ "validate-package-exports": "^1.3.1",
113
113
  "vitest": "^4.1.10"
114
114
  }
115
115
  }