@trpc-proto/utility 0.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.
- package/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/bytes.d.ts +3 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +14 -0
- package/dist/bytes.js.map +1 -0
- package/dist/case.d.ts +5 -0
- package/dist/case.d.ts.map +1 -0
- package/dist/case.js +22 -0
- package/dist/case.js.map +1 -0
- package/dist/exhaustiveness.d.ts +13 -0
- package/dist/exhaustiveness.d.ts.map +1 -0
- package/dist/exhaustiveness.js +5 -0
- package/dist/exhaustiveness.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/iterable.d.ts +2 -0
- package/dist/iterable.d.ts.map +1 -0
- package/dist/iterable.js +6 -0
- package/dist/iterable.js.map +1 -0
- package/dist/string.d.ts +2 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +9 -0
- package/dist/string.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thanh Ngo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @trpc-proto/utility
|
|
2
|
+
|
|
3
|
+
Shared TypeScript helpers used by the trpc-proto packages.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @trpc-proto/utility
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package primarily supports `@trpc-proto/schema_ir`, `@trpc-proto/plugin`, and `@trpc-proto/runtime`.
|
|
12
|
+
|
|
13
|
+
See the [trpc-proto repository](https://github.com/iocat/trpc-proto) for project documentation.
|
package/dist/bytes.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAE3D;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,2BAS1C"}
|
package/dist/bytes.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function isBytes(value) {
|
|
2
|
+
return value instanceof Uint8Array;
|
|
3
|
+
}
|
|
4
|
+
export function concat(chunks) {
|
|
5
|
+
const length = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
6
|
+
const out = new Uint8Array(length);
|
|
7
|
+
let offset = 0;
|
|
8
|
+
for (const chunk of chunks) {
|
|
9
|
+
out.set(chunk, offset);
|
|
10
|
+
offset += chunk.length;
|
|
11
|
+
}
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,UAAU,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,MAAoB;IACzC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACpE,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IACzB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/case.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function toPascalCase(name: string): string;
|
|
2
|
+
export declare function toSnakeCase(name: string): string;
|
|
3
|
+
export declare function toScreamingSnake(name: string): string;
|
|
4
|
+
export declare function toCamel(name: string): string;
|
|
5
|
+
//# sourceMappingURL=case.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"case.d.ts","sourceRoot":"","sources":["../src/case.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOrD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,UAEnC"}
|
package/dist/case.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function toPascalCase(name) {
|
|
2
|
+
return name
|
|
3
|
+
.split(/[._-]/g)
|
|
4
|
+
.filter(Boolean)
|
|
5
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
6
|
+
.join('');
|
|
7
|
+
}
|
|
8
|
+
export function toSnakeCase(name) {
|
|
9
|
+
return name.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
export function toScreamingSnake(name) {
|
|
12
|
+
return name
|
|
13
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
14
|
+
.replace(/[.-]+/g, '_')
|
|
15
|
+
.replace(/_+/g, '_')
|
|
16
|
+
.replace(/^_/, '')
|
|
17
|
+
.toUpperCase();
|
|
18
|
+
}
|
|
19
|
+
export function toCamel(name) {
|
|
20
|
+
return name.replace(/_([a-z])/g, (_, ch) => ch.toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=case.js.map
|
package/dist/case.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"case.js","sourceRoot":"","sources":["../src/case.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,IAAI;SACR,KAAK,CAAC,QAAQ,CAAC;SACf,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC3D,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,IAAI;SACR,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;SACjB,WAAW,EAAE,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function assumeExhaustive(value: never): never;
|
|
2
|
+
type ExhaustivenessCheck<TActual, TAllowed> = [
|
|
3
|
+
Exclude<TActual, TAllowed>
|
|
4
|
+
] extends [never] ? [Exclude<TAllowed, TActual>] extends [never] ? unknown : {
|
|
5
|
+
readonly ERROR: 'TAllowed contains cases already handled or impossible';
|
|
6
|
+
readonly REDUNDANT_CASES: Exclude<TAllowed, TActual>;
|
|
7
|
+
} : {
|
|
8
|
+
readonly ERROR: 'Unhandled value is not covered by TAllowed';
|
|
9
|
+
readonly UNHANDLED_CASES: Exclude<TActual, TAllowed>;
|
|
10
|
+
};
|
|
11
|
+
export declare function assumeExhaustiveAllowing<TAllowed, TActual>(_value: TActual & ExhaustivenessCheck<TActual, TAllowed>, _message?: string): void;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=exhaustiveness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exhaustiveness.d.ts","sourceRoot":"","sources":["../src/exhaustiveness.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAEpD;AAED,KAAK,mBAAmB,CAAC,OAAO,EAAE,QAAQ,IAAI;IAC5C,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC;CAC3B,SAAS,CAAC,KAAK,CAAC,GACb,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC1C,OAAO,GACP;IACE,QAAQ,CAAC,KAAK,EAAE,uDAAuD,CAAC;IACxE,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;CACtD,GACH;IACE,QAAQ,CAAC,KAAK,EAAE,4CAA4C,CAAC;IAC7D,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;CACtD,CAAC;AAEN,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EACxD,MAAM,EAAE,OAAO,GAAG,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,EACxD,QAAQ,CAAC,EAAE,MAAM,GAChB,IAAI,CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exhaustiveness.js","sourceRoot":"","sources":["../src/exhaustiveness.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAC,KAAY;IAC3C,MAAM,IAAI,KAAK,CAAC,qBAAqB,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACxD,CAAC;AAgBD,MAAM,UAAU,wBAAwB,CACtC,MAAwD,EACxD,QAAiB,IACV,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { assumeExhaustive, assumeExhaustiveAllowing, } from './exhaustiveness.js';
|
|
2
|
+
export { toCamel, toPascalCase, toScreamingSnake, toSnakeCase, } from './case.js';
|
|
3
|
+
export { concat, isBytes } from './bytes.js';
|
|
4
|
+
export { isAsyncIterable } from './iterable.js';
|
|
5
|
+
export { dedent } from './string.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { assumeExhaustive, assumeExhaustiveAllowing, } from './exhaustiveness.js';
|
|
2
|
+
export { toCamel, toPascalCase, toScreamingSnake, toSnakeCase, } from './case.js';
|
|
3
|
+
export { concat, isBytes } from './bytes.js';
|
|
4
|
+
export { isAsyncIterable } from './iterable.js';
|
|
5
|
+
export { dedent } from './string.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterable.d.ts","sourceRoot":"","sources":["../src/iterable.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,KAAK,EACnC,KAAK,EAAE,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAClC,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAM/B"}
|
package/dist/iterable.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterable.js","sourceRoot":"","sources":["../src/iterable.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAC7B,KAAmC;IAEnC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,KAAK,KAAK,SAAS;QACnB,OAAQ,KAA8B,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,UAAU,CAC5E,CAAC;AACJ,CAAC"}
|
package/dist/string.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO3C"}
|
package/dist/string.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function dedent(text) {
|
|
2
|
+
const lines = text.replace(/^\n/, '').split('\n');
|
|
3
|
+
const indents = lines
|
|
4
|
+
.filter((line) => line.trim().length > 0)
|
|
5
|
+
.map((line) => line.match(/^ */)?.[0].length ?? 0);
|
|
6
|
+
const n = indents.length === 0 ? 0 : Math.min(...indents);
|
|
7
|
+
return lines.map((line) => line.slice(n)).join('\n');
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,KAAK;SAClB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;SACxC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IACrD,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trpc-proto/utility",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Shared exhaustiveness, case, and byte helpers",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"typescript",
|
|
8
|
+
"utilities"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/iocat/trpc-proto#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/iocat/trpc-proto/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/iocat/trpc-proto.git",
|
|
17
|
+
"directory": "packages/utility"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Thanh Ngo <nokotavi@gmail.com>",
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^24.3.0",
|
|
38
|
+
"tsx": "^4.20.5",
|
|
39
|
+
"typescript": "^5.9.2"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -p tsconfig.json",
|
|
43
|
+
"clean": "rm -rf dist",
|
|
44
|
+
"test": "tsx --test src/**/*_test.ts"
|
|
45
|
+
}
|
|
46
|
+
}
|