@mephisto5558/better-types 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mephisto5558
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
Binary file
package/eslint.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /* eslint-disable-next-line import-x/prefer-default-export */
2
+ export declare const globals: Record<string, 'readonly'>;
package/eslint.js ADDED
@@ -0,0 +1,25 @@
1
+ /* eslint-disable-next-line import-x/prefer-default-export */
2
+ export const globals = Object.freeze({
3
+ GenericFunction: 'readonly',
4
+ OmitFirstParameters: 'readonly',
5
+ StrictOmit: 'readonly',
6
+ ReplaceMethod: 'readonly',
7
+ Snowflake: 'readonly',
8
+
9
+
10
+ // better-typescript-lib
11
+ JSONPrimitive: 'readonly',
12
+ JSONComposite: 'readonly',
13
+ JSONValueF: 'readonly',
14
+ JSONValue: 'readonly',
15
+ JSONObject: 'readonly',
16
+ JSONHolder: 'readonly',
17
+ ToJSON: 'readonly',
18
+ SomeExtends: 'readonly',
19
+
20
+ // SomeFunction: 'readonly', // use GenericFunction instead
21
+ SomeConstructor: 'readonly',
22
+ UndefinedDomain: 'readonly',
23
+ StringifyResultT: 'readonly',
24
+ StringifyResult: 'readonly'
25
+ });
package/index.d.ts ADDED
@@ -0,0 +1,95 @@
1
+ /* eslint-disable sonarjs/no-built-in-override */
2
+
3
+ /* eslint-disable-next-line unicorn/require-module-specifiers -- required */
4
+ export {};
5
+
6
+ type ISODate = `${number}${number}${number}${number}-${number}${number}-${number}${number}`;
7
+ type ISOTime = `${number}${number}:${number}${number}:${number}${number}.${number}${number}${number}`;
8
+ type ISODateTime = `${ISODate}T${ISOTime}Z`;
9
+
10
+ type KeyToString<K extends PropertyKey> = K extends string ? K : K extends number ? `${K}` : never;
11
+
12
+ type Split<S extends string, SEP extends string | undefined, L extends number = number, Acc extends string[] = []> = SEP extends unknown
13
+ ? [L] extends [Acc['length']] ? Acc
14
+ : SEP extends undefined ? [S]
15
+ : string extends S | SEP ? string[]
16
+ : SEP extends ''
17
+ ? S extends `${infer Head}${infer Tail}`
18
+ ? Split<Tail, SEP, L, [...Acc, Head]>
19
+ : Acc
20
+ : S extends `${infer Head}${SEP}${infer Tail}`
21
+ ? Split<Tail, SEP, L, [...Acc, Head]>
22
+ : [...Acc, S]
23
+ : never;
24
+
25
+ declare global {
26
+ // #region Buildins
27
+ /* eslint-disable @typescript-eslint/consistent-type-definitions */
28
+ namespace NodeJS {
29
+ interface Require {
30
+ /* eslint-disable-next-line @typescript-eslint/prefer-function-type -- overwriting only the function signature */
31
+ (id: string): unknown;
32
+ }
33
+ }
34
+
35
+ interface String {
36
+ split(separator?: string, limit: 0): [];
37
+ split<T extends string>(this: T, separator?: undefined, limit?: number): [T];
38
+ split<T extends string, SEP extends string | undefined, L extends number = number>(
39
+ this: T, separator: SEP, limit?: L
40
+ ): Split<T, SEP, L>;
41
+
42
+ toLowerCase<T extends string>(this: T): Lowercase<T>;
43
+ toUpperCase<T extends string>(this: T): Uppercase<T>;
44
+ }
45
+
46
+ interface BigInt {
47
+ toString(radix?: 10): `${bigint}`;
48
+ }
49
+
50
+ interface ObjectConstructor {
51
+ keys<K extends PropertyKey, V>(o: [K, V] extends [never, never] ? never : Record<K, V>): KeyToString<K>[]; // handles things like enums
52
+ keys<T>(o: T): KeyToString<keyof T>[];
53
+
54
+ values<K extends PropertyKey, V>(o: [K, V] extends [never, never] ? never : Record<K, V>): V[]; // handles things like enums
55
+ values<T>(o: T): ({
56
+ [K in keyof T]: undefined extends T[K] ? T[K] : Required<T>[K]
57
+ } extends { [_ in keyof T]: infer V } ? V : never)[];
58
+
59
+ entries<K extends PropertyKey, V>(o: [K, V] extends [never, never] ? never : Record<K, V>): [KeyToString<K>, V][]; // handles things like enums
60
+ entries<T>(o: T): ({
61
+ [K in keyof T]: undefined extends T[K] ? T[K] : Required<T>[K]
62
+ } extends { [_ in keyof T]: infer V } ? [KeyToString<keyof T>, V] : never)[];
63
+ }
64
+
65
+ interface Date {
66
+ /**
67
+ * Give a more precise return type to the method `toISOString()`:
68
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString */
69
+ toISOString(): ISODateTime;
70
+ }
71
+
72
+ // #endregion Buildins
73
+
74
+ type Snowflake = `${bigint}`;
75
+
76
+ /* eslint-enable @typescript-eslint/consistent-type-definitions */
77
+
78
+ // #region useful Generics
79
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any -- used only as generic constraint */
80
+ type GenericFunction<Ret = any> = (...args: any) => Ret;
81
+
82
+ type OmitFirstParameters<
83
+ T extends GenericFunction, N extends number = 1, Acc extends unknown[] = []
84
+ > = Acc['length'] extends N ? Parameters<T> extends [...Acc, ...infer Rest] ? Rest : never : OmitFirstParameters<T, N, [...Acc, unknown]>;
85
+
86
+ /**
87
+ * A stricter version of `Omit` that preserves modifiers better by using a mapped type.
88
+ *
89
+ * {@link https://github.com/microsoft/TypeScript/issues/54451#issue-1732749888 More info} */
90
+ type StrictOmit<T, K extends keyof T> = { [P in keyof T as P extends K ? never : P]: T[P] };
91
+
92
+ type ReplaceMethod<T, K extends keyof T, This, Args extends unknown[] = Parameters<T[K]>> = StrictOmit<T, K> & {
93
+ [P in K]: Exclude<T[P], GenericFunction> | ((this: This, ...args: Args) => ReturnType<Extract<T[P], GenericFunction>>);
94
+ };
95
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@mephisto5558/better-types",
3
+ "version": "1.0.0",
4
+ "description": "A collection of useful TypeScript types and augmentations to improve developer experience.",
5
+ "keywords": [
6
+ "typing",
7
+ "typescript"
8
+ ],
9
+ "homepage": "https://github.com/Mephisto5558/Better-Types#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/Mephisto5558/Better-Types/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/Mephisto5558/Better-Types.git"
16
+ },
17
+ "license": "MIT",
18
+ "author": "Mephisto5558",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./index.d.ts"
23
+ },
24
+ "./eslint": "./eslint.js"
25
+ },
26
+ "types": "index.d.ts",
27
+ "files": [
28
+ "index.d.ts",
29
+ "eslint.js",
30
+ "eslint.d.ts"
31
+ ],
32
+ "scripts": {
33
+ "test": "echo \"Error: no test specified\" && exit 1"
34
+ },
35
+ "devDependencies": {
36
+ "@mephisto5558/eslint-config": "latest",
37
+ "@types/node": "20.x",
38
+ "better-typescript-lib": "latest"
39
+ },
40
+ "peerDependencies": {
41
+ "@types/node": ">=20",
42
+ "better-typescript-lib": "latest"
43
+ },
44
+ "engines": {
45
+ "node": ">=20"
46
+ }
47
+ }