update socials section
This commit is contained in:
243
node_modules/ansi-escapes/index.d.ts
generated
vendored
Normal file
243
node_modules/ansi-escapes/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,243 @@
|
||||
/* eslint-disable @typescript-eslint/member-ordering */
|
||||
import {LiteralUnion} from 'type-fest';
|
||||
|
||||
export interface ImageOptions {
|
||||
/**
|
||||
The width is given as a number followed by a unit, or the word `'auto'`.
|
||||
|
||||
- `N`: N character cells.
|
||||
- `Npx`: N pixels.
|
||||
- `N%`: N percent of the session's width or height.
|
||||
- `auto`: The image's inherent size will be used to determine an appropriate dimension.
|
||||
*/
|
||||
readonly width?: LiteralUnion<'auto', number | string>;
|
||||
|
||||
/**
|
||||
The height is given as a number followed by a unit, or the word `'auto'`.
|
||||
|
||||
- `N`: N character cells.
|
||||
- `Npx`: N pixels.
|
||||
- `N%`: N percent of the session's width or height.
|
||||
- `auto`: The image's inherent size will be used to determine an appropriate dimension.
|
||||
*/
|
||||
readonly height?: LiteralUnion<'auto', number | string>;
|
||||
|
||||
readonly preserveAspectRatio?: boolean;
|
||||
}
|
||||
|
||||
export interface AnnotationOptions {
|
||||
/**
|
||||
Nonzero number of columns to annotate.
|
||||
|
||||
Default: The remainder of the line.
|
||||
*/
|
||||
readonly length?: number;
|
||||
|
||||
/**
|
||||
Starting X coordinate.
|
||||
|
||||
Must be used with `y` and `length`.
|
||||
|
||||
Default: The cursor position
|
||||
*/
|
||||
readonly x?: number;
|
||||
|
||||
/**
|
||||
Starting Y coordinate.
|
||||
|
||||
Must be used with `x` and `length`.
|
||||
|
||||
Default: Cursor position.
|
||||
*/
|
||||
readonly y?: number;
|
||||
|
||||
/**
|
||||
Create a "hidden" annotation.
|
||||
|
||||
Annotations created this way can be shown using the "Show Annotations" iTerm command.
|
||||
*/
|
||||
readonly isHidden?: boolean;
|
||||
}
|
||||
|
||||
declare const ansiEscapes: {
|
||||
/**
|
||||
Set the absolute position of the cursor. `x0` `y0` is the top left of the screen.
|
||||
*/
|
||||
cursorTo(x: number, y?: number): string;
|
||||
|
||||
/**
|
||||
Set the position of the cursor relative to its current position.
|
||||
*/
|
||||
cursorMove(x: number, y?: number): string;
|
||||
|
||||
/**
|
||||
Move cursor up a specific amount of rows.
|
||||
|
||||
@param count - Count of rows to move up. Default is `1`.
|
||||
*/
|
||||
cursorUp(count?: number): string;
|
||||
|
||||
/**
|
||||
Move cursor down a specific amount of rows.
|
||||
|
||||
@param count - Count of rows to move down. Default is `1`.
|
||||
*/
|
||||
cursorDown(count?: number): string;
|
||||
|
||||
/**
|
||||
Move cursor forward a specific amount of rows.
|
||||
|
||||
@param count - Count of rows to move forward. Default is `1`.
|
||||
*/
|
||||
cursorForward(count?: number): string;
|
||||
|
||||
/**
|
||||
Move cursor backward a specific amount of rows.
|
||||
|
||||
@param count - Count of rows to move backward. Default is `1`.
|
||||
*/
|
||||
cursorBackward(count?: number): string;
|
||||
|
||||
/**
|
||||
Move cursor to the left side.
|
||||
*/
|
||||
cursorLeft: string;
|
||||
|
||||
/**
|
||||
Save cursor position.
|
||||
*/
|
||||
cursorSavePosition: string;
|
||||
|
||||
/**
|
||||
Restore saved cursor position.
|
||||
*/
|
||||
cursorRestorePosition: string;
|
||||
|
||||
/**
|
||||
Get cursor position.
|
||||
*/
|
||||
cursorGetPosition: string;
|
||||
|
||||
/**
|
||||
Move cursor to the next line.
|
||||
*/
|
||||
cursorNextLine: string;
|
||||
|
||||
/**
|
||||
Move cursor to the previous line.
|
||||
*/
|
||||
cursorPrevLine: string;
|
||||
|
||||
/**
|
||||
Hide cursor.
|
||||
*/
|
||||
cursorHide: string;
|
||||
|
||||
/**
|
||||
Show cursor.
|
||||
*/
|
||||
cursorShow: string;
|
||||
|
||||
/**
|
||||
Erase from the current cursor position up the specified amount of rows.
|
||||
|
||||
@param count - Count of rows to erase.
|
||||
*/
|
||||
eraseLines(count: number): string;
|
||||
|
||||
/**
|
||||
Erase from the current cursor position to the end of the current line.
|
||||
*/
|
||||
eraseEndLine: string;
|
||||
|
||||
/**
|
||||
Erase from the current cursor position to the start of the current line.
|
||||
*/
|
||||
eraseStartLine: string;
|
||||
|
||||
/**
|
||||
Erase the entire current line.
|
||||
*/
|
||||
eraseLine: string;
|
||||
|
||||
/**
|
||||
Erase the screen from the current line down to the bottom of the screen.
|
||||
*/
|
||||
eraseDown: string;
|
||||
|
||||
/**
|
||||
Erase the screen from the current line up to the top of the screen.
|
||||
*/
|
||||
eraseUp: string;
|
||||
|
||||
/**
|
||||
Erase the screen and move the cursor the top left position.
|
||||
*/
|
||||
eraseScreen: string;
|
||||
|
||||
/**
|
||||
Scroll display up one line.
|
||||
*/
|
||||
scrollUp: string;
|
||||
|
||||
/**
|
||||
Scroll display down one line.
|
||||
*/
|
||||
scrollDown: string;
|
||||
|
||||
/**
|
||||
Clear the terminal screen. (Viewport)
|
||||
*/
|
||||
clearScreen: string;
|
||||
|
||||
/**
|
||||
Clear the whole terminal, including scrollback buffer. (Not just the visible part of it)
|
||||
*/
|
||||
clearTerminal: string;
|
||||
|
||||
/**
|
||||
Output a beeping sound.
|
||||
*/
|
||||
beep: string;
|
||||
|
||||
/**
|
||||
Create a clickable link.
|
||||
|
||||
[Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) Use [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks) to detect link support.
|
||||
*/
|
||||
link(text: string, url: string): string;
|
||||
|
||||
/**
|
||||
Display an image.
|
||||
|
||||
_Currently only supported on iTerm2 >=3_
|
||||
|
||||
See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module.
|
||||
|
||||
@param buffer - Buffer of an image. Usually read in with `fs.readFile()`.
|
||||
*/
|
||||
image(buffer: Buffer, options?: ImageOptions): string;
|
||||
|
||||
iTerm: {
|
||||
/**
|
||||
[Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click).
|
||||
|
||||
@param cwd - Current directory. Default: `process.cwd()`.
|
||||
*/
|
||||
setCwd(cwd?: string): string;
|
||||
|
||||
/**
|
||||
An annotation looks like this when shown:
|
||||
|
||||

|
||||
|
||||
See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information.
|
||||
|
||||
@param message - The message to display within the annotation. The `|` character is disallowed and will be stripped.
|
||||
@returns An escape code which will create an annotation when printed in iTerm2.
|
||||
*/
|
||||
annotation(message: string, options?: AnnotationOptions): string;
|
||||
};
|
||||
};
|
||||
|
||||
export default ansiEscapes;
|
156
node_modules/ansi-escapes/index.js
generated
vendored
Normal file
156
node_modules/ansi-escapes/index.js
generated
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
const ESC = '\u001B[';
|
||||
const OSC = '\u001B]';
|
||||
const BEL = '\u0007';
|
||||
const SEP = ';';
|
||||
const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';
|
||||
|
||||
const ansiEscapes = {};
|
||||
|
||||
ansiEscapes.cursorTo = (x, y) => {
|
||||
if (typeof x !== 'number') {
|
||||
throw new TypeError('The `x` argument is required');
|
||||
}
|
||||
|
||||
if (typeof y !== 'number') {
|
||||
return ESC + (x + 1) + 'G';
|
||||
}
|
||||
|
||||
return ESC + (y + 1) + ';' + (x + 1) + 'H';
|
||||
};
|
||||
|
||||
ansiEscapes.cursorMove = (x, y) => {
|
||||
if (typeof x !== 'number') {
|
||||
throw new TypeError('The `x` argument is required');
|
||||
}
|
||||
|
||||
let returnValue = '';
|
||||
|
||||
if (x < 0) {
|
||||
returnValue += ESC + (-x) + 'D';
|
||||
} else if (x > 0) {
|
||||
returnValue += ESC + x + 'C';
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
returnValue += ESC + (-y) + 'A';
|
||||
} else if (y > 0) {
|
||||
returnValue += ESC + y + 'B';
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
ansiEscapes.cursorUp = (count = 1) => ESC + count + 'A';
|
||||
ansiEscapes.cursorDown = (count = 1) => ESC + count + 'B';
|
||||
ansiEscapes.cursorForward = (count = 1) => ESC + count + 'C';
|
||||
ansiEscapes.cursorBackward = (count = 1) => ESC + count + 'D';
|
||||
|
||||
ansiEscapes.cursorLeft = ESC + 'G';
|
||||
ansiEscapes.cursorSavePosition = isTerminalApp ? '\u001B7' : ESC + 's';
|
||||
ansiEscapes.cursorRestorePosition = isTerminalApp ? '\u001B8' : ESC + 'u';
|
||||
ansiEscapes.cursorGetPosition = ESC + '6n';
|
||||
ansiEscapes.cursorNextLine = ESC + 'E';
|
||||
ansiEscapes.cursorPrevLine = ESC + 'F';
|
||||
ansiEscapes.cursorHide = ESC + '?25l';
|
||||
ansiEscapes.cursorShow = ESC + '?25h';
|
||||
|
||||
ansiEscapes.eraseLines = count => {
|
||||
let clear = '';
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
clear += ansiEscapes.eraseLine + (i < count - 1 ? ansiEscapes.cursorUp() : '');
|
||||
}
|
||||
|
||||
if (count) {
|
||||
clear += ansiEscapes.cursorLeft;
|
||||
}
|
||||
|
||||
return clear;
|
||||
};
|
||||
|
||||
ansiEscapes.eraseEndLine = ESC + 'K';
|
||||
ansiEscapes.eraseStartLine = ESC + '1K';
|
||||
ansiEscapes.eraseLine = ESC + '2K';
|
||||
ansiEscapes.eraseDown = ESC + 'J';
|
||||
ansiEscapes.eraseUp = ESC + '1J';
|
||||
ansiEscapes.eraseScreen = ESC + '2J';
|
||||
ansiEscapes.scrollUp = ESC + 'S';
|
||||
ansiEscapes.scrollDown = ESC + 'T';
|
||||
|
||||
ansiEscapes.clearScreen = '\u001Bc';
|
||||
|
||||
ansiEscapes.clearTerminal = process.platform === 'win32' ?
|
||||
`${ansiEscapes.eraseScreen}${ESC}0f` :
|
||||
// 1. Erases the screen (Only done in case `2` is not supported)
|
||||
// 2. Erases the whole screen including scrollback buffer
|
||||
// 3. Moves cursor to the top-left position
|
||||
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
||||
`${ansiEscapes.eraseScreen}${ESC}3J${ESC}H`;
|
||||
|
||||
ansiEscapes.beep = BEL;
|
||||
|
||||
ansiEscapes.link = (text, url) => {
|
||||
return [
|
||||
OSC,
|
||||
'8',
|
||||
SEP,
|
||||
SEP,
|
||||
url,
|
||||
BEL,
|
||||
text,
|
||||
OSC,
|
||||
'8',
|
||||
SEP,
|
||||
SEP,
|
||||
BEL
|
||||
].join('');
|
||||
};
|
||||
|
||||
ansiEscapes.image = (buffer, options = {}) => {
|
||||
let returnValue = `${OSC}1337;File=inline=1`;
|
||||
|
||||
if (options.width) {
|
||||
returnValue += `;width=${options.width}`;
|
||||
}
|
||||
|
||||
if (options.height) {
|
||||
returnValue += `;height=${options.height}`;
|
||||
}
|
||||
|
||||
if (options.preserveAspectRatio === false) {
|
||||
returnValue += ';preserveAspectRatio=0';
|
||||
}
|
||||
|
||||
return returnValue + ':' + buffer.toString('base64') + BEL;
|
||||
};
|
||||
|
||||
ansiEscapes.iTerm = {
|
||||
setCwd: (cwd = process.cwd()) => `${OSC}50;CurrentDir=${cwd}${BEL}`,
|
||||
|
||||
annotation: (message, options = {}) => {
|
||||
let returnValue = `${OSC}1337;`;
|
||||
|
||||
const hasX = typeof options.x !== 'undefined';
|
||||
const hasY = typeof options.y !== 'undefined';
|
||||
if ((hasX || hasY) && !(hasX && hasY && typeof options.length !== 'undefined')) {
|
||||
throw new Error('`x`, `y` and `length` must be defined when `x` or `y` is defined');
|
||||
}
|
||||
|
||||
message = message.replace(/\|/g, '');
|
||||
|
||||
returnValue += options.isHidden ? 'AddHiddenAnnotation=' : 'AddAnnotation=';
|
||||
|
||||
if (options.length > 0) {
|
||||
returnValue +=
|
||||
(hasX ?
|
||||
[message, options.length, options.x, options.y] :
|
||||
[options.length, message]).join('|');
|
||||
} else {
|
||||
returnValue += message;
|
||||
}
|
||||
|
||||
return returnValue + BEL;
|
||||
}
|
||||
};
|
||||
|
||||
export default ansiEscapes;
|
9
node_modules/ansi-escapes/license
generated
vendored
Normal file
9
node_modules/ansi-escapes/license
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
42
node_modules/ansi-escapes/node_modules/type-fest/base.d.ts
generated
vendored
Normal file
42
node_modules/ansi-escapes/node_modules/type-fest/base.d.ts
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// Types that are compatible with all supported TypeScript versions.
|
||||
// It's shared between all TypeScript version-specific definitions.
|
||||
|
||||
// Basic
|
||||
export * from './source/primitive';
|
||||
export * from './source/typed-array';
|
||||
export * from './source/basic';
|
||||
export * from './source/observable-like';
|
||||
|
||||
// Utilities
|
||||
export {Except} from './source/except';
|
||||
export {Mutable} from './source/mutable';
|
||||
export {Merge} from './source/merge';
|
||||
export {MergeExclusive} from './source/merge-exclusive';
|
||||
export {RequireAtLeastOne} from './source/require-at-least-one';
|
||||
export {RequireExactlyOne} from './source/require-exactly-one';
|
||||
export {PartialDeep} from './source/partial-deep';
|
||||
export {ReadonlyDeep} from './source/readonly-deep';
|
||||
export {LiteralUnion} from './source/literal-union';
|
||||
export {Promisable} from './source/promisable';
|
||||
export {Opaque} from './source/opaque';
|
||||
export {SetOptional} from './source/set-optional';
|
||||
export {SetRequired} from './source/set-required';
|
||||
export {ValueOf} from './source/value-of';
|
||||
export {PromiseValue} from './source/promise-value';
|
||||
export {AsyncReturnType} from './source/async-return-type';
|
||||
export {ConditionalExcept} from './source/conditional-except';
|
||||
export {ConditionalKeys} from './source/conditional-keys';
|
||||
export {ConditionalPick} from './source/conditional-pick';
|
||||
export {UnionToIntersection} from './source/union-to-intersection';
|
||||
export {Stringified} from './source/stringified';
|
||||
export {FixedLengthArray} from './source/fixed-length-array';
|
||||
export {IterableElement} from './source/iterable-element';
|
||||
export {Entry} from './source/entry';
|
||||
export {Entries} from './source/entries';
|
||||
export {SetReturnType} from './source/set-return-type';
|
||||
export {Asyncify} from './source/asyncify';
|
||||
export {Simplify} from './source/simplify';
|
||||
|
||||
// Miscellaneous
|
||||
export {PackageJson} from './source/package-json';
|
||||
export {TsConfigJson} from './source/tsconfig-json';
|
2
node_modules/ansi-escapes/node_modules/type-fest/index.d.ts
generated
vendored
Normal file
2
node_modules/ansi-escapes/node_modules/type-fest/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
// These are all the basic types that's compatible with all supported TypeScript versions.
|
||||
export * from './base';
|
9
node_modules/ansi-escapes/node_modules/type-fest/license
generated
vendored
Normal file
9
node_modules/ansi-escapes/node_modules/type-fest/license
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
58
node_modules/ansi-escapes/node_modules/type-fest/package.json
generated
vendored
Normal file
58
node_modules/ansi-escapes/node_modules/type-fest/package.json
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "type-fest",
|
||||
"version": "1.4.0",
|
||||
"description": "A collection of essential TypeScript types",
|
||||
"license": "(MIT OR CC0-1.0)",
|
||||
"repository": "sindresorhus/type-fest",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && tsd && tsc"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"base.d.ts",
|
||||
"source",
|
||||
"ts41"
|
||||
],
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"ts",
|
||||
"types",
|
||||
"utility",
|
||||
"util",
|
||||
"utilities",
|
||||
"omit",
|
||||
"merge",
|
||||
"json"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@sindresorhus/tsconfig": "~0.7.0",
|
||||
"expect-type": "^0.11.0",
|
||||
"tsd": "^0.14.0",
|
||||
"typescript": "^4.1.3",
|
||||
"xo": "^0.36.1"
|
||||
},
|
||||
"types": "./index.d.ts",
|
||||
"typesVersions": {
|
||||
">=4.1": {
|
||||
"*": [
|
||||
"ts41/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"xo": {
|
||||
"rules": {
|
||||
"@typescript-eslint/ban-types": "off",
|
||||
"@typescript-eslint/indent": "off",
|
||||
"node/no-unsupported-features/es-builtins": "off"
|
||||
}
|
||||
}
|
||||
}
|
794
node_modules/ansi-escapes/node_modules/type-fest/readme.md
generated
vendored
Normal file
794
node_modules/ansi-escapes/node_modules/type-fest/readme.md
generated
vendored
Normal file
@ -0,0 +1,794 @@
|
||||
<div align="center">
|
||||
<br>
|
||||
<br>
|
||||
<img src="media/logo.svg" alt="type-fest" height="300">
|
||||
<br>
|
||||
<br>
|
||||
<b>A collection of essential TypeScript types</b>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<div align="center">
|
||||
<p>
|
||||
<p>
|
||||
<sup>
|
||||
<a href="https://github.com/sponsors/sindresorhus">Sindre Sorhus' open source work is supported by the community</a>
|
||||
</sup>
|
||||
</p>
|
||||
<sup>Special thanks to:</sup>
|
||||
<br>
|
||||
<br>
|
||||
<a href="https://standardresume.co/tech">
|
||||
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="180"/>
|
||||
</a>
|
||||
<br>
|
||||
<br>
|
||||
<a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=type-fest&utm_source=github">
|
||||
<div>
|
||||
<img src="https://sindresorhus.com/assets/thanks/workos-logo-white-bg.svg" width="220" alt="WorkOS">
|
||||
</div>
|
||||
<b>Your app, enterprise-ready.</b>
|
||||
<div>
|
||||
<sub>Start selling to enterprise customers with just a few lines of code.</sub>
|
||||
<br>
|
||||
<sup>Add Single Sign-On (and more) in minutes instead of months.</sup>
|
||||
</div>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<br>
|
||||
<hr>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
[](https://giphy.com/gifs/illustration-rainbow-unicorn-26AHG5KGFxSkUWw1i)
|
||||
[](https://www.npmjs.com/package/type-fest?activeTab=dependents)
|
||||
[](https://www.npmjs.com/package/type-fest)
|
||||
[](https://paka.dev/npm/type-fest)
|
||||
|
||||
Many of the types here should have been built-in. You can help by suggesting some of them to the [TypeScript project](https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md).
|
||||
|
||||
Either add this package as a dependency or copy-paste the needed types. No credit required. 👌
|
||||
|
||||
PR welcome for additional commonly needed types and docs improvements. Read the [contributing guidelines](.github/contributing.md) first.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install type-fest
|
||||
```
|
||||
|
||||
*Requires TypeScript >=3.8*
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import {Except} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
unicorn: string;
|
||||
rainbow: boolean;
|
||||
};
|
||||
|
||||
type FooWithoutRainbow = Except<Foo, 'rainbow'>;
|
||||
//=> {unicorn: string}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
Click the type names for complete docs.
|
||||
|
||||
### Basic
|
||||
|
||||
- [`Primitive`](source/primitive.d.ts) - Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
||||
- [`Class`](source/basic.d.ts) - Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
||||
- [`TypedArray`](source/typed-array.d.ts) - Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
||||
- [`JsonObject`](source/basic.d.ts) - Matches a JSON object.
|
||||
- [`JsonArray`](source/basic.d.ts) - Matches a JSON array.
|
||||
- [`JsonValue`](source/basic.d.ts) - Matches any valid JSON value.
|
||||
- [`ObservableLike`](source/observable-like.d.ts) - Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
|
||||
|
||||
### Utilities
|
||||
|
||||
- [`Except`](source/except.d.ts) - Create a type from an object type without certain keys. This is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type).
|
||||
- [`Mutable`](source/mutable.d.ts) - Create a type that strips `readonly` from all or some of an object's keys. The inverse of `Readonly<T>`.
|
||||
- [`Merge`](source/merge.d.ts) - Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
||||
- [`MergeExclusive`](source/merge-exclusive.d.ts) - Create a type that has mutually exclusive keys.
|
||||
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given keys.
|
||||
- [`RequireExactlyOne`](source/require-exactly-one.d.ts) - Create a type that requires exactly a single key of the given keys and disallows more.
|
||||
- [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type. Use [`Partial<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1401-L1406) if you only need one level deep.
|
||||
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of an `object`/`Map`/`Set`/`Array` type. Use [`Readonly<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1415-L1420) if you only need one level deep.
|
||||
- [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union. Workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
|
||||
- [`Promisable`](source/promisable.d.ts) - Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
||||
- [`Opaque`](source/opaque.d.ts) - Create an [opaque type](https://codemix.com/opaque-types-in-javascript/).
|
||||
- [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional.
|
||||
- [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required.
|
||||
- [`ValueOf`](source/value-of.d.ts) - Create a union of the given object's values, and optionally specify which keys to get the values from.
|
||||
- [`PromiseValue`](source/promise-value.d.ts) - Returns the type that is wrapped inside a `Promise`.
|
||||
- [`AsyncReturnType`](source/async-return-type.d.ts) - Unwrap the return type of a function that returns a `Promise`.
|
||||
- [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract keys from a shape where values extend the given `Condition` type.
|
||||
- [`ConditionalPick`](source/conditional-pick.d.ts) - Like `Pick` except it selects properties from a shape where the values extend the given `Condition` type.
|
||||
- [`ConditionalExcept`](source/conditional-except.d.ts) - Like `Omit` except it removes properties from a shape where the values extend the given `Condition` type.
|
||||
- [`UnionToIntersection`](source/union-to-intersection.d.ts) - Convert a union type to an intersection type.
|
||||
- [`Stringified`](source/stringified.d.ts) - Create a type with the keys of the given type changed to `string` type.
|
||||
- [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length.
|
||||
- [`IterableElement`](source/iterable-element.d.ts) - Get the element type of an `Iterable`/`AsyncIterable`. For example, an array or a generator.
|
||||
- [`Entry`](source/entry.d.ts) - Create a type that represents the type of an entry of a collection.
|
||||
- [`Entries`](source/entries.d.ts) - Create a type that represents the type of the entries of a collection.
|
||||
- [`SetReturnType`](source/set-return-type.d.ts) - Create a function type with a return type of your choice and the same parameters as the given function type.
|
||||
- [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
|
||||
- [`Includes`](ts41/includes.ts) - Returns a boolean for whether the given array includes the given item.
|
||||
- [`Simplify`](source/simplify.d.ts) - Flatten the type output to improve type hints shown in editors.
|
||||
|
||||
### Template literal types
|
||||
|
||||
*Note:* These require [TypeScript 4.1 or newer](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#template-literal-types).
|
||||
|
||||
- [`CamelCase`](ts41/camel-case.d.ts) – Convert a string literal to camel-case (`fooBar`).
|
||||
- [`CamelCasedProperties`](ts41/camel-cased-properties.d.ts) – Convert object properties to camel-case (`fooBar`).
|
||||
- [`CamelCasedPropertiesDeep`](ts41/camel-cased-properties-deep.d.ts) – Convert object properties to camel-case recursively (`fooBar`).
|
||||
- [`KebabCase`](ts41/kebab-case.d.ts) – Convert a string literal to kebab-case (`foo-bar`).
|
||||
- [`KebabCasedProperties`](ts41/kebab-cased-properties.d.ts) – Convert a object properties to kebab-case recursively (`foo-bar`).
|
||||
- [`KebabCasedPropertiesDeep`](ts41/kebab-cased-properties-deep.d.ts) – Convert object properties to kebab-case (`foo-bar`).
|
||||
- [`PascalCase`](ts41/pascal-case.d.ts) – Converts a string literal to pascal-case (`FooBar`)
|
||||
- [`PascalCasedProperties`](ts41/pascal-cased-properties.d.ts) – Converts object properties to pascal-case (`FooBar`)
|
||||
- [`PascalCasedPropertiesDeep`](ts41/pascal-cased-properties-deep.d.ts) – Converts object properties to pascal-case (`FooBar`)
|
||||
- [`SnakeCase`](ts41/snake-case.d.ts) – Convert a string literal to snake-case (`foo_bar`).
|
||||
- [`SnakeCasedProperties`](ts41/snake-cased-properties-deep.d.ts) – Convert object properties to snake-case (`foo_bar`).
|
||||
- [`SnakeCasedPropertiesDeep`](ts41/snake-cased-properties-deep.d.ts) – Convert object properties to snake-case recursively (`foo_bar`).
|
||||
- [`ScreamingSnakeCase`](ts41/screaming-snake-case.d.ts) - Convert a string literal to screaming-snake-case (`FOO_BAR`).
|
||||
- [`DelimiterCase`](ts41/delimiter-case.d.ts) – Convert a string literal to a custom string delimiter casing.
|
||||
- [`DelimiterCasedProperties`](ts41/delimiter-cased-properties.d.ts) – Convert object properties to a custom string delimiter casing.
|
||||
- [`DelimiterCasedPropertiesDeep`](ts41/delimiter-cased-properties-deep.d.ts) – Convert object properties to a custom string delimiter casing recursively.
|
||||
- [`Split`](ts41/split.d.ts) - Represents an array of strings split using a given character or character set.
|
||||
- [`Trim`](ts41/trim.d.ts) - Remove leading and trailing spaces from a string.
|
||||
- [`Get`](ts41/get.d.ts) - Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
|
||||
- [`LastArrayElement`](ts41/last-array-element.d.ts) - Extracts the type of the last element of an array.
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file).
|
||||
- [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 4.4).
|
||||
|
||||
## Declined types
|
||||
|
||||
*If we decline a type addition, we will make sure to document the better solution here.*
|
||||
|
||||
- [`Diff` and `Spread`](https://github.com/sindresorhus/type-fest/pull/7) - The PR author didn't provide any real-world use-cases and the PR went stale. If you think this type is useful, provide some real-world use-cases and we might reconsider.
|
||||
- [`Dictionary`](https://github.com/sindresorhus/type-fest/issues/33) - You only save a few characters (`Dictionary<number>` vs `Record<string, number>`) from [`Record`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1429-L1434), which is more flexible and well-known. Also, you shouldn't use an object as a dictionary. We have `Map` in JavaScript now.
|
||||
- [`ExtractProperties` and `ExtractMethods`](https://github.com/sindresorhus/type-fest/pull/4) - The types violate the single responsibility principle. Instead, refine your types into more granular type hierarchies.
|
||||
|
||||
## Tips
|
||||
|
||||
### Related
|
||||
|
||||
- [typed-query-selector](https://github.com/g-plane/typed-query-selector) - Enhances `document.querySelector` and `document.querySelectorAll` with a template literal type that matches element types returned from an HTML element query selector.
|
||||
|
||||
### Built-in types
|
||||
|
||||
There are many advanced types most users don't know about.
|
||||
|
||||
- [`Partial<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1401-L1406) - Make all properties in `T` optional.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgHIHsAmEDC6QzADmyA3gLABQyycADnanALYQBcyAzmFKEQNxUaddFDAcQAV2YAjaIMoBfKlQQAbOJ05osEAIIMAQpOBrsUMkOR1eANziRkCfISKSoD4Pg4ZseAsTIALyW1DS0DEysHADkvvoMMQA0VsKi4sgAzAAMuVaKClY2wPaOknSYDrguADwA0sgQAB6QIJjaANYQAJ7oMDp+LsQAfAAUXd0cdUnI9mo+uv6uANp1ALoAlKHhyGAAFsCcAHTOAW4eYF4gyxNrwbNwago0ypRWp66jH8QcAApwYmAjxq8SWIy2FDCNDA3ToKFBQyIdR69wmfQG1TOhShyBgomQX3w3GQE2Q6IA8jIAFYQBBgI4TTiEs5bTQYsFInrLTbbHZOIlgZDlSqQABqj0kKBC3yINx6a2xfOQwH6o2FVXFaklwSCIUkbQghBAEEwENSfNOlykEGefNe5uhB2O6sgS3GPRmLogmslG1tLxUOKgEDA7hAuydtteryAA)
|
||||
|
||||
```ts
|
||||
interface NodeConfig {
|
||||
appName: string;
|
||||
port: number;
|
||||
}
|
||||
|
||||
class NodeAppBuilder {
|
||||
private configuration: NodeConfig = {
|
||||
appName: 'NodeApp',
|
||||
port: 3000
|
||||
};
|
||||
|
||||
private updateConfig<Key extends keyof NodeConfig>(key: Key, value: NodeConfig[Key]) {
|
||||
this.configuration[key] = value;
|
||||
}
|
||||
|
||||
config(config: Partial<NodeConfig>) {
|
||||
type NodeConfigKey = keyof NodeConfig;
|
||||
|
||||
for (const key of Object.keys(config) as NodeConfigKey[]) {
|
||||
const updateValue = config[key];
|
||||
|
||||
if (updateValue === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.updateConfig(key, updateValue);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
// `Partial<NodeConfig>`` allows us to provide only a part of the
|
||||
// NodeConfig interface.
|
||||
new NodeAppBuilder().config({appName: 'ToDoApp'});
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Required<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1408-L1413) - Make all properties in `T` required.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/AQ4SwOwFwUwJwGYEMDGNgGED21VQGJZwC2wA3gFCjXAzFJgA2A-AFzADOUckA5gNxUaIYjA4ckvGG07c+g6gF8KQkAgCuEFFDA5O6gEbEwUbLm2ESwABQIixACJIoSdgCUYAR3Vg4MACYAPGYuFvYAfACU5Ko0APRxwADKMBD+wFAAFuh2Vv7OSBlYGdmc8ABu8LHKsRyGxqY4oQT21pTCIHQMjOwA5DAAHgACxAAOjDAAdChYxL0ANLHUouKSMH0AEmAAhJhY6ozpAJ77GTCMjMCiV0ToSAb7UJPPC9WRgrEJwAAqR6MwSRQPFGUFocDgRHYxnEfGAowh-zgUCOwF6KwkUl6tXqJhCeEsxDaS1AXSYfUGI3GUxmc0WSneQA)
|
||||
|
||||
```ts
|
||||
interface ContactForm {
|
||||
email?: string;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
function submitContactForm(formData: Required<ContactForm>) {
|
||||
// Send the form data to the server.
|
||||
}
|
||||
|
||||
submitContactForm({
|
||||
email: 'ex@mple.com',
|
||||
message: 'Hi! Could you tell me more about…',
|
||||
});
|
||||
|
||||
// TypeScript error: missing property 'message'
|
||||
submitContactForm({
|
||||
email: 'ex@mple.com',
|
||||
});
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Readonly<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1415-L1420) - Make all properties in `T` readonly.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/AQ4UwOwVwW2AZA9gc3mAbmANsA3gKFCOAHkAzMgGkOJABEwAjKZa2kAUQCcvEu32AMQCGAF2FYBIAL4BufDRABLCKLBcywgMZgEKZOoDCiCGSXI8i4hGEwwALmABnUVxXJ57YFgzZHSVF8sT1BpBSItLGEnJz1kAy5LLy0TM2RHACUwYQATEywATwAeAITjU3MAPnkrCJMXLigtUT4AClxgGztKbyDgaX99I1TzAEokr1BRAAslJwA6FIqLAF48TtswHp9MHDla9hJGACswZvmyLjAwAC8wVpm5xZHkUZDaMKIwqyWXYCW0oN4sNlsA1h0ug5gAByACyBQAggAHJHQ7ZBIFoXbzBjMCz7OoQP5YIaJNYQMAAdziCVaALGNSIAHomcAACoFJFgADKWjcSNEwG4vC4ji0wggEEQguiTnMEGALWAV1yAFp8gVgEjeFyuKICvMrCTgVxnst5jtsGC4ljsPNhXxGaAWcAAOq6YRXYDCRg+RWIcA5JSC+kWdCepQ+v3RYCU3RInzRMCGwlpC19NYBW1Ye08R1AA)
|
||||
|
||||
```ts
|
||||
enum LogLevel {
|
||||
Off,
|
||||
Debug,
|
||||
Error,
|
||||
Fatal
|
||||
};
|
||||
|
||||
interface LoggerConfig {
|
||||
name: string;
|
||||
level: LogLevel;
|
||||
}
|
||||
|
||||
class Logger {
|
||||
config: Readonly<LoggerConfig>;
|
||||
|
||||
constructor({name, level}: LoggerConfig) {
|
||||
this.config = {name, level};
|
||||
Object.freeze(this.config);
|
||||
}
|
||||
}
|
||||
|
||||
const config: LoggerConfig = {
|
||||
name: 'MyApp',
|
||||
level: LogLevel.Debug
|
||||
};
|
||||
|
||||
const logger = new Logger(config);
|
||||
|
||||
// TypeScript Error: cannot assign to read-only property.
|
||||
logger.config.level = LogLevel.Error;
|
||||
|
||||
// We are able to edit config variable as we please.
|
||||
config.level = LogLevel.Error;
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Pick<T, K>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1422-L1427) - From `T`, pick a set of properties whose keys are in the union `K`.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/AQ4SwOwFwUwJwGYEMDGNgEE5TCgNugN4BQoZwOUBAXMAM5RyQDmA3KeSFABYCuAtgCMISMHloMmENh04oA9tBjQJjFuzIBfYrOAB6PcADCcGElh1gEGAHcKATwAO6ebyjB5CTNlwFwSxFR0BX5HeToYABNgBDh5fm8cfBg6AHIKG3ldA2BHOOcfFNpUygJ0pAhokr4hETFUgDpswywkggAFUwA3MFtgAF5gQgowKhhVKTYKGuFRcXo1aVZgbTIoJ3RW3xhOmB6+wfbcAGsAHi3kgBpgEtGy4AAfG54BWfqAPnZm4AAlZUj4MAkMA8GAGB4vEgfMlLLw6CwPBA8PYRmMgZVgAC6CgmI4cIommQELwICh8RBgKZKvALh1ur0bHQABR5PYMui0Wk7em2ADaAF0AJS0AASABUALIAGQAogR+Mp3CROCAFBBwVC2ikBpj5CgBIqGjizLA5TAFdAmalImAuqlBRoVQh5HBgEy1eDWfs7J5cjzGYKhroVfpDEhHM4MV6GRR5NN0JrtnRg6BVirTFBeHAKYmYY6QNpdB73LmCJZBlSAXAubtvczeSmQMNSuMbmKNgBlHFgPEUNwusBIPAAQlS1xetTmxT0SDoESgdD0C4aACtHMwxytLrohawgA)
|
||||
|
||||
```ts
|
||||
interface Article {
|
||||
title: string;
|
||||
thumbnail: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
// Creates new type out of the `Article` interface composed
|
||||
// from the Articles' two properties: `title` and `thumbnail`.
|
||||
// `ArticlePreview = {title: string; thumbnail: string}`
|
||||
type ArticlePreview = Pick<Article, 'title' | 'thumbnail'>;
|
||||
|
||||
// Render a list of articles using only title and description.
|
||||
function renderArticlePreviews(previews: ArticlePreview[]): HTMLElement {
|
||||
const articles = document.createElement('div');
|
||||
|
||||
for (const preview of previews) {
|
||||
// Append preview to the articles.
|
||||
}
|
||||
|
||||
return articles;
|
||||
}
|
||||
|
||||
const articles = renderArticlePreviews([
|
||||
{
|
||||
title: 'TypeScript tutorial!',
|
||||
thumbnail: '/assets/ts.jpg'
|
||||
}
|
||||
]);
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Record<K, T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1429-L1434) - Construct a type with a set of properties `K` of type `T`.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/AQ4ejYAUHsGcCWAXBMB2dgwGbAKYC2ADgDYwCeeemCaWArgE7ADGMxAhmuQHQBQoYEnJE8wALKEARnkaxEKdMAC8wAOS0kstGuAAfdQBM8ANzxlRjXQbVaWACwC0JPB0NqA3HwGgIwAJJoWozYHCxixnAsjAhStADmwESMMJYo1Fi4HMCIaPEu+MRklHj8gpqyoeHAAKJFFFTAAN4+giDYCIxwSAByHAR4AFw5SDF5Xm2gJBzdfQPD3WPxE5PAlBxdAPLYNQAelgh4aOHDaPQEMowrIAC+3oJ+AMKMrlrAXFhSAFZ4LEhC9g4-0BmA4JBISXgiCkBQABpILrJ5MhUGhYcATGD6Bk4Hh-jNgABrPDkOBlXyQAAq9ngYmJpOAAHcEOCRjAXqwYODfoo6DhakUSph+Uh7GI4P0xER4Cj0OSQGwMP8tP1hgAlX7swwAHgRl2RvIANALSA08ABtAC6AD4VM1Wm0Kow0MMrYaHYJjGYLLJXZb3at1HYnC43Go-QHQDcvA6-JsmEJXARgCDgMYWAhjIYhDAU+YiMAAFIwex0ZmilMITCGF79TLAGRsAgJYAAZRwSEZGzEABFTOZUrJ5Yn+jwnWgeER6HB7AAKJrADpdXqS4ZqYultTG6azVfqHswPBbtauLY7fayQ7HIbAAAMwBuAEoYw9IBq2Ixs9h2eFMOQYPQObALQKJgggABeYhghCIpikkKRpOQRIknAsZUiIeCttECBEP8NSMCkjDDAARMGziuIYxHwYOjDCMBmDNnAuTxA6irdCOBB1Lh5Dqpqn66tISIykawBnOCtqqC0gbjqc9DgpGkxegOliyfJDrRkAA)
|
||||
|
||||
```ts
|
||||
// Positions of employees in our company.
|
||||
type MemberPosition = 'intern' | 'developer' | 'tech-lead';
|
||||
|
||||
// Interface describing properties of a single employee.
|
||||
interface Employee {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
yearsOfExperience: number;
|
||||
}
|
||||
|
||||
// Create an object that has all possible `MemberPosition` values set as keys.
|
||||
// Those keys will store a collection of Employees of the same position.
|
||||
const team: Record<MemberPosition, Employee[]> = {
|
||||
intern: [],
|
||||
developer: [],
|
||||
'tech-lead': [],
|
||||
};
|
||||
|
||||
// Our team has decided to help John with his dream of becoming Software Developer.
|
||||
team.intern.push({
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
yearsOfExperience: 0
|
||||
});
|
||||
|
||||
// `Record` forces you to initialize all of the property keys.
|
||||
// TypeScript Error: "tech-lead" property is missing
|
||||
const teamEmpty: Record<MemberPosition, null> = {
|
||||
intern: null,
|
||||
developer: null,
|
||||
};
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Exclude<T, U>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1436-L1439) - Exclude from `T` those types that are assignable to `U`.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/JYOwLgpgTgZghgYwgAgMrQG7QMIHsQzADmyA3gFDLIAOuUYAXMiAK4A2byAPsgM5hRQJHqwC2AI2gBucgF9y5MAE9qKAEoQAjiwj8AEnBAATNtGQBeZAAooWphu26wAGmS3e93bRC8IASgsAPmRDJRlyAHoI5ABRAA8ENhYjFFYOZGVVZBgoXFFkAAM0zh5+QRBhZhYJaAKAOkjogEkQZAQ4X2QAdwALCFbaemRgXmQtFjhOMFwq9K6ULuB0lk6U+HYwZAxJnQaYFhAEMGB8ZCIIMAAFOjAANR2IK0HGWISklIAedCgsKDwCYgAbQA5M9gQBdVzFQJ+JhiSRQMiUYYwayZCC4VHPCzmSzAspCYEBWxgFhQAZwKC+FpgJ43VwARgADH4ZFQSWSBjcZPJyPtDsdTvxKWBvr8rD1DCZoJ5HPopaYoK4EPhCEQmGKcKriLCtrhgEYkVQVT5Nr4fmZLLZtMBbFZgT0wGBqES6ghbHBIJqoBKFdBWQpjfh+DQbhY2tqiHVsbjLMVkAB+ZAAZiZaeQTHOVxu9ySjxNaujNwDVHNvzqbBGkBAdPoAfkQA)
|
||||
|
||||
```ts
|
||||
interface ServerConfig {
|
||||
port: null | string | number;
|
||||
}
|
||||
|
||||
type RequestHandler = (request: Request, response: Response) => void;
|
||||
|
||||
// Exclude `null` type from `null | string | number`.
|
||||
// In case the port is equal to `null`, we will use default value.
|
||||
function getPortValue(port: Exclude<ServerConfig['port'], null>): number {
|
||||
if (typeof port === 'string') {
|
||||
return parseInt(port, 10);
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
function startServer(handler: RequestHandler, config: ServerConfig): void {
|
||||
const server = require('http').createServer(handler);
|
||||
|
||||
const port = config.port === null ? 3000 : getPortValue(config.port);
|
||||
server.listen(port);
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Extract<T, U>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1441-L1444) - Extract from `T` those types that are assignable to `U`.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXzSwEdkQBJYACgEoAueVZAWwCMQYBuAKDDwGcM8MgBF4AXngBlAJ6scESgHIRi6ty5ZUGdoihgEABXZ888AN5d48ANoiAuvUat23K6ihMQ9ATE0BzV3goPy8GZjZOLgBfLi4Aejj4AEEICBwAdz54MAALKFQQ+BxEeAAHY1NgKAwoIKy0grr4DByEUpgccpgMaXgAaxBerCzi+B9-ZulygDouFHRsU1z8kKMYE1RhaqgAHkt4AHkWACt4EAAPbVRgLLWNgBp9gGlBs8uQa6yAUUuYPQwdgNpKM7nh7mMML4CgA+R5WABqUAgpDeVxuhxO1he0jsXGh8EoOBO9COx3BQPo2PBADckaR6IjkSA6PBqTgsMBzPsicdrEC7OJWXSQNwYvFEgAVTS9JLXODpeDpKBZFg4GCoWa8VACIJykAKiQWKy2YQOAioYikCg0OEMDyhRSy4DyxS24KhAAMjyi6gS8AAwjh5OD0iBFHAkJoEOksC1mnkMJq8gUQKDNttKPlnfrwYp3J5XfBHXqoKpfYkAOI4ansTxaeDADmoRSCCBYAbxhC6TDx6rwYHIRX5bScjA4bLJwoDmDwDkfbA9JMrVMVdM1TN69LgkTgwgkchUahqIA)
|
||||
|
||||
```ts
|
||||
declare function uniqueId(): number;
|
||||
|
||||
const ID = Symbol('ID');
|
||||
|
||||
interface Person {
|
||||
[ID]: number;
|
||||
name: string;
|
||||
age: number;
|
||||
}
|
||||
|
||||
// Allows changing the person data as long as the property key is of string type.
|
||||
function changePersonData<
|
||||
Obj extends Person,
|
||||
Key extends Extract<keyof Person, string>,
|
||||
Value extends Obj[Key]
|
||||
> (obj: Obj, key: Key, value: Value): void {
|
||||
obj[key] = value;
|
||||
}
|
||||
|
||||
// Tiny Andrew was born.
|
||||
const andrew = {
|
||||
[ID]: uniqueId(),
|
||||
name: 'Andrew',
|
||||
age: 0,
|
||||
};
|
||||
|
||||
// Cool, we're fine with that.
|
||||
changePersonData(andrew, 'name', 'Pony');
|
||||
|
||||
// Goverment didn't like the fact that you wanted to change your identity.
|
||||
changePersonData(andrew, ID, uniqueId());
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`NonNullable<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1446-L1449) - Exclude `null` and `undefined` from `T`.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
Works with <code>strictNullChecks</code> set to <code>true</code>. (Read more <a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html">here</a>)
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/C4TwDgpgBACg9gJ2AOQK4FsBGEFQLxQDOwCAlgHYDmUAPlORtrnQwDasDcAUFwPQBU-WAEMkUOADMowqAGNWwwoSgATCBIqlgpOOSjAAFsOBRSy1IQgr9cKJlSlW1mZYQA3HFH68u8xcoBlHA8EACEHJ08Aby4oKDBUTFZSWXjEFEYcAEIALihkXTR2YSSIAB54JDQsHAA+blj4xOTUsHSACkMzPKD3HHDHNQQAGjSkPMqMmoQASh7g-oihqBi4uNIpdraxPAI2VhmVxrX9AzMAOm2ppnwoAA4ABifuE4BfKAhWSyOTuK7CS7pao3AhXF5rV48E4ICDAVAIPT-cGQyG+XTEIgLMJLTx7CAAdygvRCA0iCHaMwarhJOIQjUBSHaACJHk8mYdeLwxtdcVAAOSsh58+lXdr7Dlcq7A3n3J4PEUdADMcspUE53OluAIUGVTx46oAKuAIAFZGQwCYAKIIBCILjUxaDHAMnla+iodjcIA)
|
||||
|
||||
```ts
|
||||
type PortNumber = string | number | null;
|
||||
|
||||
/** Part of a class definition that is used to build a server */
|
||||
class ServerBuilder {
|
||||
portNumber!: NonNullable<PortNumber>;
|
||||
|
||||
port(this: ServerBuilder, port: PortNumber): ServerBuilder {
|
||||
if (port == null) {
|
||||
this.portNumber = 8000;
|
||||
} else {
|
||||
this.portNumber = port;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
const serverBuilder = new ServerBuilder();
|
||||
|
||||
serverBuilder
|
||||
.port('8000') // portNumber = '8000'
|
||||
.port(null) // portNumber = 8000
|
||||
.port(3000); // portNumber = 3000
|
||||
|
||||
// TypeScript error
|
||||
serverBuilder.portNumber = null;
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Parameters<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1451-L1454) - Obtain the parameters of a function type in a tuple.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/GYVwdgxgLglg9mABAZwBYmMANgUwBQxgAOIUAXIgIZgCeA2gLoCUFAbnDACaIDeAUIkQB6IYgCypSlBxUATrMo1ECsJzgBbLEoipqAc0J7EMKMgDkiHLnU4wp46pwAPHMgB0fAL58+oSLARECEosLAA5ABUYG2QAHgAxJGdpVWREPDdMylk9ZApqemZEAF4APipacrw-CApEgBogkKwAYThwckQwEHUAIxxZJl4BYVEImiIZKF0oZRwiWVdbeygJmThgOYgcGFYcbhqApCJsyhtpWXcR1cnEePBoeDAABVPzgbTixFeFd8uEsClADcIxGiygIFkSEOT3SmTc2VydQeRx+ZxwF2QQ34gkEwDgsnSuFmMBKiAADEDjIhYk1Qm0OlSYABqZnYka4xA1DJZHJYkGc7yCbyeRA+CAIZCzNAYbA4CIAdxg2zJwVCkWirjwMswuEaACYmCCgA)
|
||||
|
||||
```ts
|
||||
function shuffle(input: any[]): void {
|
||||
// Mutate array randomly changing its' elements indexes.
|
||||
}
|
||||
|
||||
function callNTimes<Fn extends (...args: any[]) => any> (func: Fn, callCount: number) {
|
||||
// Type that represents the type of the received function parameters.
|
||||
type FunctionParameters = Parameters<Fn>;
|
||||
|
||||
return function (...args: FunctionParameters) {
|
||||
for (let i = 0; i < callCount; i++) {
|
||||
func(...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const shuffleTwice = callNTimes(shuffle, 2);
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`ConstructorParameters<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1456-L1459) - Obtain the parameters of a constructor function type in a tuple.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/MYGwhgzhAECCBOAXAlqApgWQPYBM0mgG8AoaaFRENALmgkXmQDsBzAblOmCycTV4D8teo1YdO3JiICuwRFngAKClWENmLAJRFOZRAAtkEAHQq00ALzlklNBzIBfYk+KhIMAJJTEYJsDQAwmDA+mgAPAAq0GgAHnxMODCKTGgA7tCKxllg8CwQtL4AngDaALraFgB80EWa1SRkAA6MAG5gfNAB4FABPDJyCrQR9tDNyG0dwMGhtBhgjWEiGgA00F70vv4RhY3hEZXVVinpc42KmuJkkv3y8Bly8EPaDWTkhiZd7r3e8LK3llwGCMXGQWGhEOsfH5zJlsrl8p0+gw-goAAo5MAAW3BaHgEEilU0tEhmzQ212BJ0ry4SOg+kg+gBBiMximIGA0nAfAQLGk2N4EAAEgzYcYcnkLsRdDTvNEYkYUKwSdCme9WdM0MYwYhFPSIPpJdTkAAzDKxBUaZX+aAAQgsVmkCTQxuYaBw2ng4Ok8CYcotSu8pMur09iG9vuObxZnx6SN+AyUWTF8MN0CcZE4Ywm5jZHK5aB5fP4iCFIqT4oRRTKRLo6lYVNeAHpG50wOzOe1zHr9NLQ+HoABybsD4HOKXXRA1JCoKhBELmI5pNaB6Fz0KKBAodDYPAgSUTmqYsAALx4m5nC6nW9nGq14KtaEUA9gR9PvuNCjQ9BgACNvcwNBtAcLiAA)
|
||||
|
||||
```ts
|
||||
class ArticleModel {
|
||||
title: string;
|
||||
content?: string;
|
||||
|
||||
constructor(title: string) {
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
|
||||
class InstanceCache<T extends (new (...args: any[]) => any)> {
|
||||
private ClassConstructor: T;
|
||||
private cache: Map<string, InstanceType<T>> = new Map();
|
||||
|
||||
constructor (ctr: T) {
|
||||
this.ClassConstructor = ctr;
|
||||
}
|
||||
|
||||
getInstance (...args: ConstructorParameters<T>): InstanceType<T> {
|
||||
const hash = this.calculateArgumentsHash(...args);
|
||||
|
||||
const existingInstance = this.cache.get(hash);
|
||||
if (existingInstance !== undefined) {
|
||||
return existingInstance;
|
||||
}
|
||||
|
||||
return new this.ClassConstructor(...args);
|
||||
}
|
||||
|
||||
private calculateArgumentsHash(...args: any[]): string {
|
||||
// Calculate hash.
|
||||
return 'hash';
|
||||
}
|
||||
}
|
||||
|
||||
const articleCache = new InstanceCache(ArticleModel);
|
||||
const amazonArticle = articleCache.getInstance('Amazon forests burining!');
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`ReturnType<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1461-L1464) – Obtain the return type of a function type.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/MYGwhgzhAECSAmICmBlJAnAbgS2E6A3gFDTTwD2AcuQC4AW2AdgOYAUAlAFzSbnbyEAvkWFFQkGJSQB3GMVI1sNZNwg10TZgG4S0YOUY0kh1es07d+xmvQBXYDXLpWi5UlMaWAGj0GjJ6BtNdkJdBQYIADpXZGgAXmgYpB1ScOwoq38aeN9DYxoU6GFRKzVoJjUwRjwAYXJbPPRuAFkwAAcAHgAxBodsAx9GWwBbACMMAD4cxhloVraOCyYjdAAzMDxoOut1e0d0UNIZ6WhWSPOwdGYIbiqATwBtAF0uaHudUQB6ACpv6ABpJBINqJdAbADW0Do5BOw3u5R2VTwMHIq2gAANtjZ0bkbHsnFCwJh8ONjHp0EgwEZ4JFoN9PkRVr1FAZoMwkDRYIjqkgOrosepoEgAB7+eAwAV2BxOLy6ACCVxgIrFEoMeOl6AACpcwMMORgIB1JRMiBNWKVdhruJKfOdIpdrtwFddXlzKjyACp3Nq842HaDIbL6BrZBIVGhIpB1EMYSLsmjmtWW-YhAA+qegAAYLKQLQj3ZsEsdccmnGcLor2Dn8xGedHGpEIBzEzspfsfMHDNAANTQACMVaIljV5GQkRA5DYmIpVKQAgAJARO9le33BDXIyi0YuLW2nJFGLqkOvxFB0YPdBSaLZ0IwNzyPkO8-xkGgsLh8Al427a3hWAhXwwHA8EHT5PmgAB1bAQBAANJ24adKWpft72RaBUTgRBUCAj89HAM8xCTaBjggABRQx0DuHJv25P9dCkWRZVIAAiBjoFImpmjlFBgA0NpsjadByDacgIDAEAIAAQmYpjoGYgAZSBsmGPw6DtZiiFA8CoJguDmAQmoZ2QvtUKQLdoAYmBTwgdEiCAA)
|
||||
|
||||
```ts
|
||||
/** Provides every element of the iterable `iter` into the `callback` function and stores the results in an array. */
|
||||
function mapIter<
|
||||
Elem,
|
||||
Func extends (elem: Elem) => any,
|
||||
Ret extends ReturnType<Func>
|
||||
>(iter: Iterable<Elem>, callback: Func): Ret[] {
|
||||
const mapped: Ret[] = [];
|
||||
|
||||
for (const elem of iter) {
|
||||
mapped.push(callback(elem));
|
||||
}
|
||||
|
||||
return mapped;
|
||||
}
|
||||
|
||||
const setObject: Set<string> = new Set();
|
||||
const mapObject: Map<number, string> = new Map();
|
||||
|
||||
mapIter(setObject, (value: string) => value.indexOf('Foo')); // number[]
|
||||
|
||||
mapIter(mapObject, ([key, value]: [number, string]) => {
|
||||
return key % 2 === 0 ? value : 'Odd';
|
||||
}); // string[]
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`InstanceType<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1466-L1469) – Obtain the instance type of a constructor function type.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/MYGwhgzhAECSAmICmBlJAnAbgS2E6A3gFDTTwD2AcuQC4AW2AdgOYAUAlAFzSbnbyEAvkWFFQkGJSQB3GMVI1sNZNwg10TZgG4S0YOUY0kh1es07d+xmvQBXYDXLpWi5UlMaWAGj0GjJ6BtNdkJdBQYIADpXZGgAXmgYpB1ScOwoq38aeN9DYxoU6GFRKzVoJjUwRjwAYXJbPPRuAFkwAAcAHgAxBodsAx9GWwBbACMMAD4cxhloVraOCyYjdAAzMDxoOut1e0d0UNIZ6WhWSPOwdGYIbiqATwBtAF0uaHudUQB6ACpv6ABpJBINqJdAbADW0Do5BOw3u5R2VTwMHIq2gAANtjZ0bkbHsnFCwJh8ONjHp0EgwEZ4JFoN9PkRVr1FAZoMwkDRYIjqkgOrosepoEgAB7+eAwAV2BxOLy6ACCVxgIrFEoMeOl6AACpcwMMORgIB1JRMiBNWKVdhruJKfOdIpdrtwFddXlzKjyACp3Nq842HaDIbL6BrZBIVGhIpB1EMYSLsmjmtWW-YhAA+qegAAYLKQLQj3ZsEsdccmnGcLor2Dn8xGedHGpEIBzEzspfsfMHDNAANTQACMVaIljV5GQkRA5DYmIpVKQAgAJARO9le33BDXIyi0YuLW2nJFGLqkOvxFB0YPdBSaLZ0IwNzyPkO8-xkGgsLh8Al427a3hWAhXwwHA8EHT5PmgAB1bAQBAANJ24adKWpft72RaBUTgRBUCAj89HAM8xCTaBjggABRQx0DuHJv25P9dCkWRZVIAAiBjoFImpmjlFBgA0NpsjadByDacgIDAEAIAAQmYpjoGYgAZSBsmGPw6DtZiiFA8CoJguDmAQmoZ2QvtUKQLdoAYmBTwgdEiCAA)
|
||||
|
||||
```ts
|
||||
class IdleService {
|
||||
doNothing (): void {}
|
||||
}
|
||||
|
||||
class News {
|
||||
title: string;
|
||||
content: string;
|
||||
|
||||
constructor(title: string, content: string) {
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
const instanceCounter: Map<Function, number> = new Map();
|
||||
|
||||
interface Constructor {
|
||||
new(...args: any[]): any;
|
||||
}
|
||||
|
||||
// Keep track how many instances of `Constr` constructor have been created.
|
||||
function getInstance<
|
||||
Constr extends Constructor,
|
||||
Args extends ConstructorParameters<Constr>
|
||||
>(constructor: Constr, ...args: Args): InstanceType<Constr> {
|
||||
let count = instanceCounter.get(constructor) || 0;
|
||||
|
||||
const instance = new constructor(...args);
|
||||
|
||||
instanceCounter.set(constructor, count + 1);
|
||||
|
||||
console.log(`Created ${count + 1} instances of ${Constr.name} class`);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
const idleService = getInstance(IdleService);
|
||||
// Will log: `Created 1 instances of IdleService class`
|
||||
const newsEntry = getInstance(News, 'New ECMAScript proposals!', 'Last month...');
|
||||
// Will log: `Created 1 instances of News class`
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Omit<T, K>`](https://github.com/microsoft/TypeScript/blob/71af02f7459dc812e85ac31365bfe23daf14b4e4/src/lib/es5.d.ts#L1446) – Constructs a type by picking all properties from T and then removing K.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
[Playground](https://typescript-play.js.org/?target=6#code/JYOwLgpgTgZghgYwgAgIImAWzgG2QbwChlks4BzCAVShwC5kBnMKUcgbmKYAcIFgIjBs1YgOXMpSFMWbANoBdTiW5woFddwAW0kfKWEAvoUIB6U8gDCUCHEiNkICAHdkYAJ69kz4GC3JcPG4oAHteKDABBxCYNAxsPFBIWEQUCAAPJG4wZABySUFcgJAAEzMLXNV1ck0dIuCw6EjBADpy5AB1FAQ4EGQAV0YUP2AHDy8wEOQbUugmBLwtEIA3OcmQnEjuZBgQqE7gAGtgZAhwKHdkHFGwNvGUdDIcAGUliIBJEF3kAF5kAHlML4ADyPBIAGjyBUYRQAPnkqho4NoYQA+TiEGD9EAISIhPozErQMG4AASK2gn2+AApek9pCSXm8wFSQooAJQMUkAFQAsgAZACiOAgmDOOSIJAQ+OYyGl4DgoDmf2QJRCCH6YvALQQNjsEGFovF1NyJWAy1y7OUyHMyE+yRAuFImG4Iq1YDswHxbRINjA-SgfXlHqVUE4xiAA)
|
||||
|
||||
```ts
|
||||
interface Animal {
|
||||
imageUrl: string;
|
||||
species: string;
|
||||
images: string[];
|
||||
paragraphs: string[];
|
||||
}
|
||||
|
||||
// Creates new type with all properties of the `Animal` interface
|
||||
// except 'images' and 'paragraphs' properties. We can use this
|
||||
// type to render small hover tooltip for a wiki entry list.
|
||||
type AnimalShortInfo = Omit<Animal, 'images' | 'paragraphs'>;
|
||||
|
||||
function renderAnimalHoverInfo (animals: AnimalShortInfo[]): HTMLElement {
|
||||
const container = document.createElement('div');
|
||||
// Internal implementation.
|
||||
return container;
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Uppercase<S extends string>`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types) - Transforms every character in a string into uppercase.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
```ts
|
||||
type T = Uppercase<'hello'>; // 'HELLO'
|
||||
|
||||
type T2 = Uppercase<'foo' | 'bar'>; // 'FOO' | 'BAR'
|
||||
|
||||
type T3<S extends string> = Uppercase<`aB${S}`>;
|
||||
type T4 = T30<'xYz'>; // 'ABXYZ'
|
||||
|
||||
type T5 = Uppercase<string>; // string
|
||||
type T6 = Uppercase<any>; // any
|
||||
type T7 = Uppercase<never>; // never
|
||||
type T8 = Uppercase<42>; // Error, type 'number' does not satisfy the constraint 'string'
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Lowercase<S extends string>`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types) - Transforms every character in a string into lowercase.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
```ts
|
||||
type T = Lowercase<'HELLO'>; // 'hello'
|
||||
|
||||
type T2 = Lowercase<'FOO' | 'BAR'>; // 'foo' | 'bar'
|
||||
|
||||
type T3<S extends string> = Lowercase<`aB${S}`>;
|
||||
type T4 = T32<'xYz'>; // 'abxyz'
|
||||
|
||||
type T5 = Lowercase<string>; // string
|
||||
type T6 = Lowercase<any>; // any
|
||||
type T7 = Lowercase<never>; // never
|
||||
type T8 = Lowercase<42>; // Error, type 'number' does not satisfy the constraint 'string'
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Capitalize<S extends string>`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types) - Transforms the first character in a string into uppercase.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
```ts
|
||||
type T = Capitalize<'hello'>; // 'Hello'
|
||||
|
||||
type T2 = Capitalize<'foo' | 'bar'>; // 'Foo' | 'Bar'
|
||||
|
||||
type T3<S extends string> = Capitalize<`aB${S}`>;
|
||||
type T4 = T32<'xYz'>; // 'ABxYz'
|
||||
|
||||
type T5 = Capitalize<string>; // string
|
||||
type T6 = Capitalize<any>; // any
|
||||
type T7 = Capitalize<never>; // never
|
||||
type T8 = Capitalize<42>; // Error, type 'number' does not satisfy the constraint 'string'
|
||||
```
|
||||
</details>
|
||||
|
||||
- [`Uncapitalize<S extends string>`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types) - Transforms the first character in a string into lowercase.
|
||||
<details>
|
||||
<summary>
|
||||
Example
|
||||
</summary>
|
||||
|
||||
```ts
|
||||
type T = Uncapitalize<'Hello'>; // 'hello'
|
||||
|
||||
type T2 = Uncapitalize<'Foo' | 'Bar'>; // 'foo' | 'bar'
|
||||
|
||||
type T3<S extends string> = Uncapitalize<`AB${S}`>;
|
||||
type T4 = T30<'xYz'>; // 'aBxYz'
|
||||
|
||||
type T5 = Uncapitalize<string>; // string
|
||||
type T6 = Uncapitalize<any>; // any
|
||||
type T7 = Uncapitalize<never>; // never
|
||||
type T8 = Uncapitalize<42>; // Error, type 'number' does not satisfy the constraint 'string'
|
||||
```
|
||||
</details>
|
||||
|
||||
You can find some examples in the [TypeScript docs](https://www.typescriptlang.org/docs/handbook/advanced-types.html#predefined-conditional-types).
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Jarek Radosz](https://github.com/CvX)
|
||||
- [Dimitri Benin](https://github.com/BendingBender)
|
||||
- [Pelle Wessman](https://github.com/voxpelli)
|
||||
|
||||
## License
|
||||
|
||||
(MIT OR CC0-1.0)
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-type-fest?utm_source=npm-type-fest&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
25
node_modules/ansi-escapes/node_modules/type-fest/source/async-return-type.d.ts
generated
vendored
Normal file
25
node_modules/ansi-escapes/node_modules/type-fest/source/async-return-type.d.ts
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
import {PromiseValue} from './promise-value';
|
||||
|
||||
type AsyncFunction = (...args: any[]) => Promise<unknown>;
|
||||
|
||||
/**
|
||||
Unwrap the return type of a function that returns a `Promise`.
|
||||
|
||||
There has been [discussion](https://github.com/microsoft/TypeScript/pull/35998) about implementing this type in TypeScript.
|
||||
|
||||
@example
|
||||
```ts
|
||||
import {AsyncReturnType} from 'type-fest';
|
||||
import {asyncFunction} from 'api';
|
||||
|
||||
// This type resolves to the unwrapped return type of `asyncFunction`.
|
||||
type Value = AsyncReturnType<typeof asyncFunction>;
|
||||
|
||||
async function doSomething(value: Value) {}
|
||||
|
||||
asyncFunction().then(value => doSomething(value));
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type AsyncReturnType<Target extends AsyncFunction> = PromiseValue<ReturnType<Target>>;
|
33
node_modules/ansi-escapes/node_modules/type-fest/source/asyncify.d.ts
generated
vendored
Normal file
33
node_modules/ansi-escapes/node_modules/type-fest/source/asyncify.d.ts
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
import {PromiseValue} from './promise-value';
|
||||
import {SetReturnType} from './set-return-type';
|
||||
|
||||
/**
|
||||
Create an async version of the given function type, by boxing the return type in `Promise` while keeping the same parameter types.
|
||||
|
||||
Use-case: You have two functions, one synchronous and one asynchronous that do the same thing. Instead of having to duplicate the type definition, you can use `Asyncify` to reuse the synchronous type.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Asyncify} from 'type-fest';
|
||||
|
||||
// Synchronous function.
|
||||
function getFooSync(someArg: SomeType): Foo {
|
||||
// …
|
||||
}
|
||||
|
||||
type AsyncifiedFooGetter = Asyncify<typeof getFooSync>;
|
||||
//=> type AsyncifiedFooGetter = (someArg: SomeType) => Promise<Foo>;
|
||||
|
||||
// Same as `getFooSync` but asynchronous.
|
||||
const getFooAsync: AsyncifiedFooGetter = (someArg) => {
|
||||
// TypeScript now knows that `someArg` is `SomeType` automatically.
|
||||
// It also knows that this function must return `Promise<Foo>`.
|
||||
// If you have `@typescript-eslint/promise-function-async` linter rule enabled, it will even report that "Functions that return promises must be async.".
|
||||
|
||||
// …
|
||||
}
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Asyncify<Fn extends (...args: any[]) => any> = SetReturnType<Fn, Promise<PromiseValue<ReturnType<Fn>>>>;
|
32
node_modules/ansi-escapes/node_modules/type-fest/source/basic.d.ts
generated
vendored
Normal file
32
node_modules/ansi-escapes/node_modules/type-fest/source/basic.d.ts
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
// TODO: Remove the `= unknown` sometime in the future when most users are on TS 3.5 as it's now the default
|
||||
/**
|
||||
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
||||
|
||||
@category Basic
|
||||
*/
|
||||
export type Class<T = unknown, Arguments extends any[] = any[]> = new(...arguments_: Arguments) => T;
|
||||
|
||||
/**
|
||||
Matches a JSON object.
|
||||
|
||||
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 { … }`.
|
||||
|
||||
@category Basic
|
||||
*/
|
||||
export type JsonObject = {[Key in string]?: JsonValue};
|
||||
|
||||
/**
|
||||
Matches a JSON array.
|
||||
|
||||
@category Basic
|
||||
*/
|
||||
export interface JsonArray extends Array<JsonValue> {}
|
||||
// TODO: Make it this when targeting TypeScript 4.1:
|
||||
// export type JsonArray = JsonValue[];
|
||||
|
||||
/**
|
||||
Matches any valid JSON value.
|
||||
|
||||
@category Basic
|
||||
*/
|
||||
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
45
node_modules/ansi-escapes/node_modules/type-fest/source/conditional-except.d.ts
generated
vendored
Normal file
45
node_modules/ansi-escapes/node_modules/type-fest/source/conditional-except.d.ts
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
import {Except} from './except';
|
||||
import {ConditionalKeys} from './conditional-keys';
|
||||
|
||||
/**
|
||||
Exclude keys from a shape that matches the given `Condition`.
|
||||
|
||||
This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Primitive, ConditionalExcept} from 'type-fest';
|
||||
|
||||
class Awesome {
|
||||
name: string;
|
||||
successes: number;
|
||||
failures: bigint;
|
||||
|
||||
run() {}
|
||||
}
|
||||
|
||||
type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
|
||||
//=> {run: () => void}
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import {ConditionalExcept} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
a: string;
|
||||
b: string | number;
|
||||
c: () => void;
|
||||
d: {};
|
||||
}
|
||||
|
||||
type NonStringKeysOnly = ConditionalExcept<Example, string>;
|
||||
//=> {b: string | number; c: () => void; d: {}}
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type ConditionalExcept<Base, Condition> = Except<
|
||||
Base,
|
||||
ConditionalKeys<Base, Condition>
|
||||
>;
|
45
node_modules/ansi-escapes/node_modules/type-fest/source/conditional-keys.d.ts
generated
vendored
Normal file
45
node_modules/ansi-escapes/node_modules/type-fest/source/conditional-keys.d.ts
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
Extract the keys from a type where the value type of the key extends the given `Condition`.
|
||||
|
||||
Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
|
||||
|
||||
@example
|
||||
```
|
||||
import {ConditionalKeys} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
a: string;
|
||||
b: string | number;
|
||||
c?: string;
|
||||
d: {};
|
||||
}
|
||||
|
||||
type StringKeysOnly = ConditionalKeys<Example, string>;
|
||||
//=> 'a'
|
||||
```
|
||||
|
||||
To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
|
||||
|
||||
@example
|
||||
```
|
||||
type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
||||
//=> 'a' | 'c'
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type ConditionalKeys<Base, Condition> = NonNullable<
|
||||
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
||||
{
|
||||
// Map through all the keys of the given base type.
|
||||
[Key in keyof Base]:
|
||||
// Pick only keys with types extending the given `Condition` type.
|
||||
Base[Key] extends Condition
|
||||
// Retain this key since the condition passes.
|
||||
? Key
|
||||
// Discard this key since the condition fails.
|
||||
: never;
|
||||
|
||||
// Convert the produced object into a union type of the keys which passed the conditional test.
|
||||
}[keyof Base]
|
||||
>;
|
44
node_modules/ansi-escapes/node_modules/type-fest/source/conditional-pick.d.ts
generated
vendored
Normal file
44
node_modules/ansi-escapes/node_modules/type-fest/source/conditional-pick.d.ts
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
import {ConditionalKeys} from './conditional-keys';
|
||||
|
||||
/**
|
||||
Pick keys from the shape that matches the given `Condition`.
|
||||
|
||||
This is useful when you want to create a new type from a specific subset of an existing type. For example, you might want to pick all the primitive properties from a class and form a new automatically derived type.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Primitive, ConditionalPick} from 'type-fest';
|
||||
|
||||
class Awesome {
|
||||
name: string;
|
||||
successes: number;
|
||||
failures: bigint;
|
||||
|
||||
run() {}
|
||||
}
|
||||
|
||||
type PickPrimitivesFromAwesome = ConditionalPick<Awesome, Primitive>;
|
||||
//=> {name: string; successes: number; failures: bigint}
|
||||
```
|
||||
|
||||
@example
|
||||
```
|
||||
import {ConditionalPick} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
a: string;
|
||||
b: string | number;
|
||||
c: () => void;
|
||||
d: {};
|
||||
}
|
||||
|
||||
type StringKeysOnly = ConditionalPick<Example, string>;
|
||||
//=> {a: string}
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type ConditionalPick<Base, Condition> = Pick<
|
||||
Base,
|
||||
ConditionalKeys<Base, Condition>
|
||||
>;
|
59
node_modules/ansi-escapes/node_modules/type-fest/source/entries.d.ts
generated
vendored
Normal file
59
node_modules/ansi-escapes/node_modules/type-fest/source/entries.d.ts
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
import {ArrayEntry, MapEntry, ObjectEntry, SetEntry} from './entry';
|
||||
|
||||
type ArrayEntries<BaseType extends readonly unknown[]> = Array<ArrayEntry<BaseType>>;
|
||||
type MapEntries<BaseType> = Array<MapEntry<BaseType>>;
|
||||
type ObjectEntries<BaseType> = Array<ObjectEntry<BaseType>>;
|
||||
type SetEntries<BaseType extends Set<unknown>> = Array<SetEntry<BaseType>>;
|
||||
|
||||
/**
|
||||
Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entries` type will return the type of that collection's entries.
|
||||
|
||||
For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
|
||||
|
||||
@see `Entry` if you want to just access the type of a single entry.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Entries} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
someKey: number;
|
||||
}
|
||||
|
||||
const manipulatesEntries = (examples: Entries<Example>) => examples.map(example => [
|
||||
// Does some arbitrary processing on the key (with type information available)
|
||||
example[0].toUpperCase(),
|
||||
|
||||
// Does some arbitrary processing on the value (with type information available)
|
||||
example[1].toFixed()
|
||||
]);
|
||||
|
||||
const example: Example = {someKey: 1};
|
||||
const entries = Object.entries(example) as Entries<Example>;
|
||||
const output = manipulatesEntries(entries);
|
||||
|
||||
// Objects
|
||||
const objectExample = {a: 1};
|
||||
const objectEntries: Entries<typeof objectExample> = [['a', 1]];
|
||||
|
||||
// Arrays
|
||||
const arrayExample = ['a', 1];
|
||||
const arrayEntries: Entries<typeof arrayExample> = [[0, 'a'], [1, 1]];
|
||||
|
||||
// Maps
|
||||
const mapExample = new Map([['a', 1]]);
|
||||
const mapEntries: Entries<typeof map> = [['a', 1]];
|
||||
|
||||
// Sets
|
||||
const setExample = new Set(['a', 1]);
|
||||
const setEntries: Entries<typeof setExample> = [['a', 'a'], [1, 1]];
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Entries<BaseType> =
|
||||
BaseType extends Map<unknown, unknown> ? MapEntries<BaseType>
|
||||
: BaseType extends Set<unknown> ? SetEntries<BaseType>
|
||||
: BaseType extends unknown[] ? ArrayEntries<BaseType>
|
||||
: BaseType extends object ? ObjectEntries<BaseType>
|
||||
: never;
|
62
node_modules/ansi-escapes/node_modules/type-fest/source/entry.d.ts
generated
vendored
Normal file
62
node_modules/ansi-escapes/node_modules/type-fest/source/entry.d.ts
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
type MapKey<BaseType> = BaseType extends Map<infer KeyType, unknown> ? KeyType : never;
|
||||
type MapValue<BaseType> = BaseType extends Map<unknown, infer ValueType> ? ValueType : never;
|
||||
|
||||
export type ArrayEntry<BaseType extends readonly unknown[]> = [number, BaseType[number]];
|
||||
export type MapEntry<BaseType> = [MapKey<BaseType>, MapValue<BaseType>];
|
||||
export type ObjectEntry<BaseType> = [keyof BaseType, BaseType[keyof BaseType]];
|
||||
export type SetEntry<BaseType> = BaseType extends Set<infer ItemType> ? [ItemType, ItemType] : never;
|
||||
|
||||
/**
|
||||
Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entry` type will return the type of that collection's entry.
|
||||
|
||||
For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
|
||||
|
||||
@see `Entries` if you want to just access the type of the array of entries (which is the return of the `.entries()` method).
|
||||
|
||||
@example
|
||||
```
|
||||
import {Entry} from 'type-fest';
|
||||
|
||||
interface Example {
|
||||
someKey: number;
|
||||
}
|
||||
|
||||
const manipulatesEntry = (example: Entry<Example>) => [
|
||||
// Does some arbitrary processing on the key (with type information available)
|
||||
example[0].toUpperCase(),
|
||||
|
||||
// Does some arbitrary processing on the value (with type information available)
|
||||
example[1].toFixed(),
|
||||
];
|
||||
|
||||
const example: Example = {someKey: 1};
|
||||
const entry = Object.entries(example)[0] as Entry<Example>;
|
||||
const output = manipulatesEntry(entry);
|
||||
|
||||
// Objects
|
||||
const objectExample = {a: 1};
|
||||
const objectEntry: Entry<typeof objectExample> = ['a', 1];
|
||||
|
||||
// Arrays
|
||||
const arrayExample = ['a', 1];
|
||||
const arrayEntryString: Entry<typeof arrayExample> = [0, 'a'];
|
||||
const arrayEntryNumber: Entry<typeof arrayExample> = [1, 1];
|
||||
|
||||
// Maps
|
||||
const mapExample = new Map([['a', 1]]);
|
||||
const mapEntry: Entry<typeof mapExample> = ['a', 1];
|
||||
|
||||
// Sets
|
||||
const setExample = new Set(['a', 1]);
|
||||
const setEntryString: Entry<typeof setExample> = ['a', 'a'];
|
||||
const setEntryNumber: Entry<typeof setExample> = [1, 1];
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Entry<BaseType> =
|
||||
BaseType extends Map<unknown, unknown> ? MapEntry<BaseType>
|
||||
: BaseType extends Set<unknown> ? SetEntry<BaseType>
|
||||
: BaseType extends unknown[] ? ArrayEntry<BaseType>
|
||||
: BaseType extends object ? ObjectEntry<BaseType>
|
||||
: never;
|
24
node_modules/ansi-escapes/node_modules/type-fest/source/except.d.ts
generated
vendored
Normal file
24
node_modules/ansi-escapes/node_modules/type-fest/source/except.d.ts
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
Create a type from an object type without certain keys.
|
||||
|
||||
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
||||
|
||||
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
||||
|
||||
@example
|
||||
```
|
||||
import {Except} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
a: number;
|
||||
b: string;
|
||||
c: boolean;
|
||||
};
|
||||
|
||||
type FooWithoutA = Except<Foo, 'a' | 'c'>;
|
||||
//=> {b: string};
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Except<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
|
40
node_modules/ansi-escapes/node_modules/type-fest/source/fixed-length-array.d.ts
generated
vendored
Normal file
40
node_modules/ansi-escapes/node_modules/type-fest/source/fixed-length-array.d.ts
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
Methods to exclude.
|
||||
*/
|
||||
type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift';
|
||||
|
||||
/**
|
||||
Create a type that represents an array of the given type and length. The array's length and the `Array` prototype methods that manipulate its length are excluded in the resulting type.
|
||||
|
||||
Please participate in [this issue](https://github.com/microsoft/TypeScript/issues/26223) if you want to have a similiar type built into TypeScript.
|
||||
|
||||
Use-cases:
|
||||
- Declaring fixed-length tuples or arrays with a large number of items.
|
||||
- Creating a range union (for example, `0 | 1 | 2 | 3 | 4` from the keys of such a type) without having to resort to recursive types.
|
||||
- Creating an array of coordinates with a static length, for example, length of 3 for a 3D vector.
|
||||
|
||||
@example
|
||||
```
|
||||
import {FixedLengthArray} from 'type-fest';
|
||||
|
||||
type FencingTeam = FixedLengthArray<string, 3>;
|
||||
|
||||
const guestFencingTeam: FencingTeam = ['Josh', 'Michael', 'Robert'];
|
||||
|
||||
const homeFencingTeam: FencingTeam = ['George', 'John'];
|
||||
//=> error TS2322: Type string[] is not assignable to type 'FencingTeam'
|
||||
|
||||
guestFencingTeam.push('Sam');
|
||||
//=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type FixedLengthArray<Element, Length extends number, ArrayPrototype = [Element, ...Element[]]> = Pick<
|
||||
ArrayPrototype,
|
||||
Exclude<keyof ArrayPrototype, ArrayLengthMutationKeys>
|
||||
> & {
|
||||
[index: number]: Element;
|
||||
[Symbol.iterator]: () => IterableIterator<Element>;
|
||||
readonly length: Length;
|
||||
};
|
48
node_modules/ansi-escapes/node_modules/type-fest/source/iterable-element.d.ts
generated
vendored
Normal file
48
node_modules/ansi-escapes/node_modules/type-fest/source/iterable-element.d.ts
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
Get the element type of an `Iterable`/`AsyncIterable`. For example, an array or a generator.
|
||||
|
||||
This can be useful, for example, if you want to get the type that is yielded in a generator function. Often the return type of those functions are not specified.
|
||||
|
||||
This type works with both `Iterable`s and `AsyncIterable`s, so it can be use with synchronous and asynchronous generators.
|
||||
|
||||
Here is an example of `IterableElement` in action with a generator function:
|
||||
|
||||
@example
|
||||
```
|
||||
function * iAmGenerator() {
|
||||
yield 1;
|
||||
yield 2;
|
||||
}
|
||||
|
||||
type MeNumber = IterableElement<ReturnType<typeof iAmGenerator>>
|
||||
```
|
||||
|
||||
And here is an example with an async generator:
|
||||
|
||||
@example
|
||||
```
|
||||
async function * iAmGeneratorAsync() {
|
||||
yield 'hi';
|
||||
yield true;
|
||||
}
|
||||
|
||||
type MeStringOrBoolean = IterableElement<ReturnType<typeof iAmGeneratorAsync>>
|
||||
```
|
||||
|
||||
Many types in JavaScript/TypeScript are iterables. This type works on all types that implement those interfaces. For example, `Array`, `Set`, `Map`, `stream.Readable`, etc.
|
||||
|
||||
An example with an array of strings:
|
||||
|
||||
@example
|
||||
```
|
||||
type MeString = IterableElement<string[]>
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type IterableElement<TargetIterable> =
|
||||
TargetIterable extends Iterable<infer ElementType> ?
|
||||
ElementType :
|
||||
TargetIterable extends AsyncIterable<infer ElementType> ?
|
||||
ElementType :
|
||||
never;
|
35
node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
generated
vendored
Normal file
35
node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
import {Primitive} from './primitive';
|
||||
|
||||
/**
|
||||
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
||||
|
||||
Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
|
||||
|
||||
This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
|
||||
|
||||
@example
|
||||
```
|
||||
import {LiteralUnion} from 'type-fest';
|
||||
|
||||
// Before
|
||||
|
||||
type Pet = 'dog' | 'cat' | string;
|
||||
|
||||
const pet: Pet = '';
|
||||
// Start typing in your TypeScript-enabled IDE.
|
||||
// You **will not** get auto-completion for `dog` and `cat` literals.
|
||||
|
||||
// After
|
||||
|
||||
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
||||
|
||||
const pet: Pet2 = '';
|
||||
// You **will** get auto-completion for `dog` and `cat` literals.
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type LiteralUnion<
|
||||
LiteralType,
|
||||
BaseType extends Primitive
|
||||
> = LiteralType | (BaseType & {_?: never});
|
41
node_modules/ansi-escapes/node_modules/type-fest/source/merge-exclusive.d.ts
generated
vendored
Normal file
41
node_modules/ansi-escapes/node_modules/type-fest/source/merge-exclusive.d.ts
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
// Helper type. Not useful on its own.
|
||||
type Without<FirstType, SecondType> = {[KeyType in Exclude<keyof FirstType, keyof SecondType>]?: never};
|
||||
|
||||
/**
|
||||
Create a type that has mutually exclusive keys.
|
||||
|
||||
This type was inspired by [this comment](https://github.com/Microsoft/TypeScript/issues/14094#issuecomment-373782604).
|
||||
|
||||
This type works with a helper type, called `Without`. `Without<FirstType, SecondType>` produces a type that has only keys from `FirstType` which are not present on `SecondType` and sets the value type for these keys to `never`. This helper type is then used in `MergeExclusive` to remove keys from either `FirstType` or `SecondType`.
|
||||
|
||||
@example
|
||||
```
|
||||
import {MergeExclusive} from 'type-fest';
|
||||
|
||||
interface ExclusiveVariation1 {
|
||||
exclusive1: boolean;
|
||||
}
|
||||
|
||||
interface ExclusiveVariation2 {
|
||||
exclusive2: string;
|
||||
}
|
||||
|
||||
type ExclusiveOptions = MergeExclusive<ExclusiveVariation1, ExclusiveVariation2>;
|
||||
|
||||
let exclusiveOptions: ExclusiveOptions;
|
||||
|
||||
exclusiveOptions = {exclusive1: true};
|
||||
//=> Works
|
||||
exclusiveOptions = {exclusive2: 'hi'};
|
||||
//=> Works
|
||||
exclusiveOptions = {exclusive1: true, exclusive2: 'hi'};
|
||||
//=> Error
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type MergeExclusive<FirstType, SecondType> =
|
||||
(FirstType | SecondType) extends object ?
|
||||
(Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType) :
|
||||
FirstType | SecondType;
|
||||
|
27
node_modules/ansi-escapes/node_modules/type-fest/source/merge.d.ts
generated
vendored
Normal file
27
node_modules/ansi-escapes/node_modules/type-fest/source/merge.d.ts
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
import {Except} from './except';
|
||||
import {Simplify} from './simplify';
|
||||
|
||||
type Merge_<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType;
|
||||
|
||||
/**
|
||||
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Merge} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
a: number;
|
||||
b: string;
|
||||
};
|
||||
|
||||
type Bar = {
|
||||
b: number;
|
||||
};
|
||||
|
||||
const ab: Merge<Foo, Bar> = {a: 1, b: 2};
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Merge<FirstType, SecondType> = Simplify<Merge_<FirstType, SecondType>>;
|
40
node_modules/ansi-escapes/node_modules/type-fest/source/mutable.d.ts
generated
vendored
Normal file
40
node_modules/ansi-escapes/node_modules/type-fest/source/mutable.d.ts
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
import {Except} from './except';
|
||||
import {Simplify} from './simplify';
|
||||
|
||||
/**
|
||||
Create a type that strips `readonly` from all or some of an object's keys. Inverse of `Readonly<T>`.
|
||||
|
||||
This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are mutable.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Mutable} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
readonly a: number;
|
||||
readonly b: readonly string[]; // To show that only the mutability status of the properties, not their values, are affected.
|
||||
readonly c: boolean;
|
||||
};
|
||||
|
||||
const mutableFoo: Mutable<Foo> = {a: 1, b: ['2'], c: true};
|
||||
mutableFoo.a = 3;
|
||||
mutableFoo.b[0] = 'new value'; // Will still fail as the value of property "b" is still a readonly type.
|
||||
mutableFoo.b = ['something']; // Will work as the "b" property itself is no longer readonly.
|
||||
|
||||
type SomeMutable = Mutable<Foo, 'b' | 'c'>;
|
||||
// type SomeMutable = {
|
||||
// readonly a: number;
|
||||
// b: readonly string[]; // It's now mutable. The type of the property remains unaffected.
|
||||
// c: boolean; // It's now mutable.
|
||||
// }
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Mutable<BaseType, Keys extends keyof BaseType = keyof BaseType> =
|
||||
Simplify<
|
||||
// Pick just the keys that are not mutable from the base type.
|
||||
Except<BaseType, Keys> &
|
||||
// Pick the keys that should be mutable from the base type and make them mutable by removing the `readonly` modifier from the key.
|
||||
{-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType]}
|
||||
>;
|
15
node_modules/ansi-escapes/node_modules/type-fest/source/observable-like.d.ts
generated
vendored
Normal file
15
node_modules/ansi-escapes/node_modules/type-fest/source/observable-like.d.ts
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
declare global {
|
||||
interface SymbolConstructor {
|
||||
readonly observable: symbol;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
|
||||
|
||||
@category Basic
|
||||
*/
|
||||
export interface ObservableLike {
|
||||
subscribe(observer: (value: unknown) => void): void;
|
||||
[Symbol.observable](): ObservableLike;
|
||||
}
|
67
node_modules/ansi-escapes/node_modules/type-fest/source/opaque.d.ts
generated
vendored
Normal file
67
node_modules/ansi-escapes/node_modules/type-fest/source/opaque.d.ts
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
/**
|
||||
Create an opaque type, which hides its internal details from the public, and can only be created by being used explicitly.
|
||||
|
||||
The generic type parameter can be anything. It doesn't have to be an object.
|
||||
|
||||
[Read more about opaque types.](https://codemix.com/opaque-types-in-javascript/)
|
||||
|
||||
There have been several discussions about adding this feature to TypeScript via the `opaque type` operator, similar to how Flow does it. Unfortunately, nothing has (yet) moved forward:
|
||||
- [Microsoft/TypeScript#15408](https://github.com/Microsoft/TypeScript/issues/15408)
|
||||
- [Microsoft/TypeScript#15807](https://github.com/Microsoft/TypeScript/issues/15807)
|
||||
|
||||
@example
|
||||
```
|
||||
import {Opaque} from 'type-fest';
|
||||
|
||||
type AccountNumber = Opaque<number, 'AccountNumber'>;
|
||||
type AccountBalance = Opaque<number, 'AccountBalance'>;
|
||||
|
||||
// The Token parameter allows the compiler to differentiate between types, whereas "unknown" will not. For example, consider the following structures:
|
||||
type ThingOne = Opaque<string>;
|
||||
type ThingTwo = Opaque<string>;
|
||||
|
||||
// To the compiler, these types are allowed to be cast to each other as they have the same underlying type. They are both `string & { __opaque__: unknown }`.
|
||||
// To avoid this behaviour, you would instead pass the "Token" parameter, like so.
|
||||
type NewThingOne = Opaque<string, 'ThingOne'>;
|
||||
type NewThingTwo = Opaque<string, 'ThingTwo'>;
|
||||
|
||||
// Now they're completely separate types, so the following will fail to compile.
|
||||
function createNewThingOne (): NewThingOne {
|
||||
// As you can see, casting from a string is still allowed. However, you may not cast NewThingOne to NewThingTwo, and vice versa.
|
||||
return 'new thing one' as NewThingOne;
|
||||
}
|
||||
|
||||
// This will fail to compile, as they are fundamentally different types.
|
||||
const thingTwo = createNewThingOne() as NewThingTwo;
|
||||
|
||||
// Here's another example of opaque typing.
|
||||
function createAccountNumber(): AccountNumber {
|
||||
return 2 as AccountNumber;
|
||||
}
|
||||
|
||||
function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance {
|
||||
return 4 as AccountBalance;
|
||||
}
|
||||
|
||||
// This will compile successfully.
|
||||
getMoneyForAccount(createAccountNumber());
|
||||
|
||||
// But this won't, because it has to be explicitly passed as an `AccountNumber` type.
|
||||
getMoneyForAccount(2);
|
||||
|
||||
// You can use opaque values like they aren't opaque too.
|
||||
const accountNumber = createAccountNumber();
|
||||
|
||||
// This will not compile successfully.
|
||||
const newAccountNumber = accountNumber + 2;
|
||||
|
||||
// As a side note, you can (and should) use recursive types for your opaque types to make them stronger and hopefully easier to type.
|
||||
type Person = {
|
||||
id: Opaque<number, Person>;
|
||||
name: string;
|
||||
};
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Opaque<Type, Token = unknown> = Type & {readonly __opaque__: Token};
|
645
node_modules/ansi-escapes/node_modules/type-fest/source/package-json.d.ts
generated
vendored
Normal file
645
node_modules/ansi-escapes/node_modules/type-fest/source/package-json.d.ts
generated
vendored
Normal file
@ -0,0 +1,645 @@
|
||||
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
|
||||
| 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;
|
||||
|
||||
/**
|
||||
Version selection map of TypeScript.
|
||||
*/
|
||||
typesVersions?: Record<string, Record<string, 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?: PublishConfig;
|
||||
|
||||
/**
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PublishConfig {
|
||||
/**
|
||||
Additional, less common properties from the [npm docs on `publishConfig`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#publishconfig).
|
||||
*/
|
||||
[additionalProperties: string]: unknown;
|
||||
|
||||
/**
|
||||
When publishing scoped packages, the access level defaults to restricted. If you want your scoped package to be publicly viewable (and installable) set `--access=public`. The only valid values for access are public and restricted. Unscoped packages always have an access level of public.
|
||||
*/
|
||||
access?: 'public' | 'restricted';
|
||||
|
||||
/**
|
||||
The base URL of the npm registry.
|
||||
|
||||
Default: `'https://registry.npmjs.org/'`
|
||||
*/
|
||||
registry?: string;
|
||||
|
||||
/**
|
||||
The tag to publish the package under.
|
||||
|
||||
Default: `'latest'`
|
||||
*/
|
||||
tag?: 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.
|
||||
|
||||
@category Miscellaneous
|
||||
*/
|
||||
export type PackageJson =
|
||||
PackageJson.PackageJsonStandard &
|
||||
PackageJson.NonStandardEntryPoints &
|
||||
PackageJson.TypeScriptConfiguration &
|
||||
PackageJson.YarnConfiguration &
|
||||
PackageJson.JSPMConfiguration;
|
74
node_modules/ansi-escapes/node_modules/type-fest/source/partial-deep.d.ts
generated
vendored
Normal file
74
node_modules/ansi-escapes/node_modules/type-fest/source/partial-deep.d.ts
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
import {Primitive} from './primitive';
|
||||
|
||||
/**
|
||||
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}});
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
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]>
|
||||
};
|
13
node_modules/ansi-escapes/node_modules/type-fest/source/primitive.d.ts
generated
vendored
Normal file
13
node_modules/ansi-escapes/node_modules/type-fest/source/primitive.d.ts
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
||||
|
||||
@category Basic
|
||||
*/
|
||||
export type Primitive =
|
||||
| null
|
||||
| undefined
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| symbol
|
||||
| bigint;
|
25
node_modules/ansi-escapes/node_modules/type-fest/source/promisable.d.ts
generated
vendored
Normal file
25
node_modules/ansi-escapes/node_modules/type-fest/source/promisable.d.ts
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
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'));
|
||||
|
||||
@category Utilities
|
||||
```
|
||||
*/
|
||||
export type Promisable<T> = T | PromiseLike<T>;
|
29
node_modules/ansi-escapes/node_modules/type-fest/source/promise-value.d.ts
generated
vendored
Normal file
29
node_modules/ansi-escapes/node_modules/type-fest/source/promise-value.d.ts
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
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'));
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
|
||||
? { 0: PromiseValue<Value>; 1: Value }[PromiseType extends Promise<unknown> ? 0 : 1]
|
||||
: Otherwise;
|
61
node_modules/ansi-escapes/node_modules/type-fest/source/readonly-deep.d.ts
generated
vendored
Normal file
61
node_modules/ansi-escapes/node_modules/type-fest/source/readonly-deep.d.ts
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
import {Primitive} from './primitive';
|
||||
|
||||
/**
|
||||
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[]'
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
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]>
|
||||
};
|
35
node_modules/ansi-escapes/node_modules/type-fest/source/require-at-least-one.d.ts
generated
vendored
Normal file
35
node_modules/ansi-escapes/node_modules/type-fest/source/require-at-least-one.d.ts
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
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
|
||||
};
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
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>;
|
37
node_modules/ansi-escapes/node_modules/type-fest/source/require-exactly-one.d.ts
generated
vendored
Normal file
37
node_modules/ansi-escapes/node_modules/type-fest/source/require-exactly-one.d.ts
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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
|
||||
};
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
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>;
|
35
node_modules/ansi-escapes/node_modules/type-fest/source/set-optional.d.ts
generated
vendored
Normal file
35
node_modules/ansi-escapes/node_modules/type-fest/source/set-optional.d.ts
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
import {Except} from './except';
|
||||
import {Simplify} from './simplify';
|
||||
|
||||
/**
|
||||
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.
|
||||
// }
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type SetOptional<BaseType, Keys extends keyof BaseType> =
|
||||
Simplify<
|
||||
// Pick just the keys that are readonly from the base type.
|
||||
Except<BaseType, Keys> &
|
||||
// Pick the keys that should be mutable from the base type and make them mutable.
|
||||
Partial<Pick<BaseType, Keys>>
|
||||
>;
|
35
node_modules/ansi-escapes/node_modules/type-fest/source/set-required.d.ts
generated
vendored
Normal file
35
node_modules/ansi-escapes/node_modules/type-fest/source/set-required.d.ts
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
import {Except} from './except';
|
||||
import {Simplify} from './simplify';
|
||||
|
||||
/**
|
||||
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.
|
||||
// }
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type SetRequired<BaseType, Keys extends keyof BaseType> =
|
||||
Simplify<
|
||||
// Pick just the keys that are optional 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>>
|
||||
>;
|
31
node_modules/ansi-escapes/node_modules/type-fest/source/set-return-type.d.ts
generated
vendored
Normal file
31
node_modules/ansi-escapes/node_modules/type-fest/source/set-return-type.d.ts
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
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;
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
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
|
||||
);
|
24
node_modules/ansi-escapes/node_modules/type-fest/source/simplify.d.ts
generated
vendored
Normal file
24
node_modules/ansi-escapes/node_modules/type-fest/source/simplify.d.ts
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
Flatten the type output to improve type hints shown in editors.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Simplify} from 'type-fest';
|
||||
|
||||
type PositionProps = {
|
||||
top: number;
|
||||
left: number;
|
||||
};
|
||||
|
||||
type SizeProps = {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
||||
type Props = Simplify<PositionProps & SizeProps>;
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Simplify<T> = {[KeyType in keyof T]: T[KeyType]};
|
23
node_modules/ansi-escapes/node_modules/type-fest/source/stringified.d.ts
generated
vendored
Normal file
23
node_modules/ansi-escapes/node_modules/type-fest/source/stringified.d.ts
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
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'
|
||||
};
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Stringified<ObjectType> = {[KeyType in keyof ObjectType]: string};
|
1095
node_modules/ansi-escapes/node_modules/type-fest/source/tsconfig-json.d.ts
generated
vendored
Normal file
1095
node_modules/ansi-escapes/node_modules/type-fest/source/tsconfig-json.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
19
node_modules/ansi-escapes/node_modules/type-fest/source/typed-array.d.ts
generated
vendored
Normal file
19
node_modules/ansi-escapes/node_modules/type-fest/source/typed-array.d.ts
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/// <reference lib="es2020.bigint"/>
|
||||
|
||||
/**
|
||||
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
||||
|
||||
@category Basic
|
||||
*/
|
||||
export type TypedArray =
|
||||
| Int8Array
|
||||
| Uint8Array
|
||||
| Uint8ClampedArray
|
||||
| Int16Array
|
||||
| Uint16Array
|
||||
| Int32Array
|
||||
| Uint32Array
|
||||
| Float32Array
|
||||
| Float64Array
|
||||
| BigInt64Array
|
||||
| BigUint64Array;
|
60
node_modules/ansi-escapes/node_modules/type-fest/source/union-to-intersection.d.ts
generated
vendored
Normal file
60
node_modules/ansi-escapes/node_modules/type-fest/source/union-to-intersection.d.ts
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
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}
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
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;
|
5
node_modules/ansi-escapes/node_modules/type-fest/source/utilities.d.ts
generated
vendored
Normal file
5
node_modules/ansi-escapes/node_modules/type-fest/source/utilities.d.ts
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
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 = '-' | '_' | ' ';
|
||||
|
||||
export type StringDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
42
node_modules/ansi-escapes/node_modules/type-fest/source/value-of.d.ts
generated
vendored
Normal file
42
node_modules/ansi-escapes/node_modules/type-fest/source/value-of.d.ts
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
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
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
72
node_modules/ansi-escapes/node_modules/type-fest/ts41/camel-case.d.ts
generated
vendored
Normal file
72
node_modules/ansi-escapes/node_modules/type-fest/ts41/camel-case.d.ts
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
import {WordSeparators} from '../source/utilities';
|
||||
import {Split} from './utilities';
|
||||
|
||||
/**
|
||||
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 CamelCasedProperties<T> = {
|
||||
[K in keyof T as CamelCase<K>]: T[K]
|
||||
};
|
||||
|
||||
interface RawOptions {
|
||||
'dry-run': boolean;
|
||||
'full_family_name': string;
|
||||
foo: number;
|
||||
BAR: string;
|
||||
QUZ_QUX: number;
|
||||
'OTHER-FIELD': boolean;
|
||||
}
|
||||
|
||||
const dbResult: CamelCasedProperties<ModelProps> = {
|
||||
dryRun: true,
|
||||
fullFamilyName: 'bar.js',
|
||||
foo: 123,
|
||||
bar: 'foo',
|
||||
quzQux: 6,
|
||||
otherField: false
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type CamelCase<K> = K extends string ? K extends Uppercase<K> ? CamelCaseStringArray<Split<Lowercase<K>, WordSeparators>> : CamelCaseStringArray<Split<K, WordSeparators>> : K;
|
50
node_modules/ansi-escapes/node_modules/type-fest/ts41/camel-cased-properties-deep.d.ts
generated
vendored
Normal file
50
node_modules/ansi-escapes/node_modules/type-fest/ts41/camel-cased-properties-deep.d.ts
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
import {CamelCase} from './camel-case';
|
||||
|
||||
/**
|
||||
Convert object properties to camel case recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see CamelCasedProperties
|
||||
@see CamelCase
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
UserId: number;
|
||||
UserName: string;
|
||||
}
|
||||
|
||||
interface UserWithFriends {
|
||||
UserInfo: User;
|
||||
UserFriends: User[];
|
||||
}
|
||||
|
||||
const result: CamelCasedPropertiesDeep<UserWithFriends> = {
|
||||
userInfo: {
|
||||
userId: 1,
|
||||
userName: 'Tom',
|
||||
},
|
||||
userFriends: [
|
||||
{
|
||||
userId: 2,
|
||||
userName: 'Jerry',
|
||||
},
|
||||
{
|
||||
userId: 3,
|
||||
userName: 'Spike',
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type CamelCasedPropertiesDeep<Value> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Array<CamelCasedPropertiesDeep<U>>
|
||||
: Value extends Set<infer U>
|
||||
? Set<CamelCasedPropertiesDeep<U>> : {
|
||||
[K in keyof Value as CamelCase<K>]: CamelCasedPropertiesDeep<Value[K]>;
|
||||
};
|
32
node_modules/ansi-escapes/node_modules/type-fest/ts41/camel-cased-properties.d.ts
generated
vendored
Normal file
32
node_modules/ansi-escapes/node_modules/type-fest/ts41/camel-cased-properties.d.ts
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
import {CamelCase} from './camel-case';
|
||||
|
||||
/**
|
||||
Convert object properties to camel case but not recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see CamelCasedPropertiesDeep
|
||||
@see CamelCase
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
UserId: number;
|
||||
UserName: string;
|
||||
}
|
||||
|
||||
const result: CamelCasedProperties<User> = {
|
||||
userId: 1,
|
||||
userName: 'Tom',
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type CamelCasedProperties<Value> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Value
|
||||
: {
|
||||
[K in keyof Value as CamelCase<K>]: Value[K];
|
||||
};
|
88
node_modules/ansi-escapes/node_modules/type-fest/ts41/delimiter-case.d.ts
generated
vendored
Normal file
88
node_modules/ansi-escapes/node_modules/type-fest/ts41/delimiter-case.d.ts
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
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.
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
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 OddlyCasedProperties<T> = {
|
||||
[K in keyof T as DelimiterCase<K, '#'>]: T[K]
|
||||
};
|
||||
|
||||
interface SomeOptions {
|
||||
dryRun: boolean;
|
||||
includeFile: string;
|
||||
foo: number;
|
||||
}
|
||||
|
||||
const rawCliOptions: OddlyCasedProperties<SomeOptions> = {
|
||||
'dry#run': true,
|
||||
'include#file': 'bar.js',
|
||||
foo: 123
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type DelimiterCase<Value, Delimiter extends string> = Value extends string
|
||||
? StringArrayToDelimiterCase<
|
||||
SplitIncludingDelimiters<Value, WordSeparators | UpperCaseCharacters>,
|
||||
WordSeparators,
|
||||
UpperCaseCharacters,
|
||||
Delimiter
|
||||
>
|
||||
: Value;
|
56
node_modules/ansi-escapes/node_modules/type-fest/ts41/delimiter-cased-properties-deep.d.ts
generated
vendored
Normal file
56
node_modules/ansi-escapes/node_modules/type-fest/ts41/delimiter-cased-properties-deep.d.ts
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
import {DelimiterCase} from './delimiter-case';
|
||||
|
||||
/**
|
||||
Convert object properties to delimiter case recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see DelimiterCase
|
||||
@see DelimiterCasedProperties
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
interface UserWithFriends {
|
||||
userInfo: User;
|
||||
userFriends: User[];
|
||||
}
|
||||
|
||||
const result: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
|
||||
'user-info': {
|
||||
'user-id': 1,
|
||||
'user-name': 'Tom',
|
||||
},
|
||||
'user-friends': [
|
||||
{
|
||||
'user-id': 2,
|
||||
'user-name': 'Jerry',
|
||||
},
|
||||
{
|
||||
'user-id': 3,
|
||||
'user-name': 'Spike',
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type DelimiterCasedPropertiesDeep<
|
||||
Value,
|
||||
Delimiter extends string
|
||||
> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Array<DelimiterCasedPropertiesDeep<U, Delimiter>>
|
||||
: Value extends Set<infer U>
|
||||
? Set<DelimiterCasedPropertiesDeep<U, Delimiter>> : {
|
||||
[K in keyof Value as DelimiterCase<
|
||||
K,
|
||||
Delimiter
|
||||
>]: DelimiterCasedPropertiesDeep<Value[K], Delimiter>;
|
||||
};
|
33
node_modules/ansi-escapes/node_modules/type-fest/ts41/delimiter-cased-properties.d.ts
generated
vendored
Normal file
33
node_modules/ansi-escapes/node_modules/type-fest/ts41/delimiter-cased-properties.d.ts
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
import {DelimiterCase} from './delimiter-case';
|
||||
|
||||
/**
|
||||
Convert object properties to delimiter case but not recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see DelimiterCase
|
||||
@see DelimiterCasedPropertiesDeep
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
const result: DelimiterCasedProperties<User, '-'> = {
|
||||
'user-id': 1,
|
||||
'user-name': 'Tom',
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type DelimiterCasedProperties<
|
||||
Value,
|
||||
Delimiter extends string
|
||||
> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Value
|
||||
: { [K in keyof Value as DelimiterCase<K, Delimiter>]: Value[K] };
|
135
node_modules/ansi-escapes/node_modules/type-fest/ts41/get.d.ts
generated
vendored
Normal file
135
node_modules/ansi-escapes/node_modules/type-fest/ts41/get.d.ts
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
import {Split} from './utilities';
|
||||
import {StringDigit} from '../source/utilities';
|
||||
|
||||
/**
|
||||
Like the `Get` type but receives an array of strings as a path parameter.
|
||||
*/
|
||||
type GetWithPath<BaseType, Keys extends readonly string[]> =
|
||||
Keys extends []
|
||||
? BaseType
|
||||
: Keys extends [infer Head, ...infer Tail]
|
||||
? GetWithPath<PropertyOf<BaseType, Extract<Head, string>>, Extract<Tail, string[]>>
|
||||
: never;
|
||||
|
||||
/**
|
||||
Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
|
||||
|
||||
@example
|
||||
```
|
||||
ToPath<'foo.bar.baz'>
|
||||
//=> ['foo', 'bar', 'baz']
|
||||
|
||||
ToPath<'foo[0].bar.baz'>
|
||||
//=> ['foo', '0', 'bar', 'baz']
|
||||
```
|
||||
*/
|
||||
type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.'>;
|
||||
|
||||
/**
|
||||
Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
|
||||
*/
|
||||
type FixPathSquareBrackets<Path extends string> =
|
||||
Path extends `${infer Head}[${infer Middle}]${infer Tail}`
|
||||
? `${Head}.${Middle}${FixPathSquareBrackets<Tail>}`
|
||||
: Path;
|
||||
|
||||
/**
|
||||
Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
|
||||
|
||||
@example
|
||||
```
|
||||
ConsistsOnlyOf<'aaa', 'a'> //=> true
|
||||
ConsistsOnlyOf<'ababab', 'ab'> //=> true
|
||||
ConsistsOnlyOf<'aBa', 'a'> //=> false
|
||||
ConsistsOnlyOf<'', 'a'> //=> true
|
||||
```
|
||||
*/
|
||||
type ConsistsOnlyOf<LongString extends string, Substring extends string> =
|
||||
LongString extends ''
|
||||
? true
|
||||
: LongString extends `${Substring}${infer Tail}`
|
||||
? ConsistsOnlyOf<Tail, Substring>
|
||||
: false;
|
||||
|
||||
/**
|
||||
Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
|
||||
|
||||
@example
|
||||
```
|
||||
type WithNumbers = {foo: string; 0: boolean};
|
||||
type WithStrings = WithStringKeys<WithNumbers>;
|
||||
|
||||
type WithNumbersKeys = keyof WithNumbers;
|
||||
//=> 'foo' | 0
|
||||
type WithStringsKeys = keyof WithStrings;
|
||||
//=> 'foo' | '0'
|
||||
```
|
||||
*/
|
||||
type WithStringKeys<BaseType extends Record<string | number, any>> = {
|
||||
[Key in `${Extract<keyof BaseType, string | number>}`]: BaseType[Key]
|
||||
};
|
||||
|
||||
/**
|
||||
Get a property of an object or array. Works when indexing arrays using number-literal-strings, for example, `PropertyOf<number[], '0'> = number`, and when indexing objects with number keys.
|
||||
|
||||
Note:
|
||||
- Returns `unknown` if `Key` is not a property of `BaseType`, since TypeScript uses structural typing, and it cannot be guaranteed that extra properties unknown to the type system will exist at runtime.
|
||||
- Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
|
||||
*/
|
||||
type PropertyOf<BaseType, Key extends string> =
|
||||
BaseType extends null | undefined
|
||||
? undefined
|
||||
: Key extends keyof BaseType
|
||||
? BaseType[Key]
|
||||
: BaseType extends [] | [unknown, ...unknown[]]
|
||||
? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
|
||||
: BaseType extends {
|
||||
[n: number]: infer Item;
|
||||
length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
|
||||
}
|
||||
? (
|
||||
ConsistsOnlyOf<Key, StringDigit> extends true
|
||||
? Item
|
||||
: unknown
|
||||
)
|
||||
: Key extends keyof WithStringKeys<BaseType>
|
||||
? WithStringKeys<BaseType>[Key]
|
||||
: unknown;
|
||||
|
||||
// This works by first splitting the path based on `.` and `[...]` characters into a tuple of string keys. Then it recursively uses the head key to get the next property of the current object, until there are no keys left. Number keys extract the item type from arrays, or are converted to strings to extract types from tuples and dictionaries with number keys.
|
||||
/**
|
||||
Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
|
||||
|
||||
Use-case: Retrieve a property from deep inside an API response or some other complex object.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Get} from 'type-fest';
|
||||
import * as lodash from 'lodash';
|
||||
|
||||
const get = <BaseType, Path extends string>(object: BaseType, path: Path): Get<BaseType, Path> =>
|
||||
lodash.get(object, path);
|
||||
|
||||
interface ApiResponse {
|
||||
hits: {
|
||||
hits: Array<{
|
||||
_id: string
|
||||
_source: {
|
||||
name: Array<{
|
||||
given: string[]
|
||||
family: string
|
||||
}>
|
||||
birthDate: string
|
||||
}
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
const getName = (apiResponse: ApiResponse) =>
|
||||
get(apiResponse, 'hits.hits[0]._source.name');
|
||||
//=> Array<{given: string[]; family: string}>
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type Get<BaseType, Path extends string> = GetWithPath<BaseType, ToPath<Path>>;
|
31
node_modules/ansi-escapes/node_modules/type-fest/ts41/includes.d.ts
generated
vendored
Normal file
31
node_modules/ansi-escapes/node_modules/type-fest/ts41/includes.d.ts
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
Returns a boolean for whether given two types are equal.
|
||||
|
||||
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
||||
*/
|
||||
type IsEqual<T, U> =
|
||||
(<G>() => G extends T ? 1 : 2) extends
|
||||
(<G>() => G extends U ? 1 : 2)
|
||||
? true
|
||||
: false;
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the given array includes the given item.
|
||||
|
||||
This can be useful if another type wants to make a decision based on whether the array includes that item.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Includes} from 'type-fest';
|
||||
|
||||
type hasRed<array extends any[]> = Includes<array, 'red'>;
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type Includes<Value extends any[], Item> =
|
||||
IsEqual<Value[0], Item> extends true
|
||||
? true
|
||||
: Value extends [Value[0], ...infer rest]
|
||||
? Includes<rest, Item>
|
||||
: false;
|
25
node_modules/ansi-escapes/node_modules/type-fest/ts41/index.d.ts
generated
vendored
Normal file
25
node_modules/ansi-escapes/node_modules/type-fest/ts41/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
// 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 {CamelCasedProperties} from './camel-cased-properties';
|
||||
export {CamelCasedPropertiesDeep} from './camel-cased-properties-deep';
|
||||
export {KebabCase} from './kebab-case';
|
||||
export {KebabCasedProperties} from './kebab-cased-properties';
|
||||
export {KebabCasedPropertiesDeep} from './kebab-cased-properties-deep';
|
||||
export {PascalCase} from './pascal-case';
|
||||
export {PascalCasedProperties} from './pascal-cased-properties';
|
||||
export {PascalCasedPropertiesDeep} from './pascal-cased-properties-deep';
|
||||
export {SnakeCase} from './snake-case';
|
||||
export {SnakeCasedProperties} from './snake-cased-properties';
|
||||
export {SnakeCasedPropertiesDeep} from './snake-cased-properties-deep';
|
||||
export {ScreamingSnakeCase} from './screaming-snake-case';
|
||||
export {DelimiterCase} from './delimiter-case';
|
||||
export {DelimiterCasedProperties} from './delimiter-cased-properties';
|
||||
export {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
|
||||
export {Split} from './split';
|
||||
export {Trim} from './trim';
|
||||
export {Includes} from './includes';
|
||||
export {Get} from './get';
|
||||
export {LastArrayElement} from './last-array-element';
|
37
node_modules/ansi-escapes/node_modules/type-fest/ts41/kebab-case.d.ts
generated
vendored
Normal file
37
node_modules/ansi-escapes/node_modules/type-fest/ts41/kebab-case.d.ts
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
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 KebabCasedProperties<T> = {
|
||||
[K in keyof T as KebabCase<K>]: T[K]
|
||||
};
|
||||
|
||||
interface CliOptions {
|
||||
dryRun: boolean;
|
||||
includeFile: string;
|
||||
foo: number;
|
||||
}
|
||||
|
||||
const rawCliOptions: KebabCasedProperties<CliOptions> = {
|
||||
'dry-run': true,
|
||||
'include-file': 'bar.js',
|
||||
foo: 123
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type KebabCase<Value> = DelimiterCase<Value, '-'>;
|
43
node_modules/ansi-escapes/node_modules/type-fest/ts41/kebab-cased-properties-deep.d.ts
generated
vendored
Normal file
43
node_modules/ansi-escapes/node_modules/type-fest/ts41/kebab-cased-properties-deep.d.ts
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
import {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
|
||||
|
||||
/**
|
||||
Convert object properties to kebab case recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see KebabCase
|
||||
@see KebabCasedProperties
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
interface UserWithFriends {
|
||||
userInfo: User;
|
||||
userFriends: User[];
|
||||
}
|
||||
|
||||
const result: KebabCasedPropertiesDeep<UserWithFriends> = {
|
||||
'user-info': {
|
||||
'user-id': 1,
|
||||
'user-name': 'Tom',
|
||||
},
|
||||
'user-friends': [
|
||||
{
|
||||
'user-id': 2,
|
||||
'user-name': 'Jerry',
|
||||
},
|
||||
{
|
||||
'user-id': 3,
|
||||
'user-name': 'Spike',
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type KebabCasedPropertiesDeep<Value> = DelimiterCasedPropertiesDeep<Value, '-'>;
|
26
node_modules/ansi-escapes/node_modules/type-fest/ts41/kebab-cased-properties.d.ts
generated
vendored
Normal file
26
node_modules/ansi-escapes/node_modules/type-fest/ts41/kebab-cased-properties.d.ts
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
import {DelimiterCasedProperties} from './delimiter-cased-properties';
|
||||
|
||||
/**
|
||||
Convert object properties to kebab case but not recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see KebabCase
|
||||
@see KebabCasedPropertiesDeep
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
const result: KebabCasedProperties<User> = {
|
||||
'user-id': 1,
|
||||
'user-name': 'Tom',
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type KebabCasedProperties<Value> = DelimiterCasedProperties<Value, '-'>;
|
25
node_modules/ansi-escapes/node_modules/type-fest/ts41/last-array-element.d.ts
generated
vendored
Normal file
25
node_modules/ansi-escapes/node_modules/type-fest/ts41/last-array-element.d.ts
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
Extracts the type of the last element of an array.
|
||||
|
||||
Use-case: Defining the return type of functions that extract the last element of an array, for example [`lodash.last`](https://lodash.com/docs/4.17.15#last).
|
||||
|
||||
@example
|
||||
```
|
||||
import {LastArrayElement} from 'type-fest';
|
||||
|
||||
declare function lastOf<V extends any[]>(array: V): LastArrayElement<V>;
|
||||
|
||||
const array = ['foo', 2];
|
||||
|
||||
typeof lastOf(array);
|
||||
//=> number
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type LastArrayElement<ValueType extends unknown[]> =
|
||||
ValueType extends [infer ElementType]
|
||||
? ElementType
|
||||
: ValueType extends [infer _, ...infer Tail]
|
||||
? LastArrayElement<Tail>
|
||||
: never;
|
37
node_modules/ansi-escapes/node_modules/type-fest/ts41/pascal-case.d.ts
generated
vendored
Normal file
37
node_modules/ansi-escapes/node_modules/type-fest/ts41/pascal-case.d.ts
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
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: CamelCasedProperties<ModelProps> = {
|
||||
DryRun: true,
|
||||
FullFamilyName: 'bar.js',
|
||||
Foo: 123
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type PascalCase<Value> = CamelCase<Value> extends string
|
||||
? Capitalize<CamelCase<Value>>
|
||||
: CamelCase<Value>;
|
50
node_modules/ansi-escapes/node_modules/type-fest/ts41/pascal-cased-properties-deep.d.ts
generated
vendored
Normal file
50
node_modules/ansi-escapes/node_modules/type-fest/ts41/pascal-cased-properties-deep.d.ts
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
import {PascalCase} from './pascal-case';
|
||||
|
||||
/**
|
||||
Convert object properties to pascal case recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see PascalCase
|
||||
@see PascalCasedProperties
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
interface UserWithFriends {
|
||||
userInfo: User;
|
||||
userFriends: User[];
|
||||
}
|
||||
|
||||
const result: PascalCasedPropertiesDeep<UserWithFriends> = {
|
||||
UserInfo: {
|
||||
UserId: 1,
|
||||
UserName: 'Tom',
|
||||
},
|
||||
UserFriends: [
|
||||
{
|
||||
UserId: 2,
|
||||
UserName: 'Jerry',
|
||||
},
|
||||
{
|
||||
UserId: 3,
|
||||
UserName: 'Spike',
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type PascalCasedPropertiesDeep<Value> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Array<PascalCasedPropertiesDeep<U>>
|
||||
: Value extends Set<infer U>
|
||||
? Set<PascalCasedPropertiesDeep<U>> : {
|
||||
[K in keyof Value as PascalCase<K>]: PascalCasedPropertiesDeep<Value[K]>;
|
||||
};
|
30
node_modules/ansi-escapes/node_modules/type-fest/ts41/pascal-cased-properties.d.ts
generated
vendored
Normal file
30
node_modules/ansi-escapes/node_modules/type-fest/ts41/pascal-cased-properties.d.ts
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
import {PascalCase} from './pascal-case';
|
||||
|
||||
/**
|
||||
Convert object properties to pascal case but not recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see PascalCase
|
||||
@see PascalCasedPropertiesDeep
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
const result: PascalCasedProperties<User> = {
|
||||
UserId: 1,
|
||||
UserName: 'Tom',
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type PascalCasedProperties<Value> = Value extends Function
|
||||
? Value
|
||||
: Value extends Array<infer U>
|
||||
? Value
|
||||
: { [K in keyof Value as PascalCase<K>]: Value[K] };
|
32
node_modules/ansi-escapes/node_modules/type-fest/ts41/screaming-snake-case.d.ts
generated
vendored
Normal file
32
node_modules/ansi-escapes/node_modules/type-fest/ts41/screaming-snake-case.d.ts
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
import {SplitIncludingDelimiters} from './delimiter-case';
|
||||
import {SnakeCase} from './snake-case';
|
||||
import {Includes} from './includes';
|
||||
|
||||
/**
|
||||
Returns a boolean for whether the string is screaming snake case.
|
||||
*/
|
||||
type IsScreamingSnakeCase<Value extends string> = Value extends Uppercase<Value>
|
||||
? Includes<SplitIncludingDelimiters<Lowercase<Value>, '_'>, '_'> extends true
|
||||
? true
|
||||
: false
|
||||
: false;
|
||||
|
||||
/**
|
||||
Convert a string literal to screaming-snake-case.
|
||||
|
||||
This can be useful when, for example, converting a camel-cased object property to a screaming-snake-cased SQL column name.
|
||||
|
||||
@example
|
||||
```
|
||||
import {ScreamingSnakeCase} from 'type-fest';
|
||||
|
||||
const someVariable: ScreamingSnakeCase<'fooBar'> = 'FOO_BAR';
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type ScreamingSnakeCase<Value> = Value extends string
|
||||
? IsScreamingSnakeCase<Value> extends true
|
||||
? Value
|
||||
: Uppercase<SnakeCase<Value>>
|
||||
: Value;
|
37
node_modules/ansi-escapes/node_modules/type-fest/ts41/snake-case.d.ts
generated
vendored
Normal file
37
node_modules/ansi-escapes/node_modules/type-fest/ts41/snake-case.d.ts
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
import {DelimiterCase} from './delimiter-case';
|
||||
|
||||
/**
|
||||
Convert a string literal to snake-case.
|
||||
|
||||
This can be useful when, for example, converting a camel-cased object property to a snake-cased SQL column name.
|
||||
|
||||
@example
|
||||
```
|
||||
import {SnakeCase} from 'type-fest';
|
||||
|
||||
// Simple
|
||||
|
||||
const someVariable: SnakeCase<'fooBar'> = 'foo_bar';
|
||||
|
||||
// Advanced
|
||||
|
||||
type SnakeCasedProperties<T> = {
|
||||
[K in keyof T as SnakeCase<K>]: T[K]
|
||||
};
|
||||
|
||||
interface ModelProps {
|
||||
isHappy: boolean;
|
||||
fullFamilyName: string;
|
||||
foo: number;
|
||||
}
|
||||
|
||||
const dbResult: SnakeCasedProperties<ModelProps> = {
|
||||
'is_happy': true,
|
||||
'full_family_name': 'Carla Smith',
|
||||
foo: 123
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type SnakeCase<Value> = DelimiterCase<Value, '_'>;
|
43
node_modules/ansi-escapes/node_modules/type-fest/ts41/snake-cased-properties-deep.d.ts
generated
vendored
Normal file
43
node_modules/ansi-escapes/node_modules/type-fest/ts41/snake-cased-properties-deep.d.ts
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
import {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
|
||||
|
||||
/**
|
||||
Convert object properties to snake case recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see SnakeCase
|
||||
@see SnakeCasedProperties
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
interface UserWithFriends {
|
||||
userInfo: User;
|
||||
userFriends: User[];
|
||||
}
|
||||
|
||||
const result: SnakeCasedPropertiesDeep<UserWithFriends> = {
|
||||
user_info: {
|
||||
user_id: 1,
|
||||
user_name: 'Tom',
|
||||
},
|
||||
user_friends: [
|
||||
{
|
||||
user_id: 2,
|
||||
user_name: 'Jerry',
|
||||
},
|
||||
{
|
||||
user_id: 3,
|
||||
user_name: 'Spike',
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type SnakeCasedPropertiesDeep<Value> = DelimiterCasedPropertiesDeep<Value, '_'>;
|
26
node_modules/ansi-escapes/node_modules/type-fest/ts41/snake-cased-properties.d.ts
generated
vendored
Normal file
26
node_modules/ansi-escapes/node_modules/type-fest/ts41/snake-cased-properties.d.ts
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
import {DelimiterCasedProperties} from './delimiter-cased-properties';
|
||||
|
||||
/**
|
||||
Convert object properties to snake case but not recursively.
|
||||
|
||||
This can be useful when, for example, converting some API types from a different style.
|
||||
|
||||
@see SnakeCase
|
||||
@see SnakeCasedPropertiesDeep
|
||||
|
||||
@example
|
||||
```
|
||||
interface User {
|
||||
userId: number;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
const result: SnakeCasedProperties<User> = {
|
||||
user_id: 1,
|
||||
user_name: 'Tom',
|
||||
};
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type SnakeCasedProperties<Value> = DelimiterCasedProperties<Value, '_'>;
|
28
node_modules/ansi-escapes/node_modules/type-fest/ts41/split.d.ts
generated
vendored
Normal file
28
node_modules/ansi-escapes/node_modules/type-fest/ts41/split.d.ts
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
Represents an array of strings split using a given character or character set.
|
||||
|
||||
Use-case: Defining the return type of a method like `String.prototype.split`.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Split} from 'type-fest';
|
||||
|
||||
declare function split<S extends string, D extends string>(string: S, separator: D): Split<S, D>;
|
||||
|
||||
type Item = 'foo' | 'bar' | 'baz' | 'waldo';
|
||||
const items = 'foo,bar,baz,waldo';
|
||||
let array: Item[];
|
||||
|
||||
array = split(items, ',');
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type Split<
|
||||
S extends string,
|
||||
Delimiter extends string
|
||||
> = S extends `${infer Head}${Delimiter}${infer Tail}`
|
||||
? [Head, ...Split<Tail, Delimiter>]
|
||||
: S extends Delimiter
|
||||
? []
|
||||
: [S];
|
24
node_modules/ansi-escapes/node_modules/type-fest/ts41/trim.d.ts
generated
vendored
Normal file
24
node_modules/ansi-escapes/node_modules/type-fest/ts41/trim.d.ts
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
Remove spaces from the left side.
|
||||
*/
|
||||
type TrimLeft<V extends string> = V extends ` ${infer R}` ? TrimLeft<R> : V;
|
||||
|
||||
/**
|
||||
Remove spaces from the right side.
|
||||
*/
|
||||
type TrimRight<V extends string> = V extends `${infer R} ` ? TrimRight<R> : V;
|
||||
|
||||
/**
|
||||
Remove leading and trailing spaces from a string.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Trim} from 'type-fest';
|
||||
|
||||
Trim<' foo '>
|
||||
//=> 'foo'
|
||||
```
|
||||
|
||||
@category Template Literals
|
||||
*/
|
||||
export type Trim<V extends string> = TrimLeft<TrimRight<V>>;
|
8
node_modules/ansi-escapes/node_modules/type-fest/ts41/utilities.d.ts
generated
vendored
Normal file
8
node_modules/ansi-escapes/node_modules/type-fest/ts41/utilities.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
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];
|
59
node_modules/ansi-escapes/package.json
generated
vendored
Normal file
59
node_modules/ansi-escapes/package.json
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"name": "ansi-escapes",
|
||||
"version": "5.0.0",
|
||||
"description": "ANSI escape codes for manipulating the terminal",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/ansi-escapes",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"ansi",
|
||||
"terminal",
|
||||
"console",
|
||||
"cli",
|
||||
"string",
|
||||
"tty",
|
||||
"escape",
|
||||
"escapes",
|
||||
"formatting",
|
||||
"shell",
|
||||
"xterm",
|
||||
"log",
|
||||
"logging",
|
||||
"command-line",
|
||||
"text",
|
||||
"vt100",
|
||||
"sequence",
|
||||
"control",
|
||||
"code",
|
||||
"codes",
|
||||
"cursor",
|
||||
"iterm",
|
||||
"iterm2"
|
||||
],
|
||||
"dependencies": {
|
||||
"type-fest": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.14.41",
|
||||
"ava": "^3.15.0",
|
||||
"tsd": "^0.14.0",
|
||||
"xo": "^0.38.2"
|
||||
}
|
||||
}
|
245
node_modules/ansi-escapes/readme.md
generated
vendored
Normal file
245
node_modules/ansi-escapes/readme.md
generated
vendored
Normal file
@ -0,0 +1,245 @@
|
||||
# ansi-escapes
|
||||
|
||||
> [ANSI escape codes](http://www.termsys.demon.co.uk/vtansi.htm) for manipulating the terminal
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install ansi-escapes
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import ansiEscapes from 'ansi-escapes';
|
||||
|
||||
// Moves the cursor two rows up and to the left
|
||||
process.stdout.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft);
|
||||
//=> '\u001B[2A\u001B[1000D'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### cursorTo(x, y?)
|
||||
|
||||
Set the absolute position of the cursor. `x0` `y0` is the top left of the screen.
|
||||
|
||||
### cursorMove(x, y?)
|
||||
|
||||
Set the position of the cursor relative to its current position.
|
||||
|
||||
### cursorUp(count)
|
||||
|
||||
Move cursor up a specific amount of rows. Default is `1`.
|
||||
|
||||
### cursorDown(count)
|
||||
|
||||
Move cursor down a specific amount of rows. Default is `1`.
|
||||
|
||||
### cursorForward(count)
|
||||
|
||||
Move cursor forward a specific amount of columns. Default is `1`.
|
||||
|
||||
### cursorBackward(count)
|
||||
|
||||
Move cursor backward a specific amount of columns. Default is `1`.
|
||||
|
||||
### cursorLeft
|
||||
|
||||
Move cursor to the left side.
|
||||
|
||||
### cursorSavePosition
|
||||
|
||||
Save cursor position.
|
||||
|
||||
### cursorRestorePosition
|
||||
|
||||
Restore saved cursor position.
|
||||
|
||||
### cursorGetPosition
|
||||
|
||||
Get cursor position.
|
||||
|
||||
### cursorNextLine
|
||||
|
||||
Move cursor to the next line.
|
||||
|
||||
### cursorPrevLine
|
||||
|
||||
Move cursor to the previous line.
|
||||
|
||||
### cursorHide
|
||||
|
||||
Hide cursor.
|
||||
|
||||
### cursorShow
|
||||
|
||||
Show cursor.
|
||||
|
||||
### eraseLines(count)
|
||||
|
||||
Erase from the current cursor position up the specified amount of rows.
|
||||
|
||||
### eraseEndLine
|
||||
|
||||
Erase from the current cursor position to the end of the current line.
|
||||
|
||||
### eraseStartLine
|
||||
|
||||
Erase from the current cursor position to the start of the current line.
|
||||
|
||||
### eraseLine
|
||||
|
||||
Erase the entire current line.
|
||||
|
||||
### eraseDown
|
||||
|
||||
Erase the screen from the current line down to the bottom of the screen.
|
||||
|
||||
### eraseUp
|
||||
|
||||
Erase the screen from the current line up to the top of the screen.
|
||||
|
||||
### eraseScreen
|
||||
|
||||
Erase the screen and move the cursor the top left position.
|
||||
|
||||
### scrollUp
|
||||
|
||||
Scroll display up one line.
|
||||
|
||||
### scrollDown
|
||||
|
||||
Scroll display down one line.
|
||||
|
||||
### clearScreen
|
||||
|
||||
Clear the terminal screen. (Viewport)
|
||||
|
||||
### clearTerminal
|
||||
|
||||
Clear the whole terminal, including scrollback buffer. (Not just the visible part of it)
|
||||
|
||||
### beep
|
||||
|
||||
Output a beeping sound.
|
||||
|
||||
### link(text, url)
|
||||
|
||||
Create a clickable link.
|
||||
|
||||
[Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) Use [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks) to detect link support.
|
||||
|
||||
### image(filePath, options?)
|
||||
|
||||
Display an image.
|
||||
|
||||
*Currently only supported on iTerm2 >=3*
|
||||
|
||||
See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module.
|
||||
|
||||
#### input
|
||||
|
||||
Type: `Buffer`
|
||||
|
||||
Buffer of an image. Usually read in with `fs.readFile()`.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### width
|
||||
##### height
|
||||
|
||||
Type: `string | number`
|
||||
|
||||
The width and height are given as a number followed by a unit, or the word "auto".
|
||||
|
||||
- `N`: N character cells.
|
||||
- `Npx`: N pixels.
|
||||
- `N%`: N percent of the session's width or height.
|
||||
- `auto`: The image's inherent size will be used to determine an appropriate dimension.
|
||||
|
||||
##### preserveAspectRatio
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
### iTerm.setCwd(path?)
|
||||
|
||||
Type: `string`\
|
||||
Default: `process.cwd()`
|
||||
|
||||
[Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click).
|
||||
|
||||
### iTerm.annotation(message, options?)
|
||||
|
||||
Creates an escape code to display an "annotation" in iTerm2.
|
||||
|
||||
An annotation looks like this when shown:
|
||||
|
||||
<img src="https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png" width="500">
|
||||
|
||||
See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information.
|
||||
|
||||
#### message
|
||||
|
||||
Type: `string`
|
||||
|
||||
The message to display within the annotation.
|
||||
|
||||
The `|` character is disallowed and will be stripped.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### length
|
||||
|
||||
Type: `number`\
|
||||
Default: The remainder of the line
|
||||
|
||||
Nonzero number of columns to annotate.
|
||||
|
||||
##### x
|
||||
|
||||
Type: `number`\
|
||||
Default: Cursor position
|
||||
|
||||
Starting X coordinate.
|
||||
|
||||
Must be used with `y` and `length`.
|
||||
|
||||
##### y
|
||||
|
||||
Type: `number`\
|
||||
Default: Cursor position
|
||||
|
||||
Starting Y coordinate.
|
||||
|
||||
Must be used with `x` and `length`.
|
||||
|
||||
##### isHidden
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Create a "hidden" annotation.
|
||||
|
||||
Annotations created this way can be shown using the "Show Annotations" iTerm command.
|
||||
|
||||
## Related
|
||||
|
||||
- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-ansi-escapes?utm_source=npm-ansi-escapes&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
Reference in New Issue
Block a user