fix: Try again with different node_modules
parent
229f06de58
commit
9378b3051a
|
@ -1 +0,0 @@
|
|||
../@commitlint/cli/cli.js
|
|
@ -1 +0,0 @@
|
|||
../husky/bin/run.js
|
|
@ -1 +0,0 @@
|
|||
../husky/lib/upgrader/bin.js
|
|
@ -1 +0,0 @@
|
|||
../@vercel/ncc/dist/ncc/cli.js
|
|
@ -1 +0,0 @@
|
|||
../which/bin/node-which
|
|
@ -1 +0,0 @@
|
|||
../opencollective-postinstall/index.js
|
|
@ -1 +0,0 @@
|
|||
../ts-node/dist/bin.js
|
|
@ -1 +0,0 @@
|
|||
../ts-node/dist/bin-script.js
|
|
@ -1 +0,0 @@
|
|||
../ts-node/dist/bin-transpile.js
|
|
@ -1 +0,0 @@
|
|||
../ts-node/dist/bin-script-deprecated.js
|
|
@ -3,6 +3,14 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [3.1.24](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-changelog@3.1.23...conventional-changelog@3.1.24) (2020-11-05)
|
||||
|
||||
**Note:** Version bump only for package conventional-changelog
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [3.1.23](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-changelog@3.1.22...conventional-changelog@3.1.23) (2020-08-12)
|
||||
|
||||
**Note:** Version bump only for package conventional-changelog
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
var conventionalChangelogCore = require('conventional-changelog-core')
|
||||
var conventionalChangelogPresetLoader = require('conventional-changelog-preset-loader')
|
||||
const conventionalChangelogCore = require('conventional-changelog-core')
|
||||
const conventionalChangelogPresetLoader = require('conventional-changelog-preset-loader')
|
||||
|
||||
function conventionalChangelog (options, context, gitRawCommitsOpts, parserOpts, writerOpts) {
|
||||
options.warn = options.warn || function () {}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "conventional-changelog",
|
||||
"version": "3.1.23",
|
||||
"version": "3.1.24",
|
||||
"description": "Generate a changelog from git metadata",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -35,24 +35,24 @@
|
|||
},
|
||||
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog#readme",
|
||||
"dependencies": {
|
||||
"conventional-changelog-angular": "^5.0.11",
|
||||
"conventional-changelog-atom": "^2.0.7",
|
||||
"conventional-changelog-codemirror": "^2.0.7",
|
||||
"conventional-changelog-conventionalcommits": "^4.4.0",
|
||||
"conventional-changelog-core": "^4.2.0",
|
||||
"conventional-changelog-ember": "^2.0.8",
|
||||
"conventional-changelog-eslint": "^3.0.8",
|
||||
"conventional-changelog-express": "^2.0.5",
|
||||
"conventional-changelog-jquery": "^3.0.10",
|
||||
"conventional-changelog-jshint": "^2.0.8",
|
||||
"conventional-changelog-angular": "^5.0.12",
|
||||
"conventional-changelog-atom": "^2.0.8",
|
||||
"conventional-changelog-codemirror": "^2.0.8",
|
||||
"conventional-changelog-conventionalcommits": "^4.5.0",
|
||||
"conventional-changelog-core": "^4.2.1",
|
||||
"conventional-changelog-ember": "^2.0.9",
|
||||
"conventional-changelog-eslint": "^3.0.9",
|
||||
"conventional-changelog-express": "^2.0.6",
|
||||
"conventional-changelog-jquery": "^3.0.11",
|
||||
"conventional-changelog-jshint": "^2.0.9",
|
||||
"conventional-changelog-preset-loader": "^2.3.4"
|
||||
},
|
||||
"scripts": {
|
||||
"test-windows": "mocha --timeout 30000"
|
||||
},
|
||||
"gitHead": "be1246c68f5dc4e6f28996129951a75bbf1cf307"
|
||||
"gitHead": "cc567b98facf71315f4b1620d81ce01d155efaca"
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/conventional-changelog/-/conventional-changelog-3.1.23.tgz"
|
||||
,"_integrity": "sha512-sScUu2NHusjRC1dPc5p8/b3kT78OYr95/Bx7Vl8CPB8tF2mG1xei5iylDTRjONV5hTlzt+Cn/tBWrKdd299b7A=="
|
||||
,"_from": "conventional-changelog@3.1.23"
|
||||
,"_resolved": "https://registry.npmjs.org/conventional-changelog/-/conventional-changelog-3.1.24.tgz"
|
||||
,"_integrity": "sha512-ed6k8PO00UVvhExYohroVPXcOJ/K1N0/drJHx/faTH37OIZthlecuLIRX/T6uOp682CAoVoFpu+sSEaeuH6Asg=="
|
||||
,"_from": "conventional-changelog@3.1.24"
|
||||
}
|
|
@ -3,6 +3,14 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [6.0.11](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-recommended-bump@6.0.10...conventional-recommended-bump@6.0.11) (2020-11-05)
|
||||
|
||||
**Note:** Version bump only for package conventional-recommended-bump
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [6.0.10](https://github.com/conventional-changelog/conventional-changelog/compare/conventional-recommended-bump@6.0.9...conventional-recommended-bump@6.0.10) (2020-08-12)
|
||||
|
||||
**Note:** Version bump only for package conventional-recommended-bump
|
||||
|
|
|
@ -1,301 +0,0 @@
|
|||
import {PackageJson} from 'type-fest';
|
||||
|
||||
declare namespace meow {
|
||||
type FlagType = 'string' | 'boolean' | 'number';
|
||||
|
||||
/**
|
||||
Callback function to determine if a flag is required during runtime.
|
||||
|
||||
@param flags - Contains the flags converted to camel-case excluding aliases.
|
||||
@param input - Contains the non-flag arguments.
|
||||
|
||||
@returns True if the flag is required, otherwise false.
|
||||
*/
|
||||
type IsRequiredPredicate = (flags: Readonly<AnyFlags>, input: readonly string[]) => boolean;
|
||||
|
||||
interface Flag<Type extends FlagType, Default> {
|
||||
readonly type?: Type;
|
||||
readonly alias?: string;
|
||||
readonly default?: Default;
|
||||
readonly isRequired?: boolean | IsRequiredPredicate;
|
||||
readonly isMultiple?: boolean;
|
||||
}
|
||||
|
||||
type StringFlag = Flag<'string', string>;
|
||||
type BooleanFlag = Flag<'boolean', boolean>;
|
||||
type NumberFlag = Flag<'number', number>;
|
||||
|
||||
type AnyFlag = StringFlag | BooleanFlag | NumberFlag;
|
||||
type AnyFlags = {[key: string]: AnyFlag};
|
||||
|
||||
interface Options<Flags extends AnyFlags> {
|
||||
/**
|
||||
Define argument flags.
|
||||
|
||||
The key is the flag name and the value is an object with any of:
|
||||
|
||||
- `type`: Type of value. (Possible values: `string` `boolean` `number`)
|
||||
- `alias`: Usually used to define a short flag alias.
|
||||
- `default`: Default value when the flag is not specified.
|
||||
- `isRequired`: Determine if the flag is required.
|
||||
If it's only known at runtime whether the flag is required or not you can pass a Function instead of a boolean, which based on the given flags and other non-flag arguments should decide if the flag is required.
|
||||
- `isMultiple`: Indicates a flag can be set multiple times. Values are turned into an array. (Default: false)
|
||||
|
||||
@example
|
||||
```
|
||||
flags: {
|
||||
unicorn: {
|
||||
type: 'string',
|
||||
alias: 'u',
|
||||
default: ['rainbow', 'cat'],
|
||||
isMultiple: true,
|
||||
isRequired: (flags, input) => {
|
||||
if (flags.otherFlag) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
*/
|
||||
readonly flags?: Flags;
|
||||
|
||||
/**
|
||||
Description to show above the help text. Default: The package.json `"description"` property.
|
||||
|
||||
Set it to `false` to disable it altogether.
|
||||
*/
|
||||
readonly description?: string | false;
|
||||
|
||||
/**
|
||||
The help text you want shown.
|
||||
|
||||
The input is reindented and starting/ending newlines are trimmed which means you can use a [template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings) without having to care about using the correct amount of indent.
|
||||
|
||||
The description will be shown above your help text automatically.
|
||||
|
||||
Set it to `false` to disable it altogether.
|
||||
*/
|
||||
readonly help?: string | false;
|
||||
|
||||
/**
|
||||
Set a custom version output. Default: The package.json `"version"` property.
|
||||
|
||||
Set it to `false` to disable it altogether.
|
||||
*/
|
||||
readonly version?: string | false;
|
||||
|
||||
/**
|
||||
Automatically show the help text when the `--help` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own help text.
|
||||
|
||||
This option is only considered when there is only one argument in `process.argv`.
|
||||
*/
|
||||
readonly autoHelp?: boolean;
|
||||
|
||||
/**
|
||||
Automatically show the version text when the `--version` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own version text.
|
||||
|
||||
This option is only considered when there is only one argument in `process.argv`.
|
||||
*/
|
||||
readonly autoVersion?: boolean;
|
||||
|
||||
/**
|
||||
`package.json` as an `Object`. Default: Closest `package.json` upwards.
|
||||
|
||||
_You most likely don't need this option._
|
||||
*/
|
||||
readonly pkg?: {[key: string]: unknown};
|
||||
|
||||
/**
|
||||
Custom arguments object.
|
||||
|
||||
@default process.argv.slice(2)
|
||||
*/
|
||||
readonly argv?: readonly string[];
|
||||
|
||||
/**
|
||||
Infer the argument type.
|
||||
|
||||
By default, the argument `5` in `$ foo 5` becomes a string. Enabling this would infer it as a number.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly inferType?: boolean;
|
||||
|
||||
/**
|
||||
Value of `boolean` flags not defined in `argv`. If set to `undefined` the flags not defined in `argv` will be excluded from the result. The `default` value set in `boolean` flags take precedence over `booleanDefault`.
|
||||
|
||||
__Caution: Explicitly specifying undefined for `booleanDefault` has different meaning from omitting key itself.__
|
||||
|
||||
@example
|
||||
```
|
||||
import meow = require('meow');
|
||||
|
||||
const cli = meow(`
|
||||
Usage
|
||||
$ foo
|
||||
|
||||
Options
|
||||
--rainbow, -r Include a rainbow
|
||||
--unicorn, -u Include a unicorn
|
||||
--no-sparkles Exclude sparkles
|
||||
|
||||
Examples
|
||||
$ foo
|
||||
🌈 unicorns✨🌈
|
||||
`, {
|
||||
booleanDefault: undefined,
|
||||
flags: {
|
||||
rainbow: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
alias: 'r'
|
||||
},
|
||||
unicorn: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
alias: 'u'
|
||||
},
|
||||
cake: {
|
||||
type: 'boolean',
|
||||
alias: 'c'
|
||||
},
|
||||
sparkles: {
|
||||
type: 'boolean',
|
||||
default: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//{
|
||||
// flags: {
|
||||
// rainbow: true,
|
||||
// unicorn: false,
|
||||
// sparkles: true
|
||||
// },
|
||||
// unnormalizedFlags: {
|
||||
// rainbow: true,
|
||||
// r: true,
|
||||
// unicorn: false,
|
||||
// u: false,
|
||||
// sparkles: true
|
||||
// },
|
||||
// …
|
||||
//}
|
||||
```
|
||||
*/
|
||||
readonly booleanDefault?: boolean | null | undefined;
|
||||
|
||||
/**
|
||||
Whether to use [hard-rejection](https://github.com/sindresorhus/hard-rejection) or not. Disabling this can be useful if you need to handle `process.on('unhandledRejection')` yourself.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly hardRejection?: boolean;
|
||||
}
|
||||
|
||||
type TypedFlag<Flag extends AnyFlag> =
|
||||
Flag extends {type: 'number'}
|
||||
? number
|
||||
: Flag extends {type: 'string'}
|
||||
? string
|
||||
: Flag extends {type: 'boolean'}
|
||||
? boolean
|
||||
: unknown;
|
||||
|
||||
type PossiblyOptionalFlag<Flag extends AnyFlag, FlagType> =
|
||||
Flag extends {isRequired: true}
|
||||
? FlagType
|
||||
: Flag extends {default: any}
|
||||
? FlagType
|
||||
: FlagType | undefined;
|
||||
|
||||
type TypedFlags<Flags extends AnyFlags> = {
|
||||
[F in keyof Flags]: Flags[F] extends {isMultiple: true}
|
||||
? PossiblyOptionalFlag<Flags[F], Array<TypedFlag<Flags[F]>>>
|
||||
: PossiblyOptionalFlag<Flags[F], TypedFlag<Flags[F]>>
|
||||
};
|
||||
|
||||
interface Result<Flags extends AnyFlags> {
|
||||
/**
|
||||
Non-flag arguments.
|
||||
*/
|
||||
input: string[];
|
||||
|
||||
/**
|
||||
Flags converted to camelCase excluding aliases.
|
||||
*/
|
||||
flags: TypedFlags<Flags> & {[name: string]: unknown};
|
||||
|
||||
/**
|
||||
Flags converted camelCase including aliases.
|
||||
*/
|
||||
unnormalizedFlags: TypedFlags<Flags> & {[name: string]: unknown};
|
||||
|
||||
/**
|
||||
The `package.json` object.
|
||||
*/
|
||||
pkg: PackageJson;
|
||||
|
||||
/**
|
||||
The help text used with `--help`.
|
||||
*/
|
||||
help: string;
|
||||
|
||||
/**
|
||||
Show the help text and exit with code.
|
||||
|
||||
@param exitCode - The exit code to use. Default: `2`.
|
||||
*/
|
||||
showHelp: (exitCode?: number) => void;
|
||||
|
||||
/**
|
||||
Show the version text and exit.
|
||||
*/
|
||||
showVersion: () => void;
|
||||
}
|
||||
}
|
||||
/**
|
||||
@param helpMessage - Shortcut for the `help` option.
|
||||
|
||||
@example
|
||||
```
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
import meow = require('meow');
|
||||
import foo = require('.');
|
||||
|
||||
const cli = meow(`
|
||||
Usage
|
||||
$ foo <input>
|
||||
|
||||
Options
|
||||
--rainbow, -r Include a rainbow
|
||||
|
||||
Examples
|
||||
$ foo unicorns --rainbow
|
||||
🌈 unicorns 🌈
|
||||
`, {
|
||||
flags: {
|
||||
rainbow: {
|
||||
type: 'boolean',
|
||||
alias: 'r'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//{
|
||||
// input: ['unicorns'],
|
||||
// flags: {rainbow: true},
|
||||
// ...
|
||||
//}
|
||||
|
||||
foo(cli.input[0], cli.flags);
|
||||
```
|
||||
*/
|
||||
declare function meow<Flags extends meow.AnyFlags>(helpMessage: string, options?: meow.Options<Flags>): meow.Result<Flags>;
|
||||
declare function meow<Flags extends meow.AnyFlags>(options?: meow.Options<Flags>): meow.Result<Flags>;
|
||||
|
||||
export = meow;
|
|
@ -1,198 +0,0 @@
|
|||
'use strict';
|
||||
const path = require('path');
|
||||
const buildParserOptions = require('minimist-options');
|
||||
const parseArguments = require('yargs-parser');
|
||||
const camelCaseKeys = require('camelcase-keys');
|
||||
const decamelizeKeys = require('decamelize-keys');
|
||||
const trimNewlines = require('trim-newlines');
|
||||
const redent = require('redent');
|
||||
const readPkgUp = require('read-pkg-up');
|
||||
const hardRejection = require('hard-rejection');
|
||||
const normalizePackageData = require('normalize-package-data');
|
||||
|
||||
// Prevent caching of this module so module.parent is always accurate
|
||||
delete require.cache[__filename];
|
||||
const parentDir = path.dirname(module.parent && module.parent.filename ? module.parent.filename : '.');
|
||||
|
||||
const isFlagMissing = (flagName, definedFlags, receivedFlags, input) => {
|
||||
const flag = definedFlags[flagName];
|
||||
let isFlagRequired = true;
|
||||
|
||||
if (typeof flag.isRequired === 'function') {
|
||||
isFlagRequired = flag.isRequired(receivedFlags, input);
|
||||
if (typeof isFlagRequired !== 'boolean') {
|
||||
throw new TypeError(`Return value for isRequired callback should be of type boolean, but ${typeof isFlagRequired} was returned.`);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof receivedFlags[flagName] === 'undefined') {
|
||||
return isFlagRequired;
|
||||
}
|
||||
|
||||
return flag.isMultiple && receivedFlags[flagName].length === 0;
|
||||
};
|
||||
|
||||
const getMissingRequiredFlags = (flags, receivedFlags, input) => {
|
||||
const missingRequiredFlags = [];
|
||||
if (typeof flags === 'undefined') {
|
||||
return [];
|
||||
}
|
||||
|
||||
for (const flagName of Object.keys(flags)) {
|
||||
if (flags[flagName].isRequired && isFlagMissing(flagName, flags, receivedFlags, input)) {
|
||||
missingRequiredFlags.push({key: flagName, ...flags[flagName]});
|
||||
}
|
||||
}
|
||||
|
||||
return missingRequiredFlags;
|
||||
};
|
||||
|
||||
const reportMissingRequiredFlags = missingRequiredFlags => {
|
||||
console.error(`Missing required flag${missingRequiredFlags.length > 1 ? 's' : ''}`);
|
||||
for (const flag of missingRequiredFlags) {
|
||||
console.error(`\t--${flag.key}${flag.alias ? `, -${flag.alias}` : ''}`);
|
||||
}
|
||||
};
|
||||
|
||||
const buildParserFlags = ({flags, booleanDefault}) =>
|
||||
Object.entries(flags).reduce((parserFlags, [flagKey, flagValue]) => {
|
||||
const flag = {...flagValue};
|
||||
|
||||
if (
|
||||
typeof booleanDefault !== 'undefined' &&
|
||||
flag.type === 'boolean' &&
|
||||
!Object.prototype.hasOwnProperty.call(flag, 'default')
|
||||
) {
|
||||
flag.default = flag.isMultiple ? [booleanDefault] : booleanDefault;
|
||||
}
|
||||
|
||||
if (flag.isMultiple) {
|
||||
flag.type = flag.type ? `${flag.type}-array` : 'array';
|
||||
delete flag.isMultiple;
|
||||
}
|
||||
|
||||
parserFlags[flagKey] = flag;
|
||||
|
||||
return parserFlags;
|
||||
}, {});
|
||||
|
||||
const validateFlags = (flags, options) => {
|
||||
for (const [flagKey, flagValue] of Object.entries(options.flags)) {
|
||||
if (flagKey !== '--' && !flagValue.isMultiple && Array.isArray(flags[flagKey])) {
|
||||
throw new Error(`The flag --${flagKey} can only be set once.`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const meow = (helpText, options) => {
|
||||
if (typeof helpText !== 'string') {
|
||||
options = helpText;
|
||||
helpText = '';
|
||||
}
|
||||
|
||||
options = {
|
||||
pkg: readPkgUp.sync({
|
||||
cwd: parentDir,
|
||||
normalize: false
|
||||
}).packageJson || {},
|
||||
argv: process.argv.slice(2),
|
||||
flags: {},
|
||||
inferType: false,
|
||||
input: 'string',
|
||||
help: helpText,
|
||||
autoHelp: true,
|
||||
autoVersion: true,
|
||||
booleanDefault: false,
|
||||
hardRejection: true,
|
||||
...options
|
||||
};
|
||||
|
||||
if (options.hardRejection) {
|
||||
hardRejection();
|
||||
}
|
||||
|
||||
let parserOptions = {
|
||||
arguments: options.input,
|
||||
...buildParserFlags(options)
|
||||
};
|
||||
|
||||
parserOptions = decamelizeKeys(parserOptions, '-', {exclude: ['stopEarly', '--']});
|
||||
|
||||
if (options.inferType) {
|
||||
delete parserOptions.arguments;
|
||||
}
|
||||
|
||||
parserOptions = buildParserOptions(parserOptions);
|
||||
|
||||
if (parserOptions['--']) {
|
||||
parserOptions.configuration = {
|
||||
...parserOptions.configuration,
|
||||
'populate--': true
|
||||
};
|
||||
}
|
||||
|
||||
const {pkg} = options;
|
||||
const argv = parseArguments(options.argv, parserOptions);
|
||||
let help = redent(trimNewlines((options.help || '').replace(/\t+\n*$/, '')), 2);
|
||||
|
||||
normalizePackageData(pkg);
|
||||
|
||||
process.title = pkg.bin ? Object.keys(pkg.bin)[0] : pkg.name;
|
||||
|
||||
let {description} = options;
|
||||
if (!description && description !== false) {
|
||||
({description} = pkg);
|
||||
}
|
||||
|
||||
help = (description ? `\n ${description}\n` : '') + (help ? `\n${help}\n` : '\n');
|
||||
|
||||
const showHelp = code => {
|
||||
console.log(help);
|
||||
process.exit(typeof code === 'number' ? code : 2);
|
||||
};
|
||||
|
||||
const showVersion = () => {
|
||||
console.log(typeof options.version === 'string' ? options.version : pkg.version);
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
if (argv._.length === 0 && options.argv.length === 1) {
|
||||
if (argv.version === true && options.autoVersion) {
|
||||
showVersion();
|
||||
}
|
||||
|
||||
if (argv.help === true && options.autoHelp) {
|
||||
showHelp(0);
|
||||
}
|
||||
}
|
||||
|
||||
const input = argv._;
|
||||
delete argv._;
|
||||
|
||||
const flags = camelCaseKeys(argv, {exclude: ['--', /^\w$/]});
|
||||
const unnormalizedFlags = {...flags};
|
||||
|
||||
validateFlags(flags, options);
|
||||
|
||||
for (const flagValue of Object.values(options.flags)) {
|
||||
delete flags[flagValue.alias];
|
||||
}
|
||||
|
||||
const missingRequiredFlags = getMissingRequiredFlags(options.flags, flags, input);
|
||||
if (missingRequiredFlags.length > 0) {
|
||||
reportMissingRequiredFlags(missingRequiredFlags);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
return {
|
||||
input,
|
||||
flags,
|
||||
unnormalizedFlags,
|
||||
pkg,
|
||||
help,
|
||||
showHelp,
|
||||
showVersion
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = meow;
|
|
@ -1,9 +0,0 @@
|
|||
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.
|
|
@ -1,103 +0,0 @@
|
|||
declare namespace camelcaseKeys {
|
||||
interface Options {
|
||||
/**
|
||||
Recurse nested objects and objects in arrays.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly deep?: boolean;
|
||||
|
||||
/**
|
||||
Exclude keys from being camel-cased.
|
||||
|
||||
@default []
|
||||
*/
|
||||
readonly exclude?: ReadonlyArray<string | RegExp>;
|
||||
|
||||
/**
|
||||
Exclude children at the given object paths in dot-notation from being camel-cased. For example, with an object like `{a: {b: '🦄'}}`, the object path to reach the unicorn is `'a.b'`.
|
||||
|
||||
@default []
|
||||
|
||||
@example
|
||||
```
|
||||
camelcaseKeys({
|
||||
a_b: 1,
|
||||
a_c: {
|
||||
c_d: 1,
|
||||
c_e: {
|
||||
e_f: 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
deep: true,
|
||||
stopPaths: [
|
||||
'a_c.c_e'
|
||||
]
|
||||
}),
|
||||
// {
|
||||
// aB: 1,
|
||||
// aC: {
|
||||
// cD: 1,
|
||||
// cE: {
|
||||
// e_f: 1
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
```
|
||||
*/
|
||||
readonly stopPaths?: ReadonlyArray<string>;
|
||||
|
||||
/**
|
||||
Uppercase the first character as in `bye-bye` → `ByeBye`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly pascalCase?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Convert object keys to camel case using [`camelcase`](https://github.com/sindresorhus/camelcase).
|
||||
|
||||
@param input - Object or array of objects to camel-case.
|
||||
|
||||
@example
|
||||
```
|
||||
import camelcaseKeys = require('camelcase-keys');
|
||||
|
||||
// Convert an object
|
||||
camelcaseKeys({'foo-bar': true});
|
||||
//=> {fooBar: true}
|
||||
|
||||
// Convert an array of objects
|
||||
camelcaseKeys([{'foo-bar': true}, {'bar-foo': false}]);
|
||||
//=> [{fooBar: true}, {barFoo: false}]
|
||||
|
||||
camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true});
|
||||
//=> {fooBar: true, nested: {unicornRainbow: true}}
|
||||
|
||||
// Convert object keys to pascal case
|
||||
camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true, pascalCase: true});
|
||||
//=> {FooBar: true, Nested: {UnicornRainbow: true}}
|
||||
|
||||
import minimist = require('minimist');
|
||||
|
||||
const argv = minimist(process.argv.slice(2));
|
||||
//=> {_: [], 'foo-bar': true}
|
||||
|
||||
camelcaseKeys(argv);
|
||||
//=> {_: [], fooBar: true}
|
||||
```
|
||||
*/
|
||||
declare function camelcaseKeys<T extends ReadonlyArray<{[key: string]: any}>>(
|
||||
input: T,
|
||||
options?: camelcaseKeys.Options,
|
||||
): T;
|
||||
|
||||
declare function camelcaseKeys<T extends {[key: string]: any}>(
|
||||
input: T,
|
||||
options?: camelcaseKeys.Options,
|
||||
): T;
|
||||
|
||||
export = camelcaseKeys;
|
|
@ -1,77 +0,0 @@
|
|||
'use strict';
|
||||
const mapObj = require('map-obj');
|
||||
const camelCase = require('camelcase');
|
||||
const QuickLru = require('quick-lru');
|
||||
|
||||
const has = (array, key) => array.some(x => {
|
||||
if (typeof x === 'string') {
|
||||
return x === key;
|
||||
}
|
||||
|
||||
x.lastIndex = 0;
|
||||
return x.test(key);
|
||||
});
|
||||
|
||||
const cache = new QuickLru({maxSize: 100000});
|
||||
|
||||
// Reproduces behavior from `map-obj`
|
||||
const isObject = value =>
|
||||
typeof value === 'object' &&
|
||||
value !== null &&
|
||||
!(value instanceof RegExp) &&
|
||||
!(value instanceof Error) &&
|
||||
!(value instanceof Date);
|
||||
|
||||
const camelCaseConvert = (input, options) => {
|
||||
if (!isObject(input)) {
|
||||
return input;
|
||||
}
|
||||
|
||||
options = {
|
||||
deep: false,
|
||||
pascalCase: false,
|
||||
...options
|
||||
};
|
||||
|
||||
const {exclude, pascalCase, stopPaths, deep} = options;
|
||||
|
||||
const stopPathsSet = new Set(stopPaths);
|
||||
|
||||
const makeMapper = parentPath => (key, value) => {
|
||||
if (deep && isObject(value)) {
|
||||
const path = parentPath === undefined ? key : `${parentPath}.${key}`;
|
||||
|
||||
if (!stopPathsSet.has(path)) {
|
||||
value = mapObj(value, makeMapper(path));
|
||||
}
|
||||
}
|
||||
|
||||
if (!(exclude && has(exclude, key))) {
|
||||
const cacheKey = pascalCase ? `${key}_` : key;
|
||||
|
||||
if (cache.has(cacheKey)) {
|
||||
key = cache.get(cacheKey);
|
||||
} else {
|
||||
const ret = camelCase(key, {pascalCase});
|
||||
|
||||
if (key.length < 100) { // Prevent abuse
|
||||
cache.set(cacheKey, ret);
|
||||
}
|
||||
|
||||
key = ret;
|
||||
}
|
||||
}
|
||||
|
||||
return [key, value];
|
||||
};
|
||||
|
||||
return mapObj(input, makeMapper(undefined));
|
||||
};
|
||||
|
||||
module.exports = (input, options) => {
|
||||
if (Array.isArray(input)) {
|
||||
return Object.keys(input).map(key => camelCaseConvert(input[key], options));
|
||||
}
|
||||
|
||||
return camelCaseConvert(input, options);
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,77 +0,0 @@
|
|||
{
|
||||
"name": "camelcase-keys",
|
||||
"version": "6.2.2",
|
||||
"description": "Convert object keys to camel case",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/camelcase-keys",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd",
|
||||
"bench": "matcha bench/bench.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"map",
|
||||
"obj",
|
||||
"object",
|
||||
"key",
|
||||
"keys",
|
||||
"value",
|
||||
"values",
|
||||
"val",
|
||||
"iterate",
|
||||
"camelcase",
|
||||
"camel-case",
|
||||
"camel",
|
||||
"case",
|
||||
"dash",
|
||||
"hyphen",
|
||||
"dot",
|
||||
"underscore",
|
||||
"separator",
|
||||
"string",
|
||||
"text",
|
||||
"convert",
|
||||
"pascalcase",
|
||||
"pascal-case",
|
||||
"deep",
|
||||
"recurse",
|
||||
"recursive"
|
||||
],
|
||||
"dependencies": {
|
||||
"camelcase": "^5.3.1",
|
||||
"map-obj": "^4.0.0",
|
||||
"quick-lru": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^2.1.0",
|
||||
"matcha": "^0.7.0",
|
||||
"tsd": "^0.11.0",
|
||||
"xo": "^0.25.3"
|
||||
},
|
||||
"xo": {
|
||||
"overrides": [
|
||||
{
|
||||
"files": "bench/bench.js",
|
||||
"rules": {
|
||||
"import/no-unresolved": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-6.2.2.tgz"
|
||||
,"_integrity": "sha512-YrwaA0vEKazPBkn0ipTiMpSajYDSe+KjQfrjhcBMxJt/znbvlHd8Pw/Vamaz5EB4Wfhs3SUR3Z9mwRu/P3s3Yg=="
|
||||
,"_from": "camelcase-keys@6.2.2"
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
# camelcase-keys [](https://travis-ci.org/sindresorhus/camelcase-keys)
|
||||
|
||||
> Convert object keys to camel case using [`camelcase`](https://github.com/sindresorhus/camelcase)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install camelcase-keys
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const camelcaseKeys = require('camelcase-keys');
|
||||
|
||||
// Convert an object
|
||||
camelcaseKeys({'foo-bar': true});
|
||||
//=> {fooBar: true}
|
||||
|
||||
// Convert an array of objects
|
||||
camelcaseKeys([{'foo-bar': true}, {'bar-foo': false}]);
|
||||
//=> [{fooBar: true}, {barFoo: false}]
|
||||
|
||||
camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true});
|
||||
//=> {fooBar: true, nested: {unicornRainbow: true}}
|
||||
|
||||
camelcaseKeys({a_b: 1, a_c: {c_d: 1, c_e: {e_f: 1}}}, {deep: true, stopPaths: ['a_c.c_e']}),
|
||||
//=> {aB: 1, aC: {cD: 1, cE: {e_f: 1}}}
|
||||
|
||||
// Convert object keys to pascal case
|
||||
camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true, pascalCase: true});
|
||||
//=> {FooBar: true, Nested: {UnicornRainbow: true}}
|
||||
```
|
||||
|
||||
```js
|
||||
const camelcaseKeys = require('camelcase-keys');
|
||||
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
//=> {_: [], 'foo-bar': true}
|
||||
|
||||
camelcaseKeys(argv);
|
||||
//=> {_: [], fooBar: true}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### camelcaseKeys(input, options?)
|
||||
|
||||
#### input
|
||||
|
||||
Type: `object | object[]`
|
||||
|
||||
An object or array of objects to camel-case.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### exclude
|
||||
|
||||
Type: `Array<string | RegExp>`\
|
||||
Default: `[]`
|
||||
|
||||
Exclude keys from being camel-cased.
|
||||
|
||||
##### stopPaths
|
||||
|
||||
Type: `string[]`\
|
||||
Default: `[]`
|
||||
|
||||
Exclude children at the given object paths in dot-notation from being camel-cased. For example, with an object like `{a: {b: '🦄'}}`, the object path to reach the unicorn is `'a.b'`.
|
||||
|
||||
```js
|
||||
camelcaseKeys({
|
||||
a_b: 1,
|
||||
a_c: {
|
||||
c_d: 1,
|
||||
c_e: {
|
||||
e_f: 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
deep: true,
|
||||
stopPaths: [
|
||||
'a_c.c_e'
|
||||
]
|
||||
}),
|
||||
/*
|
||||
{
|
||||
aB: 1,
|
||||
aC: {
|
||||
cD: 1,
|
||||
cE: {
|
||||
e_f: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
##### deep
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Recurse nested objects and objects in arrays.
|
||||
|
||||
##### pascalCase
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Uppercase the first character as in `bye-bye` → `ByeBye`.
|
||||
|
||||
## camelcase-keys for enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription.
|
||||
|
||||
The maintainers of camelcase-keys and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-camelcase-keys?utm_source=npm-camelcase-keys&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
|
||||
## Related
|
||||
|
||||
- [snakecase-keys](https://github.com/bendrucker/snakecase-keys)
|
||||
- [kebabcase-keys](https://github.com/mattiloh/kebabcase-keys)
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
declare namespace camelcase {
|
||||
interface Options {
|
||||
/**
|
||||
Uppercase the first character: `foo-bar` → `FooBar`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly pascalCase?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare const camelcase: {
|
||||
/**
|
||||
Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`.
|
||||
|
||||
@param input - String to convert to camel case.
|
||||
|
||||
@example
|
||||
```
|
||||
import camelCase = require('camelcase');
|
||||
|
||||
camelCase('foo-bar');
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('foo_bar');
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('Foo-Bar');
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('Foo-Bar', {pascalCase: true});
|
||||
//=> 'FooBar'
|
||||
|
||||
camelCase('--foo.bar', {pascalCase: false});
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('foo bar');
|
||||
//=> 'fooBar'
|
||||
|
||||
console.log(process.argv[3]);
|
||||
//=> '--foo-bar'
|
||||
camelCase(process.argv[3]);
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase(['foo', 'bar']);
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase(['__foo__', '--bar'], {pascalCase: true});
|
||||
//=> 'FooBar'
|
||||
```
|
||||
*/
|
||||
(input: string | ReadonlyArray<string>, options?: camelcase.Options): string;
|
||||
|
||||
// TODO: Remove this for the next major release, refactor the whole definition to:
|
||||
// declare function camelcase(
|
||||
// input: string | ReadonlyArray<string>,
|
||||
// options?: camelcase.Options
|
||||
// ): string;
|
||||
// export = camelcase;
|
||||
default: typeof camelcase;
|
||||
};
|
||||
|
||||
export = camelcase;
|
|
@ -1,76 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const preserveCamelCase = string => {
|
||||
let isLastCharLower = false;
|
||||
let isLastCharUpper = false;
|
||||
let isLastLastCharUpper = false;
|
||||
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
const character = string[i];
|
||||
|
||||
if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) {
|
||||
string = string.slice(0, i) + '-' + string.slice(i);
|
||||
isLastCharLower = false;
|
||||
isLastLastCharUpper = isLastCharUpper;
|
||||
isLastCharUpper = true;
|
||||
i++;
|
||||
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(character) && character.toLowerCase() === character) {
|
||||
string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
|
||||
isLastLastCharUpper = isLastCharUpper;
|
||||
isLastCharUpper = false;
|
||||
isLastCharLower = true;
|
||||
} else {
|
||||
isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;
|
||||
isLastLastCharUpper = isLastCharUpper;
|
||||
isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;
|
||||
}
|
||||
}
|
||||
|
||||
return string;
|
||||
};
|
||||
|
||||
const camelCase = (input, options) => {
|
||||
if (!(typeof input === 'string' || Array.isArray(input))) {
|
||||
throw new TypeError('Expected the input to be `string | string[]`');
|
||||
}
|
||||
|
||||
options = Object.assign({
|
||||
pascalCase: false
|
||||
}, options);
|
||||
|
||||
const postProcess = x => options.pascalCase ? x.charAt(0).toUpperCase() + x.slice(1) : x;
|
||||
|
||||
if (Array.isArray(input)) {
|
||||
input = input.map(x => x.trim())
|
||||
.filter(x => x.length)
|
||||
.join('-');
|
||||
} else {
|
||||
input = input.trim();
|
||||
}
|
||||
|
||||
if (input.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (input.length === 1) {
|
||||
return options.pascalCase ? input.toUpperCase() : input.toLowerCase();
|
||||
}
|
||||
|
||||
const hasUpperCase = input !== input.toLowerCase();
|
||||
|
||||
if (hasUpperCase) {
|
||||
input = preserveCamelCase(input);
|
||||
}
|
||||
|
||||
input = input
|
||||
.replace(/^[_.\- ]+/, '')
|
||||
.toLowerCase()
|
||||
.replace(/[_.\- ]+(\w|$)/g, (_, p1) => p1.toUpperCase())
|
||||
.replace(/\d+(\w|$)/g, m => m.toUpperCase());
|
||||
|
||||
return postProcess(input);
|
||||
};
|
||||
|
||||
module.exports = camelCase;
|
||||
// TODO: Remove this for the next major release
|
||||
module.exports.default = camelCase;
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,47 +0,0 @@
|
|||
{
|
||||
"name": "camelcase",
|
||||
"version": "5.3.1",
|
||||
"description": "Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/camelcase",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"camelcase",
|
||||
"camel-case",
|
||||
"camel",
|
||||
"case",
|
||||
"dash",
|
||||
"hyphen",
|
||||
"dot",
|
||||
"underscore",
|
||||
"separator",
|
||||
"string",
|
||||
"text",
|
||||
"convert",
|
||||
"pascalcase",
|
||||
"pascal-case"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.7.1",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz"
|
||||
,"_integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg=="
|
||||
,"_from": "camelcase@5.3.1"
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
# camelcase [](https://travis-ci.org/sindresorhus/camelcase)
|
||||
|
||||
> Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-camelcase?utm_source=npm-camelcase&utm_medium=referral&utm_campaign=readme">Get professional support for 'camelcase' 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>
|
||||
|
||||
---
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install camelcase
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const camelCase = require('camelcase');
|
||||
|
||||
camelCase('foo-bar');
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('foo_bar');
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('Foo-Bar');
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('Foo-Bar', {pascalCase: true});
|
||||
//=> 'FooBar'
|
||||
|
||||
camelCase('--foo.bar', {pascalCase: false});
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase('foo bar');
|
||||
//=> 'fooBar'
|
||||
|
||||
console.log(process.argv[3]);
|
||||
//=> '--foo-bar'
|
||||
camelCase(process.argv[3]);
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase(['foo', 'bar']);
|
||||
//=> 'fooBar'
|
||||
|
||||
camelCase(['__foo__', '--bar'], {pascalCase: true});
|
||||
//=> 'FooBar'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### camelCase(input, [options])
|
||||
|
||||
#### input
|
||||
|
||||
Type: `string` `string[]`
|
||||
|
||||
String to convert to camel case.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
##### pascalCase
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Uppercase the first character: `foo-bar` → `FooBar`
|
||||
|
||||
|
||||
## Security
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module
|
||||
- [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase
|
||||
- [titleize](https://github.com/sindresorhus/titleize) - Capitalize every word in string
|
||||
- [humanize-string](https://github.com/sindresorhus/humanize-string) - Convert a camelized/dasherized/underscored string into a humanized one
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
|
@ -1,42 +0,0 @@
|
|||
declare namespace indentString {
|
||||
interface Options {
|
||||
/**
|
||||
The string to use for the indent.
|
||||
|
||||
@default ' '
|
||||
*/
|
||||
readonly indent?: string;
|
||||
|
||||
/**
|
||||
Also indent empty lines.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly includeEmptyLines?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Indent each line in a string.
|
||||
|
||||
@param string - The string to indent.
|
||||
@param count - How many times you want `options.indent` repeated. Default: `1`.
|
||||
|
||||
@example
|
||||
```
|
||||
import indentString = require('indent-string');
|
||||
|
||||
indentString('Unicorns\nRainbows', 4);
|
||||
//=> ' Unicorns\n Rainbows'
|
||||
|
||||
indentString('Unicorns\nRainbows', 4, {indent: '♥'});
|
||||
//=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows'
|
||||
```
|
||||
*/
|
||||
declare function indentString(
|
||||
string: string,
|
||||
count?: number,
|
||||
options?: indentString.Options
|
||||
): string;
|
||||
|
||||
export = indentString;
|
|
@ -1,35 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (string, count = 1, options) => {
|
||||
options = {
|
||||
indent: ' ',
|
||||
includeEmptyLines: false,
|
||||
...options
|
||||
};
|
||||
|
||||
if (typeof string !== 'string') {
|
||||
throw new TypeError(
|
||||
`Expected \`input\` to be a \`string\`, got \`${typeof string}\``
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof count !== 'number') {
|
||||
throw new TypeError(
|
||||
`Expected \`count\` to be a \`number\`, got \`${typeof count}\``
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof options.indent !== 'string') {
|
||||
throw new TypeError(
|
||||
`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``
|
||||
);
|
||||
}
|
||||
|
||||
if (count === 0) {
|
||||
return string;
|
||||
}
|
||||
|
||||
const regex = options.includeEmptyLines ? /^/gm : /^(?!\s*$)/gm;
|
||||
|
||||
return string.replace(regex, options.indent.repeat(count));
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,41 +0,0 @@
|
|||
{
|
||||
"name": "indent-string",
|
||||
"version": "4.0.0",
|
||||
"description": "Indent each line in a string",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/indent-string",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"indent",
|
||||
"string",
|
||||
"pad",
|
||||
"align",
|
||||
"line",
|
||||
"text",
|
||||
"each",
|
||||
"every"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz"
|
||||
,"_integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg=="
|
||||
,"_from": "indent-string@4.0.0"
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
# indent-string [](https://travis-ci.org/sindresorhus/indent-string)
|
||||
|
||||
> Indent each line in a string
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install indent-string
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const indentString = require('indent-string');
|
||||
|
||||
indentString('Unicorns\nRainbows', 4);
|
||||
//=> ' Unicorns\n Rainbows'
|
||||
|
||||
indentString('Unicorns\nRainbows', 4, {indent: '♥'});
|
||||
//=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### indentString(string, [count], [options])
|
||||
|
||||
#### string
|
||||
|
||||
Type: `string`
|
||||
|
||||
The string to indent.
|
||||
|
||||
#### count
|
||||
|
||||
Type: `number`<br>
|
||||
Default: `1`
|
||||
|
||||
How many times you want `options.indent` repeated.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### indent
|
||||
|
||||
Type: `string`<br>
|
||||
Default: `' '`
|
||||
|
||||
The string to use for the indent.
|
||||
|
||||
##### includeEmptyLines
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Also indent empty lines.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [indent-string-cli](https://github.com/sindresorhus/indent-string-cli) - CLI for this module
|
||||
- [strip-indent](https://github.com/sindresorhus/strip-indent) - Strip leading whitespace from every line in a string
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
151
node_modules/conventional-recommended-bump/node_modules/meow/node_modules/map-obj/index.d.ts
generated
vendored
151
node_modules/conventional-recommended-bump/node_modules/meow/node_modules/map-obj/index.d.ts
generated
vendored
|
@ -1,151 +0,0 @@
|
|||
// Unique symbol cannot be declared in a namespace directly, so we declare it top-level
|
||||
// See: https://github.com/sindresorhus/map-obj/pull/38#discussion_r702396878
|
||||
declare const skipSymbol: unique symbol;
|
||||
|
||||
declare namespace mapObject {
|
||||
type Mapper<
|
||||
SourceObjectType extends {[key: string]: any},
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
> = (
|
||||
sourceKey: keyof SourceObjectType,
|
||||
sourceValue: SourceObjectType[keyof SourceObjectType],
|
||||
source: SourceObjectType
|
||||
) => [
|
||||
targetKey: MappedObjectKeyType,
|
||||
targetValue: MappedObjectValueType,
|
||||
mapperOptions?: mapObject.MapperOptions
|
||||
] | typeof mapObject.mapObjectSkip;
|
||||
|
||||
interface Options {
|
||||
/**
|
||||
Recurse nested objects and objects in arrays.
|
||||
|
||||
@default false
|
||||
*/
|
||||
deep?: boolean;
|
||||
|
||||
/**
|
||||
Target object to map properties on to.
|
||||
|
||||
@default {}
|
||||
*/
|
||||
target?: {[key: string]: any};
|
||||
}
|
||||
|
||||
interface DeepOptions extends Options {
|
||||
deep: true;
|
||||
}
|
||||
|
||||
interface TargetOptions<TargetObjectType extends {[key: string]: any}> extends Options {
|
||||
target: TargetObjectType;
|
||||
}
|
||||
|
||||
interface MapperOptions {
|
||||
/**
|
||||
Whether `targetValue` should be recursed.
|
||||
|
||||
Requires `deep: true`.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly shouldRecurse?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
Return this value from a `mapper` function to remove a key from an object.
|
||||
|
||||
@example
|
||||
```
|
||||
const mapObject = require('map-obj');
|
||||
|
||||
const object = {one: 1, two: 2}
|
||||
const mapper = (key, value) => value === 1 ? [key, value] : mapObject.mapObjectSkip
|
||||
const result = mapObject(object, mapper);
|
||||
|
||||
console.log(result);
|
||||
//=> {one: 1}
|
||||
```
|
||||
*/
|
||||
const mapObjectSkip: typeof skipSymbol
|
||||
}
|
||||
|
||||
/**
|
||||
Map object keys and values into a new object.
|
||||
|
||||
@param source - Source object to copy properties from.
|
||||
@param mapper - Mapping function.
|
||||
|
||||
@example
|
||||
```
|
||||
import mapObject = require('map-obj');
|
||||
|
||||
const newObject = mapObject({foo: 'bar'}, (key, value) => [value, key]);
|
||||
//=> {bar: 'foo'}
|
||||
|
||||
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value]);
|
||||
//=> {foo: true, bar: {bAz: true}}
|
||||
|
||||
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value], {deep: true});
|
||||
//=> {foo: true, bar: {baz: true}}
|
||||
|
||||
const newObject = mapObject({one: 1, two: 2}, (key, value) => value === 1 ? [key, value] : mapObject.mapObjectSkip);
|
||||
//=> {one: 1}
|
||||
```
|
||||
*/
|
||||
declare function mapObject<
|
||||
SourceObjectType extends object,
|
||||
TargetObjectType extends {[key: string]: any},
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
>(
|
||||
source: SourceObjectType,
|
||||
mapper: mapObject.Mapper<
|
||||
SourceObjectType,
|
||||
MappedObjectKeyType,
|
||||
MappedObjectValueType
|
||||
>,
|
||||
options: mapObject.DeepOptions & mapObject.TargetOptions<TargetObjectType>
|
||||
): TargetObjectType & {[key: string]: unknown};
|
||||
declare function mapObject<
|
||||
SourceObjectType extends object,
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
>(
|
||||
source: SourceObjectType,
|
||||
mapper: mapObject.Mapper<
|
||||
SourceObjectType,
|
||||
MappedObjectKeyType,
|
||||
MappedObjectValueType
|
||||
>,
|
||||
options: mapObject.DeepOptions
|
||||
): {[key: string]: unknown};
|
||||
declare function mapObject<
|
||||
SourceObjectType extends {[key: string]: any},
|
||||
TargetObjectType extends {[key: string]: any},
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
>(
|
||||
source: SourceObjectType,
|
||||
mapper: mapObject.Mapper<
|
||||
SourceObjectType,
|
||||
MappedObjectKeyType,
|
||||
MappedObjectValueType
|
||||
>,
|
||||
options: mapObject.TargetOptions<TargetObjectType>
|
||||
): TargetObjectType & {[K in MappedObjectKeyType]: MappedObjectValueType};
|
||||
declare function mapObject<
|
||||
SourceObjectType extends {[key: string]: any},
|
||||
MappedObjectKeyType extends string,
|
||||
MappedObjectValueType
|
||||
>(
|
||||
source: SourceObjectType,
|
||||
mapper: mapObject.Mapper<
|
||||
SourceObjectType,
|
||||
MappedObjectKeyType,
|
||||
MappedObjectValueType
|
||||
>,
|
||||
options?: mapObject.Options
|
||||
): {[K in MappedObjectKeyType]: MappedObjectValueType};
|
||||
|
||||
export = mapObject;
|
|
@ -1,68 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const isObject = value => typeof value === 'object' && value !== null;
|
||||
const mapObjectSkip = Symbol('skip');
|
||||
|
||||
// Customized for this use-case
|
||||
const isObjectCustom = value =>
|
||||
isObject(value) &&
|
||||
!(value instanceof RegExp) &&
|
||||
!(value instanceof Error) &&
|
||||
!(value instanceof Date);
|
||||
|
||||
const mapObject = (object, mapper, options, isSeen = new WeakMap()) => {
|
||||
options = {
|
||||
deep: false,
|
||||
target: {},
|
||||
...options
|
||||
};
|
||||
|
||||
if (isSeen.has(object)) {
|
||||
return isSeen.get(object);
|
||||
}
|
||||
|
||||
isSeen.set(object, options.target);
|
||||
|
||||
const {target} = options;
|
||||
delete options.target;
|
||||
|
||||
const mapArray = array => array.map(element => isObjectCustom(element) ? mapObject(element, mapper, options, isSeen) : element);
|
||||
if (Array.isArray(object)) {
|
||||
return mapArray(object);
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
const mapResult = mapper(key, value, object);
|
||||
|
||||
if (mapResult === mapObjectSkip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let [newKey, newValue, {shouldRecurse = true} = {}] = mapResult;
|
||||
|
||||
// Drop `__proto__` keys.
|
||||
if (newKey === '__proto__') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (options.deep && shouldRecurse && isObjectCustom(newValue)) {
|
||||
newValue = Array.isArray(newValue) ?
|
||||
mapArray(newValue) :
|
||||
mapObject(newValue, mapper, options, isSeen);
|
||||
}
|
||||
|
||||
target[newKey] = newValue;
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
module.exports = (object, mapper, options) => {
|
||||
if (!isObject(object)) {
|
||||
throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`);
|
||||
}
|
||||
|
||||
return mapObject(object, mapper, options);
|
||||
};
|
||||
|
||||
module.exports.mapObjectSkip = mapObjectSkip;
|
|
@ -1,9 +0,0 @@
|
|||
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.
|
|
@ -1,47 +0,0 @@
|
|||
{
|
||||
"name": "map-obj",
|
||||
"version": "4.3.0",
|
||||
"description": "Map object keys and values into a new object",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/map-obj",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"map",
|
||||
"object",
|
||||
"key",
|
||||
"keys",
|
||||
"value",
|
||||
"values",
|
||||
"iterate",
|
||||
"iterator",
|
||||
"rename",
|
||||
"modify",
|
||||
"deep",
|
||||
"recurse",
|
||||
"recursive"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^2.0.0",
|
||||
"tsd": "^0.14.0",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.3.0.tgz"
|
||||
,"_integrity": "sha512-hdN1wVrZbb29eBGiGjJbeP8JbKjq1urkHJ/LIP/NY48MZ1QVXUsQBV1G1zvYFHn1XE06cwjBsOI2K3Ulnj1YXQ=="
|
||||
,"_from": "map-obj@4.3.0"
|
||||
}
|
105
node_modules/conventional-recommended-bump/node_modules/meow/node_modules/map-obj/readme.md
generated
vendored
105
node_modules/conventional-recommended-bump/node_modules/meow/node_modules/map-obj/readme.md
generated
vendored
|
@ -1,105 +0,0 @@
|
|||
# map-obj
|
||||
|
||||
> Map object keys and values into a new object
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install map-obj
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const mapObject = require('map-obj');
|
||||
|
||||
const newObject = mapObject({foo: 'bar'}, (key, value) => [value, key]);
|
||||
//=> {bar: 'foo'}
|
||||
|
||||
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value]);
|
||||
//=> {foo: true, bar: {bAz: true}}
|
||||
|
||||
const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value], {deep: true});
|
||||
//=> {foo: true, bar: {baz: true}}
|
||||
|
||||
const newObject = mapObject({one: 1, two: 2}, (key, value) => value === 1 ? [key, value] : mapObject.mapObjectSkip);
|
||||
//=> {one: 1}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### mapObject(source, mapper, options?)
|
||||
|
||||
#### source
|
||||
|
||||
Type: `object`
|
||||
|
||||
Source object to copy properties from.
|
||||
|
||||
#### mapper
|
||||
|
||||
Type: `(sourceKey, sourceValue, source) => [targetKey, targetValue, mapperOptions?] | mapObject.mapObjectSkip`
|
||||
|
||||
Mapping function.
|
||||
|
||||
##### mapperOptions
|
||||
|
||||
Type: `object`
|
||||
|
||||
###### shouldRecurse
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Whether `targetValue` should be recursed.
|
||||
|
||||
Requires `deep: true`.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### deep
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Recurse nested objects and objects in arrays.
|
||||
|
||||
##### target
|
||||
|
||||
Type: `object`\
|
||||
Default: `{}`
|
||||
|
||||
Target object to map properties on to.
|
||||
|
||||
### mapObject.mapObjectSkip
|
||||
|
||||
Return this value from a `mapper` function to exclude the key from the new object.
|
||||
|
||||
```js
|
||||
const mapObject = require('map-obj');
|
||||
|
||||
const object = {one: 1, two: 2}
|
||||
const mapper = (key, value) => value === 1 ? [key, value] : mapObject.mapObjectSkip
|
||||
const result = mapObject(object, mapper);
|
||||
|
||||
console.log(result);
|
||||
//=> {one: 1}
|
||||
```
|
||||
|
||||
## Related
|
||||
|
||||
- [filter-obj](https://github.com/sindresorhus/filter-obj) - Filter object keys and values into a new object
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-map-obj?utm_source=npm-map-obj&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>
|
|
@ -1,55 +0,0 @@
|
|||
import {Opts as MinimistOptions} from 'minimist';
|
||||
|
||||
export type OptionType = 'string' | 'boolean' | 'number' | 'array' | 'string-array' | 'boolean-array' | 'number-array';
|
||||
|
||||
export interface BaseOption<
|
||||
TypeOptionType extends OptionType,
|
||||
DefaultOptionType
|
||||
> {
|
||||
/**
|
||||
* The data type the option should be parsed to.
|
||||
*/
|
||||
readonly type?: TypeOptionType;
|
||||
|
||||
/**
|
||||
* An alias/list of aliases for the option.
|
||||
*/
|
||||
readonly alias?: string | ReadonlyArray<string>;
|
||||
|
||||
/**
|
||||
* The default value for the option.
|
||||
*/
|
||||
readonly default?: DefaultOptionType;
|
||||
}
|
||||
|
||||
export type StringOption = BaseOption<'string', string>;
|
||||
export type BooleanOption = BaseOption<'boolean', boolean>;
|
||||
export type NumberOption = BaseOption<'number', number>;
|
||||
export type DefaultArrayOption = BaseOption<'array', ReadonlyArray<string>>;
|
||||
export type StringArrayOption = BaseOption<'string-array', ReadonlyArray<string>>;
|
||||
export type BooleanArrayOption = BaseOption<'boolean-array', ReadonlyArray<boolean>>;
|
||||
export type NumberArrayOption = BaseOption<'number-array', ReadonlyArray<number>>;
|
||||
|
||||
type MinimistOption = NonNullable<
|
||||
| MinimistOptions['stopEarly']
|
||||
| MinimistOptions['unknown']
|
||||
| MinimistOptions['--']
|
||||
>;
|
||||
|
||||
export type Options = {
|
||||
[key: string]:
|
||||
| OptionType
|
||||
| StringOption
|
||||
| BooleanOption
|
||||
| NumberOption
|
||||
| DefaultArrayOption
|
||||
| StringArrayOption
|
||||
| BooleanArrayOption
|
||||
| NumberArrayOption
|
||||
| MinimistOption; // Workaround for https://github.com/microsoft/TypeScript/issues/17867
|
||||
};
|
||||
|
||||
/**
|
||||
* Write options for [minimist](https://npmjs.org/package/minimist) in a comfortable way. Support string, boolean, number and array options.
|
||||
*/
|
||||
export default function buildOptions(options?: Options): MinimistOptions;
|
|
@ -1,117 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const isPlainObject = require('is-plain-obj');
|
||||
const arrify = require('arrify');
|
||||
const kindOf = require('kind-of');
|
||||
|
||||
const push = (obj, prop, value) => {
|
||||
if (!obj[prop]) {
|
||||
obj[prop] = [];
|
||||
}
|
||||
|
||||
obj[prop].push(value);
|
||||
};
|
||||
|
||||
const insert = (obj, prop, key, value) => {
|
||||
if (!obj[prop]) {
|
||||
obj[prop] = {};
|
||||
}
|
||||
|
||||
obj[prop][key] = value;
|
||||
};
|
||||
|
||||
const prettyPrint = output => {
|
||||
return Array.isArray(output) ?
|
||||
`[${output.map(prettyPrint).join(', ')}]` :
|
||||
kindOf(output) === 'string' ? JSON.stringify(output) : output;
|
||||
};
|
||||
|
||||
const resolveType = value => {
|
||||
if (Array.isArray(value) && value.length > 0) {
|
||||
const [element] = value;
|
||||
return `${kindOf(element)}-array`;
|
||||
}
|
||||
|
||||
return kindOf(value);
|
||||
};
|
||||
|
||||
const normalizeExpectedType = (type, defaultValue) => {
|
||||
const inferredType = type === 'array' ? 'string-array' : type;
|
||||
|
||||
if (arrayTypes.includes(inferredType) && Array.isArray(defaultValue) && defaultValue.length === 0) {
|
||||
return 'array';
|
||||
}
|
||||
|
||||
return inferredType;
|
||||
};
|
||||
|
||||
const passthroughOptions = ['stopEarly', 'unknown', '--'];
|
||||
const primitiveTypes = ['string', 'boolean', 'number'];
|
||||
const arrayTypes = primitiveTypes.map(t => `${t}-array`);
|
||||
const availableTypes = [...primitiveTypes, 'array', ...arrayTypes];
|
||||
|
||||
const buildOptions = options => {
|
||||
options = options || {};
|
||||
|
||||
const result = {};
|
||||
|
||||
passthroughOptions.forEach(key => {
|
||||
if (options[key]) {
|
||||
result[key] = options[key];
|
||||
}
|
||||
});
|
||||
|
||||
Object.keys(options).forEach(key => {
|
||||
let value = options[key];
|
||||
|
||||
if (key === 'arguments') {
|
||||
key = '_';
|
||||
}
|
||||
|
||||
// If short form is used
|
||||
// convert it to long form
|
||||
// e.g. { 'name': 'string' }
|
||||
if (typeof value === 'string') {
|
||||
value = {type: value};
|
||||
}
|
||||
|
||||
if (isPlainObject(value)) {
|
||||
const props = value;
|
||||
const {type} = props;
|
||||
|
||||
if (type) {
|
||||
if (!availableTypes.includes(type)) {
|
||||
throw new TypeError(`Expected type of "${key}" to be one of ${prettyPrint(availableTypes)}, got ${prettyPrint(type)}`);
|
||||
}
|
||||
|
||||
if (arrayTypes.includes(type)) {
|
||||
const [elementType] = type.split('-');
|
||||
push(result, 'array', {key, [elementType]: true});
|
||||
} else {
|
||||
push(result, type, key);
|
||||
}
|
||||
}
|
||||
|
||||
if ({}.hasOwnProperty.call(props, 'default')) {
|
||||
const {default: defaultValue} = props;
|
||||
const defaultType = resolveType(defaultValue);
|
||||
const expectedType = normalizeExpectedType(type, defaultValue);
|
||||
|
||||
if (expectedType && expectedType !== defaultType) {
|
||||
throw new TypeError(`Expected "${key}" default value to be of type "${expectedType}", got ${prettyPrint(defaultType)}`);
|
||||
}
|
||||
|
||||
insert(result, 'default', key, defaultValue);
|
||||
}
|
||||
|
||||
arrify(props.alias).forEach(alias => {
|
||||
insert(result, 'alias', alias, key);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = buildOptions;
|
||||
module.exports.default = buildOptions;
|
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Vadim Demedes <vdemedes@gmail.com> (vadimdemedes.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.
|
|
@ -1,38 +0,0 @@
|
|||
{
|
||||
"name": "minimist-options",
|
||||
"version": "4.1.0",
|
||||
"description": "Pretty options for minimist",
|
||||
"repository": "vadimdemedes/minimist-options",
|
||||
"author": "Vadim Demedes <vdemedes@gmail.com>",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"minimist",
|
||||
"argv",
|
||||
"args"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd-check"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"dependencies": {
|
||||
"arrify": "^1.0.1",
|
||||
"is-plain-obj": "^1.1.0",
|
||||
"kind-of": "^6.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/minimist": "^1.2.0",
|
||||
"ava": "^1.0.1",
|
||||
"tsd-check": "^0.3.0",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/minimist-options/-/minimist-options-4.1.0.tgz"
|
||||
,"_integrity": "sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A=="
|
||||
,"_from": "minimist-options@4.1.0"
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
# minimist-options 
|
||||
|
||||
> Write options for [minimist](https://npmjs.org/package/minimist) and [yargs](https://npmjs.org/package/yargs) in a comfortable way.
|
||||
> Supports string, boolean, number and array options.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
$ npm install --save minimist-options
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const buildOptions = require('minimist-options');
|
||||
const minimist = require('minimist');
|
||||
|
||||
const options = buildOptions({
|
||||
name: {
|
||||
type: 'string',
|
||||
alias: 'n',
|
||||
default: 'john'
|
||||
},
|
||||
|
||||
force: {
|
||||
type: 'boolean',
|
||||
alias: ['f', 'o'],
|
||||
default: false
|
||||
},
|
||||
|
||||
score: {
|
||||
type: 'number',
|
||||
alias: 's',
|
||||
default: 0
|
||||
},
|
||||
|
||||
arr: {
|
||||
type: 'array',
|
||||
alias: 'a',
|
||||
default: []
|
||||
},
|
||||
|
||||
strings: {
|
||||
type: 'string-array',
|
||||
alias: 's',
|
||||
default: ['a', 'b']
|
||||
},
|
||||
|
||||
booleans: {
|
||||
type: 'boolean-array',
|
||||
alias: 'b',
|
||||
default: [true, false]
|
||||
},
|
||||
|
||||
numbers: {
|
||||
type: 'number-array',
|
||||
alias: 'n',
|
||||
default: [0, 1]
|
||||
},
|
||||
|
||||
published: 'boolean',
|
||||
|
||||
// Special option for positional arguments (`_` in minimist)
|
||||
arguments: 'string'
|
||||
});
|
||||
|
||||
const args = minimist(process.argv.slice(2), options);
|
||||
```
|
||||
|
||||
instead of:
|
||||
|
||||
```js
|
||||
const minimist = require('minimist');
|
||||
|
||||
const options = {
|
||||
string: ['name', '_'],
|
||||
number: ['score'],
|
||||
array: [
|
||||
'arr',
|
||||
{key: 'strings', string: true},
|
||||
{key: 'booleans', boolean: true},
|
||||
{key: 'numbers', number: true}
|
||||
],
|
||||
boolean: ['force', 'published'],
|
||||
alias: {
|
||||
n: 'name',
|
||||
f: 'force',
|
||||
s: 'score',
|
||||
a: 'arr'
|
||||
},
|
||||
default: {
|
||||
name: 'john',
|
||||
f: false,
|
||||
score: 0,
|
||||
arr: []
|
||||
}
|
||||
};
|
||||
|
||||
const args = minimist(process.argv.slice(2), options);
|
||||
```
|
||||
|
||||
## Array options
|
||||
|
||||
The `array` types are only supported by [yargs](https://npmjs.org/package/yargs).
|
||||
|
||||
[minimist](https://npmjs.org/package/minimist) does _not_ explicitly support array type options. If you set an option multiple times, it will indeed yield an array of values. However, if you only set it once, it will simply give the value as is, without wrapping it in an array. Thus, effectively ignoring `{type: 'array'}`.
|
||||
|
||||
`{type: 'array'}` is shorthand for `{type: 'string-array'}`. To have values coerced to `boolean` or `number`, use `boolean-array` or `number-array`, respectively.
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Vadim Demedes](https://vadimdemedes.com)
|
|
@ -1,90 +0,0 @@
|
|||
declare namespace QuickLRU {
|
||||
interface Options {
|
||||
/**
|
||||
The maximum number of items before evicting the least recently used items.
|
||||
*/
|
||||
readonly maxSize: number;
|
||||
}
|
||||
}
|
||||
|
||||
declare class QuickLRU<KeyType extends unknown, ValueType extends unknown>
|
||||
implements Iterable<[KeyType, ValueType]> {
|
||||
/**
|
||||
The stored item count.
|
||||
*/
|
||||
readonly size: number;
|
||||
|
||||
/**
|
||||
Simple ["Least Recently Used" (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29).
|
||||
|
||||
The instance is [`iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
|
||||
|
||||
@example
|
||||
```
|
||||
import QuickLRU = require('quick-lru');
|
||||
|
||||
const lru = new QuickLRU({maxSize: 1000});
|
||||
|
||||
lru.set('🦄', '🌈');
|
||||
|
||||
lru.has('🦄');
|
||||
//=> true
|
||||
|
||||
lru.get('🦄');
|
||||
//=> '🌈'
|
||||
```
|
||||
*/
|
||||
constructor(options: QuickLRU.Options);
|
||||
|
||||
[Symbol.iterator](): IterableIterator<[KeyType, ValueType]>;
|
||||
|
||||
/**
|
||||
Set an item.
|
||||
|
||||
@returns The list instance.
|
||||
*/
|
||||
set(key: KeyType, value: ValueType): this;
|
||||
|
||||
/**
|
||||
Get an item.
|
||||
|
||||
@returns The stored item or `undefined`.
|
||||
*/
|
||||
get(key: KeyType): ValueType | undefined;
|
||||
|
||||
/**
|
||||
Check if an item exists.
|
||||
*/
|
||||
has(key: KeyType): boolean;
|
||||
|
||||
/**
|
||||
Get an item without marking it as recently used.
|
||||
|
||||
@returns The stored item or `undefined`.
|
||||
*/
|
||||
peek(key: KeyType): ValueType | undefined;
|
||||
|
||||
/**
|
||||
Delete an item.
|
||||
|
||||
@returns `true` if the item is removed or `false` if the item doesn't exist.
|
||||
*/
|
||||
delete(key: KeyType): boolean;
|
||||
|
||||
/**
|
||||
Delete all items.
|
||||
*/
|
||||
clear(): void;
|
||||
|
||||
/**
|
||||
Iterable for all the keys.
|
||||
*/
|
||||
keys(): IterableIterator<KeyType>;
|
||||
|
||||
/**
|
||||
Iterable for all the values.
|
||||
*/
|
||||
values(): IterableIterator<ValueType>;
|
||||
}
|
||||
|
||||
export = QuickLRU;
|
115
node_modules/conventional-recommended-bump/node_modules/meow/node_modules/quick-lru/index.js
generated
vendored
115
node_modules/conventional-recommended-bump/node_modules/meow/node_modules/quick-lru/index.js
generated
vendored
|
@ -1,115 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
class QuickLRU {
|
||||
constructor(options = {}) {
|
||||
if (!(options.maxSize && options.maxSize > 0)) {
|
||||
throw new TypeError('`maxSize` must be a number greater than 0');
|
||||
}
|
||||
|
||||
this.maxSize = options.maxSize;
|
||||
this.cache = new Map();
|
||||
this.oldCache = new Map();
|
||||
this._size = 0;
|
||||
}
|
||||
|
||||
_set(key, value) {
|
||||
this.cache.set(key, value);
|
||||
this._size++;
|
||||
|
||||
if (this._size >= this.maxSize) {
|
||||
this._size = 0;
|
||||
this.oldCache = this.cache;
|
||||
this.cache = new Map();
|
||||
}
|
||||
}
|
||||
|
||||
get(key) {
|
||||
if (this.cache.has(key)) {
|
||||
return this.cache.get(key);
|
||||
}
|
||||
|
||||
if (this.oldCache.has(key)) {
|
||||
const value = this.oldCache.get(key);
|
||||
this.oldCache.delete(key);
|
||||
this._set(key, value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
if (this.cache.has(key)) {
|
||||
this.cache.set(key, value);
|
||||
} else {
|
||||
this._set(key, value);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
has(key) {
|
||||
return this.cache.has(key) || this.oldCache.has(key);
|
||||
}
|
||||
|
||||
peek(key) {
|
||||
if (this.cache.has(key)) {
|
||||
return this.cache.get(key);
|
||||
}
|
||||
|
||||
if (this.oldCache.has(key)) {
|
||||
return this.oldCache.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
delete(key) {
|
||||
const deleted = this.cache.delete(key);
|
||||
if (deleted) {
|
||||
this._size--;
|
||||
}
|
||||
|
||||
return this.oldCache.delete(key) || deleted;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.cache.clear();
|
||||
this.oldCache.clear();
|
||||
this._size = 0;
|
||||
}
|
||||
|
||||
* keys() {
|
||||
for (const [key] of this) {
|
||||
yield key;
|
||||
}
|
||||
}
|
||||
|
||||
* values() {
|
||||
for (const [, value] of this) {
|
||||
yield value;
|
||||
}
|
||||
}
|
||||
|
||||
* [Symbol.iterator]() {
|
||||
for (const item of this.cache) {
|
||||
yield item;
|
||||
}
|
||||
|
||||
for (const item of this.oldCache) {
|
||||
const [key] = item;
|
||||
if (!this.cache.has(key)) {
|
||||
yield item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get size() {
|
||||
let oldCacheSize = 0;
|
||||
for (const key of this.oldCache.keys()) {
|
||||
if (!this.cache.has(key)) {
|
||||
oldCacheSize++;
|
||||
}
|
||||
}
|
||||
|
||||
return this._size + oldCacheSize;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = QuickLRU;
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,46 +0,0 @@
|
|||
{
|
||||
"name": "quick-lru",
|
||||
"version": "4.0.1",
|
||||
"description": "Simple \"Least Recently Used\" (LRU) cache",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/quick-lru",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && nyc ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"lru",
|
||||
"quick",
|
||||
"cache",
|
||||
"caching",
|
||||
"least",
|
||||
"recently",
|
||||
"used",
|
||||
"fast",
|
||||
"map",
|
||||
"hash",
|
||||
"buffer"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"coveralls": "^3.0.3",
|
||||
"nyc": "^14.1.1",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz"
|
||||
,"_integrity": "sha512-ARhCpm70fzdcvNQfPoy49IaanKkTlRWF2JMzqhcJbhSFRZv7nPTvZJdcY7301IPmvW+/p0RgIWnQDLJxifsQ7g=="
|
||||
,"_from": "quick-lru@4.0.1"
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
# quick-lru [](https://travis-ci.org/sindresorhus/quick-lru) [](https://coveralls.io/github/sindresorhus/quick-lru?branch=master)
|
||||
|
||||
> Simple ["Least Recently Used" (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29)
|
||||
|
||||
Useful when you need to cache something and limit memory usage.
|
||||
|
||||
Inspired by the [`hashlru` algorithm](https://github.com/dominictarr/hashlru#algorithm), but instead uses [`Map`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) to support keys of any type, not just strings, and values can be `undefined`.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install quick-lru
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const QuickLRU = require('quick-lru');
|
||||
|
||||
const lru = new QuickLRU({maxSize: 1000});
|
||||
|
||||
lru.set('🦄', '🌈');
|
||||
|
||||
lru.has('🦄');
|
||||
//=> true
|
||||
|
||||
lru.get('🦄');
|
||||
//=> '🌈'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### new QuickLRU(options?)
|
||||
|
||||
Returns a new instance.
|
||||
|
||||
### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
#### maxSize
|
||||
|
||||
*Required*<br>
|
||||
Type: `number`
|
||||
|
||||
The maximum number of items before evicting the least recently used items.
|
||||
|
||||
### Instance
|
||||
|
||||
The instance is [`iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
|
||||
|
||||
Both `key` and `value` can be of any type.
|
||||
|
||||
#### .set(key, value)
|
||||
|
||||
Set an item. Returns the instance.
|
||||
|
||||
#### .get(key)
|
||||
|
||||
Get an item.
|
||||
|
||||
#### .has(key)
|
||||
|
||||
Check if an item exists.
|
||||
|
||||
#### .peek(key)
|
||||
|
||||
Get an item without marking it as recently used.
|
||||
|
||||
#### .delete(key)
|
||||
|
||||
Delete an item.
|
||||
|
||||
Returns `true` if the item is removed or `false` if the item doesn't exist.
|
||||
|
||||
#### .clear()
|
||||
|
||||
Delete all items.
|
||||
|
||||
#### .keys()
|
||||
|
||||
Iterable for all the keys.
|
||||
|
||||
#### .values()
|
||||
|
||||
Iterable for all the values.
|
||||
|
||||
#### .size
|
||||
|
||||
The stored item count.
|
|
@ -1,87 +0,0 @@
|
|||
import {Except} from 'type-fest';
|
||||
import readPkg = require('read-pkg');
|
||||
|
||||
declare namespace readPkgUp {
|
||||
type Options = {
|
||||
/**
|
||||
Directory to start looking for a package.json file.
|
||||
|
||||
@default process.cwd()
|
||||
*/
|
||||
cwd?: string;
|
||||
} & Except<readPkg.Options, 'cwd'>;
|
||||
|
||||
type NormalizeOptions = {
|
||||
/**
|
||||
Directory to start looking for a package.json file.
|
||||
|
||||
@default process.cwd()
|
||||
*/
|
||||
cwd?: string;
|
||||
} & Except<readPkg.NormalizeOptions, 'cwd'>;
|
||||
|
||||
type PackageJson = readPkg.PackageJson;
|
||||
type NormalizedPackageJson = readPkg.NormalizedPackageJson;
|
||||
|
||||
interface ReadResult {
|
||||
packageJson: PackageJson;
|
||||
path: string;
|
||||
}
|
||||
|
||||
interface NormalizedReadResult {
|
||||
packageJson: NormalizedPackageJson;
|
||||
path: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare const readPkgUp: {
|
||||
/**
|
||||
Read the closest `package.json` file.
|
||||
|
||||
@example
|
||||
```
|
||||
import readPkgUp = require('read-pkg-up');
|
||||
|
||||
(async () => {
|
||||
console.log(await readPkgUp());
|
||||
// {
|
||||
// packageJson: {
|
||||
// name: 'awesome-package',
|
||||
// version: '1.0.0',
|
||||
// …
|
||||
// },
|
||||
// path: '/Users/sindresorhus/dev/awesome-package/package.json'
|
||||
// }
|
||||
})();
|
||||
```
|
||||
*/
|
||||
(options?: readPkgUp.NormalizeOptions): Promise<
|
||||
readPkgUp.NormalizedReadResult | undefined
|
||||
>;
|
||||
(options: readPkgUp.Options): Promise<readPkgUp.ReadResult | undefined>;
|
||||
|
||||
/**
|
||||
Synchronously read the closest `package.json` file.
|
||||
|
||||
@example
|
||||
```
|
||||
import readPkgUp = require('read-pkg-up');
|
||||
|
||||
console.log(readPkgUp.sync());
|
||||
// {
|
||||
// packageJson: {
|
||||
// name: 'awesome-package',
|
||||
// version: '1.0.0',
|
||||
// …
|
||||
// },
|
||||
// path: '/Users/sindresorhus/dev/awesome-package/package.json'
|
||||
// }
|
||||
```
|
||||
*/
|
||||
sync(
|
||||
options?: readPkgUp.NormalizeOptions
|
||||
): readPkgUp.NormalizedReadResult | undefined;
|
||||
sync(options: readPkgUp.Options): readPkgUp.ReadResult | undefined;
|
||||
};
|
||||
|
||||
export = readPkgUp;
|
|
@ -1,30 +0,0 @@
|
|||
'use strict';
|
||||
const path = require('path');
|
||||
const findUp = require('find-up');
|
||||
const readPkg = require('read-pkg');
|
||||
|
||||
module.exports = async options => {
|
||||
const filePath = await findUp('package.json', options);
|
||||
|
||||
if (!filePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
packageJson: await readPkg({...options, cwd: path.dirname(filePath)}),
|
||||
path: filePath
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.sync = options => {
|
||||
const filePath = findUp.sync('package.json', options);
|
||||
|
||||
if (!filePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
packageJson: readPkg.sync({...options, cwd: path.dirname(filePath)}),
|
||||
path: filePath
|
||||
};
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,20 +0,0 @@
|
|||
// Basic
|
||||
export * from './source/basic';
|
||||
|
||||
// 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';
|
||||
|
||||
// Miscellaneous
|
||||
export {PackageJson} from './source/package-json';
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,55 +0,0 @@
|
|||
{
|
||||
"name": "type-fest",
|
||||
"version": "0.8.1",
|
||||
"description": "A collection of essential TypeScript types",
|
||||
"license": "(MIT OR CC0-1.0)",
|
||||
"repository": "sindresorhus/type-fest",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"source"
|
||||
],
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"ts",
|
||||
"types",
|
||||
"utility",
|
||||
"util",
|
||||
"utilities",
|
||||
"omit",
|
||||
"merge",
|
||||
"json"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@sindresorhus/tsconfig": "^0.4.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.2.0",
|
||||
"@typescript-eslint/parser": "^2.2.0",
|
||||
"eslint-config-xo-typescript": "^0.18.0",
|
||||
"tsd": "^0.7.3",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"xo": {
|
||||
"extends": "xo-typescript",
|
||||
"extensions": [
|
||||
"ts"
|
||||
],
|
||||
"rules": {
|
||||
"import/no-unresolved": "off",
|
||||
"@typescript-eslint/indent": "off"
|
||||
}
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz"
|
||||
,"_integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA=="
|
||||
,"_from": "type-fest@0.8.1"
|
||||
}
|
|
@ -1,635 +0,0 @@
|
|||
<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>
|
||||
<hr>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
[](https://travis-ci.com/sindresorhus/type-fest)
|
||||
[](https://www.youtube.com/watch?v=9auOCbH5Ns4)
|
||||
<!-- Commented out until they actually show anything
|
||||
[](https://www.npmjs.com/package/type-fest?activeTab=dependents) [](https://www.npmjs.com/package/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.2*
|
||||
|
||||
|
||||
## 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/basic.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/basic.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/basic.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) - Convert an object with `readonly` keys into a mutable object. 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-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.
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file).
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
|
||||
## Tips
|
||||
|
||||
### 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://typescript-play.js.org/?target=6#code/KYOwrgtgBAMg9gcxsAbsANlA3gKClAeQDMiAaPKAEWACMwFz8BRAJxbhcagDEBDAF17ocAXxw4AliH7AWRXgGNgUAHJwAJsADCcEEQkJsFXgAcTK3hGAAuKAGd+LKQgDcFEx363wEGrLf46IjIaOi28EioGG5iOArovHZ2qhrAAIJmAEJgEuiaLEb4Jk4oAsoKuvoIYCwCErq2apo6egZQALyF+FCm5pY2UABETelmg1xFnrYAzAAM8xNQQZGh4cFR6AB0xEQUIm4UFa0IABRHVbYACrws-BJCADwjLVUAfACUXfhEHFBnug4oABrYAATygcCIhBoACtgAp+JsQaC7P9ju9Prhut0joCwCZ1GUAGpCMDKTrnAwAbWRPWSyMhKWalQMAF0Dtj8BIoSd8YSZCT0GSOu1OmAQJp9CBgOpPkc7uBgBzOfwABYSOybSnVWp3XQ0sF04FgxnPFkIVkdKB84mkpUUfCxbEsYD8GogKBqjUBKBiWIAen9UGut3u6CeqReBlePXQQQA7skwMl+HAoMU4CgJJoISB0ODeOmbvwIVC1cAcIGmdpzVApDI5IpgJscNL49WMiZsrl8id3lrzScsD0zBYrLZBgAVOCUOCdwa+95uIA)
|
||||
|
||||
```ts
|
||||
interface NodeConfig {
|
||||
appName: string;
|
||||
port: number;
|
||||
}
|
||||
|
||||
class NodeAppBuilder {
|
||||
private configuration: NodeConfig = {
|
||||
appName: 'NodeApp',
|
||||
port: 3000
|
||||
};
|
||||
|
||||
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.configuration[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>
|
||||
|
||||
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)
|
||||
|
||||
|
||||
## 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>
|
|
@ -1,67 +0,0 @@
|
|||
/// <reference lib="esnext"/>
|
||||
|
||||
// TODO: This can just be `export type Primitive = not object` when the `not` keyword is out.
|
||||
/**
|
||||
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
||||
*/
|
||||
export type Primitive =
|
||||
| null
|
||||
| undefined
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| symbol
|
||||
| bigint;
|
||||
|
||||
// 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).
|
||||
*/
|
||||
export type Class<T = unknown, Arguments extends any[] = any[]> = new(...arguments_: Arguments) => T;
|
||||
|
||||
/**
|
||||
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
||||
*/
|
||||
export type TypedArray =
|
||||
| Int8Array
|
||||
| Uint8Array
|
||||
| Uint8ClampedArray
|
||||
| Int16Array
|
||||
| Uint16Array
|
||||
| Int32Array
|
||||
| Uint32Array
|
||||
| Float32Array
|
||||
| Float64Array
|
||||
| BigInt64Array
|
||||
| BigUint64Array;
|
||||
|
||||
/**
|
||||
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 { … }`.
|
||||
*/
|
||||
export type JsonObject = {[key: string]: JsonValue};
|
||||
|
||||
/**
|
||||
Matches a JSON array.
|
||||
*/
|
||||
export interface JsonArray extends Array<JsonValue> {}
|
||||
|
||||
/**
|
||||
Matches any valid JSON value.
|
||||
*/
|
||||
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
||||
|
||||
declare global {
|
||||
interface SymbolConstructor {
|
||||
readonly observable: symbol;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
|
||||
*/
|
||||
export interface ObservableLike {
|
||||
subscribe(observer: (value: unknown) => void): void;
|
||||
[Symbol.observable](): ObservableLike;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/**
|
||||
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.
|
||||
|
||||
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/30825) if you want to have the stricter version as a built-in in TypeScript.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Except} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
a: number;
|
||||
b: string;
|
||||
c: boolean;
|
||||
};
|
||||
|
||||
type FooWithoutA = Except<Foo, 'a' | 'c'>;
|
||||
//=> {b: string};
|
||||
```
|
||||
*/
|
||||
export type Except<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
|
|
@ -1,33 +0,0 @@
|
|||
import {Primitive} from './basic';
|
||||
|
||||
/**
|
||||
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.
|
||||
```
|
||||
*/
|
||||
export type LiteralUnion<
|
||||
LiteralType extends BaseType,
|
||||
BaseType extends Primitive
|
||||
> = LiteralType | (BaseType & {_?: never});
|
|
@ -1,39 +0,0 @@
|
|||
// 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
|
||||
```
|
||||
*/
|
||||
export type MergeExclusive<FirstType, SecondType> =
|
||||
(FirstType | SecondType) extends object ?
|
||||
(Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType) :
|
||||
FirstType | SecondType;
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
import {Except} from './except';
|
||||
|
||||
/**
|
||||
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};
|
||||
```
|
||||
*/
|
||||
export type Merge<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType;
|
|
@ -1,22 +0,0 @@
|
|||
/**
|
||||
Convert an object with `readonly` keys into a mutable object. 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), and [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509).
|
||||
|
||||
@example
|
||||
```
|
||||
import {Mutable} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
readonly a: number;
|
||||
readonly b: string;
|
||||
};
|
||||
|
||||
const mutableFoo: Mutable<Foo> = {a: 1, b: '2'};
|
||||
mutableFoo.a = 3;
|
||||
```
|
||||
*/
|
||||
export type Mutable<ObjectType> = {
|
||||
// For each `Key` in the keys of `ObjectType`, make a mapped type by removing the `readonly` modifier from the key.
|
||||
-readonly [KeyType in keyof ObjectType]: ObjectType[KeyType];
|
||||
};
|
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
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>;
|
||||
type AccountBalance = Opaque<number>;
|
||||
|
||||
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 compile successfully.
|
||||
accountNumber + 2;
|
||||
```
|
||||
*/
|
||||
export type Opaque<Type> = Type & {readonly __opaque__: unique symbol};
|
|
@ -1,501 +0,0 @@
|
|||
import {LiteralUnion} from '..';
|
||||
|
||||
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 {
|
||||
/**
|
||||
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;
|
||||
|
||||
[directoryType: string]: unknown;
|
||||
}
|
||||
|
||||
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;
|
||||
} & {
|
||||
[scriptName: 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 interface Dependency {
|
||||
[packageName: string]: string;
|
||||
}
|
||||
|
||||
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
|
||||
| {
|
||||
main?: string;
|
||||
browser?: string;
|
||||
[moduleName: string]: string | undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
A hint to JavaScript bundlers or component tools when packaging modules for client side use.
|
||||
*/
|
||||
browser?:
|
||||
| string
|
||||
| {
|
||||
[moduleName: string]: string | false;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TypeScriptConfiguration {
|
||||
/**
|
||||
Location of the bundled TypeScript declaration file.
|
||||
*/
|
||||
types?: string;
|
||||
|
||||
/**
|
||||
Location of the bundled TypeScript declaration file. Alias of `types`.
|
||||
*/
|
||||
typings?: string;
|
||||
}
|
||||
|
||||
export interface YarnConfiguration {
|
||||
/**
|
||||
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 application), 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). Also includes types for fields used by other popular projects, like TypeScript and Yarn.
|
||||
*/
|
||||
export type PackageJson = {
|
||||
/**
|
||||
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?: PackageJson.BugsLocation;
|
||||
|
||||
/**
|
||||
The license for the package.
|
||||
*/
|
||||
license?: string;
|
||||
|
||||
/**
|
||||
The licenses for the package.
|
||||
*/
|
||||
licenses?: Array<{
|
||||
type?: string;
|
||||
url?: string;
|
||||
}>;
|
||||
|
||||
author?: PackageJson.Person;
|
||||
|
||||
/**
|
||||
A list of people who contributed to the package.
|
||||
*/
|
||||
contributors?: PackageJson.Person[];
|
||||
|
||||
/**
|
||||
A list of people who maintain the package.
|
||||
*/
|
||||
maintainers?: PackageJson.Person[];
|
||||
|
||||
/**
|
||||
The files included in the package.
|
||||
*/
|
||||
files?: string[];
|
||||
|
||||
/**
|
||||
The module ID that is the primary entry point to the program.
|
||||
*/
|
||||
main?: string;
|
||||
|
||||
/**
|
||||
The executable files that should be installed into the `PATH`.
|
||||
*/
|
||||
bin?:
|
||||
| string
|
||||
| {
|
||||
[binary: string]: string;
|
||||
};
|
||||
|
||||
/**
|
||||
Filenames to put in place for the `man` program to find.
|
||||
*/
|
||||
man?: string | string[];
|
||||
|
||||
/**
|
||||
Indicates the structure of the package.
|
||||
*/
|
||||
directories?: PackageJson.DirectoryLocations;
|
||||
|
||||
/**
|
||||
Location for the code repository.
|
||||
*/
|
||||
repository?:
|
||||
| string
|
||||
| {
|
||||
type: string;
|
||||
url: 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?: PackageJson.Scripts;
|
||||
|
||||
/**
|
||||
Is used to set configuration parameters used in package scripts that persist across upgrades.
|
||||
*/
|
||||
config?: {
|
||||
[configKey: string]: unknown;
|
||||
};
|
||||
|
||||
/**
|
||||
The dependencies of the package.
|
||||
*/
|
||||
dependencies?: PackageJson.Dependency;
|
||||
|
||||
/**
|
||||
Additional tooling dependencies that are not required for the package to work. Usually test, build, or documentation tooling.
|
||||
*/
|
||||
devDependencies?: PackageJson.Dependency;
|
||||
|
||||
/**
|
||||
Dependencies that are skipped if they fail to install.
|
||||
*/
|
||||
optionalDependencies?: PackageJson.Dependency;
|
||||
|
||||
/**
|
||||
Dependencies that will usually be required by the package user directly or via another dependency.
|
||||
*/
|
||||
peerDependencies?: PackageJson.Dependency;
|
||||
|
||||
/**
|
||||
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?: {
|
||||
[config: string]: unknown;
|
||||
};
|
||||
} &
|
||||
PackageJson.NonStandardEntryPoints &
|
||||
PackageJson.TypeScriptConfiguration &
|
||||
PackageJson.YarnConfiguration &
|
||||
PackageJson.JSPMConfiguration & {
|
||||
[key: string]: unknown;
|
||||
};
|
|
@ -1,72 +0,0 @@
|
|||
import {Primitive} from './basic';
|
||||
|
||||
/**
|
||||
Create a type from another type with all keys and nested keys set to optional.
|
||||
|
||||
Use-cases:
|
||||
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
||||
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
||||
|
||||
@example
|
||||
```
|
||||
import {PartialDeep} from 'type-fest';
|
||||
|
||||
const settings: Settings = {
|
||||
textEditor: {
|
||||
fontSize: 14;
|
||||
fontColor: '#000000';
|
||||
fontWeight: 400;
|
||||
}
|
||||
autocomplete: false;
|
||||
autosave: true;
|
||||
};
|
||||
|
||||
const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
|
||||
return {...settings, ...savedSettings};
|
||||
}
|
||||
|
||||
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
||||
```
|
||||
*/
|
||||
export type PartialDeep<T> = T extends Primitive
|
||||
? Partial<T>
|
||||
: T extends Map<infer KeyType, infer ValueType>
|
||||
? PartialMapDeep<KeyType, ValueType>
|
||||
: T extends Set<infer ItemType>
|
||||
? PartialSetDeep<ItemType>
|
||||
: T extends ReadonlyMap<infer KeyType, infer ValueType>
|
||||
? PartialReadonlyMapDeep<KeyType, ValueType>
|
||||
: T extends ReadonlySet<infer ItemType>
|
||||
? PartialReadonlySetDeep<ItemType>
|
||||
: T extends ((...arguments: any[]) => unknown)
|
||||
? T | undefined
|
||||
: T extends object
|
||||
? PartialObjectDeep<T>
|
||||
: unknown;
|
||||
|
||||
/**
|
||||
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
||||
*/
|
||||
interface PartialMapDeep<KeyType, ValueType> extends Map<PartialDeep<KeyType>, PartialDeep<ValueType>> {}
|
||||
|
||||
/**
|
||||
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
||||
*/
|
||||
interface PartialSetDeep<T> extends Set<PartialDeep<T>> {}
|
||||
|
||||
/**
|
||||
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
||||
*/
|
||||
interface PartialReadonlyMapDeep<KeyType, ValueType> extends ReadonlyMap<PartialDeep<KeyType>, PartialDeep<ValueType>> {}
|
||||
|
||||
/**
|
||||
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
||||
*/
|
||||
interface PartialReadonlySetDeep<T> extends ReadonlySet<PartialDeep<T>> {}
|
||||
|
||||
/**
|
||||
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
||||
*/
|
||||
type PartialObjectDeep<ObjectType extends object> = {
|
||||
[KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType]>
|
||||
};
|
|
@ -1,23 +0,0 @@
|
|||
/**
|
||||
Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
||||
|
||||
Use-cases:
|
||||
- A function accepts a callback that may either return a value synchronously or may return a promised value.
|
||||
- This type could be the return type of `Promise#then()`, `Promise#catch()`, and `Promise#finally()` callbacks.
|
||||
|
||||
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31394) if you want to have this type as a built-in in TypeScript.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Promisable} from 'type-fest';
|
||||
|
||||
async function logger(getLogEntry: () => Promisable<string>): Promise<void> {
|
||||
const entry = await getLogEntry();
|
||||
console.log(entry);
|
||||
}
|
||||
|
||||
logger(() => 'foo');
|
||||
logger(() => Promise.resolve('bar'));
|
||||
```
|
||||
*/
|
||||
export type Promisable<T> = T | PromiseLike<T>;
|
|
@ -1,59 +0,0 @@
|
|||
import {Primitive} from './basic';
|
||||
|
||||
/**
|
||||
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
|
||||
|
||||
This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.
|
||||
|
||||
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
|
||||
|
||||
@example
|
||||
```
|
||||
// data.json
|
||||
{
|
||||
"foo": ["bar"]
|
||||
}
|
||||
|
||||
// main.ts
|
||||
import {ReadonlyDeep} from 'type-fest';
|
||||
import dataJson = require('./data.json');
|
||||
|
||||
const data: ReadonlyDeep<typeof dataJson> = dataJson;
|
||||
|
||||
export default data;
|
||||
|
||||
// test.ts
|
||||
import data from './main';
|
||||
|
||||
data.foo.push('bar');
|
||||
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
||||
```
|
||||
*/
|
||||
export type ReadonlyDeep<T> = T extends Primitive | ((...arguments: any[]) => unknown)
|
||||
? T
|
||||
: T extends ReadonlyMap<infer KeyType, infer ValueType>
|
||||
? ReadonlyMapDeep<KeyType, ValueType>
|
||||
: T extends ReadonlySet<infer ItemType>
|
||||
? ReadonlySetDeep<ItemType>
|
||||
: T extends object
|
||||
? ReadonlyObjectDeep<T>
|
||||
: unknown;
|
||||
|
||||
/**
|
||||
Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
|
||||
*/
|
||||
interface ReadonlyMapDeep<KeyType, ValueType>
|
||||
extends ReadonlyMap<ReadonlyDeep<KeyType>, ReadonlyDeep<ValueType>> {}
|
||||
|
||||
/**
|
||||
Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
|
||||
*/
|
||||
interface ReadonlySetDeep<ItemType>
|
||||
extends ReadonlySet<ReadonlyDeep<ItemType>> {}
|
||||
|
||||
/**
|
||||
Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
|
||||
*/
|
||||
type ReadonlyObjectDeep<ObjectType extends object> = {
|
||||
readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
import {Except} from './except';
|
||||
|
||||
/**
|
||||
Create a type that requires at least one of the given keys. The remaining keys are kept as is.
|
||||
|
||||
@example
|
||||
```
|
||||
import {RequireAtLeastOne} from 'type-fest';
|
||||
|
||||
type Responder = {
|
||||
text?: () => string;
|
||||
json?: () => string;
|
||||
|
||||
secure?: boolean;
|
||||
};
|
||||
|
||||
const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
|
||||
json: () => '{"message": "ok"}',
|
||||
secure: true
|
||||
};
|
||||
```
|
||||
*/
|
||||
export type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
|
||||
{
|
||||
// For each Key in KeysType make a mapped type
|
||||
[Key in KeysType]: (
|
||||
// …by picking that Key's type and making it required
|
||||
Required<Pick<ObjectType, Key>>
|
||||
)
|
||||
}[KeysType]
|
||||
// …then, make intersection types by adding the remaining keys to each mapped type.
|
||||
& Except<ObjectType, KeysType>;
|
|
@ -1,36 +0,0 @@
|
|||
// TODO: Remove this when we target TypeScript >=3.5.
|
||||
// eslint-disable-next-line @typescript-eslint/generic-type-naming
|
||||
type _Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
|
||||
|
||||
/**
|
||||
Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
|
||||
|
||||
Use-cases:
|
||||
- Creating interfaces for components that only need one of the keys to display properly.
|
||||
- Declaring generic keys in a single place for a single use-case that gets narrowed down via `RequireExactlyOne`.
|
||||
|
||||
The caveat with `RequireExactlyOne` is that TypeScript doesn't always know at compile time every key that will exist at runtime. Therefore `RequireExactlyOne` can't do anything to prevent extra keys it doesn't know about.
|
||||
|
||||
@example
|
||||
```
|
||||
import {RequireExactlyOne} from 'type-fest';
|
||||
|
||||
type Responder = {
|
||||
text: () => string;
|
||||
json: () => string;
|
||||
secure: boolean;
|
||||
};
|
||||
|
||||
const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
|
||||
// Adding a `text` key here would cause a compile error.
|
||||
|
||||
json: () => '{"message": "ok"}',
|
||||
secure: true
|
||||
};
|
||||
```
|
||||
*/
|
||||
export type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
|
||||
{[Key in KeysType]: (
|
||||
Required<Pick<ObjectType, Key>> &
|
||||
Partial<Record<Exclude<KeysType, Key>, never>>
|
||||
)}[KeysType] & _Omit<ObjectType, KeysType>;
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
|
||||
|
||||
Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
|
||||
|
||||
@example
|
||||
```
|
||||
import {SetOptional} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
a: number;
|
||||
b?: string;
|
||||
c: boolean;
|
||||
}
|
||||
|
||||
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
||||
// type SomeOptional = {
|
||||
// a: number;
|
||||
// b?: string; // Was already optional and still is.
|
||||
// c?: boolean; // Is now optional.
|
||||
// }
|
||||
```
|
||||
*/
|
||||
export type SetOptional<BaseType, Keys extends keyof BaseType = keyof BaseType> =
|
||||
// Pick just the keys that are not optional from the base type.
|
||||
Pick<BaseType, Exclude<keyof BaseType, Keys>> &
|
||||
// Pick the keys that should be optional from the base type and make them optional.
|
||||
Partial<Pick<BaseType, Keys>> extends
|
||||
// If `InferredType` extends the previous, then for each key, use the inferred type key.
|
||||
infer InferredType
|
||||
? {[KeyType in keyof InferredType]: InferredType[KeyType]}
|
||||
: never;
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
|
||||
|
||||
Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are required.
|
||||
|
||||
@example
|
||||
```
|
||||
import {SetRequired} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
a?: number;
|
||||
b: string;
|
||||
c?: boolean;
|
||||
}
|
||||
|
||||
type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
|
||||
// type SomeRequired = {
|
||||
// a?: number;
|
||||
// b: string; // Was already required and still is.
|
||||
// c: boolean; // Is now required.
|
||||
// }
|
||||
```
|
||||
*/
|
||||
export type SetRequired<BaseType, Keys extends keyof BaseType = keyof BaseType> =
|
||||
// Pick just the keys that are not required from the base type.
|
||||
Pick<BaseType, Exclude<keyof BaseType, Keys>> &
|
||||
// Pick the keys that should be required from the base type and make them required.
|
||||
Required<Pick<BaseType, Keys>> extends
|
||||
// If `InferredType` extends the previous, then for each key, use the inferred type key.
|
||||
infer InferredType
|
||||
? {[KeyType in keyof InferredType]: InferredType[KeyType]}
|
||||
: never;
|
|
@ -1,63 +0,0 @@
|
|||
{
|
||||
"name": "read-pkg-up",
|
||||
"version": "7.0.1",
|
||||
"description": "Read the closest package.json file",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/read-pkg-up",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"json",
|
||||
"read",
|
||||
"parse",
|
||||
"file",
|
||||
"fs",
|
||||
"graceful",
|
||||
"load",
|
||||
"package",
|
||||
"find",
|
||||
"up",
|
||||
"find-up",
|
||||
"findup",
|
||||
"look-up",
|
||||
"look",
|
||||
"search",
|
||||
"match",
|
||||
"resolve",
|
||||
"parent",
|
||||
"parents",
|
||||
"folder",
|
||||
"directory",
|
||||
"walk",
|
||||
"walking",
|
||||
"path"
|
||||
],
|
||||
"dependencies": {
|
||||
"find-up": "^4.1.0",
|
||||
"read-pkg": "^5.2.0",
|
||||
"type-fest": "^0.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^2.4.0",
|
||||
"tsd": "^0.9.0",
|
||||
"xo": "^0.25.3"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz"
|
||||
,"_integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg=="
|
||||
,"_from": "read-pkg-up@7.0.1"
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
# read-pkg-up [](https://travis-ci.org/sindresorhus/read-pkg-up)
|
||||
|
||||
> Read the closest package.json file
|
||||
|
||||
## Why
|
||||
|
||||
- [Finds the closest package.json](https://github.com/sindresorhus/find-up)
|
||||
- [Gracefully handles filesystem issues](https://github.com/isaacs/node-graceful-fs)
|
||||
- [Throws more helpful JSON errors](https://github.com/sindresorhus/parse-json)
|
||||
- [Normalizes the data](https://github.com/npm/normalize-package-data#what-normalization-currently-entails)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install read-pkg-up
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const readPkgUp = require('read-pkg-up');
|
||||
|
||||
(async () => {
|
||||
console.log(await readPkgUp());
|
||||
/*
|
||||
{
|
||||
packageJson: {
|
||||
name: 'awesome-package',
|
||||
version: '1.0.0',
|
||||
…
|
||||
},
|
||||
path: '/Users/sindresorhus/dev/awesome-package/package.json'
|
||||
}
|
||||
*/
|
||||
})();
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### readPkgUp(options?)
|
||||
|
||||
Returns a `Promise<object>` or `Promise<undefined>` if no `package.json` was found.
|
||||
|
||||
### readPkgUp.sync(options?)
|
||||
|
||||
Returns the result object or `undefined` if no `package.json` was found.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### cwd
|
||||
|
||||
Type: `string`\
|
||||
Default: `process.cwd()`
|
||||
|
||||
Directory to start looking for a package.json file.
|
||||
|
||||
##### normalize
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
[Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
|
||||
|
||||
## read-pkg-up for enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription.
|
||||
|
||||
The maintainers of read-pkg-up and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-read-pkg-up?utm_source=npm-read-pkg-up&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
|
||||
## Related
|
||||
|
||||
- [read-pkg](https://github.com/sindresorhus/read-pkg) - Read a package.json file
|
||||
- [pkg-up](https://github.com/sindresorhus/pkg-up) - Find the closest package.json file
|
||||
- [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories
|
||||
- [pkg-conf](https://github.com/sindresorhus/pkg-conf) - Get namespaced config from the closest package.json
|
|
@ -1,27 +0,0 @@
|
|||
import {Options as IndentStringOptions} from 'indent-string';
|
||||
|
||||
declare namespace redent {
|
||||
type Options = IndentStringOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
[Strip redundant indentation](https://github.com/sindresorhus/strip-indent) and [indent the string](https://github.com/sindresorhus/indent-string).
|
||||
|
||||
@param string - The string to normalize indentation.
|
||||
@param count - How many times you want `options.indent` repeated. Default: `0`.
|
||||
|
||||
@example
|
||||
```
|
||||
import redent = require('redent');
|
||||
|
||||
redent('\n foo\n bar\n', 1);
|
||||
//=> '\n foo\n bar\n'
|
||||
```
|
||||
*/
|
||||
declare function redent(
|
||||
string: string,
|
||||
count?: number,
|
||||
options?: redent.Options
|
||||
): string;
|
||||
|
||||
export = redent;
|
|
@ -1,5 +0,0 @@
|
|||
'use strict';
|
||||
const stripIndent = require('strip-indent');
|
||||
const indentString = require('indent-string');
|
||||
|
||||
module.exports = (string, count = 0, options) => indentString(stripIndent(string), count, options);
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,48 +0,0 @@
|
|||
{
|
||||
"name": "redent",
|
||||
"version": "3.0.0",
|
||||
"description": "Strip redundant indentation and indent the string",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/redent",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"string",
|
||||
"strip",
|
||||
"trim",
|
||||
"indent",
|
||||
"indentation",
|
||||
"add",
|
||||
"reindent",
|
||||
"normalize",
|
||||
"remove",
|
||||
"whitespace",
|
||||
"space"
|
||||
],
|
||||
"dependencies": {
|
||||
"indent-string": "^4.0.0",
|
||||
"strip-indent": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz"
|
||||
,"_integrity": "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg=="
|
||||
,"_from": "redent@3.0.0"
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
# redent [](https://travis-ci.org/sindresorhus/redent)
|
||||
|
||||
> [Strip redundant indentation](https://github.com/sindresorhus/strip-indent) and [indent the string](https://github.com/sindresorhus/indent-string)
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install redent
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const redent = require('redent');
|
||||
|
||||
redent('\n foo\n bar\n', 1);
|
||||
//=> '\n foo\n bar\n'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### redent(string, [count], [options])
|
||||
|
||||
#### string
|
||||
|
||||
Type: `string`
|
||||
|
||||
The string to normalize indentation.
|
||||
|
||||
#### count
|
||||
|
||||
Type: `number`<br>
|
||||
Default: `0`
|
||||
|
||||
How many times you want `options.indent` repeated.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### indent
|
||||
|
||||
Type: `string`<br>
|
||||
Default: `' '`
|
||||
|
||||
The string to use for the indent.
|
||||
|
||||
##### includeEmptyLines
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Also indent empty lines.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
|
@ -1,21 +0,0 @@
|
|||
/**
|
||||
Strip leading whitespace from each line in a string.
|
||||
|
||||
The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.
|
||||
|
||||
@example
|
||||
```
|
||||
import stripIndent = require('strip-indent');
|
||||
|
||||
const string = '\tunicorn\n\t\tcake';
|
||||
// unicorn
|
||||
// cake
|
||||
|
||||
stripIndent(string);
|
||||
//unicorn
|
||||
// cake
|
||||
```
|
||||
*/
|
||||
declare function stripIndent(string: string): string;
|
||||
|
||||
export = stripIndent;
|
|
@ -1,14 +0,0 @@
|
|||
'use strict';
|
||||
const minIndent = require('min-indent');
|
||||
|
||||
module.exports = string => {
|
||||
const indent = minIndent(string);
|
||||
|
||||
if (indent === 0) {
|
||||
return string;
|
||||
}
|
||||
|
||||
const regex = new RegExp(`^[ \\t]{${indent}}`, 'gm');
|
||||
|
||||
return string.replace(regex, '');
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,46 +0,0 @@
|
|||
{
|
||||
"name": "strip-indent",
|
||||
"version": "3.0.0",
|
||||
"description": "Strip leading whitespace from each line in a string",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/strip-indent",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"strip",
|
||||
"indent",
|
||||
"indentation",
|
||||
"normalize",
|
||||
"remove",
|
||||
"delete",
|
||||
"whitespace",
|
||||
"space",
|
||||
"tab",
|
||||
"string"
|
||||
],
|
||||
"dependencies": {
|
||||
"min-indent": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz"
|
||||
,"_integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ=="
|
||||
,"_from": "strip-indent@3.0.0"
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
# strip-indent [](https://travis-ci.org/sindresorhus/strip-indent)
|
||||
|
||||
> Strip leading whitespace from each line in a string
|
||||
|
||||
The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.
|
||||
|
||||
Useful for removing redundant indentation.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install strip-indent
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const stripIndent = require('strip-indent');
|
||||
|
||||
const string = '\tunicorn\n\t\tcake';
|
||||
/*
|
||||
unicorn
|
||||
cake
|
||||
*/
|
||||
|
||||
stripIndent(string);
|
||||
/*
|
||||
unicorn
|
||||
cake
|
||||
*/
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [strip-indent-cli](https://github.com/sindresorhus/strip-indent-cli) - CLI for this module
|
||||
- [indent-string](https://github.com/sindresorhus/indent-string) - Indent each line in a string
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
|
@ -1,42 +0,0 @@
|
|||
declare const trimNewlines: {
|
||||
/**
|
||||
Trim from the start and end of a string.
|
||||
|
||||
@example
|
||||
```js
|
||||
import trimNewlines = require('trim-newlines');
|
||||
|
||||
trimNewlines('\n🦄\r\n');
|
||||
//=> '🦄'
|
||||
```
|
||||
*/
|
||||
(string: string): string;
|
||||
|
||||
/**
|
||||
Trim from the start of a string.
|
||||
|
||||
@example
|
||||
```js
|
||||
import trimNewlines = require('trim-newlines');
|
||||
|
||||
trimNewlines.start('\n🦄\r\n');
|
||||
//=> '🦄\r\n'
|
||||
```
|
||||
*/
|
||||
start(string: string): string;
|
||||
|
||||
/**
|
||||
Trim from the end of a string.
|
||||
|
||||
@example
|
||||
```js
|
||||
import trimNewlines = require('trim-newlines');
|
||||
|
||||
trimNewlines.end('\n🦄\r\n');
|
||||
//=> '\n🦄'
|
||||
```
|
||||
*/
|
||||
end(string: string): string;
|
||||
};
|
||||
|
||||
export = trimNewlines;
|
|
@ -1,13 +0,0 @@
|
|||
'use strict';
|
||||
module.exports = string => string.replace(/^[\r\n]+/, '').replace(/[\r\n]+$/, '');
|
||||
module.exports.start = string => string.replace(/^[\r\n]+/, '');
|
||||
|
||||
module.exports.end = string => {
|
||||
let end = string.length;
|
||||
|
||||
while (end > 0 && (string[end - 1] === '\r' || string[end - 1] === '\n')) {
|
||||
end--;
|
||||
}
|
||||
|
||||
return end < string.length ? string.slice(0, end) : string;
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,47 +0,0 @@
|
|||
{
|
||||
"name": "trim-newlines",
|
||||
"version": "3.0.1",
|
||||
"description": "Trim newlines from the start and/or end of a string",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/trim-newlines",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"trim",
|
||||
"newline",
|
||||
"newlines",
|
||||
"linebreak",
|
||||
"lf",
|
||||
"crlf",
|
||||
"left",
|
||||
"right",
|
||||
"start",
|
||||
"end",
|
||||
"string",
|
||||
"remove",
|
||||
"delete",
|
||||
"strip"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz"
|
||||
,"_integrity": "sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw=="
|
||||
,"_from": "trim-newlines@3.0.1"
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
# trim-newlines [](https://travis-ci.org/sindresorhus/trim-newlines)
|
||||
|
||||
> Trim [newlines](https://en.wikipedia.org/wiki/Newline) from the start and/or end of a string
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install trim-newlines
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const trimNewlines = require('trim-newlines');
|
||||
|
||||
trimNewlines('\n🦄\r\n');
|
||||
//=> '🦄'
|
||||
|
||||
trimNewlines.start('\n🦄\r\n');
|
||||
//=> '🦄\r\n'
|
||||
|
||||
trimNewlines.end('\n🦄\r\n');
|
||||
//=> '\n🦄'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### trimNewlines(string)
|
||||
|
||||
Trim from the start and end of a string.
|
||||
|
||||
### trimNewlines.start(string)
|
||||
|
||||
Trim from the start of a string.
|
||||
|
||||
### trimNewlines.end(string)
|
||||
|
||||
Trim from the end of a string.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [trim-left](https://github.com/sindresorhus/trim-left) - Similar to `String#trim()` but removes only whitespace on the left
|
||||
- [trim-right](https://github.com/sindresorhus/trim-right) - Similar to `String#trim()` but removes only whitespace on the right.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
|
@ -1,80 +0,0 @@
|
|||
{
|
||||
"name": "meow",
|
||||
"version": "7.1.1",
|
||||
"description": "CLI app helper",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/meow",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"cli",
|
||||
"bin",
|
||||
"util",
|
||||
"utility",
|
||||
"helper",
|
||||
"argv",
|
||||
"command",
|
||||
"line",
|
||||
"meow",
|
||||
"cat",
|
||||
"kitten",
|
||||
"parser",
|
||||
"option",
|
||||
"flags",
|
||||
"input",
|
||||
"cmd",
|
||||
"console"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/minimist": "^1.2.0",
|
||||
"camelcase-keys": "^6.2.2",
|
||||
"decamelize-keys": "^1.1.0",
|
||||
"hard-rejection": "^2.1.0",
|
||||
"minimist-options": "4.1.0",
|
||||
"normalize-package-data": "^2.5.0",
|
||||
"read-pkg-up": "^7.0.1",
|
||||
"redent": "^3.0.0",
|
||||
"trim-newlines": "^3.0.0",
|
||||
"type-fest": "^0.13.1",
|
||||
"yargs-parser": "^18.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^2.4.0",
|
||||
"execa": "^4.0.0",
|
||||
"indent-string": "^4.0.0",
|
||||
"tsd": "^0.11.0",
|
||||
"xo": "^0.30.0"
|
||||
},
|
||||
"xo": {
|
||||
"rules": {
|
||||
"unicorn/no-process-exit": "off",
|
||||
"node/no-unsupported-features/es-syntax": "off"
|
||||
},
|
||||
"ignores": [
|
||||
"estest/index.js"
|
||||
]
|
||||
},
|
||||
"ava": {
|
||||
"files": [
|
||||
"test/*"
|
||||
]
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/meow/-/meow-7.1.1.tgz"
|
||||
,"_integrity": "sha512-GWHvA5QOcS412WCo8vwKDlTelGLsCGBVevQB5Kva961rmNfun0PCbv5+xta2kUMFJyR8/oWnn7ddeKdosbAPbA=="
|
||||
,"_from": "meow@7.1.1"
|
||||
}
|
|
@ -1,337 +0,0 @@
|
|||
# meow [](https://travis-ci.org/sindresorhus/meow)
|
||||
|
||||
> CLI app helper
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
- Parses arguments
|
||||
- Converts flags to [camelCase](https://github.com/sindresorhus/camelcase)
|
||||
- Negates flags when using the `--no-` prefix
|
||||
- Outputs version when `--version`
|
||||
- Outputs description and supplied help text when `--help`
|
||||
- Makes unhandled rejected promises [fail hard](https://github.com/sindresorhus/hard-rejection) instead of the default silent fail
|
||||
- Sets the process title to the binary name defined in package.json
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install meow
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
$ ./foo-app.js unicorns --rainbow
|
||||
```
|
||||
|
||||
**CommonJS**
|
||||
|
||||
```js
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
const meow = require('meow');
|
||||
const foo = require('.');
|
||||
|
||||
const cli = meow(`
|
||||
Usage
|
||||
$ foo <input>
|
||||
|
||||
Options
|
||||
--rainbow, -r Include a rainbow
|
||||
|
||||
Examples
|
||||
$ foo unicorns --rainbow
|
||||
🌈 unicorns 🌈
|
||||
`, {
|
||||
flags: {
|
||||
rainbow: {
|
||||
type: 'boolean',
|
||||
alias: 'r'
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
{
|
||||
input: ['unicorns'],
|
||||
flags: {rainbow: true},
|
||||
...
|
||||
}
|
||||
*/
|
||||
|
||||
foo(cli.input[0], cli.flags);
|
||||
```
|
||||
|
||||
**ES Modules**
|
||||
|
||||
```js
|
||||
#!/usr/bin/env node
|
||||
import {createRequire} from 'module';
|
||||
import foo from './lib/index.js';
|
||||
|
||||
const meow = createRequire(import.meta.url)('meow');
|
||||
|
||||
const cli = meow(`
|
||||
Usage
|
||||
$ foo <input>
|
||||
|
||||
Options
|
||||
--rainbow, -r Include a rainbow
|
||||
|
||||
Examples
|
||||
$ foo unicorns --rainbow
|
||||
🌈 unicorns 🌈
|
||||
`, {
|
||||
flags: {
|
||||
rainbow: {
|
||||
type: 'boolean',
|
||||
alias: 'r'
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
{
|
||||
input: ['unicorns'],
|
||||
flags: {rainbow: true},
|
||||
...
|
||||
}
|
||||
*/
|
||||
|
||||
foo(cli.input[0], cli.flags);
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### meow(helpText, options?)
|
||||
### meow(options)
|
||||
|
||||
Returns an `object` with:
|
||||
|
||||
- `input` *(Array)* - Non-flag arguments
|
||||
- `flags` *(Object)* - Flags converted to camelCase excluding aliases
|
||||
- `unnormalizedFlags` *(Object)* - Flags converted to camelCase including aliases
|
||||
- `pkg` *(Object)* - The `package.json` object
|
||||
- `help` *(string)* - The help text used with `--help`
|
||||
- `showHelp([exitCode=2])` *(Function)* - Show the help text and exit with `exitCode`
|
||||
- `showVersion()` *(Function)* - Show the version text and exit
|
||||
|
||||
#### helpText
|
||||
|
||||
Type: `string`
|
||||
|
||||
Shortcut for the `help` option.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### flags
|
||||
|
||||
Type: `object`
|
||||
|
||||
Define argument flags.
|
||||
|
||||
The key is the flag name and the value is an object with any of:
|
||||
|
||||
- `type`: Type of value. (Possible values: `string` `boolean` `number`)
|
||||
- `alias`: Usually used to define a short flag alias.
|
||||
- `default`: Default value when the flag is not specified.
|
||||
- `isRequired`: Determine if the flag is required. (Default: false)
|
||||
- If it's only known at runtime whether the flag is required or not, you can pass a `Function` instead of a `boolean`, which based on the given flags and other non-flag arguments, should decide if the flag is required. Two arguments are passed to the function:
|
||||
- The first argument is the **flags** object, which contains the flags converted to camel-case excluding aliases.
|
||||
- The second argument is the **input** string array, which contains the non-flag arguments.
|
||||
- The function should return a `boolean`, true if the flag is required, otherwise false.
|
||||
- `isMultiple`: Indicates a flag can be set multiple times. Values are turned into an array. (Default: false)
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
flags: {
|
||||
unicorn: {
|
||||
type: 'string',
|
||||
alias: 'u',
|
||||
default: ['rainbow', 'cat'],
|
||||
isMultiple: true,
|
||||
isRequired: (flags, input) => {
|
||||
if (flags.otherFlag) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
##### description
|
||||
|
||||
Type: `string | boolean`\
|
||||
Default: The package.json `"description"` property
|
||||
|
||||
Description to show above the help text.
|
||||
|
||||
Set it to `false` to disable it altogether.
|
||||
|
||||
##### help
|
||||
|
||||
Type: `string | boolean`
|
||||
|
||||
The help text you want shown.
|
||||
|
||||
The input is reindented and starting/ending newlines are trimmed which means you can use a [template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings) without having to care about using the correct amount of indent.
|
||||
|
||||
The description will be shown above your help text automatically.
|
||||
|
||||
##### version
|
||||
|
||||
Type: `string | boolean`\
|
||||
Default: The package.json `"version"` property
|
||||
|
||||
Set a custom version output.
|
||||
|
||||
##### autoHelp
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Automatically show the help text when the `--help` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own help text.
|
||||
|
||||
This option is only considered when there is only one argument in `process.argv`.
|
||||
|
||||
##### autoVersion
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Automatically show the version text when the `--version` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own version text.
|
||||
|
||||
This option is only considered when there is only one argument in `process.argv`.
|
||||
|
||||
##### pkg
|
||||
|
||||
Type: `object`\
|
||||
Default: Closest package.json upwards
|
||||
|
||||
package.json as an `object`.
|
||||
|
||||
*You most likely don't need this option.*
|
||||
|
||||
##### argv
|
||||
|
||||
Type: `string[]`\
|
||||
Default: `process.argv.slice(2)`
|
||||
|
||||
Custom arguments object.
|
||||
|
||||
##### inferType
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Infer the argument type.
|
||||
|
||||
By default, the argument `5` in `$ foo 5` becomes a string. Enabling this would infer it as a number.
|
||||
|
||||
##### booleanDefault
|
||||
|
||||
Type: `boolean | null | undefined`\
|
||||
Default: `false`
|
||||
|
||||
Value of `boolean` flags not defined in `argv`.
|
||||
If set to `undefined` the flags not defined in `argv` will be excluded from the result.
|
||||
The `default` value set in `boolean` flags take precedence over `booleanDefault`.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
const meow = require('meow');
|
||||
|
||||
const cli = meow(`
|
||||
Usage
|
||||
$ foo
|
||||
|
||||
Options
|
||||
--rainbow, -r Include a rainbow
|
||||
--unicorn, -u Include a unicorn
|
||||
--no-sparkles Exclude sparkles
|
||||
|
||||
Examples
|
||||
$ foo
|
||||
🌈 unicorns✨🌈
|
||||
`, {
|
||||
booleanDefault: undefined,
|
||||
flags: {
|
||||
rainbow: {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
alias: 'r'
|
||||
},
|
||||
unicorn: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
alias: 'u'
|
||||
},
|
||||
cake: {
|
||||
type: 'boolean',
|
||||
alias: 'c'
|
||||
},
|
||||
sparkles: {
|
||||
type: 'boolean',
|
||||
default: true
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
{
|
||||
flags: {
|
||||
rainbow: true,
|
||||
unicorn: false,
|
||||
sparkles: true
|
||||
},
|
||||
unnormalizedFlags: {
|
||||
rainbow: true,
|
||||
r: true,
|
||||
unicorn: false,
|
||||
u: false,
|
||||
sparkles: true
|
||||
},
|
||||
…
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
##### hardRejection
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Whether to use [`hard-rejection`](https://github.com/sindresorhus/hard-rejection) or not. Disabling this can be useful if you need to handle `process.on('unhandledRejection')` yourself.
|
||||
|
||||
## Promises
|
||||
|
||||
Meow will make unhandled rejected promises [fail hard](https://github.com/sindresorhus/hard-rejection) instead of the default silent fail. Meaning you don't have to manually `.catch()` promises used in your CLI.
|
||||
|
||||
## Tips
|
||||
|
||||
See [`chalk`](https://github.com/chalk/chalk) if you want to colorize the terminal output.
|
||||
|
||||
See [`get-stdin`](https://github.com/sindresorhus/get-stdin) if you want to accept input from stdin.
|
||||
|
||||
See [`conf`](https://github.com/sindresorhus/conf) if you need to persist some data.
|
||||
|
||||
See [`update-notifier`](https://github.com/yeoman/update-notifier) if you want update notifications.
|
||||
|
||||
[More useful CLI utilities…](https://github.com/sindresorhus/awesome-nodejs#command-line-utilities)
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-meow?utm_source=npm-meow&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>
|
|
@ -1,67 +0,0 @@
|
|||
import * as typeFest from 'type-fest';
|
||||
import normalize = require('normalize-package-data');
|
||||
|
||||
declare namespace readPkg {
|
||||
interface Options {
|
||||
/**
|
||||
[Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly normalize?: boolean;
|
||||
|
||||
/**
|
||||
Current working directory.
|
||||
|
||||
@default process.cwd()
|
||||
*/
|
||||
readonly cwd?: string;
|
||||
}
|
||||
|
||||
interface NormalizeOptions extends Options {
|
||||
readonly normalize?: true;
|
||||
}
|
||||
|
||||
type NormalizedPackageJson = PackageJson & normalize.Package;
|
||||
type PackageJson = typeFest.PackageJson;
|
||||
}
|
||||
|
||||
declare const readPkg: {
|
||||
/**
|
||||
@returns The parsed JSON.
|
||||
|
||||
@example
|
||||
```
|
||||
import readPkg = require('read-pkg');
|
||||
|
||||
(async () => {
|
||||
console.log(await readPkg());
|
||||
//=> {name: 'read-pkg', …}
|
||||
|
||||
console.log(await readPkg({cwd: 'some-other-directory'});
|
||||
//=> {name: 'unicorn', …}
|
||||
})();
|
||||
```
|
||||
*/
|
||||
(options?: readPkg.NormalizeOptions): Promise<readPkg.NormalizedPackageJson>;
|
||||
(options: readPkg.Options): Promise<readPkg.PackageJson>;
|
||||
|
||||
/**
|
||||
@returns The parsed JSON.
|
||||
|
||||
@example
|
||||
```
|
||||
import readPkg = require('read-pkg');
|
||||
|
||||
console.log(readPkg.sync());
|
||||
//=> {name: 'read-pkg', …}
|
||||
|
||||
console.log(readPkg.sync({cwd: 'some-other-directory'});
|
||||
//=> {name: 'unicorn', …}
|
||||
```
|
||||
*/
|
||||
sync(options?: readPkg.NormalizeOptions): readPkg.NormalizedPackageJson;
|
||||
sync(options: readPkg.Options): readPkg.PackageJson;
|
||||
};
|
||||
|
||||
export = readPkg;
|
|
@ -1,41 +0,0 @@
|
|||
'use strict';
|
||||
const {promisify} = require('util');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const parseJson = require('parse-json');
|
||||
|
||||
const readFileAsync = promisify(fs.readFile);
|
||||
|
||||
module.exports = async options => {
|
||||
options = {
|
||||
cwd: process.cwd(),
|
||||
normalize: true,
|
||||
...options
|
||||
};
|
||||
|
||||
const filePath = path.resolve(options.cwd, 'package.json');
|
||||
const json = parseJson(await readFileAsync(filePath, 'utf8'));
|
||||
|
||||
if (options.normalize) {
|
||||
require('normalize-package-data')(json);
|
||||
}
|
||||
|
||||
return json;
|
||||
};
|
||||
|
||||
module.exports.sync = options => {
|
||||
options = {
|
||||
cwd: process.cwd(),
|
||||
normalize: true,
|
||||
...options
|
||||
};
|
||||
|
||||
const filePath = path.resolve(options.cwd, 'package.json');
|
||||
const json = parseJson(fs.readFileSync(filePath, 'utf8'));
|
||||
|
||||
if (options.normalize) {
|
||||
require('normalize-package-data')(json);
|
||||
}
|
||||
|
||||
return json;
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,15 +0,0 @@
|
|||
// Basic
|
||||
export * from './source/basic';
|
||||
|
||||
// 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 {ReadonlyDeep} from './source/readonly-deep';
|
||||
export {LiteralUnion} from './source/literal-union';
|
||||
export {Promisable} from './source/promisable';
|
||||
|
||||
// Miscellaneous
|
||||
export {PackageJson} from './source/package-json';
|
|
@ -1,9 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
|
@ -1,55 +0,0 @@
|
|||
{
|
||||
"name": "type-fest",
|
||||
"version": "0.6.0",
|
||||
"description": "A collection of essential TypeScript types",
|
||||
"license": "(MIT OR CC0-1.0)",
|
||||
"repository": "sindresorhus/type-fest",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"source"
|
||||
],
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"ts",
|
||||
"types",
|
||||
"utility",
|
||||
"util",
|
||||
"utilities",
|
||||
"omit",
|
||||
"merge",
|
||||
"json"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@sindresorhus/tsconfig": "^0.4.0",
|
||||
"@typescript-eslint/eslint-plugin": "^1.9.0",
|
||||
"@typescript-eslint/parser": "^1.10.2",
|
||||
"eslint-config-xo-typescript": "^0.14.0",
|
||||
"tsd": "^0.7.3",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"xo": {
|
||||
"extends": "xo-typescript",
|
||||
"extensions": [
|
||||
"ts"
|
||||
],
|
||||
"rules": {
|
||||
"import/no-unresolved": "off",
|
||||
"@typescript-eslint/indent": "off"
|
||||
}
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz"
|
||||
,"_integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg=="
|
||||
,"_from": "type-fest@0.6.0"
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
<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>
|
||||
<hr>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
[](https://travis-ci.com/sindresorhus/type-fest)
|
||||
[](https://www.youtube.com/watch?v=9auOCbH5Ns4)
|
||||
<!-- Commented out until they actually show anything
|
||||
[](https://www.npmjs.com/package/type-fest?activeTab=dependents) [](https://www.npmjs.com/package/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.2*
|
||||
|
||||
|
||||
## 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/basic.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/basic.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/basic.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) - Convert an object with `readonly` properties into a mutable object. 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 properties.
|
||||
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given properties.
|
||||
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of a `object`/`Map`/`Set`/`Array` type.
|
||||
- [`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`.
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file).
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
|
||||
## Tips
|
||||
|
||||
### 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.
|
||||
- [`Required<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1408-L1413) - Make all properties in `T` required.
|
||||
- [`Readonly<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1415-L1420) - Make all properties in `T` readonly.
|
||||
- [`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`.
|
||||
- [`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`.
|
||||
- [`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`.
|
||||
- [`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`.
|
||||
- [`NonNullable<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1446-L1449) - Exclude `null` and `undefined` from `T`.
|
||||
- [`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.
|
||||
- [`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.
|
||||
- [`ReturnType<T>`](https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts#L1461-L1464) – Obtain the return type of a function type.
|
||||
- [`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.
|
||||
|
||||
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)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
(MIT OR CC0-1.0)
|
|
@ -1,67 +0,0 @@
|
|||
/// <reference lib="esnext"/>
|
||||
|
||||
// TODO: This can just be `export type Primitive = not object` when the `not` keyword is out.
|
||||
/**
|
||||
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
||||
*/
|
||||
export type Primitive =
|
||||
| null
|
||||
| undefined
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| symbol
|
||||
| bigint;
|
||||
|
||||
// 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).
|
||||
*/
|
||||
export type Class<T = unknown> = new(...arguments_: any[]) => T;
|
||||
|
||||
/**
|
||||
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
||||
*/
|
||||
export type TypedArray =
|
||||
| Int8Array
|
||||
| Uint8Array
|
||||
| Uint8ClampedArray
|
||||
| Int16Array
|
||||
| Uint16Array
|
||||
| Int32Array
|
||||
| Uint32Array
|
||||
| Float32Array
|
||||
| Float64Array
|
||||
| BigInt64Array
|
||||
| BigUint64Array;
|
||||
|
||||
/**
|
||||
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 { … }`.
|
||||
*/
|
||||
export type JsonObject = {[key: string]: JsonValue};
|
||||
|
||||
/**
|
||||
Matches a JSON array.
|
||||
*/
|
||||
export interface JsonArray extends Array<JsonValue> {}
|
||||
|
||||
/**
|
||||
Matches any valid JSON value.
|
||||
*/
|
||||
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
||||
|
||||
declare global {
|
||||
interface SymbolConstructor {
|
||||
readonly observable: symbol;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
|
||||
*/
|
||||
export interface ObservableLike {
|
||||
subscribe(observer: (value: unknown) => void): void;
|
||||
[Symbol.observable](): ObservableLike;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/**
|
||||
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.
|
||||
|
||||
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/30825) if you want to have the stricter version as a built-in in TypeScript.
|
||||
|
||||
@example
|
||||
```
|
||||
import {Except} from 'type-fest';
|
||||
|
||||
type Foo = {
|
||||
a: number;
|
||||
b: string;
|
||||
c: boolean;
|
||||
};
|
||||
|
||||
type FooWithoutA = Except<Foo, 'a' | 'c'>;
|
||||
//=> {b: string};
|
||||
```
|
||||
*/
|
||||
export type Except<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
|
|
@ -1,33 +0,0 @@
|
|||
import {Primitive} from './basic';
|
||||
|
||||
/**
|
||||
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.
|
||||
```
|
||||
*/
|
||||
export type LiteralUnion<
|
||||
LiteralType extends BaseType,
|
||||
BaseType extends Primitive
|
||||
> = LiteralType | (BaseType & {_?: never});
|
|
@ -1,39 +0,0 @@
|
|||
// 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 properties.
|
||||
|
||||
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
|
||||
```
|
||||
*/
|
||||
export type MergeExclusive<FirstType, SecondType> =
|
||||
(FirstType | SecondType) extends object ?
|
||||
(Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType) :
|
||||
FirstType | SecondType;
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
import {Except} from './except';
|
||||
|
||||
/**
|
||||
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};
|
||||
```
|
||||
*/
|
||||
export type Merge<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue