@ptolemy2002/ts-utils 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/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Typescript Utils
2
+ This library contains a collection of utility types and functions for use in Typescript projects.
3
+
4
+ The types and functions are not exported as default, so you can import them in one of the following ways:
5
+ ```javascript
6
+ // ES6
7
+ import { functionName } from '@ptolemy2002/ts-utils';
8
+ // CommonJS
9
+ const { functionName } = require('@ptolemy2002/ts-utils');
10
+ ```
11
+
12
+ ## Types
13
+ The following types are available in the library:
14
+
15
+ ### ValueOf<T>
16
+ This type returns a union of every possible value in an object of type `T`.
17
+
18
+ ### MaybeTransformer<T, Args extends any[] = []>
19
+ Given a type `T`, this type returns a union of that type itself and a function that takes the specified arguments and returns the type `T`.
20
+
21
+ ### MaybeTransformerRecord<T, Args extends any[] = []>
22
+ Given a type `T`, this type loops through every key `K` and wraps that key's value in a `MaybeTransformer` with the specified arguments.
23
+
24
+ ### MaybePromise<T>
25
+ This type returns a union of the type `T` and a promise that resolves to the type `T`.
26
+
27
+ ### TAndOthers<T, K extends keyof any = PropertyKey>
28
+ This type returns an object with all the properties of `T` and any number of other properties under keys that fit the type `K`. The additional properties will all have the type `any` because I couldn't figure out how to make them have a type that does not include `ValueOf<T>` due to the way Typescript handles mapped object types.
29
+
30
+ ## Peer Dependencies
31
+ None
32
+
33
+ ## Commands
34
+ The following commands exist in the project:
35
+
36
+ - `npm run uninstall` - Uninstalls all dependencies for the library
37
+ - `npm run reinstall` - Uninstalls and then Reinstalls all dependencies for the library
38
+ - `npm run example-uninstall` - Uninstalls all dependencies for the example app
39
+ - `npm run example-install` - Installs all dependencies for the example app
40
+ - `npm run example-reinstall` - Uninstalls and then Reinstalls all dependencies for the example app
41
+ - `npm run example-start` - Starts the example app after building the library
42
+ - `npm run build` - Builds the library
43
+ - `npm run release` - Publishes the library to npm without changing the version
44
+ - `npm run release-patch` - Publishes the library to npm with a patch version bump
45
+ - `npm run release-minor` - Publishes the library to npm with a minor version bump
46
+ - `npm run release-major` - Publishes the library to npm with a major version bump
@@ -0,0 +1,7 @@
1
+ export type ValueOf<T> = T[keyof T];
2
+ export type MaybeTransformer<T, Args extends any[] = []> = T | ((...args: Args) => T);
3
+ export type MaybeTransformerRecord<T, Args extends any[] = []> = {
4
+ [K in keyof T]: MaybeTransformer<T[K], Args>;
5
+ };
6
+ export type MaybePromise<T> = T | Promise<T>;
7
+ export type TAndOthers<T, K extends keyof any = PropertyKey> = Record<K, any> & T;
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@ptolemy2002/ts-utils",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/Ptolemy2002/ts-utils",
13
+ "directory": "lib"
14
+ },
15
+ "scripts": {
16
+ "build": "tsc --project ./tsconfig.json",
17
+ "postinstall": "npx typesync",
18
+ "uninstall": "bash ./scripts/uninstall.sh",
19
+ "reinstall": "bash ./scripts/reinstall.sh",
20
+ "example-uninstall": "bash ./scripts/example-uninstall.sh",
21
+ "example-install": "bash ./scripts/example-install.sh",
22
+ "example-reinstall": "bash ./scripts/example-reinstall.sh",
23
+ "example-start": "bash ./scripts/example-start.sh",
24
+ "release": "bash ./scripts/release.sh",
25
+ "release-patch": "bash ./scripts/release.sh patch",
26
+ "release-minor": "bash ./scripts/release.sh minor",
27
+ "release-major": "bash ./scripts/release.sh major"
28
+ },
29
+ "devDependencies": {}
30
+ }