Commit d27c335f authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

update required modules

parent e7c08cdb
import {LiteralUnion} from './literal-union';
declare namespace PackageJson {
/**
A person who has been involved in creating or maintaining the package.
*/
export type Person =
| string
| {
name: string;
url?: string;
email?: string;
};
export type BugsLocation =
| string
| {
/**
The URL to the package's issue tracker.
*/
url?: string;
/**
The email address to which issues should be reported.
*/
email?: string;
};
export interface DirectoryLocations {
[directoryType: string]: unknown;
/**
Location for executable scripts. Sugar to generate entries in the `bin` property by walking the folder.
*/
bin?: string;
/**
Location for Markdown files.
*/
doc?: string;
/**
Location for example scripts.
*/
example?: string;
/**
Location for the bulk of the library.
*/
lib?: string;
/**
Location for man pages. Sugar to generate a `man` array by walking the folder.
*/
man?: string;
/**
Location for test files.
*/
test?: string;
}
export type Scripts = {
/**
Run **before** the package is published (Also run on local `npm install` without any arguments).
*/
prepublish?: string;
/**
Run both **before** the package is packed and published, and on local `npm install` without any arguments. This is run **after** `prepublish`, but **before** `prepublishOnly`.
*/
prepare?: string;
/**
Run **before** the package is prepared and packed, **only** on `npm publish`.
*/
prepublishOnly?: string;
/**
Run **before** a tarball is packed (on `npm pack`, `npm publish`, and when installing git dependencies).
*/
prepack?: string;
/**
Run **after** the tarball has been generated and moved to its final destination.
*/
postpack?: string;
/**
Run **after** the package is published.
*/
publish?: string;
/**
Run **after** the package is published.
*/
postpublish?: string;
/**
Run **before** the package is installed.
*/
preinstall?: string;
/**
Run **after** the package is installed.
*/
install?: string;
/**
Run **after** the package is installed and after `install`.
*/
postinstall?: string;
/**
Run **before** the package is uninstalled and before `uninstall`.
*/
preuninstall?: string;
/**
Run **before** the package is uninstalled.
*/
uninstall?: string;
/**
Run **after** the package is uninstalled.
*/
postuninstall?: string;
/**
Run **before** bump the package version and before `version`.
*/
preversion?: string;
/**
Run **before** bump the package version.
*/
version?: string;
/**
Run **after** bump the package version.
*/
postversion?: string;
/**
Run with the `npm test` command, before `test`.
*/
pretest?: string;
/**
Run with the `npm test` command.
*/
test?: string;
/**
Run with the `npm test` command, after `test`.
*/
posttest?: string;
/**
Run with the `npm stop` command, before `stop`.
*/
prestop?: string;
/**
Run with the `npm stop` command.
*/
stop?: string;
/**
Run with the `npm stop` command, after `stop`.
*/
poststop?: string;
/**
Run with the `npm start` command, before `start`.
*/
prestart?: string;
/**
Run with the `npm start` command.
*/
start?: string;
/**
Run with the `npm start` command, after `start`.
*/
poststart?: string;
/**
Run with the `npm restart` command, before `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
*/
prerestart?: string;
/**
Run with the `npm restart` command. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
*/
restart?: string;
/**
Run with the `npm restart` command, after `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
*/
postrestart?: string;
} & Record<string, string>;
/**
Dependencies of the package. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or Git URL.
*/
export type Dependency = Record<string, string>;
/**
Conditions which provide a way to resolve a package entry point based on the environment.
*/
export type ExportCondition = LiteralUnion<
| 'import'
| 'require'
| 'node'
| 'deno'
| 'browser'
| 'electron'
| 'react-native'
| 'default',
string
>;
/**
Entry points of a module, optionally with conditions and subpath exports.
*/
export type Exports =
| string
| {[key in ExportCondition]: Exports}
| {[key: string]: Exports}; // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
export interface NonStandardEntryPoints {
/**
An ECMAScript module ID that is the primary entry point to the program.
*/
module?: string;
/**
A module ID with untranspiled code that is the primary entry point to the program.
*/
esnext?:
| string
| {
[moduleName: string]: string | undefined;
main?: string;
browser?: string;
};
/**
A hint to JavaScript bundlers or component tools when packaging modules for client side use.
*/
browser?:
| string
| Record<string, string | false>;
/**
Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused.
[Read more.](https://webpack.js.org/guides/tree-shaking/)
*/
sideEffects?: boolean | string[];
}
export interface TypeScriptConfiguration {
/**
Location of the bundled TypeScript declaration file.
*/
types?: string;
/**
Location of the bundled TypeScript declaration file. Alias of `types`.
*/
typings?: string;
}
/**
An alternative configuration for Yarn workspaces.
*/
export interface WorkspaceConfig {
/**
An array of workspace pattern strings which contain the workspace packages.
*/
packages?: WorkspacePattern[];
/**
Designed to solve the problem of packages which break when their `node_modules` are moved to the root workspace directory - a process known as hoisting. For these packages, both within your workspace, and also some that have been installed via `node_modules`, it is important to have a mechanism for preventing the default Yarn workspace behavior. By adding workspace pattern strings here, Yarn will resume non-workspace behavior for any package which matches the defined patterns.
[Read more](https://classic.yarnpkg.com/blog/2018/02/15/nohoist/)
*/
nohoist?: WorkspacePattern[];
}
/**
A workspace pattern points to a directory or group of directories which contain packages that should be included in the workspace installation process.
The patterns are handled with [minimatch](https://github.com/isaacs/minimatch).
@example
`docs` → Include the docs directory and install its dependencies.
`packages/*` → Include all nested directories within the packages directory, like `packages/cli` and `packages/core`.
*/
type WorkspacePattern = string;
export interface YarnConfiguration {
/**
Used to configure [Yarn workspaces](https://classic.yarnpkg.com/docs/workspaces/).
Workspaces allow you to manage multiple packages within the same repository in such a way that you only need to run `yarn install` once to install all of them in a single pass.
Please note that the top-level `private` property of `package.json` **must** be set to `true` in order to use workspaces.
*/
workspaces?: WorkspacePattern[] | WorkspaceConfig;
/**
If your package only allows one version of a given dependency, and you’d like to enforce the same behavior as `yarn install --flat` on the command-line, set this to `true`.
Note that if your `package.json` contains `"flat": true` and other packages depend on yours (e.g. you are building a library rather than an app), those other packages will also need `"flat": true` in their `package.json` or be installed with `yarn install --flat` on the command-line.
*/
flat?: boolean;
/**
Selective version resolutions. Allows the definition of custom package versions inside dependencies without manual edits in the `yarn.lock` file.
*/
resolutions?: Dependency;
}
export interface JSPMConfiguration {
/**
JSPM configuration.
*/
jspm?: PackageJson;
}
/**
Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Containing standard npm properties.
*/
export interface PackageJsonStandard {
/**
The name of the package.
*/
name?: string;
/**
Package version, parseable by [`node-semver`](https://github.com/npm/node-semver).
*/
version?: string;
/**
Package description, listed in `npm search`.
*/
description?: string;
/**
Keywords associated with package, listed in `npm search`.
*/
keywords?: string[];
/**
The URL to the package's homepage.
*/
homepage?: LiteralUnion<'.', string>;
/**
The URL to the package's issue tracker and/or the email address to which issues should be reported.
*/
bugs?: BugsLocation;
/**
The license for the package.
*/
license?: string;
/**
The licenses for the package.
*/
licenses?: Array<{
type?: string;
url?: string;
}>;
author?: Person;
/**
A list of people who contributed to the package.
*/
contributors?: Person[];
/**
A list of people who maintain the package.
*/
maintainers?: Person[];
/**
The files included in the package.
*/
files?: string[];
/**
Resolution algorithm for importing ".js" files from the package's scope.
[Read more.](https://nodejs.org/api/esm.html#esm_package_json_type_field)
*/
type?: 'module' | 'commonjs';
/**
The module ID that is the primary entry point to the program.
*/
main?: string;
/**
Standard entry points of the package, with enhanced support for ECMAScript Modules.
[Read more.](https://nodejs.org/api/esm.html#esm_package_entry_points)
*/
exports?: Exports;
/**
The executable files that should be installed into the `PATH`.
*/
bin?:
| string
| Record<string, string>;
/**
Filenames to put in place for the `man` program to find.
*/
man?: string | string[];
/**
Indicates the structure of the package.
*/
directories?: DirectoryLocations;
/**
Location for the code repository.
*/
repository?:
| string
| {
type: string;
url: string;
/**
Relative path to package.json if it is placed in non-root directory (for example if it is part of a monorepo).
[Read more.](https://github.com/npm/rfcs/blob/latest/implemented/0010-monorepo-subdirectory-declaration.md)
*/
directory?: string;
};
/**
Script commands that are run at various times in the lifecycle of the package. The key is the lifecycle event, and the value is the command to run at that point.
*/
scripts?: Scripts;
/**
Is used to set configuration parameters used in package scripts that persist across upgrades.
*/
config?: Record<string, unknown>;
/**
The dependencies of the package.
*/
dependencies?: Dependency;
/**
Additional tooling dependencies that are not required for the package to work. Usually test, build, or documentation tooling.
*/
devDependencies?: Dependency;
/**
Dependencies that are skipped if they fail to install.
*/
optionalDependencies?: Dependency;
/**
Dependencies that will usually be required by the package user directly or via another dependency.
*/
peerDependencies?: Dependency;
/**
Indicate peer dependencies that are optional.
*/
peerDependenciesMeta?: Record<string, {optional: true}>;
/**
Package names that are bundled when the package is published.
*/
bundledDependencies?: string[];
/**
Alias of `bundledDependencies`.
*/
bundleDependencies?: string[];
/**
Engines that this package runs on.
*/
engines?: {
[EngineName in 'npm' | 'node' | string]: string;
};
/**
@deprecated
*/
engineStrict?: boolean;
/**
Operating systems the module runs on.
*/
os?: Array<LiteralUnion<
| 'aix'
| 'darwin'
| 'freebsd'
| 'linux'
| 'openbsd'
| 'sunos'
| 'win32'
| '!aix'
| '!darwin'
| '!freebsd'
| '!linux'
| '!openbsd'
| '!sunos'
| '!win32',
string
>>;
/**
CPU architectures the module runs on.
*/
cpu?: Array<LiteralUnion<
| 'arm'
| 'arm64'
| 'ia32'
| 'mips'
| 'mipsel'
| 'ppc'
| 'ppc64'
| 's390'
| 's390x'
| 'x32'
| 'x64'
| '!arm'
| '!arm64'
| '!ia32'
| '!mips'
| '!mipsel'
| '!ppc'
| '!ppc64'
| '!s390'
| '!s390x'
| '!x32'
| '!x64',
string
>>;
/**
If set to `true`, a warning will be shown if package is installed locally. Useful if the package is primarily a command-line application that should be installed globally.
@deprecated
*/
preferGlobal?: boolean;
/**
If set to `true`, then npm will refuse to publish it.
*/
private?: boolean;
/**
A set of config values that will be used at publish-time. It's especially handy to set the tag, registry or access, to ensure that a given package is not tagged with 'latest', published to the global public registry or that a scoped module is private by default.
*/
publishConfig?: Record<string, unknown>;
/**
Describes and notifies consumers of a package's monetary support information.
[Read more.](https://github.com/npm/rfcs/blob/latest/accepted/0017-add-funding-support.md)
*/
funding?: string | {
/**
The type of funding.
*/
type?: LiteralUnion<
| 'github'
| 'opencollective'
| 'patreon'
| 'individual'
| 'foundation'
| 'corporation',
string
>;
/**
The URL to the funding page.
*/
url: string;
};
}
}
/**
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.
*/
export type PackageJson =
PackageJson.PackageJsonStandard &
PackageJson.NonStandardEntryPoints &
PackageJson.TypeScriptConfiguration &
PackageJson.YarnConfiguration &
PackageJson.JSPMConfiguration;
import {Primitive} from './basic';
/**
Create a type from another type with all keys and nested keys set to optional.
Use-cases:
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
@example
```
import {PartialDeep} from 'type-fest';
const settings: Settings = {
textEditor: {
fontSize: 14;
fontColor: '#000000';
fontWeight: 400;
}
autocomplete: false;
autosave: true;
};
const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
return {...settings, ...savedSettings};
}
settings = applySavedSettings({textEditor: {fontWeight: 500}});
```
*/
export type PartialDeep<T> = T extends Primitive
? Partial<T>
: T extends Map<infer KeyType, infer ValueType>
? PartialMapDeep<KeyType, ValueType>
: T extends Set<infer ItemType>
? PartialSetDeep<ItemType>
: T extends ReadonlyMap<infer KeyType, infer ValueType>
? PartialReadonlyMapDeep<KeyType, ValueType>
: T extends ReadonlySet<infer ItemType>
? PartialReadonlySetDeep<ItemType>
: T extends ((...arguments: any[]) => unknown)
? T | undefined
: T extends object
? PartialObjectDeep<T>
: unknown;
/**
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
*/
interface PartialMapDeep<KeyType, ValueType> extends Map<PartialDeep<KeyType>, PartialDeep<ValueType>> {}
/**
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
*/
interface PartialSetDeep<T> extends Set<PartialDeep<T>> {}
/**
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
*/
interface PartialReadonlyMapDeep<KeyType, ValueType> extends ReadonlyMap<PartialDeep<KeyType>, PartialDeep<ValueType>> {}
/**
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
*/
interface PartialReadonlySetDeep<T> extends ReadonlySet<PartialDeep<T>> {}
/**
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
*/
type PartialObjectDeep<ObjectType extends object> = {
[KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType]>
};
/**
Create a type that represents either the value or the value wrapped in `PromiseLike`.
Use-cases:
- A function accepts a callback that may either return a value synchronously or may return a promised value.
- This type could be the return type of `Promise#then()`, `Promise#catch()`, and `Promise#finally()` callbacks.
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31394) if you want to have this type as a built-in in TypeScript.
@example
```
import {Promisable} from 'type-fest';
async function logger(getLogEntry: () => Promisable<string>): Promise<void> {
const entry = await getLogEntry();
console.log(entry);
}
logger(() => 'foo');
logger(() => Promise.resolve('bar'));
```
*/
export type Promisable<T> = T | PromiseLike<T>;
/**
Returns the type that is wrapped inside a `Promise` type.
If the type is a nested Promise, it is unwrapped recursively until a non-Promise type is obtained.
If the type is not a `Promise`, the type itself is returned.
@example
```
import {PromiseValue} from 'type-fest';
type AsyncData = Promise<string>;
let asyncData: PromiseValue<AsyncData> = Promise.resolve('ABC');
type Data = PromiseValue<AsyncData>;
let data: Data = await asyncData;
// Here's an example that shows how this type reacts to non-Promise types.
type SyncData = PromiseValue<string>;
let syncData: SyncData = getSyncData();
// Here's an example that shows how this type reacts to recursive Promise types.
type RecursiveAsyncData = Promise<Promise<string> >;
let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = Promise.resolve(Promise.resolve('ABC'));
```
*/
export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
? { 0: PromiseValue<Value>; 1: Value }[PromiseType extends Promise<unknown> ? 0 : 1]
: Otherwise;
import {Primitive} from './basic';
/**
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
@example
```
// data.json
{
"foo": ["bar"]
}
// main.ts
import {ReadonlyDeep} from 'type-fest';
import dataJson = require('./data.json');
const data: ReadonlyDeep<typeof dataJson> = dataJson;
export default data;
// test.ts
import data from './main';
data.foo.push('bar');
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
```
*/
export type ReadonlyDeep<T> = T extends Primitive | ((...arguments: any[]) => unknown)
? T
: T extends ReadonlyMap<infer KeyType, infer ValueType>
? ReadonlyMapDeep<KeyType, ValueType>
: T extends ReadonlySet<infer ItemType>
? ReadonlySetDeep<ItemType>
: T extends object
? ReadonlyObjectDeep<T>
: unknown;
/**
Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
*/
interface ReadonlyMapDeep<KeyType, ValueType>
extends ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>> {}
/**
Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
*/
interface ReadonlySetDeep<ItemType>
extends ReadonlySet<ReadonlyDeep<ItemType>> {}
/**
Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
*/
type ReadonlyObjectDeep<ObjectType extends object> = {
readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
};
import {Except} from './except';
/**
Create a type that requires at least one of the given keys. The remaining keys are kept as is.
@example
```
import {RequireAtLeastOne} from 'type-fest';
type Responder = {
text?: () => string;
json?: () => string;
secure?: boolean;
};
const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
json: () => '{"message": "ok"}',
secure: true
};
```
*/
export type RequireAtLeastOne<
ObjectType,
KeysType extends keyof ObjectType = keyof ObjectType
> = {
// For each `Key` in `KeysType` make a mapped type:
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> & // 1. Make `Key`'s type required
// 2. Make all other keys in `KeysType` optional
Partial<Pick<ObjectType, Exclude<KeysType, Key>>>;
}[KeysType] &
// 3. Add the remaining keys not in `KeysType`
Except<ObjectType, KeysType>;
// TODO: Remove this when we target TypeScript >=3.5.
type _Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
/**
Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
Use-cases:
- Creating interfaces for components that only need one of the keys to display properly.
- Declaring generic keys in a single place for a single use-case that gets narrowed down via `RequireExactlyOne`.
The caveat with `RequireExactlyOne` is that TypeScript doesn't always know at compile time every key that will exist at runtime. Therefore `RequireExactlyOne` can't do anything to prevent extra keys it doesn't know about.
@example
```
import {RequireExactlyOne} from 'type-fest';
type Responder = {
text: () => string;
json: () => string;
secure: boolean;
};
const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
// Adding a `text` key here would cause a compile error.
json: () => '{"message": "ok"}',
secure: true
};
```
*/
export type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
{[Key in KeysType]: (
Required<Pick<ObjectType, Key>> &
Partial<Record<Exclude<KeysType, Key>, never>>
)}[KeysType] & _Omit<ObjectType, KeysType>;
import {Except} from './except';
/**
Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
@example
```
import {SetOptional} from 'type-fest';
type Foo = {
a: number;
b?: string;
c: boolean;
}
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
// type SomeOptional = {
// a: number;
// b?: string; // Was already optional and still is.
// c?: boolean; // Is now optional.
// }
```
*/
export type SetOptional<BaseType, Keys extends keyof BaseType = keyof BaseType> =
// Pick just the keys that are not optional from the base type.
Except<BaseType, Keys> &
// Pick the keys that should be optional from the base type and make them optional.
Partial<Pick<BaseType, Keys>> extends
// If `InferredType` extends the previous, then for each key, use the inferred type key.
infer InferredType
? {[KeyType in keyof InferredType]: InferredType[KeyType]}
: never;
import {Except} from './except';
/**
Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are required.
@example
```
import {SetRequired} from 'type-fest';
type Foo = {
a?: number;
b: string;
c?: boolean;
}
type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
// type SomeRequired = {
// a?: number;
// b: string; // Was already required and still is.
// c: boolean; // Is now required.
// }
```
*/
export type SetRequired<BaseType, Keys extends keyof BaseType = keyof BaseType> =
// Pick just the keys that are not required from the base type.
Except<BaseType, Keys> &
// Pick the keys that should be required from the base type and make them required.
Required<Pick<BaseType, Keys>> extends
// If `InferredType` extends the previous, then for each key, use the inferred type key.
infer InferredType
? {[KeyType in keyof InferredType]: InferredType[KeyType]}
: never;
type IsAny<T> = 0 extends (1 & T) ? true : false; // https://stackoverflow.com/a/49928360/3406963
type IsNever<T> = [T] extends [never] ? true : false;
type IsUnknown<T> = IsNever<T> extends false ? T extends unknown ? unknown extends T ? IsAny<T> extends false ? true : false : false : false : false;
/**
Create a function type with a return type of your choice and the same parameters as the given function type.
Use-case: You want to define a wrapped function that returns something different while receiving the same parameters. For example, you might want to wrap a function that can throw an error into one that will return `undefined` instead.
@example
```
import {SetReturnType} from 'type-fest';
type MyFunctionThatCanThrow = (foo: SomeType, bar: unknown) => SomeOtherType;
type MyWrappedFunction = SetReturnType<MyFunctionThatCanThrow, SomeOtherType | undefined>;
//=> type MyWrappedFunction = (foo: SomeType, bar: unknown) => SomeOtherType | undefined;
```
*/
export type SetReturnType<Fn extends (...args: any[]) => any, TypeToReturn> =
// Just using `Parameters<Fn>` isn't ideal because it doesn't handle the `this` fake parameter.
Fn extends (this: infer ThisArg, ...args: infer Arguments) => any ? (
// If a function did not specify the `this` fake parameter, it will be inferred to `unknown`.
// We want to detect this situation just to display a friendlier type upon hovering on an IntelliSense-powered IDE.
IsUnknown<ThisArg> extends true ? (...args: Arguments) => TypeToReturn : (this: ThisArg, ...args: Arguments) => TypeToReturn
) : (
// This part should be unreachable, but we make it meaningful just in case…
(...args: Parameters<Fn>) => TypeToReturn
);
/**
Create a type with the keys of the given type changed to `string` type.
Use-case: Changing interface values to strings in order to use them in a form model.
@example
```
import {Stringified} from 'type-fest';
type Car {
model: string;
speed: number;
}
const carForm: Stringified<Car> = {
model: 'Foo',
speed: '101'
};
```
*/
export type Stringified<ObjectType> = {[KeyType in keyof ObjectType]: string};
declare namespace TsConfigJson {
namespace CompilerOptions {
export type JSX =
| 'preserve'
| 'react'
| 'react-native';
export type Module =
| 'CommonJS'
| 'AMD'
| 'System'
| 'UMD'
| 'ES6'
| 'ES2015'
| 'ESNext'
| 'None'
// Lowercase alternatives
| 'commonjs'
| 'amd'
| 'system'
| 'umd'
| 'es6'
| 'es2015'
| 'esnext'
| 'none';
export type NewLine =
| 'CRLF'
| 'LF'
// Lowercase alternatives
| 'crlf'
| 'lf';
export type Target =
| 'ES3'
| 'ES5'
| 'ES6'
| 'ES2015'
| 'ES2016'
| 'ES2017'
| 'ES2018'
| 'ES2019'
| 'ES2020'
| 'ESNext'
// Lowercase alternatives
| 'es3'
| 'es5'
| 'es6'
| 'es2015'
| 'es2016'
| 'es2017'
| 'es2018'
| 'es2019'
| 'es2020'
| 'esnext';
export type Lib =
| 'ES5'
| 'ES6'
| 'ES7'
| 'ES2015'
| 'ES2015.Collection'
| 'ES2015.Core'
| 'ES2015.Generator'
| 'ES2015.Iterable'
| 'ES2015.Promise'
| 'ES2015.Proxy'
| 'ES2015.Reflect'
| 'ES2015.Symbol.WellKnown'
| 'ES2015.Symbol'
| 'ES2016'
| 'ES2016.Array.Include'
| 'ES2017'
| 'ES2017.Intl'
| 'ES2017.Object'
| 'ES2017.SharedMemory'
| 'ES2017.String'
| 'ES2017.TypedArrays'
| 'ES2018'
| 'ES2018.AsyncIterable'
| 'ES2018.Intl'
| 'ES2018.Promise'
| 'ES2018.Regexp'
| 'ES2019'
| 'ES2019.Array'
| 'ES2019.Object'
| 'ES2019.String'
| 'ES2019.Symbol'
| 'ES2020'
| 'ES2020.String'
| 'ES2020.Symbol.WellKnown'
| 'ESNext'
| 'ESNext.Array'
| 'ESNext.AsyncIterable'
| 'ESNext.BigInt'
| 'ESNext.Intl'
| 'ESNext.Symbol'
| 'DOM'
| 'DOM.Iterable'
| 'ScriptHost'
| 'WebWorker'
| 'WebWorker.ImportScripts'
// Lowercase alternatives
| 'es5'
| 'es6'
| 'es7'
| 'es2015'
| 'es2015.collection'
| 'es2015.core'
| 'es2015.generator'
| 'es2015.iterable'
| 'es2015.promise'
| 'es2015.proxy'
| 'es2015.reflect'
| 'es2015.symbol.wellknown'
| 'es2015.symbol'
| 'es2016'
| 'es2016.array.include'
| 'es2017'
| 'es2017.intl'
| 'es2017.object'
| 'es2017.sharedmemory'
| 'es2017.string'
| 'es2017.typedarrays'
| 'es2018'
| 'es2018.asynciterable'
| 'es2018.intl'
| 'es2018.promise'
| 'es2018.regexp'
| 'es2019'
| 'es2019.array'
| 'es2019.object'
| 'es2019.string'
| 'es2019.symbol'
| 'es2020'
| 'es2020.string'
| 'es2020.symbol.wellknown'
| 'esnext'
| 'esnext.array'
| 'esnext.asynciterable'
| 'esnext.bigint'
| 'esnext.intl'
| 'esnext.symbol'
| 'dom'
| 'dom.iterable'
| 'scripthost'
| 'webworker'
| 'webworker.importscripts';
export interface Plugin {
[key: string]: unknown;
/**
Plugin name.
*/
name?: string;
}
}
export interface CompilerOptions {
/**
The character set of the input files.
@default 'utf8'
*/
charset?: string;
/**
Enables building for project references.
@default true
*/
composite?: boolean;
/**
Generates corresponding d.ts files.
@default false
*/
declaration?: boolean;
/**
Specify output directory for generated declaration files.
Requires TypeScript version 2.0 or later.
*/
declarationDir?: string;
/**
Show diagnostic information.
@default false
*/
diagnostics?: boolean;
/**
Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.
@default false
*/
emitBOM?: boolean;
/**
Only emit `.d.ts` declaration files.
@default false
*/
emitDeclarationOnly?: boolean;
/**
Enable incremental compilation.
@default `composite`
*/
incremental?: boolean;
/**
Specify file to store incremental compilation information.
@default '.tsbuildinfo'
*/
tsBuildInfoFile?: string;
/**
Emit a single file with source maps instead of having a separate file.
@default false
*/
inlineSourceMap?: boolean;
/**
Emit the source alongside the sourcemaps within a single file.
Requires `--inlineSourceMap` to be set.
@default false
*/
inlineSources?: boolean;
/**
Specify JSX code generation: `'preserve'`, `'react'`, or `'react-native'`.
@default 'preserve'
*/
jsx?: CompilerOptions.JSX;
/**
Specifies the object invoked for `createElement` and `__spread` when targeting `'react'` JSX emit.
@default 'React'
*/
reactNamespace?: string;
/**
Print names of files part of the compilation.
@default false
*/
listFiles?: boolean;
/**
Specifies the location where debugger should locate map files instead of generated locations.
*/
mapRoot?: string;
/**
Specify module code generation: 'None', 'CommonJS', 'AMD', 'System', 'UMD', 'ES6', 'ES2015' or 'ESNext'. Only 'AMD' and 'System' can be used in conjunction with `--outFile`. 'ES6' and 'ES2015' values may be used when targeting 'ES5' or lower.
@default ['ES3', 'ES5'].includes(target) ? 'CommonJS' : 'ES6'
*/
module?: CompilerOptions.Module;
/**
Specifies the end of line sequence to be used when emitting files: 'crlf' (Windows) or 'lf' (Unix).
Default: Platform specific
*/
newLine?: CompilerOptions.NewLine;
/**
Do not emit output.
@default false
*/
noEmit?: boolean;
/**
Do not generate custom helper functions like `__extends` in compiled output.
@default false
*/
noEmitHelpers?: boolean;
/**
Do not emit outputs if any type checking errors were reported.
@default false
*/
noEmitOnError?: boolean;
/**
Warn on expressions and declarations with an implied 'any' type.
@default false
*/
noImplicitAny?: boolean;
/**
Raise error on 'this' expressions with an implied any type.
@default false
*/
noImplicitThis?: boolean;
/**
Report errors on unused locals.
Requires TypeScript version 2.0 or later.
@default false
*/
noUnusedLocals?: boolean;
/**
Report errors on unused parameters.
Requires TypeScript version 2.0 or later.
@default false
*/
noUnusedParameters?: boolean;
/**
Do not include the default library file (lib.d.ts).
@default false
*/
noLib?: boolean;
/**
Do not add triple-slash references or module import targets to the list of compiled files.
@default false
*/
noResolve?: boolean;
/**
Disable strict checking of generic signatures in function types.
@default false
*/
noStrictGenericChecks?: boolean;
/**
@deprecated use `skipLibCheck` instead.
*/
skipDefaultLibCheck?: boolean;
/**
Skip type checking of declaration files.
Requires TypeScript version 2.0 or later.
@default false
*/
skipLibCheck?: boolean;
/**
Concatenate and emit output to single file.
*/
outFile?: string;
/**
Redirect output structure to the directory.
*/
outDir?: string;
/**
Do not erase const enum declarations in generated code.
@default false
*/
preserveConstEnums?: boolean;
/**
Do not resolve symlinks to their real path; treat a symlinked file like a real one.
@default false
*/
preserveSymlinks?: boolean;
/**
Keep outdated console output in watch mode instead of clearing the screen.
@default false
*/
preserveWatchOutput?: boolean;
/**
Stylize errors and messages using color and context (experimental).
@default true // Unless piping to another program or redirecting output to a file.
*/
pretty?: boolean;
/**
Do not emit comments to output.
@default false
*/
removeComments?: boolean;
/**
Specifies the root directory of input files.
Use to control the output directory structure with `--outDir`.
*/
rootDir?: string;
/**
Unconditionally emit imports for unresolved files.
@default false
*/
isolatedModules?: boolean;
/**
Generates corresponding '.map' file.
@default false
*/
sourceMap?: boolean;
/**
Specifies the location where debugger should locate TypeScript files instead of source locations.
*/
sourceRoot?: string;
/**
Suppress excess property checks for object literals.
@default false
*/
suppressExcessPropertyErrors?: boolean;
/**
Suppress noImplicitAny errors for indexing objects lacking index signatures.
@default false
*/
suppressImplicitAnyIndexErrors?: boolean;
/**
Do not emit declarations for code that has an `@internal` annotation.
*/
stripInternal?: boolean;
/**
Specify ECMAScript target version.
@default 'es3'
*/
target?: CompilerOptions.Target;
/**
Watch input files.
@default false
*/
watch?: boolean;
/**
Enables experimental support for ES7 decorators.
@default false
*/
experimentalDecorators?: boolean;
/**
Emit design-type metadata for decorated declarations in source.
@default false
*/
emitDecoratorMetadata?: boolean;
/**
Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6).
@default ['AMD', 'System', 'ES6'].includes(module) ? 'classic' : 'node'
*/
moduleResolution?: 'classic' | 'node';
/**
Do not report errors on unused labels.
@default false
*/
allowUnusedLabels?: boolean;
/**
Report error when not all code paths in function return a value.
@default false
*/
noImplicitReturns?: boolean;
/**
Report errors for fallthrough cases in switch statement.
@default false
*/
noFallthroughCasesInSwitch?: boolean;
/**
Do not report errors on unreachable code.
@default false
*/
allowUnreachableCode?: boolean;
/**
Disallow inconsistently-cased references to the same file.
@default false
*/
forceConsistentCasingInFileNames?: boolean;
/**
Base directory to resolve non-relative module names.
*/
baseUrl?: string;
/**
Specify path mapping to be computed relative to baseUrl option.
*/
paths?: Record<string, string[]>;
/**
List of TypeScript language server plugins to load.
Requires TypeScript version 2.3 or later.
*/
plugins?: CompilerOptions.Plugin[];
/**
Specify list of root directories to be used when resolving modules.
*/
rootDirs?: string[];
/**
Specify list of directories for type definition files to be included.
Requires TypeScript version 2.0 or later.
*/
typeRoots?: string[];
/**
Type declaration files to be included in compilation.
Requires TypeScript version 2.0 or later.
*/
types?: string[];
/**
Enable tracing of the name resolution process.
@default false
*/
traceResolution?: boolean;
/**
Allow javascript files to be compiled.
@default false
*/
allowJs?: boolean;
/**
Do not truncate error messages.
@default false
*/
noErrorTruncation?: boolean;
/**
Allow default imports from modules with no default export. This does not affect code emit, just typechecking.
@default module === 'system' || esModuleInterop
*/
allowSyntheticDefaultImports?: boolean;
/**
Do not emit `'use strict'` directives in module output.
@default false
*/
noImplicitUseStrict?: boolean;
/**
Enable to list all emitted files.
Requires TypeScript version 2.0 or later.
@default false
*/
listEmittedFiles?: boolean;
/**
Disable size limit for JavaScript project.
Requires TypeScript version 2.0 or later.
@default false
*/
disableSizeLimit?: boolean;
/**
List of library files to be included in the compilation.
Requires TypeScript version 2.0 or later.
*/
lib?: CompilerOptions.Lib[];
/**
Enable strict null checks.
Requires TypeScript version 2.0 or later.
@default false
*/
strictNullChecks?: boolean;
/**
The maximum dependency depth to search under `node_modules` and load JavaScript files. Only applicable with `--allowJs`.
@default 0
*/
maxNodeModuleJsDepth?: number;
/**
Import emit helpers (e.g. `__extends`, `__rest`, etc..) from tslib.
Requires TypeScript version 2.1 or later.
@default false
*/
importHelpers?: boolean;
/**
Specify the JSX factory function to use when targeting React JSX emit, e.g. `React.createElement` or `h`.
Requires TypeScript version 2.1 or later.
@default 'React.createElement'
*/
jsxFactory?: string;
/**
Parse in strict mode and emit `'use strict'` for each source file.
Requires TypeScript version 2.1 or later.
@default false
*/
alwaysStrict?: boolean;
/**
Enable all strict type checking options.
Requires TypeScript version 2.3 or later.
@default false
*/
strict?: boolean;
/**
Enable stricter checking of of the `bind`, `call`, and `apply` methods on functions.
@default false
*/
strictBindCallApply?: boolean;
/**
Provide full support for iterables in `for-of`, spread, and destructuring when targeting `ES5` or `ES3`.
Requires TypeScript version 2.3 or later.
@default false
*/
downlevelIteration?: boolean;
/**
Report errors in `.js` files.
Requires TypeScript version 2.3 or later.
@default false
*/
checkJs?: boolean;
/**
Disable bivariant parameter checking for function types.
Requires TypeScript version 2.6 or later.
@default false
*/
strictFunctionTypes?: boolean;
/**
Ensure non-undefined class properties are initialized in the constructor.
Requires TypeScript version 2.7 or later.
@default false
*/
strictPropertyInitialization?: boolean;
/**
Emit `__importStar` and `__importDefault` helpers for runtime Babel ecosystem compatibility and enable `--allowSyntheticDefaultImports` for typesystem compatibility.
Requires TypeScript version 2.7 or later.
@default false
*/
esModuleInterop?: boolean;
/**
Allow accessing UMD globals from modules.
@default false
*/
allowUmdGlobalAccess?: boolean;
/**
Resolve `keyof` to string valued property names only (no numbers or symbols).
Requires TypeScript version 2.9 or later.
@default false
*/
keyofStringsOnly?: boolean;
/**
Emit ECMAScript standard class fields.
Requires TypeScript version 3.7 or later.
@default false
*/
useDefineForClassFields?: boolean;
/**
Generates a sourcemap for each corresponding `.d.ts` file.
Requires TypeScript version 2.9 or later.
@default false
*/
declarationMap?: boolean;
/**
Include modules imported with `.json` extension.
Requires TypeScript version 2.9 or later.
@default false
*/
resolveJsonModule?: boolean;
}
/**
Auto type (.d.ts) acquisition options for this project.
Requires TypeScript version 2.1 or later.
*/
export interface TypeAcquisition {
/**
Enable auto type acquisition.
*/
enable?: boolean;
/**
Specifies a list of type declarations to be included in auto type acquisition. For example, `['jquery', 'lodash']`.
*/
include?: string[];
/**
Specifies a list of type declarations to be excluded from auto type acquisition. For example, `['jquery', 'lodash']`.
*/
exclude?: string[];
}
export interface References {
/**
A normalized path on disk.
*/
path: string;
/**
The path as the user originally wrote it.
*/
originalPath?: string;
/**
True if the output of this reference should be prepended to the output of this project.
Only valid for `--outFile` compilations.
*/
prepend?: boolean;
/**
True if it is intended that this reference form a circularity.
*/
circular?: boolean;
}
}
export interface TsConfigJson {
/**
Instructs the TypeScript compiler how to compile `.ts` files.
*/
compilerOptions?: TsConfigJson.CompilerOptions;
/**
Auto type (.d.ts) acquisition options for this project.
Requires TypeScript version 2.1 or later.
*/
typeAcquisition?: TsConfigJson.TypeAcquisition;
/**
Enable Compile-on-Save for this project.
*/
compileOnSave?: boolean;
/**
Path to base configuration file to inherit from.
Requires TypeScript version 2.1 or later.
*/
extends?: string;
/**
If no `files` or `include` property is present in a `tsconfig.json`, the compiler defaults to including all files in the containing directory and subdirectories except those specified by `exclude`. When a `files` property is specified, only those files and those specified by `include` are included.
*/
files?: string[];
/**
Specifies a list of files to be excluded from compilation. The `exclude` property only affects the files included via the `include` property and not the `files` property.
Glob patterns require TypeScript version 2.0 or later.
*/
exclude?: string[];
/**
Specifies a list of glob patterns that match files to be included in compilation.
If no `files` or `include` property is present in a `tsconfig.json`, the compiler defaults to including all files in the containing directory and subdirectories except those specified by `exclude`.
Requires TypeScript version 2.0 or later.
*/
include?: string[];
/**
Referenced projects.
Requires TypeScript version 3.0 or later.
*/
references?: TsConfigJson.References[];
}
/**
Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
@example
```
import {UnionToIntersection} from 'type-fest';
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
type Intersection = UnionToIntersection<Union>;
//=> {the(): void; great(arg: string): void; escape: boolean};
```
A more applicable example which could make its way into your library code follows.
@example
```
import {UnionToIntersection} from 'type-fest';
class CommandOne {
commands: {
a1: () => undefined,
b1: () => undefined,
}
}
class CommandTwo {
commands: {
a2: (argA: string) => undefined,
b2: (argB: string) => undefined,
}
}
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
type Union = typeof union;
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
type Intersection = UnionToIntersection<Union>;
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
```
*/
export type UnionToIntersection<Union> = (
// `extends unknown` is always going to be the case and is used to convert the
// `Union` into a [distributive conditional
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
Union extends unknown
// The union type is used as the only argument to a function since the union
// of function arguments is an intersection.
? (distributedUnion: Union) => void
// This won't happen.
: never
// Infer the `Intersection` type since TypeScript represents the positional
// arguments of unions of functions as an intersection of the union.
) extends ((mergedIntersection: infer Intersection) => void)
? Intersection
: never;
export type UpperCaseCharacters = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
export type WordSeparators = '-' | '_' | ' ';
/**
Create a union of the given object's values, and optionally specify which keys to get the values from.
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
@example
```
// data.json
{
'foo': 1,
'bar': 2,
'biz': 3
}
// main.ts
import {ValueOf} from 'type-fest';
import data = require('./data.json');
export function getData(name: string): ValueOf<typeof data> {
return data[name];
}
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
return data[name];
}
// file.ts
import {getData, onlyBar} from './main';
getData('foo');
//=> 1
onlyBar('foo');
//=> TypeError ...
onlyBar('bar');
//=> 2
```
*/
export type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
import {WordSeparators} from '../source/utilities';
/**
Recursively split a string literal into two parts on the first occurence of the given string, returning an array literal of all the separate parts.
*/
export type Split<S extends string, D extends string> =
string extends S ? string[] :
S extends '' ? [] :
S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] :
[S];
/**
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.
Only to be used by `CamelCaseStringArray<>`.
@see CamelCaseStringArray
*/
type InnerCamelCaseStringArray<Parts extends any[], PreviousPart> =
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
? FirstPart extends undefined
? ''
: FirstPart extends ''
? InnerCamelCaseStringArray<RemainingParts, PreviousPart>
: `${PreviousPart extends '' ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`
: '';
/**
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
*/
type CamelCaseStringArray<Parts extends string[]> =
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`>
: never;
/**
Convert a string literal to camel-case.
This can be useful when, for example, converting some kebab-cased command-line flags or a snake-cased database result.
@example
```
import {CamelCase} from 'type-fest';
// Simple
const someVariable: CamelCase<'foo-bar'> = 'fooBar';
// Advanced
type CamelCasedProps<T> = {
[K in keyof T as CamelCase<K>]: T[K]
};
interface RawOptions {
'dry-run': boolean;
'full_family_name': string;
foo: number;
}
const dbResult: CamelCasedProps<ModelProps> = {
dryRun: true,
fullFamilyName: 'bar.js',
foo: 123
};
```
*/
export type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K, WordSeparators>> : K;
import {UpperCaseCharacters, WordSeparators} from '../source/utilities';
/**
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.
*/
export type SplitIncludingDelimiters<Source extends string, Delimiter extends string> =
Source extends '' ? [] :
Source extends `${infer FirstPart}${Delimiter}${infer SecondPart}` ?
(
Source extends `${FirstPart}${infer UsedDelimiter}${SecondPart}`
? UsedDelimiter extends Delimiter
? Source extends `${infer FirstPart}${UsedDelimiter}${infer SecondPart}`
? [...SplitIncludingDelimiters<FirstPart, Delimiter>, UsedDelimiter, ...SplitIncludingDelimiters<SecondPart, Delimiter>]
: never
: never
: never
) :
[Source];
/**
Format a specific part of the splitted string literal that `StringArrayToDelimiterCase<>` fuses together, ensuring desired casing.
@see StringArrayToDelimiterCase
*/
type StringPartToDelimiterCase<StringPart extends string, UsedWordSeparators extends string, UsedUpperCaseCharacters extends string, Delimiter extends string> =
StringPart extends UsedWordSeparators ? Delimiter :
StringPart extends UsedUpperCaseCharacters ? `${Delimiter}${Lowercase<StringPart>}` :
StringPart;
/**
Takes the result of a splitted string literal and recursively concatenates it together into the desired casing.
It receives `UsedWordSeparators` and `UsedUpperCaseCharacters` as input to ensure it's fully encapsulated.
@see SplitIncludingDelimiters
*/
type StringArrayToDelimiterCase<Parts extends any[], UsedWordSeparators extends string, UsedUpperCaseCharacters extends string, Delimiter extends string> =
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
? `${StringPartToDelimiterCase<FirstPart, UsedWordSeparators, UsedUpperCaseCharacters, Delimiter>}${StringArrayToDelimiterCase<RemainingParts, UsedWordSeparators, UsedUpperCaseCharacters, Delimiter>}`
: '';
/**
Convert a string literal to a custom string delimiter casing.
This can be useful when, for example, converting a camel-cased object property to an oddly cased one.
@see KebabCase
@see SnakeCase
@example
```
import {DelimiterCase} from 'type-fest';
// Simple
const someVariable: DelimiterCase<'fooBar', '#'> = 'foo#bar';
// Advanced
type OddlyCasedProps<T> = {
[K in keyof T as DelimiterCase<K, '#'>]: T[K]
};
interface SomeOptions {
dryRun: boolean;
includeFile: string;
foo: number;
}
const rawCliOptions: OddlyCasedProps<SomeOptions> = {
'dry#run': true,
'include#file': 'bar.js',
foo: 123
};
```
*/
export type DelimiterCase<Value, Delimiter extends string> = Value extends string
? StringArrayToDelimiterCase<
SplitIncludingDelimiters<Value, WordSeparators | UpperCaseCharacters>,
WordSeparators,
UpperCaseCharacters,
Delimiter
>
: Value;
// These are all the basic types that's compatible with all supported TypeScript versions.
export * from '../base';
// These are special types that require at least TypeScript 4.1.
export {CamelCase} from './camel-case';
export {KebabCase} from './kebab-case';
export {PascalCase} from './pascal-case';
export {SnakeCase} from './snake-case';
export {DelimiterCase} from './delimiter-case';
import {DelimiterCase} from './delimiter-case';
/**
Convert a string literal to kebab-case.
This can be useful when, for example, converting a camel-cased object property to a kebab-cased CSS class name or a command-line flag.
@example
```
import {KebabCase} from 'type-fest';
// Simple
const someVariable: KebabCase<'fooBar'> = 'foo-bar';
// Advanced
type KebabCasedProps<T> = {
[K in keyof T as KebabCase<K>]: T[K]
};
interface CliOptions {
dryRun: boolean;
includeFile: string;
foo: number;
}
const rawCliOptions: KebabCasedProps<CliOptions> = {
'dry-run': true,
'include-file': 'bar.js',
foo: 123
};
```
*/
export type KebabCase<Value> = DelimiterCase<Value, '-'>;
import {CamelCase} from './camel-case';
/**
Converts a string literal to pascal-case.
@example
```
import {PascalCase} from 'type-fest';
// Simple
const someVariable: PascalCase<'foo-bar'> = 'FooBar';
// Advanced
type PascalCaseProps<T> = {
[K in keyof T as PascalCase<K>]: T[K]
};
interface RawOptions {
'dry-run': boolean;
'full_family_name': string;
foo: number;
}
const dbResult: CamelCasedProps<ModelProps> = {
DryRun: true,
FullFamilyName: 'bar.js',
Foo: 123
};
```
*/
export type PascalCase<Value> = CamelCase<Value> extends string
? Capitalize<CamelCase<Value>>
: CamelCase<Value>;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment