@insanedev2478/tstoolset 1.1.0 → 1.4.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 +134 -1
- package/dist/index.d.ts +7 -0
- package/package.json +6 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vedansh Shetti
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,137 @@
|
|
|
1
|
-
|
|
1
|
+
# 🧰 **tstoolset**
|
|
2
|
+
|
|
3
|
+
**Open-source**, **Zero‑runtime** TypeScript **utility types** for cleaner, safer, more expressive code. <br>
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🚀 Installation
|
|
2
10
|
|
|
3
11
|
```sh
|
|
4
12
|
npm install @insanedev2478/tstoolset
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## ✨ Features
|
|
18
|
+
|
|
19
|
+
- Strong, readable primitive aliases (`String`, `Number`, `Boolean`, etc.)
|
|
20
|
+
- Utility containers (`Obj<T>`, `Arr<T>`, `Func<T>`)
|
|
21
|
+
- Template‑literal types (`UUIDV4`, `TrustableEmail`)
|
|
22
|
+
- Nominal typing with `Brand<T, Name>`
|
|
23
|
+
- Exact object enforcement with `Exact<T>`
|
|
24
|
+
- Safe assertion helper: `convert<T>(x)`
|
|
25
|
+
- Zero runtime cost — pure TypeScript
|
|
26
|
+
- Object schema merger with `Merge<A, B>`
|
|
27
|
+
- snake_case to camelCase conversion with `CamelCase<string>`
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 📦 Usage
|
|
32
|
+
|
|
33
|
+
### **Primitive & container helpers**
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import type { String, Obj, Arr } from "@insanedev2478/tstoolset";
|
|
37
|
+
|
|
38
|
+
type User = Obj<String>;
|
|
39
|
+
type Tags = Arr<String>;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### **Exact object enforcement**
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import type { Exact } from "@insanedev2478/tstoolset";
|
|
46
|
+
|
|
47
|
+
type User = { id: string };
|
|
48
|
+
const u: Exact<User> = { id: "123" }; // ok
|
|
49
|
+
const x: Exact<User> = { id: "123", a: 1 }; // ❌ extra key
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### snake_case to camelCase 🔁
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import type { CamelCase } from "@insanedev2478/tstoolset";
|
|
56
|
+
import { convertToCamelCase } from "@insanedev2478/tstoolset";
|
|
57
|
+
|
|
58
|
+
// Type-level examples:
|
|
59
|
+
type A = CamelCase<"snake_case">; // 'snakeCase'
|
|
60
|
+
type B = CamelCase<"multi_part_name">; // 'multiPartName'
|
|
61
|
+
type C = CamelCase<"alreadyCamel">; // 'alreadyCamel'
|
|
62
|
+
|
|
63
|
+
// Using a literal (type-level):
|
|
64
|
+
const s = "hello_world" as const;
|
|
65
|
+
type S = CamelCase<typeof s>; // 'helloWorld'
|
|
66
|
+
|
|
67
|
+
// Runtime helper `convertToCamelCase` preserves the typed relationship when used with literal types
|
|
68
|
+
const r = convertToCamelCase(s); // 'helloWorld' (type: CamelCase<typeof s>)
|
|
69
|
+
|
|
70
|
+
// It also handles dashes and spaces, and collapses multiple separators:
|
|
71
|
+
const r2 = convertToCamelCase("multi-part name" as const); // 'multiPartName'
|
|
72
|
+
const r3 = convertToCamelCase("alreadyCamel" as const); // 'alreadyCamel'
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### **Nominal typing**
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import type { Brand } from "@insanedev2478/tstoolset";
|
|
79
|
+
|
|
80
|
+
type UserId = Brand<string, "UserId">;
|
|
81
|
+
|
|
82
|
+
const id: UserId = "abc" as UserId;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### **Merge**
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import type { Merge } from "@insanedev2478/tstoolset";
|
|
89
|
+
type A = { id: string; name: string };
|
|
90
|
+
type B = { id: number; admin: boolean };
|
|
91
|
+
|
|
92
|
+
const merged: Merge<A, B> = {
|
|
93
|
+
id: 123, // overridden by B
|
|
94
|
+
name: "John",
|
|
95
|
+
admin: true,
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### **UUID & Email template types**
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import type { UUIDV4, TrustableEmail } from "@insanedev2478/tstoolset";
|
|
103
|
+
|
|
104
|
+
const id: UUIDV4 = "550e8400-e29b-41d4-a716-446655440000";
|
|
105
|
+
const email: TrustableEmail = "user@gmail.com";
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### **Safe converter**
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { convert } from "@insanedev2478/tstoolset";
|
|
112
|
+
|
|
113
|
+
const fn = convert<(...args: any[]) => void>(() => {});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## 🗺️ Roadmap
|
|
119
|
+
|
|
120
|
+
- Deep utilities (`DeepPartial`, `DeepReadonly`, `DeepRequired`)
|
|
121
|
+
- JSON‑safe types (`JsonValue`, `JsonObject`)
|
|
122
|
+
- String manipulation types (`KebabCase`, `snake-case`)
|
|
123
|
+
- Schema‑style helpers
|
|
124
|
+
- More branded primitives
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## 🤝 Contributing
|
|
129
|
+
|
|
130
|
+
I am still a 6th grader, so new releases will only be on weekends, but <br>
|
|
131
|
+
issues, ideas, and PRs are welcome — this project is growing fast and feedback helps shape the toolkit.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 📄 License
|
|
136
|
+
|
|
137
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -26,4 +26,11 @@ declare const brand: unique symbol;
|
|
|
26
26
|
export type Brand<T, Name> = T & {
|
|
27
27
|
[brand]: Name;
|
|
28
28
|
};
|
|
29
|
+
type ConvertableTypes = Primitive | Obj | Arr | Func | TrustableEmail | UUIDV4;
|
|
30
|
+
export type Merge<A, B> = {
|
|
31
|
+
[K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;
|
|
32
|
+
};
|
|
33
|
+
export type CamelCase<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${CamelCase<Capitalize<Tail>>}` : S extends `${infer Head}-${infer Tail}` ? `${Head}${CamelCase<Capitalize<Tail>>}` : S extends `${infer Head} ${infer Tail}` ? `${Head}${CamelCase<Capitalize<Tail>>}` : S;
|
|
34
|
+
export declare function convert<T extends ConvertableTypes>(x: unknown): T;
|
|
35
|
+
export declare function convertToCamelCase<S extends string>(str: S): CamelCase<S>;
|
|
29
36
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insanedev2478/tstoolset",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Collection of handy TypeScript types, ranging from primitives like numbers all the way to UUIDs and Email Addresses. ",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,5 +29,9 @@
|
|
|
29
29
|
"type-level",
|
|
30
30
|
"zero-runtime",
|
|
31
31
|
"tstoolset"
|
|
32
|
-
]
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/vedanshshetti/tstoolset.git"
|
|
36
|
+
}
|
|
33
37
|
}
|