type-fest
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -53,2 +53,3 @@ // Basic | ||
export type {Jsonify} from './source/jsonify'; | ||
export type {Jsonifiable} from './source/jsonifiable'; | ||
export type {Schema} from './source/schema'; | ||
@@ -55,0 +56,0 @@ export type {LiteralToPrimitive} from './source/literal-to-primitive'; |
{ | ||
"name": "type-fest", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "A collection of essential TypeScript types", | ||
@@ -38,6 +38,6 @@ "license": "(MIT OR CC0-1.0)", | ||
"@sindresorhus/tsconfig": "~0.7.0", | ||
"expect-type": "^0.14.2", | ||
"expect-type": "^0.15.0", | ||
"tsd": "^0.24.1", | ||
"typescript": "^4.8.3", | ||
"xo": "^0.52.2" | ||
"typescript": "^4.8.4", | ||
"xo": "^0.52.4" | ||
}, | ||
@@ -44,0 +44,0 @@ "xo": { |
@@ -190,2 +190,3 @@ <div align="center"> | ||
- [`Jsonify`](source/jsonify.d.ts) - Transform a type to one that is assignable to the `JsonValue` type. | ||
- [`Jsonifiable`](source/jsonifiable.d.ts) - Matches a value that can be losslessly converted to JSON. | ||
- [`JsonPrimitive`](source/basic.d.ts) - Matches a JSON primitive. | ||
@@ -217,3 +218,3 @@ - [`JsonObject`](source/basic.d.ts) - Matches a JSON object. | ||
- [`ReadonlyTuple`](source/readonly-tuple.d.ts) - Create a type that represents a read-only tuple of the given type and length. | ||
- [`TupleToUnion`](source/tuple-to-union.d.ts) - Convert a tuple into a union type of its elements. | ||
- [`TupleToUnion`](source/tuple-to-union.d.ts) - Convert a tuple/array into a union type of its elements. | ||
@@ -220,0 +221,0 @@ ### Numeric |
@@ -1,31 +0,32 @@ | ||
import type {WordSeparators} from '../source/internal'; | ||
import type {Split} from './split'; | ||
import type {SplitWords} from './split-words'; | ||
/** | ||
Step by step takes the first item in an array literal, formats it and adds it to a string literal, and then recursively appends the remainder. | ||
CamelCase options. | ||
Only to be used by `CamelCaseStringArray<>`. | ||
@see CamelCaseStringArray | ||
@see {@link CamelCase} | ||
*/ | ||
type InnerCamelCaseStringArray<Parts extends readonly any[], PreviousPart> = | ||
Parts extends [`${infer FirstPart}`, ...infer RemainingParts] | ||
? FirstPart extends undefined | ||
? '' | ||
: FirstPart extends '' | ||
? InnerCamelCaseStringArray<RemainingParts, PreviousPart> | ||
: `${PreviousPart extends '' ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}` | ||
: ''; | ||
export type CamelCaseOptions = { | ||
/** | ||
Whether to preserved consecutive uppercase letter. | ||
@default true | ||
*/ | ||
preserveConsecutiveUppercase?: boolean; | ||
}; | ||
/** | ||
Starts fusing the output of `Split<>`, an array literal of strings, into a camel-cased string literal. | ||
It's separate from `InnerCamelCaseStringArray<>` to keep a clean API outwards to the rest of the code. | ||
@see Split | ||
Convert an array of words to camel-case. | ||
*/ | ||
type CamelCaseStringArray<Parts extends readonly string[]> = | ||
Parts extends [`${infer FirstPart}`, ...infer RemainingParts] | ||
? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`> | ||
: never; | ||
type CamelCaseFromArray< | ||
Words extends string[], | ||
Options extends CamelCaseOptions, | ||
OutputString extends string = '', | ||
> = Words extends [ | ||
infer FirstWord extends string, | ||
...infer RemainingWords extends string[], | ||
] | ||
? Options['preserveConsecutiveUppercase'] extends true | ||
? `${Capitalize<FirstWord>}${CamelCaseFromArray<RemainingWords, Options>}` | ||
: `${Capitalize<Lowercase<FirstWord>>}${CamelCaseFromArray<RemainingWords, Options>}` | ||
: OutputString; | ||
@@ -37,2 +38,4 @@ /** | ||
By default, consecutive uppercase letter are preserved. See {@link CamelCaseOptions.preserveConsecutiveUppercase preserveConsecutiveUppercase} option to change this behaviour. | ||
@example | ||
@@ -74,2 +77,4 @@ ``` | ||
*/ | ||
export type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K extends Uppercase<K> ? Lowercase<K> : K, WordSeparators>> : K; | ||
export type CamelCase<Type, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Type extends string | ||
? Uncapitalize<CamelCaseFromArray<SplitWords<Type extends Uppercase<Type> ? Lowercase<Type> : Type>, Options>> | ||
: Type; |
@@ -1,2 +0,2 @@ | ||
import type {CamelCase} from './camel-case'; | ||
import type {CamelCase, CamelCaseOptions} from './camel-case'; | ||
@@ -47,9 +47,9 @@ /** | ||
*/ | ||
export type CamelCasedPropertiesDeep<Value> = Value extends Function | ||
export type CamelCasedPropertiesDeep<Value, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Value extends Function | ||
? Value | ||
: Value extends Array<infer U> | ||
? Array<CamelCasedPropertiesDeep<U>> | ||
? Array<CamelCasedPropertiesDeep<U, Options>> | ||
: Value extends Set<infer U> | ||
? Set<CamelCasedPropertiesDeep<U>> : { | ||
[K in keyof Value as CamelCase<K>]: CamelCasedPropertiesDeep<Value[K]>; | ||
? Set<CamelCasedPropertiesDeep<U, Options>> : { | ||
[K in keyof Value as CamelCase<K, Options>]: CamelCasedPropertiesDeep<Value[K], Options>; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import type {CamelCase} from './camel-case'; | ||
import type {CamelCase, CamelCaseOptions} from './camel-case'; | ||
@@ -30,3 +30,3 @@ /** | ||
*/ | ||
export type CamelCasedProperties<Value> = Value extends Function | ||
export type CamelCasedProperties<Value, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Value extends Function | ||
? Value | ||
@@ -36,3 +36,3 @@ : Value extends Array<infer U> | ||
: { | ||
[K in keyof Value as CamelCase<K>]: Value[K]; | ||
[K in keyof Value as CamelCase<K, Options>]: Value[K]; | ||
}; |
import type {UpperCaseCharacters, WordSeparators} from '../source/internal'; | ||
// Transforms a string that is fully uppercase into a fully lowercase version. Needed to add support for SCREMAING_SNAKE_CASE, see https://github.com/sindresorhus/type-fest/issues/385 | ||
// Transforms a string that is fully uppercase into a fully lowercase version. Needed to add support for SCREAMING_SNAKE_CASE, see https://github.com/sindresorhus/type-fest/issues/385 | ||
type UpperCaseToLowerCase<T extends string> = T extends Uppercase<T> ? Lowercase<T> : T; | ||
// This implemntation does not supports SCREMAING_SNAKE_CASE, it used internaly by `SplitIncludingDelimiters`. | ||
// This implementation does not support SCREAMING_SNAKE_CASE, it is used internally by `SplitIncludingDelimiters`. | ||
type SplitIncludingDelimiters_<Source extends string, Delimiter extends string> = | ||
@@ -8,0 +8,0 @@ Source extends '' ? [] : |
@@ -22,3 +22,3 @@ import type {Simplify} from './simplify'; | ||
``` | ||
import type {Merge} from 'type-fest'; | ||
import type {EnforceOptional} from 'type-fest'; | ||
@@ -25,0 +25,0 @@ type Foo = { |
@@ -9,3 +9,3 @@ /** | ||
Please participate in [this issue](https://github.com/microsoft/TypeScript/issues/26223) if you want to have a similiar type built into TypeScript. | ||
Please participate in [this issue](https://github.com/microsoft/TypeScript/issues/26223) if you want to have a similar type built into TypeScript. | ||
@@ -12,0 +12,0 @@ Use-cases: |
@@ -96,1 +96,16 @@ import type {Primitive} from './primitive'; | ||
export type ArrayTail<TArray extends UnknownArrayOrTuple> = TArray extends readonly [unknown, ...infer TTail] ? TTail : []; | ||
/** | ||
Returns a boolean for whether the string is lowercased. | ||
*/ | ||
export type IsLowerCase<T extends string> = T extends Lowercase<T> ? true : false; | ||
/** | ||
Returns a boolean for whether the string is uppercased. | ||
*/ | ||
export type IsUpperCase<T extends string> = T extends Uppercase<T> ? true : false; | ||
/** | ||
Returns a boolean for whether the string is numeric. | ||
*/ | ||
export type IsNumeric<T extends string> = T extends `${number}` ? true : false; |
import type {JsonPrimitive, JsonValue} from './basic'; | ||
import type {EmptyObject} from './empty-object'; | ||
import type {Merge} from './merge'; | ||
@@ -98,3 +99,3 @@ import type {NegativeInfinity, PositiveInfinity} from './numeric'; | ||
? J // Then T is Jsonable and its Jsonable value is J | ||
: never // Not Jsonable because its toJSON() method does not return JsonValue | ||
: Jsonify<J> // Maybe if we look a level deeper we'll find a JsonValue | ||
// Instanced primitives are objects | ||
@@ -104,3 +105,3 @@ : T extends Number ? number | ||
: T extends Boolean ? boolean | ||
: T extends Map<any, any> | Set<any> ? {} | ||
: T extends Map<any, any> | Set<any> ? EmptyObject | ||
: T extends TypedArray ? Record<string, number> | ||
@@ -107,0 +108,0 @@ : T extends any[] |
@@ -16,3 +16,3 @@ import type {ConditionalSimplifyDeep} from './conditional-simplify'; | ||
/** | ||
Deeply smplifies an object excluding iterables and functions. Used internally to improve the UX and accept both interfaces and type aliases as inputs. | ||
Deeply simplifies an object excluding iterables and functions. Used internally to improve the UX and accept both interfaces and type aliases as inputs. | ||
*/ | ||
@@ -204,3 +204,3 @@ type SimplifyDeep<Type> = ConditionalSimplifyDeep<Type, Function | Iterable<unknown>, object>; | ||
/** | ||
Test if it sould spread top-level arrays. | ||
Test if it should spread top-level arrays. | ||
*/ | ||
@@ -207,0 +207,0 @@ type ShouldSpread<Options extends MergeDeepInternalOptions> = Options['spreadTopLevelArrays'] extends false |
@@ -11,3 +11,3 @@ declare global { | ||
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021. | ||
As well, some guideance on making an `Observable` do not include `closed` propery. | ||
As well, some guidance on making an `Observable` to not include `closed` property. | ||
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130 | ||
@@ -14,0 +14,0 @@ @see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85 |
@@ -243,3 +243,3 @@ import type {LiteralUnion} from './literal-union'; | ||
export type Imports = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style | ||
[key: string]: string | {[key in ExportCondition]: Exports}; | ||
[key: `#${string}`]: string | {[key in ExportCondition]: Exports}; | ||
}; | ||
@@ -246,0 +246,0 @@ |
@@ -32,3 +32,2 @@ /** | ||
}, | ||
phoneNumbers: 'mask', | ||
created: 'show', | ||
@@ -35,0 +34,0 @@ active: 'show', |
/** | ||
Convert a tuple into a union type of its elements. | ||
Convert a tuple/array into a union type of its elements. | ||
@@ -51,2 +51,2 @@ This can be useful when you have a fixed set of allowed values and want a type defining only the allowed values, but do not want to repeat yourself. | ||
*/ | ||
export type TupleToUnion<ArrayType> = ArrayType extends readonly [infer Head, ...(infer Rest)] ? Head | TupleToUnion<Rest> : never; | ||
export type TupleToUnion<ArrayType> = ArrayType extends readonly unknown[] ? ArrayType[number] : never; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237975
88
5458
917