@alessiofrittoli/type-utils 0.1.0-alpha.1

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/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # Type Utils ❇️
2
+
3
+ Version 0.1.0-alpha.1
4
+
5
+ ## Lightweight TypeScript types utilities
6
+
7
+ ### Table of Contents
8
+
9
+ - [Getting started](#gettingstarted)
10
+ - [Utility types](https://github.com/alessiofrittoli/type-utils/blob/master/docs/utils/README.md)
11
+ - [ValueOf](https://github.com/alessiofrittoli/type-utils/blob/master/docs/utils/README.md#valueof)
12
+ - [ValueOfKey](https://github.com/alessiofrittoli/type-utils/blob/master/docs/utils/README.md#valueofkey)
13
+ - [OptionalKey](https://github.com/alessiofrittoli/type-utils/blob/master/docs/utils/README.md#optionalkey)
14
+ - [Writeable](https://github.com/alessiofrittoli/type-utils/blob/master/docs/utils/README.md#writeable)
15
+ - [RenameKey](https://github.com/alessiofrittoli/type-utils/blob/master/docs/utils/README.md#renamekey)
16
+ - [ArgumentTypes](https://github.com/alessiofrittoli/type-utils/blob/master/docs/utils/README.md#argumenttypes)
17
+ - [Extenders types](https://github.com/alessiofrittoli/type-utils/blob/master/docs/extenders/README.md)
18
+ - [JSON](https://github.com/alessiofrittoli/type-utils/blob/master/docs/extenders/README.md#json)
19
+ - [JSON.stringify\<T\>()](https://github.com/alessiofrittoli/type-utils/blob/master/docs/extenders/README.md#jsonstringifyt)
20
+ - [JSON.parse\<T\>()](https://github.com/alessiofrittoli/type-utils/blob/master/docs/extenders/README.md#jsonparset)
21
+ - [Body](https://github.com/alessiofrittoli/type-utils/blob/master/docs/extenders/README.md#body)
22
+ - [Body.json\<T\>()](https://github.com/alessiofrittoli/type-utils/blob/master/docs/extenders/README.md#bodyjsont)
23
+ - [ESLint](#eslint)
24
+ - [Security](#security)
25
+ - [Credits](#made-with-)
26
+
27
+ ---
28
+
29
+ ### Getting started
30
+
31
+ Run the following command to start using `type-utils` in your projects:
32
+
33
+ ```bash
34
+ npm i -D @alessiofrittoli/type-utils
35
+ ```
36
+
37
+ or using `pnpm`
38
+
39
+ ```bash
40
+ pnpm i -D @alessiofrittoli/type-utils
41
+ ```
42
+
43
+ This tiny library defines some global types which are not imported in your IDE by default.\
44
+ After installation a `postinstall` scritp is executed to create the `type-utils.d.ts` file at the root of your project.
45
+ Please make sure to add it in the array of the "include" property in your `tsconfig.json`.
46
+
47
+ ```json
48
+ {
49
+ "compilerOptions": {
50
+ ...
51
+ },
52
+ "include": [ ..., "type-utils.d.ts" ],
53
+ }
54
+ ```
55
+
56
+ You can skip this process if `*.ts` is already in your "include" array.
57
+
58
+ ---
59
+
60
+ ### [ESLint](https://www.npmjs.com/package/eslint)
61
+
62
+ warnings / errors check.
63
+
64
+ ```bash
65
+ pnpm lint
66
+ ```
67
+
68
+ ### Security
69
+
70
+ If you believe you have found a security vulnerability, we encourage you to **_responsibly disclose this and NOT open a public issue_**. We will investigate all legitimate reports. Email `security@alessiofrittoli.it` to disclose any security vulnerabilities.
71
+
72
+ ### Made with ☕
73
+
74
+ <table style='display:flex;gap:20px;'>
75
+ <tbody>
76
+ <tr>
77
+ <td>
78
+ <img src='https://avatars.githubusercontent.com/u/35973186' style='width:60px;border-radius:50%;object-fit:contain;'>
79
+ </td>
80
+ <td>
81
+ <table style='display:flex;gap:2px;flex-direction:column;'>
82
+ <tbody>
83
+ <tr>
84
+ <td>
85
+ <a href='https://github.com/alessiofrittoli' target='_blank' rel='noopener'>Alessio Frittoli</a>
86
+ </td>
87
+ </tr>
88
+ <tr>
89
+ <td>
90
+ <small>
91
+ <a href='https://alessiofrittoli.it' target='_blank' rel='noopener'>https://alessiofrittoli.it</a> |
92
+ <a href='mailto:info@alessiofrittoli.it' target='_blank' rel='noopener'>info@alessiofrittoli.it</a>
93
+ </small>
94
+ </td>
95
+ </tr>
96
+ </tbody>
97
+ </table>
98
+ </td>
99
+ </tr>
100
+ </tbody>
101
+ </table>
@@ -0,0 +1,46 @@
1
+ declare class Stringified<T> extends String {
2
+ private ___stringified;
3
+ }
4
+ declare global {
5
+ interface JSON {
6
+ stringify<T>(value: T, replacer?: (key: string, value: any) => any, space?: string | number): string & Stringified<T>;
7
+ parse<T>(text: string | Stringified<T>, reviver?: (key: any, value: any) => any): T;
8
+ parse(text: string, reviver?: (key: any, value: any) => any): any;
9
+ }
10
+ interface Body {
11
+ json<T = any>(): Promise<T>;
12
+ }
13
+ }
14
+
15
+ declare global {
16
+ /**
17
+ * Get the Type of the Value of a object/array property.
18
+ */
19
+ type ValueOf<T> = T[keyof T];
20
+ /**
21
+ * Get the Type of the Value of object/array specific property.
22
+ */
23
+ type ValueOfKey<T, P extends keyof T> = T[P];
24
+ /**
25
+ * Make a specific property optional.
26
+ */
27
+ type OptionalKey<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
28
+ /**
29
+ * Make read-only properties of an object recursively writeable.
30
+ */
31
+ type Writeable<T> = {
32
+ -readonly [P in keyof T]: Writeable<T[P]>;
33
+ };
34
+ /**
35
+ * Renames a property while inheriting its type.
36
+ */
37
+ type RenameKey<T, K extends keyof T, R extends PropertyKey> = Omit<T, K> & {
38
+ [P in R]: T[K];
39
+ };
40
+ /** Get the Type of a function arguments. */
41
+ type ArgumentTypes<F extends Function> = F extends (...args: infer A) => any ? A : never;
42
+ }
43
+
44
+ type DoNotUse = never;
45
+
46
+ export type { DoNotUse };
@@ -0,0 +1,46 @@
1
+ declare class Stringified<T> extends String {
2
+ private ___stringified;
3
+ }
4
+ declare global {
5
+ interface JSON {
6
+ stringify<T>(value: T, replacer?: (key: string, value: any) => any, space?: string | number): string & Stringified<T>;
7
+ parse<T>(text: string | Stringified<T>, reviver?: (key: any, value: any) => any): T;
8
+ parse(text: string, reviver?: (key: any, value: any) => any): any;
9
+ }
10
+ interface Body {
11
+ json<T = any>(): Promise<T>;
12
+ }
13
+ }
14
+
15
+ declare global {
16
+ /**
17
+ * Get the Type of the Value of a object/array property.
18
+ */
19
+ type ValueOf<T> = T[keyof T];
20
+ /**
21
+ * Get the Type of the Value of object/array specific property.
22
+ */
23
+ type ValueOfKey<T, P extends keyof T> = T[P];
24
+ /**
25
+ * Make a specific property optional.
26
+ */
27
+ type OptionalKey<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
28
+ /**
29
+ * Make read-only properties of an object recursively writeable.
30
+ */
31
+ type Writeable<T> = {
32
+ -readonly [P in keyof T]: Writeable<T[P]>;
33
+ };
34
+ /**
35
+ * Renames a property while inheriting its type.
36
+ */
37
+ type RenameKey<T, K extends keyof T, R extends PropertyKey> = Omit<T, K> & {
38
+ [P in R]: T[K];
39
+ };
40
+ /** Get the Type of a function arguments. */
41
+ type ArgumentTypes<F extends Function> = F extends (...args: infer A) => any ? A : never;
42
+ }
43
+
44
+ type DoNotUse = never;
45
+
46
+ export type { DoNotUse };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';
package/dist/index.mjs ADDED
File without changes
package/license.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Alessio Frittoli.
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/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@alessiofrittoli/type-utils",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Lightweight TypeScript types utilities",
5
+ "author": {
6
+ "name": "Alessio Frittoli",
7
+ "email": "info@alessiofrittoli.it",
8
+ "url": "https://alessiofrittoli.it"
9
+ },
10
+ "license": "MIT",
11
+ "keywords": [
12
+ "typescript"
13
+ ],
14
+ "homepage": "https://github.com/alessiofrittoli/type-utils#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/alessiofrittoli/type-utils/issues",
17
+ "email": "info@alessiofrittoli.it"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/alessiofrittoli/type-utils.git"
22
+ },
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "build": "eslint && tsup",
30
+ "lint": "eslint",
31
+ "postinstall": "node scripts/postinstall.js"
32
+ },
33
+ "devDependencies": {
34
+ "@eslint/js": "^9.15.0",
35
+ "@types/node": "^22.9.3",
36
+ "eslint": "^9.15.0",
37
+ "globals": "^15.12.0",
38
+ "tsup": "^8.3.5",
39
+ "typescript": "^5.6.3",
40
+ "typescript-eslint": "^8.15.0"
41
+ }
42
+ }