type-fest 1.1.0 → 1.2.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/package.json +1 -1
- package/readme.md +1 -0
- package/source/async-return-type.d.ts +2 -0
- package/source/asyncify.d.ts +2 -0
- package/source/basic.d.ts +8 -0
- package/source/conditional-except.d.ts +2 -0
- package/source/conditional-keys.d.ts +2 -0
- package/source/conditional-pick.d.ts +2 -0
- package/source/entries.d.ts +2 -0
- package/source/entry.d.ts +2 -0
- package/source/except.d.ts +2 -0
- package/source/fixed-length-array.d.ts +2 -0
- package/source/iterable-element.d.ts +2 -0
- package/source/literal-union.d.ts +2 -0
- package/source/merge-exclusive.d.ts +2 -0
- package/source/merge.d.ts +2 -0
- package/source/mutable.d.ts +2 -0
- package/source/observable-like.d.ts +2 -0
- package/source/opaque.d.ts +2 -0
- package/source/package-json.d.ts +3 -0
- package/source/partial-deep.d.ts +2 -0
- package/source/primitive.d.ts +2 -0
- package/source/promisable.d.ts +2 -0
- package/source/promise-value.d.ts +2 -0
- package/source/readonly-deep.d.ts +2 -0
- package/source/require-at-least-one.d.ts +2 -0
- package/source/require-exactly-one.d.ts +2 -0
- package/source/set-optional.d.ts +2 -0
- package/source/set-required.d.ts +2 -0
- package/source/set-return-type.d.ts +2 -0
- package/source/stringified.d.ts +2 -0
- package/source/tsconfig-json.d.ts +5 -0
- package/source/typed-array.d.ts +4 -0
- package/source/union-to-intersection.d.ts +2 -0
- package/source/value-of.d.ts +2 -0
- package/ts41/camel-case.d.ts +2 -0
- package/ts41/camel-cased-properties-deep.d.ts +2 -0
- package/ts41/camel-cased-properties.d.ts +2 -0
- package/ts41/delimiter-case.d.ts +4 -1
- package/ts41/delimiter-cased-properties-deep.d.ts +2 -0
- package/ts41/delimiter-cased-properties.d.ts +2 -0
- package/ts41/get.d.ts +2 -0
- package/ts41/index.d.ts +1 -0
- package/ts41/kebab-case.d.ts +2 -1
- package/ts41/kebab-cased-properties-deep.d.ts +2 -0
- package/ts41/kebab-cased-properties.d.ts +2 -0
- package/ts41/last-array-element.d.ts +2 -0
- package/ts41/pascal-case.d.ts +2 -1
- package/ts41/pascal-cased-properties-deep.d.ts +2 -0
- package/ts41/pascal-cased-properties.d.ts +2 -0
- package/ts41/screaming-snake-case.d.ts +40 -0
- package/ts41/snake-case.d.ts +2 -0
- package/ts41/snake-cased-properties-deep.d.ts +2 -0
- package/ts41/snake-cased-properties.d.ts +2 -0
- package/ts41/split.d.ts +2 -0
- package/ts41/trim.d.ts +2 -0
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -136,6 +136,7 @@ Click the type names for complete docs.
|
|
|
136
136
|
- [`SnakeCase`](ts41/snake-case.d.ts) – Convert a string literal to snake-case (`foo_bar`).
|
|
137
137
|
- [`SnakeCasedProperties`](ts41/snake-cased-properties-deep.d.ts) – Convert object properties to snake-case (`foo_bar`).
|
|
138
138
|
- [`SnakeCasedPropertiesDeep`](ts41/snake-cased-properties-deep.d.ts) – Convert object properties to snake-case recursively (`foo_bar`).
|
|
139
|
+
- [`ScreamingSnakeCase`](ts41/screaming-snake-case.d.ts) - Convert a string literal to screaming-snake-case (`FOO_BAR`).
|
|
139
140
|
- [`DelimiterCase`](ts41/delimiter-case.d.ts) – Convert a string literal to a custom string delimiter casing.
|
|
140
141
|
- [`DelimiterCasedProperties`](ts41/delimiter-cased-properties.d.ts) – Convert object properties to a custom string delimiter casing.
|
|
141
142
|
- [`DelimiterCasedPropertiesDeep`](ts41/delimiter-cased-properties-deep.d.ts) – Convert object properties to a custom string delimiter casing recursively.
|
package/source/asyncify.d.ts
CHANGED
package/source/basic.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// TODO: Remove the `= unknown` sometime in the future when most users are on TS 3.5 as it's now the default
|
|
2
2
|
/**
|
|
3
3
|
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
4
|
+
|
|
5
|
+
@category Basic
|
|
4
6
|
*/
|
|
5
7
|
export type Class<T = unknown, Arguments extends any[] = any[]> = new(...arguments_: Arguments) => T;
|
|
6
8
|
|
|
@@ -8,11 +10,15 @@ export type Class<T = unknown, Arguments extends any[] = any[]> = new(...argumen
|
|
|
8
10
|
Matches a JSON object.
|
|
9
11
|
|
|
10
12
|
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
|
|
13
|
+
|
|
14
|
+
@category Basic
|
|
11
15
|
*/
|
|
12
16
|
export type JsonObject = {[Key in string]?: JsonValue};
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
Matches a JSON array.
|
|
20
|
+
|
|
21
|
+
@category Basic
|
|
16
22
|
*/
|
|
17
23
|
export interface JsonArray extends Array<JsonValue> {}
|
|
18
24
|
// TODO: Make it this when targeting TypeScript 4.1:
|
|
@@ -20,5 +26,7 @@ export interface JsonArray extends Array<JsonValue> {}
|
|
|
20
26
|
|
|
21
27
|
/**
|
|
22
28
|
Matches any valid JSON value.
|
|
29
|
+
|
|
30
|
+
@category Basic
|
|
23
31
|
*/
|
|
24
32
|
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
|
@@ -25,6 +25,8 @@ To support partial types, make sure your `Condition` is a union of undefined (fo
|
|
|
25
25
|
type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
|
26
26
|
//=> 'a' | 'c'
|
|
27
27
|
```
|
|
28
|
+
|
|
29
|
+
@category Utilities
|
|
28
30
|
*/
|
|
29
31
|
export type ConditionalKeys<Base, Condition> = NonNullable<
|
|
30
32
|
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
package/source/entries.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ const mapEntries: Entries<typeof map> = [['a', 1]];
|
|
|
48
48
|
const setExample = new Set(['a', 1]);
|
|
49
49
|
const setEntries: Entries<typeof setExample> = [['a', 'a'], [1, 1]];
|
|
50
50
|
```
|
|
51
|
+
|
|
52
|
+
@category Utilities
|
|
51
53
|
*/
|
|
52
54
|
export type Entries<BaseType> =
|
|
53
55
|
BaseType extends Map<unknown, unknown> ? MapEntries<BaseType>
|
package/source/entry.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ const setExample = new Set(['a', 1]);
|
|
|
51
51
|
const setEntryString: Entry<typeof setExample> = ['a', 'a'];
|
|
52
52
|
const setEntryNumber: Entry<typeof setExample> = [1, 1];
|
|
53
53
|
```
|
|
54
|
+
|
|
55
|
+
@category Utilities
|
|
54
56
|
*/
|
|
55
57
|
export type Entry<BaseType> =
|
|
56
58
|
BaseType extends Map<unknown, unknown> ? MapEntry<BaseType>
|
package/source/except.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ const homeFencingTeam: FencingTeam = ['George', 'John'];
|
|
|
27
27
|
guestFencingTeam.push('Sam');
|
|
28
28
|
//=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
|
|
29
29
|
```
|
|
30
|
+
|
|
31
|
+
@category Utilities
|
|
30
32
|
*/
|
|
31
33
|
export type FixedLengthArray<Element, Length extends number, ArrayPrototype = [Element, ...Element[]]> = Pick<
|
|
32
34
|
ArrayPrototype,
|
package/source/merge.d.ts
CHANGED
package/source/mutable.d.ts
CHANGED
package/source/opaque.d.ts
CHANGED
package/source/package-json.d.ts
CHANGED
|
@@ -227,6 +227,7 @@ declare namespace PackageJson {
|
|
|
227
227
|
*/
|
|
228
228
|
export type Exports =
|
|
229
229
|
| string
|
|
230
|
+
| string[]
|
|
230
231
|
| {[key in ExportCondition]: Exports}
|
|
231
232
|
| {[key: string]: Exports}; // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
|
|
232
233
|
|
|
@@ -628,6 +629,8 @@ declare namespace PackageJson {
|
|
|
628
629
|
|
|
629
630
|
/**
|
|
630
631
|
Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Also includes types for fields used by other popular projects, like TypeScript and Yarn.
|
|
632
|
+
|
|
633
|
+
@category Miscellaneous
|
|
631
634
|
*/
|
|
632
635
|
export type PackageJson =
|
|
633
636
|
PackageJson.PackageJsonStandard &
|
package/source/partial-deep.d.ts
CHANGED
package/source/primitive.d.ts
CHANGED
package/source/promisable.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ let syncData: SyncData = getSyncData();
|
|
|
21
21
|
type RecursiveAsyncData = Promise<Promise<string> >;
|
|
22
22
|
let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = Promise.resolve(Promise.resolve('ABC'));
|
|
23
23
|
```
|
|
24
|
+
|
|
25
|
+
@category Utilities
|
|
24
26
|
*/
|
|
25
27
|
export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
|
|
26
28
|
? { 0: PromiseValue<Value>; 1: Value }[PromiseType extends Promise<unknown> ? 0 : 1]
|
|
@@ -28,6 +28,8 @@ import data from './main';
|
|
|
28
28
|
data.foo.push('bar');
|
|
29
29
|
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
|
30
30
|
```
|
|
31
|
+
|
|
32
|
+
@category Utilities
|
|
31
33
|
*/
|
|
32
34
|
export type ReadonlyDeep<T> = T extends Primitive | ((...arguments: any[]) => unknown)
|
|
33
35
|
? T
|
package/source/set-optional.d.ts
CHANGED
package/source/set-required.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ type MyFunctionThatCanThrow = (foo: SomeType, bar: unknown) => SomeOtherType;
|
|
|
16
16
|
type MyWrappedFunction = SetReturnType<MyFunctionThatCanThrow, SomeOtherType | undefined>;
|
|
17
17
|
//=> type MyWrappedFunction = (foo: SomeType, bar: unknown) => SomeOtherType | undefined;
|
|
18
18
|
```
|
|
19
|
+
|
|
20
|
+
@category Utilities
|
|
19
21
|
*/
|
|
20
22
|
export type SetReturnType<Fn extends (...args: any[]) => any, TypeToReturn> =
|
|
21
23
|
// Just using `Parameters<Fn>` isn't ideal because it doesn't handle the `this` fake parameter.
|
package/source/stringified.d.ts
CHANGED
|
@@ -815,6 +815,11 @@ declare namespace TsConfigJson {
|
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
817
|
|
|
818
|
+
/**
|
|
819
|
+
Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 3.7).
|
|
820
|
+
|
|
821
|
+
@category Miscellaneous
|
|
822
|
+
*/
|
|
818
823
|
export interface TsConfigJson {
|
|
819
824
|
/**
|
|
820
825
|
Instructs the TypeScript compiler how to compile `.ts` files.
|
package/source/typed-array.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/// <reference lib="es2020.bigint"/>
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
|
5
|
+
|
|
6
|
+
@category Basic
|
|
3
7
|
*/
|
|
4
8
|
export type TypedArray =
|
|
5
9
|
| Int8Array
|
|
@@ -40,6 +40,8 @@ type Union = typeof union;
|
|
|
40
40
|
type Intersection = UnionToIntersection<Union>;
|
|
41
41
|
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
42
42
|
```
|
|
43
|
+
|
|
44
|
+
@category Utilities
|
|
43
45
|
*/
|
|
44
46
|
export type UnionToIntersection<Union> = (
|
|
45
47
|
// `extends unknown` is always going to be the case and is used to convert the
|
package/source/value-of.d.ts
CHANGED
package/ts41/camel-case.d.ts
CHANGED
package/ts41/delimiter-case.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import {UpperCaseCharacters, WordSeparators} from '../source/utilities';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
Unlike a simpler split, this one includes the delimiter splitted on in the resulting array literal. This is to enable splitting on, for example, upper-case characters.
|
|
5
|
+
|
|
6
|
+
@category Template Literals
|
|
5
7
|
*/
|
|
6
8
|
export type SplitIncludingDelimiters<Source extends string, Delimiter extends string> =
|
|
7
9
|
Source extends '' ? [] :
|
|
@@ -73,8 +75,9 @@ const rawCliOptions: OddlyCasedProperties<SomeOptions> = {
|
|
|
73
75
|
foo: 123
|
|
74
76
|
};
|
|
75
77
|
```
|
|
76
|
-
*/
|
|
77
78
|
|
|
79
|
+
@category Template Literals
|
|
80
|
+
*/
|
|
78
81
|
export type DelimiterCase<Value, Delimiter extends string> = Value extends string
|
|
79
82
|
? StringArrayToDelimiterCase<
|
|
80
83
|
SplitIncludingDelimiters<Value, WordSeparators | UpperCaseCharacters>,
|
package/ts41/get.d.ts
CHANGED
|
@@ -127,5 +127,7 @@ const getName = (apiResponse: ApiResponse) =>
|
|
|
127
127
|
get(apiResponse, 'hits.hits[0]._source.name');
|
|
128
128
|
//=> Array<{given: string[]; family: string}>
|
|
129
129
|
```
|
|
130
|
+
|
|
131
|
+
@category Template Literals
|
|
130
132
|
*/
|
|
131
133
|
export type Get<BaseType, Path extends string> = GetWithPath<BaseType, ToPath<Path>>;
|
package/ts41/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export {PascalCasedPropertiesDeep} from './pascal-cased-properties-deep';
|
|
|
14
14
|
export {SnakeCase} from './snake-case';
|
|
15
15
|
export {SnakeCasedProperties} from './snake-cased-properties';
|
|
16
16
|
export {SnakeCasedPropertiesDeep} from './snake-cased-properties-deep';
|
|
17
|
+
export {ScreamingSnakeCase} from './screaming-snake-case';
|
|
17
18
|
export {DelimiterCase} from './delimiter-case';
|
|
18
19
|
export {DelimiterCasedProperties} from './delimiter-cased-properties';
|
|
19
20
|
export {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
|
package/ts41/kebab-case.d.ts
CHANGED
package/ts41/pascal-case.d.ts
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {SplitIncludingDelimiters} from './delimiter-case';
|
|
2
|
+
import {SnakeCase} from './snake-case';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Returns a boolean for whether the given array includes the given item.
|
|
6
|
+
*/
|
|
7
|
+
type Includes<Value extends any[], Item> = {
|
|
8
|
+
[P in keyof Value & number as Value[P]]: true;
|
|
9
|
+
}[Item] extends true
|
|
10
|
+
? true
|
|
11
|
+
: false;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
Returns a boolean for whether the string is screaming snake case.
|
|
15
|
+
*/
|
|
16
|
+
type IsScreamingSnakeCase<Value extends string> = Value extends Uppercase<Value>
|
|
17
|
+
? Includes<SplitIncludingDelimiters<Lowercase<Value>, '_'>, '_'> extends true
|
|
18
|
+
? true
|
|
19
|
+
: false
|
|
20
|
+
: false;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
Convert a string literal to screaming-snake-case.
|
|
24
|
+
|
|
25
|
+
This can be useful when, for example, converting a camel-cased object property to a screaming-snake-cased SQL column name.
|
|
26
|
+
|
|
27
|
+
@example
|
|
28
|
+
```
|
|
29
|
+
import {ScreamingSnakeCase} from 'type-fest';
|
|
30
|
+
|
|
31
|
+
const someVariable: ScreamingSnakeCase<'fooBar'> = 'FOO_BAR';
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
@category Template Literals
|
|
35
|
+
*/
|
|
36
|
+
export type ScreamingSnakeCase<Value> = Value extends string
|
|
37
|
+
? IsScreamingSnakeCase<Value> extends true
|
|
38
|
+
? Value
|
|
39
|
+
: Uppercase<SnakeCase<Value>>
|
|
40
|
+
: Value;
|
package/ts41/snake-case.d.ts
CHANGED
package/ts41/split.d.ts
CHANGED