@webdeveric/utils 0.78.0 → 0.80.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,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.countCharCode = countCharCode;
4
+ function countCharCode(input, charCode) {
5
+ let count = 0;
6
+ for (let index = 0, length = input.length; index < length; ++index) {
7
+ if (input.charCodeAt(index) === charCode) {
8
+ ++count;
9
+ }
10
+ }
11
+ return count;
12
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.countCharacter = countCharacter;
4
+ const countCharCode_js_1 = require("./countCharCode.js");
5
+ function countCharacter(input, char) {
6
+ if (char.length !== 1) {
7
+ throw new Error('Expected a single character');
8
+ }
9
+ return (0, countCharCode_js_1.countCharCode)(input, char.charCodeAt(0));
10
+ }
package/dist/cjs/index.js CHANGED
@@ -28,6 +28,8 @@ __exportStar(require("./combinations.js"), exports);
28
28
  __exportStar(require("./comment.js"), exports);
29
29
  __exportStar(require("./compose.js"), exports);
30
30
  __exportStar(require("./convert.js"), exports);
31
+ __exportStar(require("./countCharacter.js"), exports);
32
+ __exportStar(require("./countCharCode.js"), exports);
31
33
  __exportStar(require("./counter.js"), exports);
32
34
  __exportStar(require("./deepDecodeURI.js"), exports);
33
35
  __exportStar(require("./deepFreeze.js"), exports);
@@ -1,18 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unique = unique;
4
- function* unique(items, getIdentity = (item) => item) {
5
- if (items instanceof Set) {
6
- yield* items;
4
+ const isAsyncIterable_js_1 = require("./predicate/isAsyncIterable.js");
5
+ const isIterable_js_1 = require("./predicate/isIterable.js");
6
+ function unique(items, options = {}) {
7
+ const ids = new Set();
8
+ const { filter, identity } = options;
9
+ if (typeof items === 'string' || (0, isIterable_js_1.isIterable)(items)) {
10
+ return {
11
+ *[Symbol.iterator]() {
12
+ for (const item of items) {
13
+ if (!filter || filter(item) === true) {
14
+ const id = identity?.(item) ?? item;
15
+ if (!ids.has(id)) {
16
+ ids.add(id);
17
+ yield item;
18
+ }
19
+ }
20
+ }
21
+ },
22
+ };
7
23
  }
8
- else {
9
- const ids = new Set();
10
- for (const item of items) {
11
- const id = getIdentity(item);
12
- if (!ids.has(id)) {
13
- ids.add(id);
14
- yield item;
15
- }
16
- }
24
+ if ((0, isAsyncIterable_js_1.isAsyncIterable)(items)) {
25
+ return {
26
+ async *[Symbol.asyncIterator]() {
27
+ for await (const item of items) {
28
+ if (!filter || filter(item) === true) {
29
+ const id = identity?.(item) ?? item;
30
+ if (!ids.has(id)) {
31
+ ids.add(id);
32
+ yield item;
33
+ }
34
+ }
35
+ }
36
+ },
37
+ };
17
38
  }
39
+ throw new TypeError('items must be an Iterable or AsyncIterable');
18
40
  }
@@ -0,0 +1,9 @@
1
+ export function countCharCode(input, charCode) {
2
+ let count = 0;
3
+ for (let index = 0, length = input.length; index < length; ++index) {
4
+ if (input.charCodeAt(index) === charCode) {
5
+ ++count;
6
+ }
7
+ }
8
+ return count;
9
+ }
@@ -0,0 +1,7 @@
1
+ import { countCharCode } from './countCharCode.js';
2
+ export function countCharacter(input, char) {
3
+ if (char.length !== 1) {
4
+ throw new Error('Expected a single character');
5
+ }
6
+ return countCharCode(input, char.charCodeAt(0));
7
+ }
package/dist/mjs/index.js CHANGED
@@ -12,6 +12,8 @@ export * from './combinations.js';
12
12
  export * from './comment.js';
13
13
  export * from './compose.js';
14
14
  export * from './convert.js';
15
+ export * from './countCharacter.js';
16
+ export * from './countCharCode.js';
15
17
  export * from './counter.js';
16
18
  export * from './deepDecodeURI.js';
17
19
  export * from './deepFreeze.js';
@@ -1,15 +1,37 @@
1
- export function* unique(items, getIdentity = (item) => item) {
2
- if (items instanceof Set) {
3
- yield* items;
1
+ import { isAsyncIterable } from './predicate/isAsyncIterable.js';
2
+ import { isIterable } from './predicate/isIterable.js';
3
+ export function unique(items, options = {}) {
4
+ const ids = new Set();
5
+ const { filter, identity } = options;
6
+ if (typeof items === 'string' || isIterable(items)) {
7
+ return {
8
+ *[Symbol.iterator]() {
9
+ for (const item of items) {
10
+ if (!filter || filter(item) === true) {
11
+ const id = identity?.(item) ?? item;
12
+ if (!ids.has(id)) {
13
+ ids.add(id);
14
+ yield item;
15
+ }
16
+ }
17
+ }
18
+ },
19
+ };
4
20
  }
5
- else {
6
- const ids = new Set();
7
- for (const item of items) {
8
- const id = getIdentity(item);
9
- if (!ids.has(id)) {
10
- ids.add(id);
11
- yield item;
12
- }
13
- }
21
+ if (isAsyncIterable(items)) {
22
+ return {
23
+ async *[Symbol.asyncIterator]() {
24
+ for await (const item of items) {
25
+ if (!filter || filter(item) === true) {
26
+ const id = identity?.(item) ?? item;
27
+ if (!ids.has(id)) {
28
+ ids.add(id);
29
+ yield item;
30
+ }
31
+ }
32
+ }
33
+ },
34
+ };
14
35
  }
36
+ throw new TypeError('items must be an Iterable or AsyncIterable');
15
37
  }
@@ -0,0 +1 @@
1
+ export declare function countCharCode(input: string, charCode: number): number;
@@ -0,0 +1 @@
1
+ export declare function countCharacter(input: string, char: string): number;
@@ -12,6 +12,8 @@ export * from './combinations.js';
12
12
  export * from './comment.js';
13
13
  export * from './compose.js';
14
14
  export * from './convert.js';
15
+ export * from './countCharacter.js';
16
+ export * from './countCharCode.js';
15
17
  export * from './counter.js';
16
18
  export * from './deepDecodeURI.js';
17
19
  export * from './deepFreeze.js';
@@ -1 +1,7 @@
1
- export declare function unique<T>(items: Iterable<T>, getIdentity?: (item: T) => unknown): Generator<T, undefined, undefined>;
1
+ export type UniqueOptions<Type> = {
2
+ identity?: (item: Type) => unknown;
3
+ filter?: (item: Type) => boolean;
4
+ };
5
+ export declare function unique<Type>(items: AsyncIterable<Type>, options?: UniqueOptions<Type>): AsyncIterable<string>;
6
+ export declare function unique<Type>(items: Iterable<Type>, options?: UniqueOptions<Type>): Iterable<Type>;
7
+ export declare function unique(items: string, options?: UniqueOptions<string>): Iterable<string>;
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": "0.78.0",
4
+ "version": "0.80.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -66,9 +66,9 @@
66
66
  "url": "https://github.com/webdeveric/utils/issues"
67
67
  },
68
68
  "homepage": "https://github.com/webdeveric/utils/#readme",
69
- "packageManager": "pnpm@10.33.2+sha512.a90faf6feeab71ad6c6e57f94e0fe1a12f5dcc22cd754db40ae9593eb6a3e0b6b12e3540218bb37ae083404b1f2ce6db2a4121e979829b4aff94b99f49da1cf8",
69
+ "packageManager": "pnpm@11.8.0+sha512.c1f5e7c4cb241c8f174b743851d82f42b802324afc8b0f116b96adb15aa06664948dde36960a3ba1079ba5b4b29dd0140135b94b5b5f5263592249d68e555f26",
70
70
  "scripts": {
71
- "clean": "rimraf ./dist/",
71
+ "clean": "rimraf ./dist/ ./cache/ ./coverage/",
72
72
  "prebuild": "pnpm clean",
73
73
  "build": "tsgo --build tsconfig.cjs.json tsconfig.mjs.json --force",
74
74
  "postbuild": "echo '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json && echo '{\"type\":\"module\"}' > ./dist/mjs/package.json && pnpm validate",
@@ -85,28 +85,28 @@
85
85
  },
86
86
  "prettier": "@webdeveric/prettier-config",
87
87
  "devDependencies": {
88
- "@commitlint/config-conventional": "^20.5.0",
89
- "@commitlint/types": "^20.5.0",
90
- "@types/node": "^24.12.2",
91
- "@typescript/native-preview": "7.0.0-dev.20260423.1",
92
- "@vitest/coverage-v8": "^4.1.5",
88
+ "@commitlint/config-conventional": "^21.0.2",
89
+ "@commitlint/types": "^21.0.1",
90
+ "@types/node": "^24.13.2",
91
+ "@typescript/native-preview": "7.0.0-dev.20260617.2",
92
+ "@vitest/coverage-v8": "^4.1.9",
93
93
  "@webdeveric/eslint-config-ts": "^0.12.0",
94
94
  "@webdeveric/prettier-config": "^0.4.0",
95
- "commitlint": "^20.5.0",
96
- "commitlint-plugin-cspell": "^0.8.0",
95
+ "commitlint": "^21.0.2",
96
+ "commitlint-plugin-cspell": "^0.9.2",
97
97
  "conventional-changelog-conventionalcommits": "^9.3.1",
98
- "cspell": "^10.0.0",
98
+ "cspell": "^10.0.1",
99
99
  "eslint": "^8.57.1",
100
100
  "eslint-config-prettier": "^10.1.8",
101
- "eslint-import-resolver-typescript": "^4.4.4",
101
+ "eslint-import-resolver-typescript": "^4.4.5",
102
102
  "eslint-plugin-import": "^2.32.0",
103
103
  "husky": "^9.1.7",
104
- "jsdom": "^29.0.2",
105
- "lint-staged": "^16.4.0",
106
- "prettier": "^3.8.3",
104
+ "jsdom": "^29.1.1",
105
+ "lint-staged": "^17.0.7",
106
+ "prettier": "^3.8.4",
107
107
  "rimraf": "^6.1.3",
108
- "semantic-release": "^25.0.3",
109
- "validate-package-exports": "^0.23.0",
110
- "vitest": "^4.1.5"
108
+ "semantic-release": "^25.0.5",
109
+ "validate-package-exports": "^1.1.0",
110
+ "vitest": "^4.1.9"
111
111
  }
112
112
  }
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1 +0,0 @@
1
- {"type":"module"}