new license file version [CI SKIP]
This commit is contained in:
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"J D E F A B CC"},B:{"1":"C K L G M N O","2":"P Q R S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H"},C:{"2":"0 1 2 3 4 5 6 7 8 9 DC tB I v J D E F A B C K L G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H xB yB EC FC"},D:{"2":"0 1 2 3 4 5 6 7 8 9 I v J D E F A B C K L G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H xB yB GC"},E:{"2":"I v J D E F A B C K L G HC zB IC JC KC LC 0B qB rB 1B MC NC 2B 3B 4B 5B sB 6B 7B 8B 9B OC"},F:{"2":"0 1 2 3 4 5 6 7 8 9 F B C G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d e PC QC RC SC qB AC TC rB"},G:{"2":"E zB UC BC VC WC XC YC","132":"ZC aC bC cC dC eC fC gC hC iC jC kC lC mC nC 2B 3B 4B 5B sB 6B 7B 8B 9B"},H:{"2":"oC"},I:{"2":"tB I f pC qC rC sC BC tC uC"},J:{"2":"D","132":"A"},K:{"2":"A B C h qB AC","132":"rB"},L:{"2":"H"},M:{"2":"H"},N:{"2":"A B"},O:{"2":"vC"},P:{"2":"I g wC xC yC zC 0C 0B 1C 2C 3C 4C 5C sB 6C 7C 8C"},Q:{"2":"1B"},R:{"2":"9C"},S:{"2":"AD BD"}},B:6,C:"AC-3 (Dolby Digital) and EC-3 (Dolby Digital Plus) codecs"};
|
||||
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
var pow = Math.pow;
|
||||
|
||||
module.exports = function (value) {
|
||||
if (isNaN(value)) return NaN;
|
||||
value = Number(value);
|
||||
if (value === 0) return value;
|
||||
if (!isFinite(value)) return value;
|
||||
if (value < 0) return -pow(-value, 1 / 3);
|
||||
return pow(value, 1 / 3);
|
||||
};
|
||||
@@ -0,0 +1,81 @@
|
||||
const conversions = require('./conversions');
|
||||
const route = require('./route');
|
||||
|
||||
const convert = {};
|
||||
|
||||
const models = Object.keys(conversions);
|
||||
|
||||
function wrapRaw(fn) {
|
||||
const wrappedFn = function (...args) {
|
||||
const arg0 = args[0];
|
||||
if (arg0 === undefined || arg0 === null) {
|
||||
return arg0;
|
||||
}
|
||||
|
||||
if (arg0.length > 1) {
|
||||
args = arg0;
|
||||
}
|
||||
|
||||
return fn(args);
|
||||
};
|
||||
|
||||
// Preserve .conversion property if there is one
|
||||
if ('conversion' in fn) {
|
||||
wrappedFn.conversion = fn.conversion;
|
||||
}
|
||||
|
||||
return wrappedFn;
|
||||
}
|
||||
|
||||
function wrapRounded(fn) {
|
||||
const wrappedFn = function (...args) {
|
||||
const arg0 = args[0];
|
||||
|
||||
if (arg0 === undefined || arg0 === null) {
|
||||
return arg0;
|
||||
}
|
||||
|
||||
if (arg0.length > 1) {
|
||||
args = arg0;
|
||||
}
|
||||
|
||||
const result = fn(args);
|
||||
|
||||
// We're assuming the result is an array here.
|
||||
// see notice in conversions.js; don't use box types
|
||||
// in conversion functions.
|
||||
if (typeof result === 'object') {
|
||||
for (let len = result.length, i = 0; i < len; i++) {
|
||||
result[i] = Math.round(result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// Preserve .conversion property if there is one
|
||||
if ('conversion' in fn) {
|
||||
wrappedFn.conversion = fn.conversion;
|
||||
}
|
||||
|
||||
return wrappedFn;
|
||||
}
|
||||
|
||||
models.forEach(fromModel => {
|
||||
convert[fromModel] = {};
|
||||
|
||||
Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels});
|
||||
Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels});
|
||||
|
||||
const routes = route(fromModel);
|
||||
const routeModels = Object.keys(routes);
|
||||
|
||||
routeModels.forEach(toModel => {
|
||||
const fn = routes[toModel];
|
||||
|
||||
convert[fromModel][toModel] = wrapRounded(fn);
|
||||
convert[fromModel][toModel].raw = wrapRaw(fn);
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = convert;
|
||||
@@ -0,0 +1,672 @@
|
||||
# sade [](https://travis-ci.org/lukeed/sade)
|
||||
|
||||
> Smooth (CLI) Operator 🎶
|
||||
|
||||
Sade is a small but powerful tool for building command-line interface (CLI) applications for Node.js that are fast, responsive, and helpful!
|
||||
|
||||
It enables default commands, git-like subcommands, option flags with aliases, default option values with type-casting, required-vs-optional argument handling, command validation, and automated help text generation!
|
||||
|
||||
Your app's UX will be as smooth as butter... just like [Sade's voice](https://www.youtube.com/watch?v=4TYv2PhG89A). 😉
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save sade
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
***Input:***
|
||||
|
||||
```js
|
||||
#!/usr/bin/env node
|
||||
|
||||
const sade = require('sade');
|
||||
|
||||
const prog = sade('my-cli');
|
||||
|
||||
prog
|
||||
.version('1.0.5')
|
||||
.option('--global, -g', 'An example global flag')
|
||||
.option('-c, --config', 'Provide path to custom config', 'foo.config.js');
|
||||
|
||||
prog
|
||||
.command('build <src> <dest>')
|
||||
.describe('Build the source directory. Expects an `index.js` entry file.')
|
||||
.option('-o, --output', 'Change the name of the output file', 'bundle.js')
|
||||
.example('build src build --global --config my-conf.js')
|
||||
.example('build app public -o main.js')
|
||||
.action((src, dest, opts) => {
|
||||
console.log(`> building from ${src} to ${dest}`);
|
||||
console.log('> these are extra opts', opts);
|
||||
});
|
||||
|
||||
prog.parse(process.argv);
|
||||
```
|
||||
|
||||
***Output:***
|
||||
|
||||
```a
|
||||
$ my-cli --help
|
||||
|
||||
Usage
|
||||
$ my-cli <command> [options]
|
||||
|
||||
Available Commands
|
||||
build Build the source directory.
|
||||
|
||||
For more info, run any command with the `--help` flag
|
||||
$ my-cli build --help
|
||||
|
||||
Options
|
||||
-v, --version Displays current version
|
||||
-g, --global An example global flag
|
||||
-c, --config Provide path to custom config (default foo.config.js)
|
||||
-h, --help Displays this message
|
||||
|
||||
|
||||
$ my-cli build --help
|
||||
|
||||
Description
|
||||
Build the source directory.
|
||||
Expects an `index.js` entry file.
|
||||
|
||||
Usage
|
||||
$ my-cli build <src> [options]
|
||||
|
||||
Options
|
||||
-o, --output Change the name of the output file (default bundle.js)
|
||||
-g, --global An example global flag
|
||||
-c, --config Provide path to custom config (default foo.config.js)
|
||||
-h, --help Displays this message
|
||||
|
||||
Examples
|
||||
$ my-cli build src build --global --config my-conf.js
|
||||
$ my-cli build app public -o main.js
|
||||
```
|
||||
|
||||
## Tips
|
||||
|
||||
- **Define your global/program-wide version, options, description, and/or examples first.**<br>
|
||||
_Once you define a Command, you can't access the global-scope again._
|
||||
|
||||
- **Define all commands & options in the order that you want them to appear.**<br>
|
||||
_Sade will not mutate or sort your CLI for you. Global options print before local options._
|
||||
|
||||
- **Required arguments without values will error & exit**<br>
|
||||
_An `Insufficient arguments!` error will be displayed along with a help prompt._
|
||||
|
||||
- **Don't worry about manually displaying help~!**<br>
|
||||
_Your help text is displayed automatically... including command-specific help text!_
|
||||
|
||||
- **Automatic default/basic patterns**<br>
|
||||
_Usage text will always append `[options]` & `--help` and `--version` are done for you._
|
||||
|
||||
- **Only define what you want to display!**<br>
|
||||
_Help text sections (example, options, etc) will only display if you provide values._
|
||||
|
||||
|
||||
## Subcommands
|
||||
|
||||
Subcommands are defined & parsed like any other command! When defining their [`usage`](#usage-1), everything up until the first argument (`[foo]` or `<foo>`) is interpreted as the command string.
|
||||
|
||||
They should be defined in the order that you want them to appear in your general `--help` output.
|
||||
|
||||
Lastly, it is _not_ necessary to define the subcommand's "base" as an additional command. However, if you choose to do so, it's recommended that you define it first for better visibility.
|
||||
|
||||
```js
|
||||
const prog = sade('git');
|
||||
|
||||
// Not necessary for subcommands to work, but it's here anyway!
|
||||
prog
|
||||
.command('remote')
|
||||
.describe('Manage set of tracked repositories')
|
||||
.action(opts => {
|
||||
console.log('~> Print current remotes...');
|
||||
});
|
||||
|
||||
prog
|
||||
.command('remote add <name> <url>', 'Demo...')
|
||||
.action((name, url, opts) => {
|
||||
console.log(`~> Adding a new remote (${name}) to ${url}`);
|
||||
});
|
||||
|
||||
prog
|
||||
.command('remote rename <old> <new>', 'Demo...')
|
||||
.action((old, nxt, opts) => {
|
||||
console.log(`~> Renaming from ${old} to ${nxt}~!`);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Single Command Mode
|
||||
|
||||
In certain circumstances, you may only need `sade` for a single-command CLI application.
|
||||
|
||||
> **Note:** Until `v1.6.0`, this made for an awkward pairing.
|
||||
|
||||
To enable this, you may make use of the [`isSingle`](#issingle) argument. Doing so allows you to pass the program's entire [`usage` text](#usage-1) into the `name` argument.
|
||||
|
||||
With "Single Command Mode" enabled, your entire binary operates as one command. This means that any [`prog.command`](#progcommandusage-desc-opts) calls are disallowed & will instead throw an Error. Of course, you may still define a program version, a description, an example or two, and declare options. You are customizing the program's attributes as a whole.<sup>*</sup>
|
||||
|
||||
> <sup>*</sup> This is true for multi-command applications, too, up until your first `prog.command()` call!
|
||||
|
||||
***Example***
|
||||
|
||||
Let's reconstruct [`sirv-cli`](https://github.com/lukeed/sirv), which is a single-command application that (optionally) accepts a directory from which to serve files. It also offers a slew of option flags:
|
||||
|
||||
```js
|
||||
sade('sirv [dir]', true)
|
||||
.version('1.0.0')
|
||||
.describe('Run a static file server')
|
||||
.example('public -qeim 31536000')
|
||||
.example('--port 8080 --etag')
|
||||
.example('my-app --dev')
|
||||
.option('-D, --dev', 'Enable "dev" mode')
|
||||
.option('-e, --etag', 'Enable "Etag" header')
|
||||
// There are a lot...
|
||||
.option('-H, --host', 'Hostname to bind', 'localhost')
|
||||
.option('-p, --port', 'Port to bind', 5000)
|
||||
.action((dir, opts) => {
|
||||
// Program handler
|
||||
})
|
||||
.parse(process.argv);
|
||||
```
|
||||
|
||||
When `sirv --help` is run, the generated help text is trimmed, fully aware that there's only one command in this program:
|
||||
|
||||
```
|
||||
Description
|
||||
Run a static file server
|
||||
|
||||
Usage
|
||||
$ sirv [dir] [options]
|
||||
|
||||
Options
|
||||
-D, --dev Enable "dev" mode
|
||||
-e, --etag Enable "Etag" header
|
||||
-H, --host Hostname to bind (default localhost)
|
||||
-p, --port Port to bind (default 5000)
|
||||
-v, --version Displays current version
|
||||
-h, --help Displays this message
|
||||
|
||||
Examples
|
||||
$ sirv public -qeim 31536000
|
||||
$ sirv --port 8080 --etag
|
||||
$ sirv my-app --dev
|
||||
```
|
||||
|
||||
## Command Aliases
|
||||
|
||||
Command aliases are alternative names (aliases) for a command. They are often used as shortcuts or as typo relief!
|
||||
|
||||
The aliased names do not appear in the general help text.<br>
|
||||
Instead, they only appear within the Command-specific help text under an "Aliases" section.
|
||||
|
||||
***Limitations***
|
||||
|
||||
* You cannot assign aliases while in [Single Command Mode](#single-command-mode)
|
||||
* You cannot call [`prog.alias()`](#progaliasnames) before defining any Commands (via `prog.commmand()`)
|
||||
* You, the developer, must keep track of which aliases have already been used and/or exist as Command names
|
||||
|
||||
***Example***
|
||||
|
||||
Let's reconstruct the `npm install` command as a Sade program:
|
||||
|
||||
```js
|
||||
sade('npm')
|
||||
// ...
|
||||
.command('install [package]', 'Install a package', {
|
||||
alias: ['i', 'add', 'isntall']
|
||||
})
|
||||
.option('-P, --save-prod', 'Package will appear in your dependencies.')
|
||||
.option('-D, --save-dev', 'Package will appear in your devDependencies.')
|
||||
.option('-O, --save-optional', 'Package will appear in your optionalDependencies')
|
||||
.option('-E, --save-exact', 'Save exact versions instead of using a semver range operator')
|
||||
// ...
|
||||
```
|
||||
|
||||
When we run `npm --help` we'll see this general help text:
|
||||
|
||||
```
|
||||
Usage
|
||||
$ npm <command> [options]
|
||||
|
||||
Available Commands
|
||||
install Install a package
|
||||
|
||||
For more info, run any command with the `--help` flag
|
||||
$ npm install --help
|
||||
|
||||
Options
|
||||
-v, --version Displays current version
|
||||
-h, --help Displays this message
|
||||
```
|
||||
|
||||
When we run `npm install --help` — ***or*** the help flag with any of `install`'s aliases — we'll see this command-specific help text:
|
||||
|
||||
```
|
||||
Description
|
||||
Install a package
|
||||
|
||||
Usage
|
||||
$ npm install [package] [options]
|
||||
|
||||
Aliases
|
||||
$ npm i
|
||||
$ npm add
|
||||
$ npm isntall
|
||||
|
||||
Options
|
||||
-P, --save-prod Package will appear in your dependencies.
|
||||
-D, --save-dev Package will appear in your devDependencies.
|
||||
-O, --save-optional Package will appear in your optionalDependencies
|
||||
-E, --save-exact Save exact versions instead of using a semver range operator
|
||||
-h, --help Displays this message
|
||||
```
|
||||
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### sade(name, isSingle)
|
||||
Returns: `Program`
|
||||
|
||||
Returns your chainable Sade instance, aka your `Program`.
|
||||
|
||||
#### name
|
||||
Type: `String`<br>
|
||||
Required: `true`
|
||||
|
||||
The name of your `Program` / binary application.
|
||||
|
||||
#### isSingle
|
||||
Type: `Boolean`<br>
|
||||
Default: `name.includes(' ');`
|
||||
|
||||
If your `Program` is meant to have ***only one command***.<br>
|
||||
When `true`, this simplifies your generated `--help` output such that:
|
||||
|
||||
* the "root-level help" is your _only_ help text
|
||||
* the "root-level help" does not display an `Available Commands` section
|
||||
* the "root-level help" does not inject `$ name <command>` into the `Usage` section
|
||||
* the "root-level help" does not display `For more info, run any command with the `--help` flag` text
|
||||
|
||||
You may customize the `Usage` of your command by modifying the `name` argument directly.<br>
|
||||
Please read [Single Command Mode](#single-command-mode) for an example and more information.
|
||||
|
||||
> **Important:** Whenever `name` includes a custom usage, then `isSingle` is automatically assumed and enforced!
|
||||
|
||||
### prog.command(usage, desc, opts)
|
||||
|
||||
Create a new Command for your Program. This changes the current state of your Program.
|
||||
|
||||
All configuration methods (`prog.describe`, `prog.action`, etc) will apply to this Command until another Command has been created!
|
||||
|
||||
#### usage
|
||||
|
||||
Type: `String`
|
||||
|
||||
The usage pattern for your current Command. This will be included in the general or command-specific `--help` output.
|
||||
|
||||
_Required_ arguments are wrapped with `<` and `>` characters; for example, `<foo>` and `<bar>`.
|
||||
|
||||
_Optional_ arguments are wrapped with `[` and `]` characters; for example, `[foo]` and `[bar]`.
|
||||
|
||||
All arguments are ***positionally important***, which means they are passed to your current Command's [`handler`](#handler) function in the order that they were defined.
|
||||
|
||||
When optional arguments are defined but don't receive a value, their positionally-equivalent function parameter will be `undefined`.
|
||||
|
||||
> **Important:** You **must** define & expect required arguments _before_ optional arguments!
|
||||
|
||||
```js
|
||||
sade('foo')
|
||||
|
||||
.command('greet <adjective> <noun>')
|
||||
.action((adjective, noun, opts) => {
|
||||
console.log(`Hello, ${adjective} ${noun}!`);
|
||||
})
|
||||
|
||||
.command('drive <vehicle> [color] [speed]')
|
||||
.action((vehicle, color, speed, opts) => {
|
||||
let arr = ['Driving my'];
|
||||
arr.push(color ? `${color} ${vehicle}` : vehicle);
|
||||
speed && arr.push(`at ${speed}`);
|
||||
opts.yolo && arr.push('...YOLO!!');
|
||||
let str = arr.join(' ');
|
||||
console.log(str);
|
||||
});
|
||||
```
|
||||
|
||||
```sh
|
||||
$ foo greet beautiful person
|
||||
# //=> Hello, beautiful person!
|
||||
|
||||
$ foo drive car
|
||||
# //=> Driving my car
|
||||
|
||||
$ foo drive car red
|
||||
# //=> Driving my red card
|
||||
|
||||
$ foo drive car blue 100mph --yolo
|
||||
# //=> Driving my blue car at 100mph ...YOLO!!
|
||||
```
|
||||
|
||||
|
||||
#### desc
|
||||
|
||||
Type: `String`<br>
|
||||
Default: `''`
|
||||
|
||||
The Command's description. The value is passed directly to [`prog.describe`](#progdescribetext).
|
||||
|
||||
#### opts
|
||||
|
||||
Type: `Object`<br>
|
||||
Default: `{}`
|
||||
|
||||
##### opts.alias
|
||||
Type: `String|Array`
|
||||
|
||||
Optionally define one or more aliases for the current Command.<br>
|
||||
When declared, the `opts.alias` value is passed _directly_ to the [`prog.alias`](#progaliasnames) method.
|
||||
|
||||
```js
|
||||
// Program A is equivalent to Program B
|
||||
// ---
|
||||
|
||||
const A = sade('bin')
|
||||
.command('build', 'My build command', { alias: 'b' })
|
||||
.command('watch', 'My watch command', { alias: ['w', 'dev'] });
|
||||
|
||||
const B = sade('bin')
|
||||
.command('build', 'My build command').alias('b')
|
||||
.command('watch', 'My watch command').alias('w', 'dev');
|
||||
```
|
||||
|
||||
|
||||
##### opts.default
|
||||
|
||||
Type: `Boolean`
|
||||
|
||||
Manually set/force the current Command to be the Program's default command. This ensures that the current Command will run if no command was specified.
|
||||
|
||||
> **Important:** If you run your Program without a Command _and_ without specifying a default command, your Program will exit with a `No command specified` error.
|
||||
|
||||
```js
|
||||
const prog = sade('greet');
|
||||
|
||||
prog.command('hello');
|
||||
//=> only runs if :: `$ greet hello`
|
||||
|
||||
// $ greet
|
||||
//=> error: No command specified.
|
||||
|
||||
prog.command('howdy', '', { default:true });
|
||||
//=> runs as `$ greet` OR `$ greet howdy`
|
||||
|
||||
// $ greet
|
||||
//=> runs 'howdy' handler
|
||||
|
||||
// $ greet foobar
|
||||
//=> error: Invalid command
|
||||
```
|
||||
|
||||
|
||||
### prog.describe(text)
|
||||
|
||||
Add a description to the current Command.
|
||||
|
||||
#### text
|
||||
|
||||
Type: `String|Array`
|
||||
|
||||
The description text for the current Command. This will be included in the general or command-specific `--help` output.
|
||||
|
||||
Internally, your description will be separated into an `Array` of sentences.
|
||||
|
||||
For general `--help` output, ***only*** the first sentence will be displayed. However, **all sentences** will be printed for command-specific `--help` text.
|
||||
|
||||
> **Note:** Pass an `Array` if you don't want internal assumptions. However, the first item is _always_ displayed in general help, so it's recommended to keep it short.
|
||||
|
||||
|
||||
### prog.alias(...names)
|
||||
|
||||
Define one or more aliases for the current Command.
|
||||
|
||||
> **Important:** An error will be thrown if:<br>1) the program is in [Single Command Mode](#single-command-mode); or<br>2) `prog.alias` is called before any `prog.command`.
|
||||
|
||||
#### names
|
||||
|
||||
Type: `String`
|
||||
|
||||
The list of alternative names (aliases) for the current Command.<br>
|
||||
For example, you may want to define shortcuts and/or common typos for the Command's full name.
|
||||
|
||||
> **Important:** Sade _does not_ check if the incoming `names` are already in use by other Commands or their aliases.<br>During conflicts, the Command with the same `name` is given priority, otherwise the first Command (according to Program order) with `name` as an alias is chosen.
|
||||
|
||||
The `prog.alias()` is append-only, so calling it multiple times within a Command context will _keep_ all aliases, including those initially passed via [`opts.alias`](#optsdefault).
|
||||
|
||||
```js
|
||||
sade('bin')
|
||||
.command('hello <name>', 'Greet someone by their name', {
|
||||
alias: ['hey', 'yo']
|
||||
})
|
||||
.alias('hi', 'howdy')
|
||||
.alias('hola', 'oi');
|
||||
//=> hello aliases: hey, yo, hi, howdy, hola, oi
|
||||
```
|
||||
|
||||
|
||||
### prog.action(handler)
|
||||
|
||||
Attach a callback to the current Command.
|
||||
|
||||
#### handler
|
||||
|
||||
Type: `Function`
|
||||
|
||||
The function to run when the current Command is executed.
|
||||
|
||||
Its parameters are based (positionally) on your Command's [`usage`](#usage-1) definition.
|
||||
|
||||
All options, flags, and extra/unknown values are included as the last parameter.
|
||||
|
||||
> **Note:** Optional arguments are also passed as parameters & may be `undefined`!
|
||||
|
||||
```js
|
||||
sade('foo')
|
||||
.command('cp <src> <dest>')
|
||||
.option('-f, --force', 'Overwrite without confirmation')
|
||||
.option('-c, --clone-dir', 'Copy files to additional directory')
|
||||
.option('-v, --verbose', 'Enable verbose output')
|
||||
.action((src, dest, opts) => {
|
||||
console.log(`Copying files from ${src} --> ${dest}`);
|
||||
opts.c && console.log(`ALSO copying files from ${src} --> ${opts['clone-dir']}`);
|
||||
console.log('My options:', opts);
|
||||
})
|
||||
|
||||
// $ foo cp original my-copy -v
|
||||
//=> Copying files from original --> my-copy
|
||||
//=> My options: { _:[], v:true, verbose:true }
|
||||
|
||||
// $ foo cp original my-copy --clone-dir my-backup
|
||||
//=> Copying files from original --> my-copy
|
||||
//=> ALSO copying files from original --> my-backup
|
||||
//=> My options: { _:[], c:'my-backup', 'clone-dir':'my-backup' }
|
||||
```
|
||||
|
||||
|
||||
### prog.example(str)
|
||||
|
||||
Add an example for the current Command.
|
||||
|
||||
#### str
|
||||
|
||||
Type: `String`
|
||||
|
||||
The example string to add. This will be included in the general or command-specific `--help` output.
|
||||
|
||||
> **Note:** Your example's `str` will be prefixed with your Program's [`name`](#sadename).
|
||||
|
||||
|
||||
### prog.option(flags, desc, value)
|
||||
|
||||
Add an Option to the current Command.
|
||||
|
||||
#### flags
|
||||
|
||||
Type: `String`
|
||||
|
||||
The Option's flags, which may optionally include an alias.
|
||||
|
||||
You may use a comma (`,`) or a space (` `) to separate the flags.
|
||||
|
||||
> **Note:** The short & long flags can be declared in any order. However, the alias will always be displayed first.
|
||||
|
||||
> **Important:** If using hyphenated flag names, they will be accessible **as declared** within your [`action()`](#progactionhandler) handler!
|
||||
|
||||
```js
|
||||
prog.option('--global'); // no alias
|
||||
prog.option('-g, --global'); // alias first, comma
|
||||
prog.option('--global -g'); // alias last, space
|
||||
// etc...
|
||||
```
|
||||
|
||||
#### desc
|
||||
|
||||
Type: `String`
|
||||
|
||||
The description for the Option.
|
||||
|
||||
#### value
|
||||
|
||||
Type: `String`
|
||||
|
||||
The **default** value for the Option.
|
||||
|
||||
Flags and aliases, if parsed, are `true` by default. See [`mri`](https://github.com/lukeed/mri#minimist) for more info.
|
||||
|
||||
> **Note:** You probably only want to define a default `value` if you're expecting a `String` or `Number` value type.
|
||||
|
||||
If you _do_ pass a `String` or `Number` value type, your flag value will be casted to the same type. See [`mri#options.default`](https://github.com/lukeed/mri#optionsdefault) for info~!
|
||||
|
||||
|
||||
### prog.version(str)
|
||||
|
||||
The `--version` and `-v` flags will automatically output the Program version.
|
||||
|
||||
#### str
|
||||
|
||||
Type: `String`<br>
|
||||
Default: `0.0.0`
|
||||
|
||||
The new version number for your Program.
|
||||
|
||||
> **Note:** Your Program `version` is `0.0.0` until you change it.
|
||||
|
||||
### prog.parse(arr, opts)
|
||||
|
||||
Parse a set of CLI arguments.
|
||||
|
||||
#### arr
|
||||
|
||||
Type: `Array`
|
||||
|
||||
Your Program's `process.argv` input.
|
||||
|
||||
> **Important:** Do not `.slice(2)`! Doing so will break parsing~!
|
||||
|
||||
#### opts
|
||||
|
||||
Type: `Object`<br>
|
||||
Default: `{}`
|
||||
|
||||
Additional `process.argv` parsing config. See [`mri`'s options](https://github.com/lukeed/mri#mriargs-options) for details.
|
||||
|
||||
> **Important:** These values _override_ any internal values!
|
||||
|
||||
```js
|
||||
prog
|
||||
.command('hello')
|
||||
.option('-f, --force', 'My flag');
|
||||
//=> currently has alias pair: f <--> force
|
||||
|
||||
prog.parse(process.argv, {
|
||||
alias: {
|
||||
f: ['foo', 'fizz']
|
||||
},
|
||||
default: {
|
||||
abc: 123
|
||||
}
|
||||
});
|
||||
//=> ADDS alias pair: f <--> foo
|
||||
//=> REMOVES alias pair: f <--> force
|
||||
//=> ADDS alias pair: f <--> fizz
|
||||
//=> ADDS default: abc -> 123 (number)
|
||||
```
|
||||
|
||||
#### opts.unknown
|
||||
|
||||
Type: `Function`<br>
|
||||
Default: `undefined`
|
||||
|
||||
Callback to run when an unspecified option flag has been found. This is [passed directly to `mri`](https://github.com/lukeed/mri#optionsunknown).
|
||||
|
||||
Your handler will receive the unknown flag (string) as its only argument.<br>
|
||||
You may return a string, which will be used as a custom error message. Otherwise, a default message is displayed.
|
||||
|
||||
```js
|
||||
sade('sirv')
|
||||
.command('start [dir]')
|
||||
.parse(process.argv, {
|
||||
unknown: arg => `Custom error message: ${arg}`
|
||||
});
|
||||
|
||||
/*
|
||||
$ sirv start --foobar
|
||||
|
||||
ERROR
|
||||
Custom error message: --foobar
|
||||
|
||||
Run `$ sirv --help` for more info.
|
||||
*/
|
||||
```
|
||||
|
||||
#### opts.lazy
|
||||
|
||||
Type: `Boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
If true, Sade will not immediately execute the `action` handler. Instead, `parse()` will return an object of `{ name, args, handler }` shape, wherein the `name` is the command name, `args` is all arguments that _would be_ passed to the action handler, and `handler` is the function itself.
|
||||
|
||||
From this, you may choose when to run the `handler` function. You also have the option to further modify the `args` for any reason, if needed.
|
||||
|
||||
```js
|
||||
let { name, args, handler } = prog.parse(process.argv, { lazy:true });
|
||||
console.log('> Received command: ', name);
|
||||
|
||||
// later on...
|
||||
handler.apply(null, args);
|
||||
```
|
||||
|
||||
### prog.help(cmd)
|
||||
|
||||
Manually display the help text for a given command. If no command name is provided, the general/global help is printed.
|
||||
|
||||
Your general and command-specific help text is automatically attached to the `--help` and `-h` flags.
|
||||
|
||||
> **Note:** You don't have to call this directly! It's automatically run when you `bin --help`
|
||||
|
||||
#### cmd
|
||||
Type: `String`<br>
|
||||
Default: `null`
|
||||
|
||||
The name of the command for which to display help. Otherwise displays the general help.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Luke Edwards](https://lukeed.com)
|
||||
@@ -0,0 +1,62 @@
|
||||
"use strict";
|
||||
|
||||
var isValue = require("type/value/is")
|
||||
, isPlainFunction = require("type/plain-function/is")
|
||||
, assign = require("es5-ext/object/assign")
|
||||
, normalizeOpts = require("es5-ext/object/normalize-options")
|
||||
, contains = require("es5-ext/string/#/contains");
|
||||
|
||||
var d = (module.exports = function (dscr, value/*, options*/) {
|
||||
var c, e, w, options, desc;
|
||||
if (arguments.length < 2 || typeof dscr !== "string") {
|
||||
options = value;
|
||||
value = dscr;
|
||||
dscr = null;
|
||||
} else {
|
||||
options = arguments[2];
|
||||
}
|
||||
if (isValue(dscr)) {
|
||||
c = contains.call(dscr, "c");
|
||||
e = contains.call(dscr, "e");
|
||||
w = contains.call(dscr, "w");
|
||||
} else {
|
||||
c = w = true;
|
||||
e = false;
|
||||
}
|
||||
|
||||
desc = { value: value, configurable: c, enumerable: e, writable: w };
|
||||
return !options ? desc : assign(normalizeOpts(options), desc);
|
||||
});
|
||||
|
||||
d.gs = function (dscr, get, set/*, options*/) {
|
||||
var c, e, options, desc;
|
||||
if (typeof dscr !== "string") {
|
||||
options = set;
|
||||
set = get;
|
||||
get = dscr;
|
||||
dscr = null;
|
||||
} else {
|
||||
options = arguments[3];
|
||||
}
|
||||
if (!isValue(get)) {
|
||||
get = undefined;
|
||||
} else if (!isPlainFunction(get)) {
|
||||
options = get;
|
||||
get = set = undefined;
|
||||
} else if (!isValue(set)) {
|
||||
set = undefined;
|
||||
} else if (!isPlainFunction(set)) {
|
||||
options = set;
|
||||
set = undefined;
|
||||
}
|
||||
if (isValue(dscr)) {
|
||||
c = contains.call(dscr, "c");
|
||||
e = contains.call(dscr, "e");
|
||||
} else {
|
||||
c = true;
|
||||
e = false;
|
||||
}
|
||||
|
||||
desc = { get: get, set: set, configurable: c, enumerable: e };
|
||||
return !options ? desc : assign(normalizeOpts(options), desc);
|
||||
};
|
||||
@@ -0,0 +1,568 @@
|
||||
semver(1) -- The semantic versioner for npm
|
||||
===========================================
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install semver
|
||||
````
|
||||
|
||||
## Usage
|
||||
|
||||
As a node module:
|
||||
|
||||
```js
|
||||
const semver = require('semver')
|
||||
|
||||
semver.valid('1.2.3') // '1.2.3'
|
||||
semver.valid('a.b.c') // null
|
||||
semver.clean(' =v1.2.3 ') // '1.2.3'
|
||||
semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
|
||||
semver.gt('1.2.3', '9.8.7') // false
|
||||
semver.lt('1.2.3', '9.8.7') // true
|
||||
semver.minVersion('>=1.0.0') // '1.0.0'
|
||||
semver.valid(semver.coerce('v2')) // '2.0.0'
|
||||
semver.valid(semver.coerce('42.6.7.9.3-alpha')) // '42.6.7'
|
||||
```
|
||||
|
||||
You can also just load the module for the function that you care about, if
|
||||
you'd like to minimize your footprint.
|
||||
|
||||
```js
|
||||
// load the whole API at once in a single object
|
||||
const semver = require('semver')
|
||||
|
||||
// or just load the bits you need
|
||||
// all of them listed here, just pick and choose what you want
|
||||
|
||||
// classes
|
||||
const SemVer = require('semver/classes/semver')
|
||||
const Comparator = require('semver/classes/comparator')
|
||||
const Range = require('semver/classes/range')
|
||||
|
||||
// functions for working with versions
|
||||
const semverParse = require('semver/functions/parse')
|
||||
const semverValid = require('semver/functions/valid')
|
||||
const semverClean = require('semver/functions/clean')
|
||||
const semverInc = require('semver/functions/inc')
|
||||
const semverDiff = require('semver/functions/diff')
|
||||
const semverMajor = require('semver/functions/major')
|
||||
const semverMinor = require('semver/functions/minor')
|
||||
const semverPatch = require('semver/functions/patch')
|
||||
const semverPrerelease = require('semver/functions/prerelease')
|
||||
const semverCompare = require('semver/functions/compare')
|
||||
const semverRcompare = require('semver/functions/rcompare')
|
||||
const semverCompareLoose = require('semver/functions/compare-loose')
|
||||
const semverCompareBuild = require('semver/functions/compare-build')
|
||||
const semverSort = require('semver/functions/sort')
|
||||
const semverRsort = require('semver/functions/rsort')
|
||||
|
||||
// low-level comparators between versions
|
||||
const semverGt = require('semver/functions/gt')
|
||||
const semverLt = require('semver/functions/lt')
|
||||
const semverEq = require('semver/functions/eq')
|
||||
const semverNeq = require('semver/functions/neq')
|
||||
const semverGte = require('semver/functions/gte')
|
||||
const semverLte = require('semver/functions/lte')
|
||||
const semverCmp = require('semver/functions/cmp')
|
||||
const semverCoerce = require('semver/functions/coerce')
|
||||
|
||||
// working with ranges
|
||||
const semverSatisfies = require('semver/functions/satisfies')
|
||||
const semverMaxSatisfying = require('semver/ranges/max-satisfying')
|
||||
const semverMinSatisfying = require('semver/ranges/min-satisfying')
|
||||
const semverToComparators = require('semver/ranges/to-comparators')
|
||||
const semverMinVersion = require('semver/ranges/min-version')
|
||||
const semverValidRange = require('semver/ranges/valid')
|
||||
const semverOutside = require('semver/ranges/outside')
|
||||
const semverGtr = require('semver/ranges/gtr')
|
||||
const semverLtr = require('semver/ranges/ltr')
|
||||
const semverIntersects = require('semver/ranges/intersects')
|
||||
const simplifyRange = require('semver/ranges/simplify')
|
||||
const rangeSubset = require('semver/ranges/subset')
|
||||
```
|
||||
|
||||
As a command-line utility:
|
||||
|
||||
```
|
||||
$ semver -h
|
||||
|
||||
A JavaScript implementation of the https://semver.org/ specification
|
||||
Copyright Isaac Z. Schlueter
|
||||
|
||||
Usage: semver [options] <version> [<version> [...]]
|
||||
Prints valid versions sorted by SemVer precedence
|
||||
|
||||
Options:
|
||||
-r --range <range>
|
||||
Print versions that match the specified range.
|
||||
|
||||
-i --increment [<level>]
|
||||
Increment a version by the specified level. Level can
|
||||
be one of: major, minor, patch, premajor, preminor,
|
||||
prepatch, or prerelease. Default level is 'patch'.
|
||||
Only one version may be specified.
|
||||
|
||||
--preid <identifier>
|
||||
Identifier to be used to prefix premajor, preminor,
|
||||
prepatch or prerelease version increments.
|
||||
|
||||
-l --loose
|
||||
Interpret versions and ranges loosely
|
||||
|
||||
-p --include-prerelease
|
||||
Always include prerelease versions in range matching
|
||||
|
||||
-c --coerce
|
||||
Coerce a string into SemVer if possible
|
||||
(does not imply --loose)
|
||||
|
||||
--rtl
|
||||
Coerce version strings right to left
|
||||
|
||||
--ltr
|
||||
Coerce version strings left to right (default)
|
||||
|
||||
Program exits successfully if any valid version satisfies
|
||||
all supplied ranges, and prints all satisfying versions.
|
||||
|
||||
If no satisfying versions are found, then exits failure.
|
||||
|
||||
Versions are printed in ascending order, so supplying
|
||||
multiple versions to the utility will just sort them.
|
||||
```
|
||||
|
||||
## Versions
|
||||
|
||||
A "version" is described by the `v2.0.0` specification found at
|
||||
<https://semver.org/>.
|
||||
|
||||
A leading `"="` or `"v"` character is stripped off and ignored.
|
||||
|
||||
## Ranges
|
||||
|
||||
A `version range` is a set of `comparators` which specify versions
|
||||
that satisfy the range.
|
||||
|
||||
A `comparator` is composed of an `operator` and a `version`. The set
|
||||
of primitive `operators` is:
|
||||
|
||||
* `<` Less than
|
||||
* `<=` Less than or equal to
|
||||
* `>` Greater than
|
||||
* `>=` Greater than or equal to
|
||||
* `=` Equal. If no operator is specified, then equality is assumed,
|
||||
so this operator is optional, but MAY be included.
|
||||
|
||||
For example, the comparator `>=1.2.7` would match the versions
|
||||
`1.2.7`, `1.2.8`, `2.5.3`, and `1.3.9`, but not the versions `1.2.6`
|
||||
or `1.1.0`.
|
||||
|
||||
Comparators can be joined by whitespace to form a `comparator set`,
|
||||
which is satisfied by the **intersection** of all of the comparators
|
||||
it includes.
|
||||
|
||||
A range is composed of one or more comparator sets, joined by `||`. A
|
||||
version matches a range if and only if every comparator in at least
|
||||
one of the `||`-separated comparator sets is satisfied by the version.
|
||||
|
||||
For example, the range `>=1.2.7 <1.3.0` would match the versions
|
||||
`1.2.7`, `1.2.8`, and `1.2.99`, but not the versions `1.2.6`, `1.3.0`,
|
||||
or `1.1.0`.
|
||||
|
||||
The range `1.2.7 || >=1.2.9 <2.0.0` would match the versions `1.2.7`,
|
||||
`1.2.9`, and `1.4.6`, but not the versions `1.2.8` or `2.0.0`.
|
||||
|
||||
### Prerelease Tags
|
||||
|
||||
If a version has a prerelease tag (for example, `1.2.3-alpha.3`) then
|
||||
it will only be allowed to satisfy comparator sets if at least one
|
||||
comparator with the same `[major, minor, patch]` tuple also has a
|
||||
prerelease tag.
|
||||
|
||||
For example, the range `>1.2.3-alpha.3` would be allowed to match the
|
||||
version `1.2.3-alpha.7`, but it would *not* be satisfied by
|
||||
`3.4.5-alpha.9`, even though `3.4.5-alpha.9` is technically "greater
|
||||
than" `1.2.3-alpha.3` according to the SemVer sort rules. The version
|
||||
range only accepts prerelease tags on the `1.2.3` version. The
|
||||
version `3.4.5` *would* satisfy the range, because it does not have a
|
||||
prerelease flag, and `3.4.5` is greater than `1.2.3-alpha.7`.
|
||||
|
||||
The purpose for this behavior is twofold. First, prerelease versions
|
||||
frequently are updated very quickly, and contain many breaking changes
|
||||
that are (by the author's design) not yet fit for public consumption.
|
||||
Therefore, by default, they are excluded from range matching
|
||||
semantics.
|
||||
|
||||
Second, a user who has opted into using a prerelease version has
|
||||
clearly indicated the intent to use *that specific* set of
|
||||
alpha/beta/rc versions. By including a prerelease tag in the range,
|
||||
the user is indicating that they are aware of the risk. However, it
|
||||
is still not appropriate to assume that they have opted into taking a
|
||||
similar risk on the *next* set of prerelease versions.
|
||||
|
||||
Note that this behavior can be suppressed (treating all prerelease
|
||||
versions as if they were normal versions, for the purpose of range
|
||||
matching) by setting the `includePrerelease` flag on the options
|
||||
object to any
|
||||
[functions](https://github.com/npm/node-semver#functions) that do
|
||||
range matching.
|
||||
|
||||
#### Prerelease Identifiers
|
||||
|
||||
The method `.inc` takes an additional `identifier` string argument that
|
||||
will append the value of the string as a prerelease identifier:
|
||||
|
||||
```javascript
|
||||
semver.inc('1.2.3', 'prerelease', 'beta')
|
||||
// '1.2.4-beta.0'
|
||||
```
|
||||
|
||||
command-line example:
|
||||
|
||||
```bash
|
||||
$ semver 1.2.3 -i prerelease --preid beta
|
||||
1.2.4-beta.0
|
||||
```
|
||||
|
||||
Which then can be used to increment further:
|
||||
|
||||
```bash
|
||||
$ semver 1.2.4-beta.0 -i prerelease
|
||||
1.2.4-beta.1
|
||||
```
|
||||
|
||||
### Advanced Range Syntax
|
||||
|
||||
Advanced range syntax desugars to primitive comparators in
|
||||
deterministic ways.
|
||||
|
||||
Advanced ranges may be combined in the same way as primitive
|
||||
comparators using white space or `||`.
|
||||
|
||||
#### Hyphen Ranges `X.Y.Z - A.B.C`
|
||||
|
||||
Specifies an inclusive set.
|
||||
|
||||
* `1.2.3 - 2.3.4` := `>=1.2.3 <=2.3.4`
|
||||
|
||||
If a partial version is provided as the first version in the inclusive
|
||||
range, then the missing pieces are replaced with zeroes.
|
||||
|
||||
* `1.2 - 2.3.4` := `>=1.2.0 <=2.3.4`
|
||||
|
||||
If a partial version is provided as the second version in the
|
||||
inclusive range, then all versions that start with the supplied parts
|
||||
of the tuple are accepted, but nothing that would be greater than the
|
||||
provided tuple parts.
|
||||
|
||||
* `1.2.3 - 2.3` := `>=1.2.3 <2.4.0-0`
|
||||
* `1.2.3 - 2` := `>=1.2.3 <3.0.0-0`
|
||||
|
||||
#### X-Ranges `1.2.x` `1.X` `1.2.*` `*`
|
||||
|
||||
Any of `X`, `x`, or `*` may be used to "stand in" for one of the
|
||||
numeric values in the `[major, minor, patch]` tuple.
|
||||
|
||||
* `*` := `>=0.0.0` (Any non-prerelease version satisfies, unless
|
||||
`includePrerelease` is specified, in which case any version at all
|
||||
satisfies)
|
||||
* `1.x` := `>=1.0.0 <2.0.0-0` (Matching major version)
|
||||
* `1.2.x` := `>=1.2.0 <1.3.0-0` (Matching major and minor versions)
|
||||
|
||||
A partial version range is treated as an X-Range, so the special
|
||||
character is in fact optional.
|
||||
|
||||
* `""` (empty string) := `*` := `>=0.0.0`
|
||||
* `1` := `1.x.x` := `>=1.0.0 <2.0.0-0`
|
||||
* `1.2` := `1.2.x` := `>=1.2.0 <1.3.0-0`
|
||||
|
||||
#### Tilde Ranges `~1.2.3` `~1.2` `~1`
|
||||
|
||||
Allows patch-level changes if a minor version is specified on the
|
||||
comparator. Allows minor-level changes if not.
|
||||
|
||||
* `~1.2.3` := `>=1.2.3 <1.(2+1).0` := `>=1.2.3 <1.3.0-0`
|
||||
* `~1.2` := `>=1.2.0 <1.(2+1).0` := `>=1.2.0 <1.3.0-0` (Same as `1.2.x`)
|
||||
* `~1` := `>=1.0.0 <(1+1).0.0` := `>=1.0.0 <2.0.0-0` (Same as `1.x`)
|
||||
* `~0.2.3` := `>=0.2.3 <0.(2+1).0` := `>=0.2.3 <0.3.0-0`
|
||||
* `~0.2` := `>=0.2.0 <0.(2+1).0` := `>=0.2.0 <0.3.0-0` (Same as `0.2.x`)
|
||||
* `~0` := `>=0.0.0 <(0+1).0.0` := `>=0.0.0 <1.0.0-0` (Same as `0.x`)
|
||||
* `~1.2.3-beta.2` := `>=1.2.3-beta.2 <1.3.0-0` Note that prereleases in
|
||||
the `1.2.3` version will be allowed, if they are greater than or
|
||||
equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but
|
||||
`1.2.4-beta.2` would not, because it is a prerelease of a
|
||||
different `[major, minor, patch]` tuple.
|
||||
|
||||
#### Caret Ranges `^1.2.3` `^0.2.5` `^0.0.4`
|
||||
|
||||
Allows changes that do not modify the left-most non-zero element in the
|
||||
`[major, minor, patch]` tuple. In other words, this allows patch and
|
||||
minor updates for versions `1.0.0` and above, patch updates for
|
||||
versions `0.X >=0.1.0`, and *no* updates for versions `0.0.X`.
|
||||
|
||||
Many authors treat a `0.x` version as if the `x` were the major
|
||||
"breaking-change" indicator.
|
||||
|
||||
Caret ranges are ideal when an author may make breaking changes
|
||||
between `0.2.4` and `0.3.0` releases, which is a common practice.
|
||||
However, it presumes that there will *not* be breaking changes between
|
||||
`0.2.4` and `0.2.5`. It allows for changes that are presumed to be
|
||||
additive (but non-breaking), according to commonly observed practices.
|
||||
|
||||
* `^1.2.3` := `>=1.2.3 <2.0.0-0`
|
||||
* `^0.2.3` := `>=0.2.3 <0.3.0-0`
|
||||
* `^0.0.3` := `>=0.0.3 <0.0.4-0`
|
||||
* `^1.2.3-beta.2` := `>=1.2.3-beta.2 <2.0.0-0` Note that prereleases in
|
||||
the `1.2.3` version will be allowed, if they are greater than or
|
||||
equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but
|
||||
`1.2.4-beta.2` would not, because it is a prerelease of a
|
||||
different `[major, minor, patch]` tuple.
|
||||
* `^0.0.3-beta` := `>=0.0.3-beta <0.0.4-0` Note that prereleases in the
|
||||
`0.0.3` version *only* will be allowed, if they are greater than or
|
||||
equal to `beta`. So, `0.0.3-pr.2` would be allowed.
|
||||
|
||||
When parsing caret ranges, a missing `patch` value desugars to the
|
||||
number `0`, but will allow flexibility within that value, even if the
|
||||
major and minor versions are both `0`.
|
||||
|
||||
* `^1.2.x` := `>=1.2.0 <2.0.0-0`
|
||||
* `^0.0.x` := `>=0.0.0 <0.1.0-0`
|
||||
* `^0.0` := `>=0.0.0 <0.1.0-0`
|
||||
|
||||
A missing `minor` and `patch` values will desugar to zero, but also
|
||||
allow flexibility within those values, even if the major version is
|
||||
zero.
|
||||
|
||||
* `^1.x` := `>=1.0.0 <2.0.0-0`
|
||||
* `^0.x` := `>=0.0.0 <1.0.0-0`
|
||||
|
||||
### Range Grammar
|
||||
|
||||
Putting all this together, here is a Backus-Naur grammar for ranges,
|
||||
for the benefit of parser authors:
|
||||
|
||||
```bnf
|
||||
range-set ::= range ( logical-or range ) *
|
||||
logical-or ::= ( ' ' ) * '||' ( ' ' ) *
|
||||
range ::= hyphen | simple ( ' ' simple ) * | ''
|
||||
hyphen ::= partial ' - ' partial
|
||||
simple ::= primitive | partial | tilde | caret
|
||||
primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
|
||||
partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
|
||||
xr ::= 'x' | 'X' | '*' | nr
|
||||
nr ::= '0' | ['1'-'9'] ( ['0'-'9'] ) *
|
||||
tilde ::= '~' partial
|
||||
caret ::= '^' partial
|
||||
qualifier ::= ( '-' pre )? ( '+' build )?
|
||||
pre ::= parts
|
||||
build ::= parts
|
||||
parts ::= part ( '.' part ) *
|
||||
part ::= nr | [-0-9A-Za-z]+
|
||||
```
|
||||
|
||||
## Functions
|
||||
|
||||
All methods and classes take a final `options` object argument. All
|
||||
options in this object are `false` by default. The options supported
|
||||
are:
|
||||
|
||||
- `loose` Be more forgiving about not-quite-valid semver strings.
|
||||
(Any resulting output will always be 100% strict compliant, of
|
||||
course.) For backwards compatibility reasons, if the `options`
|
||||
argument is a boolean value instead of an object, it is interpreted
|
||||
to be the `loose` param.
|
||||
- `includePrerelease` Set to suppress the [default
|
||||
behavior](https://github.com/npm/node-semver#prerelease-tags) of
|
||||
excluding prerelease tagged versions from ranges unless they are
|
||||
explicitly opted into.
|
||||
|
||||
Strict-mode Comparators and Ranges will be strict about the SemVer
|
||||
strings that they parse.
|
||||
|
||||
* `valid(v)`: Return the parsed version, or null if it's not valid.
|
||||
* `inc(v, release)`: Return the version incremented by the release
|
||||
type (`major`, `premajor`, `minor`, `preminor`, `patch`,
|
||||
`prepatch`, or `prerelease`), or null if it's not valid
|
||||
* `premajor` in one call will bump the version up to the next major
|
||||
version and down to a prerelease of that major version.
|
||||
`preminor`, and `prepatch` work the same way.
|
||||
* If called from a non-prerelease version, the `prerelease` will work the
|
||||
same as `prepatch`. It increments the patch version, then makes a
|
||||
prerelease. If the input version is already a prerelease it simply
|
||||
increments it.
|
||||
* `prerelease(v)`: Returns an array of prerelease components, or null
|
||||
if none exist. Example: `prerelease('1.2.3-alpha.1') -> ['alpha', 1]`
|
||||
* `major(v)`: Return the major version number.
|
||||
* `minor(v)`: Return the minor version number.
|
||||
* `patch(v)`: Return the patch version number.
|
||||
* `intersects(r1, r2, loose)`: Return true if the two supplied ranges
|
||||
or comparators intersect.
|
||||
* `parse(v)`: Attempt to parse a string as a semantic version, returning either
|
||||
a `SemVer` object or `null`.
|
||||
|
||||
### Comparison
|
||||
|
||||
* `gt(v1, v2)`: `v1 > v2`
|
||||
* `gte(v1, v2)`: `v1 >= v2`
|
||||
* `lt(v1, v2)`: `v1 < v2`
|
||||
* `lte(v1, v2)`: `v1 <= v2`
|
||||
* `eq(v1, v2)`: `v1 == v2` This is true if they're logically equivalent,
|
||||
even if they're not the exact same string. You already know how to
|
||||
compare strings.
|
||||
* `neq(v1, v2)`: `v1 != v2` The opposite of `eq`.
|
||||
* `cmp(v1, comparator, v2)`: Pass in a comparison string, and it'll call
|
||||
the corresponding function above. `"==="` and `"!=="` do simple
|
||||
string comparison, but are included for completeness. Throws if an
|
||||
invalid comparison string is provided.
|
||||
* `compare(v1, v2)`: Return `0` if `v1 == v2`, or `1` if `v1` is greater, or `-1` if
|
||||
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
|
||||
* `rcompare(v1, v2)`: The reverse of compare. Sorts an array of versions
|
||||
in descending order when passed to `Array.sort()`.
|
||||
* `compareBuild(v1, v2)`: The same as `compare` but considers `build` when two versions
|
||||
are equal. Sorts in ascending order if passed to `Array.sort()`.
|
||||
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
|
||||
* `diff(v1, v2)`: Returns difference between two versions by the release type
|
||||
(`major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`),
|
||||
or null if the versions are the same.
|
||||
|
||||
### Comparators
|
||||
|
||||
* `intersects(comparator)`: Return true if the comparators intersect
|
||||
|
||||
### Ranges
|
||||
|
||||
* `validRange(range)`: Return the valid range or null if it's not valid
|
||||
* `satisfies(version, range)`: Return true if the version satisfies the
|
||||
range.
|
||||
* `maxSatisfying(versions, range)`: Return the highest version in the list
|
||||
that satisfies the range, or `null` if none of them do.
|
||||
* `minSatisfying(versions, range)`: Return the lowest version in the list
|
||||
that satisfies the range, or `null` if none of them do.
|
||||
* `minVersion(range)`: Return the lowest version that can possibly match
|
||||
the given range.
|
||||
* `gtr(version, range)`: Return `true` if version is greater than all the
|
||||
versions possible in the range.
|
||||
* `ltr(version, range)`: Return `true` if version is less than all the
|
||||
versions possible in the range.
|
||||
* `outside(version, range, hilo)`: Return true if the version is outside
|
||||
the bounds of the range in either the high or low direction. The
|
||||
`hilo` argument must be either the string `'>'` or `'<'`. (This is
|
||||
the function called by `gtr` and `ltr`.)
|
||||
* `intersects(range)`: Return true if any of the ranges comparators intersect
|
||||
* `simplifyRange(versions, range)`: Return a "simplified" range that
|
||||
matches the same items in `versions` list as the range specified. Note
|
||||
that it does *not* guarantee that it would match the same versions in all
|
||||
cases, only for the set of versions provided. This is useful when
|
||||
generating ranges by joining together multiple versions with `||`
|
||||
programmatically, to provide the user with something a bit more
|
||||
ergonomic. If the provided range is shorter in string-length than the
|
||||
generated range, then that is returned.
|
||||
* `subset(subRange, superRange)`: Return `true` if the `subRange` range is
|
||||
entirely contained by the `superRange` range.
|
||||
|
||||
Note that, since ranges may be non-contiguous, a version might not be
|
||||
greater than a range, less than a range, *or* satisfy a range! For
|
||||
example, the range `1.2 <1.2.9 || >2.0.0` would have a hole from `1.2.9`
|
||||
until `2.0.0`, so the version `1.2.10` would not be greater than the
|
||||
range (because `2.0.1` satisfies, which is higher), nor less than the
|
||||
range (since `1.2.8` satisfies, which is lower), and it also does not
|
||||
satisfy the range.
|
||||
|
||||
If you want to know if a version satisfies or does not satisfy a
|
||||
range, use the `satisfies(version, range)` function.
|
||||
|
||||
### Coercion
|
||||
|
||||
* `coerce(version, options)`: Coerces a string to semver if possible
|
||||
|
||||
This aims to provide a very forgiving translation of a non-semver string to
|
||||
semver. It looks for the first digit in a string, and consumes all
|
||||
remaining characters which satisfy at least a partial semver (e.g., `1`,
|
||||
`1.2`, `1.2.3`) up to the max permitted length (256 characters). Longer
|
||||
versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`). All
|
||||
surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes
|
||||
`3.4.0`). Only text which lacks digits will fail coercion (`version one`
|
||||
is not valid). The maximum length for any semver component considered for
|
||||
coercion is 16 characters; longer components will be ignored
|
||||
(`10000000000000000.4.7.4` becomes `4.7.4`). The maximum value for any
|
||||
semver component is `Number.MAX_SAFE_INTEGER || (2**53 - 1)`; higher value
|
||||
components are invalid (`9999999999999999.4.7.4` is likely invalid).
|
||||
|
||||
If the `options.rtl` flag is set, then `coerce` will return the right-most
|
||||
coercible tuple that does not share an ending index with a longer coercible
|
||||
tuple. For example, `1.2.3.4` will return `2.3.4` in rtl mode, not
|
||||
`4.0.0`. `1.2.3/4` will return `4.0.0`, because the `4` is not a part of
|
||||
any other overlapping SemVer tuple.
|
||||
|
||||
### Clean
|
||||
|
||||
* `clean(version)`: Clean a string to be a valid semver if possible
|
||||
|
||||
This will return a cleaned and trimmed semver version. If the provided
|
||||
version is not valid a null will be returned. This does not work for
|
||||
ranges.
|
||||
|
||||
ex.
|
||||
* `s.clean(' = v 2.1.5foo')`: `null`
|
||||
* `s.clean(' = v 2.1.5foo', { loose: true })`: `'2.1.5-foo'`
|
||||
* `s.clean(' = v 2.1.5-foo')`: `null`
|
||||
* `s.clean(' = v 2.1.5-foo', { loose: true })`: `'2.1.5-foo'`
|
||||
* `s.clean('=v2.1.5')`: `'2.1.5'`
|
||||
* `s.clean(' =v2.1.5')`: `2.1.5`
|
||||
* `s.clean(' 2.1.5 ')`: `'2.1.5'`
|
||||
* `s.clean('~1.0.0')`: `null`
|
||||
|
||||
## Exported Modules
|
||||
|
||||
<!--
|
||||
TODO: Make sure that all of these items are documented (classes aren't,
|
||||
eg), and then pull the module name into the documentation for that specific
|
||||
thing.
|
||||
-->
|
||||
|
||||
You may pull in just the part of this semver utility that you need, if you
|
||||
are sensitive to packing and tree-shaking concerns. The main
|
||||
`require('semver')` export uses getter functions to lazily load the parts
|
||||
of the API that are used.
|
||||
|
||||
The following modules are available:
|
||||
|
||||
* `require('semver')`
|
||||
* `require('semver/classes')`
|
||||
* `require('semver/classes/comparator')`
|
||||
* `require('semver/classes/range')`
|
||||
* `require('semver/classes/semver')`
|
||||
* `require('semver/functions/clean')`
|
||||
* `require('semver/functions/cmp')`
|
||||
* `require('semver/functions/coerce')`
|
||||
* `require('semver/functions/compare')`
|
||||
* `require('semver/functions/compare-build')`
|
||||
* `require('semver/functions/compare-loose')`
|
||||
* `require('semver/functions/diff')`
|
||||
* `require('semver/functions/eq')`
|
||||
* `require('semver/functions/gt')`
|
||||
* `require('semver/functions/gte')`
|
||||
* `require('semver/functions/inc')`
|
||||
* `require('semver/functions/lt')`
|
||||
* `require('semver/functions/lte')`
|
||||
* `require('semver/functions/major')`
|
||||
* `require('semver/functions/minor')`
|
||||
* `require('semver/functions/neq')`
|
||||
* `require('semver/functions/parse')`
|
||||
* `require('semver/functions/patch')`
|
||||
* `require('semver/functions/prerelease')`
|
||||
* `require('semver/functions/rcompare')`
|
||||
* `require('semver/functions/rsort')`
|
||||
* `require('semver/functions/satisfies')`
|
||||
* `require('semver/functions/sort')`
|
||||
* `require('semver/functions/valid')`
|
||||
* `require('semver/ranges/gtr')`
|
||||
* `require('semver/ranges/intersects')`
|
||||
* `require('semver/ranges/ltr')`
|
||||
* `require('semver/ranges/max-satisfying')`
|
||||
* `require('semver/ranges/min-satisfying')`
|
||||
* `require('semver/ranges/min-version')`
|
||||
* `require('semver/ranges/outside')`
|
||||
* `require('semver/ranges/to-comparators')`
|
||||
* `require('semver/ranges/valid')`
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"receivebuffer.js","sourceRoot":"","sources":["../../src/common/receivebuffer.ts"],"names":[],"mappings":";;;AAAA,MAAM,aAAa;IAKjB,YAAY,IAAI,GAAG,IAAI;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;SACH;QAED,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YACnD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC;YACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,CAC9B,IAAI,CAAC,GAAG,CACN,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,EACtC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CACjC,CACF,CAAC;YACF,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACvB;QAED,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,MAAc;QACjB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE;YACxB,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;SACH;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,GAAG,CAAC,MAAc;QAChB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE;YACxB,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;SACH;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC;QAEtB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAEO,sCAAa"}
|
||||
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IsValidTimeZoneName = void 0;
|
||||
/**
|
||||
* https://tc39.es/ecma402/#sec-isvalidtimezonename
|
||||
* @param tz
|
||||
* @param implDetails implementation details
|
||||
*/
|
||||
function IsValidTimeZoneName(tz, _a) {
|
||||
var tzData = _a.tzData, uppercaseLinks = _a.uppercaseLinks;
|
||||
var uppercasedTz = tz.toUpperCase();
|
||||
var zoneNames = new Set();
|
||||
var linkNames = new Set();
|
||||
Object.keys(tzData)
|
||||
.map(function (z) { return z.toUpperCase(); })
|
||||
.forEach(function (z) { return zoneNames.add(z); });
|
||||
Object.keys(uppercaseLinks).forEach(function (linkName) {
|
||||
linkNames.add(linkName.toUpperCase());
|
||||
zoneNames.add(uppercaseLinks[linkName].toUpperCase());
|
||||
});
|
||||
return zoneNames.has(uppercasedTz) || linkNames.has(uppercasedTz);
|
||||
}
|
||||
exports.IsValidTimeZoneName = IsValidTimeZoneName;
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require('./takeRight');
|
||||
@@ -0,0 +1,421 @@
|
||||
# endpoint.js
|
||||
|
||||
> Turns GitHub REST API endpoints into generic request options
|
||||
|
||||
[](https://www.npmjs.com/package/@octokit/endpoint)
|
||||
[](https://github.com/octokit/endpoint.js/actions/workflows/test.yml?query=branch%3Amain)
|
||||
|
||||
`@octokit/endpoint` combines [GitHub REST API routes](https://developer.github.com/v3/) with your parameters and turns them into generic request options that can be used in any request library.
|
||||
|
||||
<!-- update table of contents by running `npx markdown-toc README.md -i` -->
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
- [Usage](#usage)
|
||||
- [API](#api)
|
||||
- [`endpoint(route, options)` or `endpoint(options)`](#endpointroute-options-or-endpointoptions)
|
||||
- [`endpoint.defaults()`](#endpointdefaults)
|
||||
- [`endpoint.DEFAULTS`](#endpointdefaults)
|
||||
- [`endpoint.merge(route, options)` or `endpoint.merge(options)`](#endpointmergeroute-options-or-endpointmergeoptions)
|
||||
- [`endpoint.parse()`](#endpointparse)
|
||||
- [Special cases](#special-cases)
|
||||
- [The `data` parameter – set request body directly](#the-data-parameter-%E2%80%93-set-request-body-directly)
|
||||
- [Set parameters for both the URL/query and the request body](#set-parameters-for-both-the-urlquery-and-the-request-body)
|
||||
- [LICENSE](#license)
|
||||
|
||||
<!-- tocstop -->
|
||||
|
||||
## Usage
|
||||
|
||||
<table>
|
||||
<tbody valign=top align=left>
|
||||
<tr><th>
|
||||
Browsers
|
||||
</th><td width=100%>
|
||||
Load <code>@octokit/endpoint</code> directly from <a href="https://cdn.skypack.dev">cdn.skypack.dev</a>
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import { endpoint } from "https://cdn.skypack.dev/@octokit/endpoint";
|
||||
</script>
|
||||
```
|
||||
|
||||
</td></tr>
|
||||
<tr><th>
|
||||
Node
|
||||
</th><td>
|
||||
|
||||
Install with <code>npm install @octokit/endpoint</code>
|
||||
|
||||
```js
|
||||
const { endpoint } = require("@octokit/endpoint");
|
||||
// or: import { endpoint } from "@octokit/endpoint";
|
||||
```
|
||||
|
||||
</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Example for [List organization repositories](https://developer.github.com/v3/repos/#list-organization-repositories)
|
||||
|
||||
```js
|
||||
const requestOptions = endpoint("GET /orgs/{org}/repos", {
|
||||
headers: {
|
||||
authorization: "token 0000000000000000000000000000000000000001",
|
||||
},
|
||||
org: "octokit",
|
||||
type: "private",
|
||||
});
|
||||
```
|
||||
|
||||
The resulting `requestOptions` looks as follows
|
||||
|
||||
```json
|
||||
{
|
||||
"method": "GET",
|
||||
"url": "https://api.github.com/orgs/octokit/repos?type=private",
|
||||
"headers": {
|
||||
"accept": "application/vnd.github.v3+json",
|
||||
"authorization": "token 0000000000000000000000000000000000000001",
|
||||
"user-agent": "octokit/endpoint.js v1.2.3"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can pass `requestOptions` to common request libraries
|
||||
|
||||
```js
|
||||
const { url, ...options } = requestOptions;
|
||||
// using with fetch (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
|
||||
fetch(url, options);
|
||||
// using with request (https://github.com/request/request)
|
||||
request(requestOptions);
|
||||
// using with got (https://github.com/sindresorhus/got)
|
||||
got[options.method](url, options);
|
||||
// using with axios
|
||||
axios(requestOptions);
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `endpoint(route, options)` or `endpoint(options)`
|
||||
|
||||
<table>
|
||||
<thead align=left>
|
||||
<tr>
|
||||
<th>
|
||||
name
|
||||
</th>
|
||||
<th>
|
||||
type
|
||||
</th>
|
||||
<th width=100%>
|
||||
description
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody align=left valign=top>
|
||||
<tr>
|
||||
<th>
|
||||
<code>route</code>
|
||||
</th>
|
||||
<td>
|
||||
String
|
||||
</td>
|
||||
<td>
|
||||
If set, it has to be a string consisting of URL and the request method, e.g., <code>GET /orgs/{org}</code>. If it’s set to a URL, only the method defaults to <code>GET</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<code>options.method</code>
|
||||
</th>
|
||||
<td>
|
||||
String
|
||||
</td>
|
||||
<td>
|
||||
<strong>Required unless <code>route</code> is set.</strong> Any supported <a href="https://developer.github.com/v3/#http-verbs">http verb</a>. <em>Defaults to <code>GET</code></em>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<code>options.url</code>
|
||||
</th>
|
||||
<td>
|
||||
String
|
||||
</td>
|
||||
<td>
|
||||
<strong>Required unless <code>route</code> is set.</strong> A path or full URL which may contain <code>:variable</code> or <code>{variable}</code> placeholders,
|
||||
e.g., <code>/orgs/{org}/repos</code>. The <code>url</code> is parsed using <a href="https://github.com/bramstein/url-template">url-template</a>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<code>options.baseUrl</code>
|
||||
</th>
|
||||
<td>
|
||||
String
|
||||
</td>
|
||||
<td>
|
||||
<em>Defaults to <code>https://api.github.com</code></em>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<code>options.headers</code>
|
||||
</th>
|
||||
<td>
|
||||
Object
|
||||
</td>
|
||||
<td>
|
||||
Custom headers. Passed headers are merged with defaults:<br>
|
||||
<em><code>headers['user-agent']</code> defaults to <code>octokit-endpoint.js/1.2.3</code> (where <code>1.2.3</code> is the released version)</em>.<br>
|
||||
<em><code>headers['accept']</code> defaults to <code>application/vnd.github.v3+json</code></em>.<br>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<code>options.mediaType.format</code>
|
||||
</th>
|
||||
<td>
|
||||
String
|
||||
</td>
|
||||
<td>
|
||||
Media type param, such as <code>raw</code>, <code>diff</code>, or <code>text+json</code>. See <a href="https://developer.github.com/v3/media/">Media Types</a>. Setting <code>options.mediaType.format</code> will amend the <code>headers.accept</code> value.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<code>options.mediaType.previews</code>
|
||||
</th>
|
||||
<td>
|
||||
Array of Strings
|
||||
</td>
|
||||
<td>
|
||||
Name of previews, such as <code>mercy</code>, <code>symmetra</code>, or <code>scarlet-witch</code>. See <a href="https://developer.github.com/v3/previews/">API Previews</a>. If <code>options.mediaType.previews</code> was set as default, the new previews will be merged into the default ones. Setting <code>options.mediaType.previews</code> will amend the <code>headers.accept</code> value. <code>options.mediaType.previews</code> will be merged with an existing array set using <code>.defaults()</code>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<code>options.data</code>
|
||||
</th>
|
||||
<td>
|
||||
Any
|
||||
</td>
|
||||
<td>
|
||||
Set request body directly instead of setting it to JSON based on additional parameters. See <a href="#data-parameter">"The <code>data</code> parameter"</a> below.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<code>options.request</code>
|
||||
</th>
|
||||
<td>
|
||||
Object
|
||||
</td>
|
||||
<td>
|
||||
Pass custom meta information for the request. The <code>request</code> object will be returned as is.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
All other options will be passed depending on the `method` and `url` options.
|
||||
|
||||
1. If the option key has a placeholder in the `url`, it will be used as the replacement. For example, if the passed options are `{url: '/orgs/{org}/repos', org: 'foo'}` the returned `options.url` is `https://api.github.com/orgs/foo/repos`.
|
||||
2. If the `method` is `GET` or `HEAD`, the option is passed as a query parameter.
|
||||
3. Otherwise, the parameter is passed in the request body as a JSON key.
|
||||
|
||||
**Result**
|
||||
|
||||
`endpoint()` is a synchronous method and returns an object with the following keys:
|
||||
|
||||
<table>
|
||||
<thead align=left>
|
||||
<tr>
|
||||
<th>
|
||||
key
|
||||
</th>
|
||||
<th>
|
||||
type
|
||||
</th>
|
||||
<th width=100%>
|
||||
description
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody align=left valign=top>
|
||||
<tr>
|
||||
<th><code>method</code></th>
|
||||
<td>String</td>
|
||||
<td>The http method. Always lowercase.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><code>url</code></th>
|
||||
<td>String</td>
|
||||
<td>The url with placeholders replaced with passed parameters.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><code>headers</code></th>
|
||||
<td>Object</td>
|
||||
<td>All header names are lowercased.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><code>body</code></th>
|
||||
<td>Any</td>
|
||||
<td>The request body if one is present. Only for <code>PATCH</code>, <code>POST</code>, <code>PUT</code>, <code>DELETE</code> requests.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><code>request</code></th>
|
||||
<td>Object</td>
|
||||
<td>Request meta option, it will be returned as it was passed into <code>endpoint()</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
### `endpoint.defaults()`
|
||||
|
||||
Override or set default options. Example:
|
||||
|
||||
```js
|
||||
const request = require("request");
|
||||
const myEndpoint = require("@octokit/endpoint").defaults({
|
||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3",
|
||||
headers: {
|
||||
"user-agent": "myApp/1.2.3",
|
||||
authorization: `token 0000000000000000000000000000000000000001`,
|
||||
},
|
||||
org: "my-project",
|
||||
per_page: 100,
|
||||
});
|
||||
|
||||
request(myEndpoint(`GET /orgs/{org}/repos`));
|
||||
```
|
||||
|
||||
You can call `.defaults()` again on the returned method, the defaults will cascade.
|
||||
|
||||
```js
|
||||
const myProjectEndpoint = endpoint.defaults({
|
||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3",
|
||||
headers: {
|
||||
"user-agent": "myApp/1.2.3",
|
||||
},
|
||||
org: "my-project",
|
||||
});
|
||||
const myProjectEndpointWithAuth = myProjectEndpoint.defaults({
|
||||
headers: {
|
||||
authorization: `token 0000000000000000000000000000000000000001`,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
`myProjectEndpointWithAuth` now defaults the `baseUrl`, `headers['user-agent']`,
|
||||
`org` and `headers['authorization']` on top of `headers['accept']` that is set
|
||||
by the global default.
|
||||
|
||||
### `endpoint.DEFAULTS`
|
||||
|
||||
The current default options.
|
||||
|
||||
```js
|
||||
endpoint.DEFAULTS.baseUrl; // https://api.github.com
|
||||
const myEndpoint = endpoint.defaults({
|
||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3",
|
||||
});
|
||||
myEndpoint.DEFAULTS.baseUrl; // https://github-enterprise.acme-inc.com/api/v3
|
||||
```
|
||||
|
||||
### `endpoint.merge(route, options)` or `endpoint.merge(options)`
|
||||
|
||||
Get the defaulted endpoint options, but without parsing them into request options:
|
||||
|
||||
```js
|
||||
const myProjectEndpoint = endpoint.defaults({
|
||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3",
|
||||
headers: {
|
||||
"user-agent": "myApp/1.2.3",
|
||||
},
|
||||
org: "my-project",
|
||||
});
|
||||
myProjectEndpoint.merge("GET /orgs/{org}/repos", {
|
||||
headers: {
|
||||
authorization: `token 0000000000000000000000000000000000000001`,
|
||||
},
|
||||
org: "my-secret-project",
|
||||
type: "private",
|
||||
});
|
||||
|
||||
// {
|
||||
// baseUrl: 'https://github-enterprise.acme-inc.com/api/v3',
|
||||
// method: 'GET',
|
||||
// url: '/orgs/{org}/repos',
|
||||
// headers: {
|
||||
// accept: 'application/vnd.github.v3+json',
|
||||
// authorization: `token 0000000000000000000000000000000000000001`,
|
||||
// 'user-agent': 'myApp/1.2.3'
|
||||
// },
|
||||
// org: 'my-secret-project',
|
||||
// type: 'private'
|
||||
// }
|
||||
```
|
||||
|
||||
### `endpoint.parse()`
|
||||
|
||||
Stateless method to turn endpoint options into request options. Calling
|
||||
`endpoint(options)` is the same as calling `endpoint.parse(endpoint.merge(options))`.
|
||||
|
||||
## Special cases
|
||||
|
||||
<a name="data-parameter"></a>
|
||||
|
||||
### The `data` parameter – set request body directly
|
||||
|
||||
Some endpoints such as [Render a Markdown document in raw mode](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode) don’t have parameters that are sent as request body keys, instead, the request body needs to be set directly. In these cases, set the `data` parameter.
|
||||
|
||||
```js
|
||||
const options = endpoint("POST /markdown/raw", {
|
||||
data: "Hello world github/linguist#1 **cool**, and #1!",
|
||||
headers: {
|
||||
accept: "text/html;charset=utf-8",
|
||||
"content-type": "text/plain",
|
||||
},
|
||||
});
|
||||
|
||||
// options is
|
||||
// {
|
||||
// method: 'post',
|
||||
// url: 'https://api.github.com/markdown/raw',
|
||||
// headers: {
|
||||
// accept: 'text/html;charset=utf-8',
|
||||
// 'content-type': 'text/plain',
|
||||
// 'user-agent': userAgent
|
||||
// },
|
||||
// body: 'Hello world github/linguist#1 **cool**, and #1!'
|
||||
// }
|
||||
```
|
||||
|
||||
### Set parameters for both the URL/query and the request body
|
||||
|
||||
There are API endpoints that accept both query parameters as well as a body. In that case, you need to add the query parameters as templates to `options.url`, as defined in the [RFC 6570 URI Template specification](https://tools.ietf.org/html/rfc6570).
|
||||
|
||||
Example
|
||||
|
||||
```js
|
||||
endpoint(
|
||||
"POST https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",
|
||||
{
|
||||
name: "example.zip",
|
||||
label: "short description",
|
||||
headers: {
|
||||
"content-type": "text/plain",
|
||||
"content-length": 14,
|
||||
authorization: `token 0000000000000000000000000000000000000001`,
|
||||
},
|
||||
data: "Hello, world!",
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
## LICENSE
|
||||
|
||||
[MIT](LICENSE)
|
||||
@@ -0,0 +1,23 @@
|
||||
/// <reference types="node" />
|
||||
import net from 'net';
|
||||
import tls from 'tls';
|
||||
import { Url } from 'url';
|
||||
import { AgentOptions } from 'agent-base';
|
||||
import { OutgoingHttpHeaders } from 'http';
|
||||
import _HttpsProxyAgent from './agent';
|
||||
declare function createHttpsProxyAgent(opts: string | createHttpsProxyAgent.HttpsProxyAgentOptions): _HttpsProxyAgent;
|
||||
declare namespace createHttpsProxyAgent {
|
||||
interface BaseHttpsProxyAgentOptions {
|
||||
headers?: OutgoingHttpHeaders;
|
||||
secureProxy?: boolean;
|
||||
host?: string | null;
|
||||
path?: string | null;
|
||||
port?: string | number | null;
|
||||
}
|
||||
export interface HttpsProxyAgentOptions extends AgentOptions, BaseHttpsProxyAgentOptions, Partial<Omit<Url & net.NetConnectOpts & tls.ConnectionOptions, keyof BaseHttpsProxyAgentOptions>> {
|
||||
}
|
||||
export type HttpsProxyAgent = _HttpsProxyAgent;
|
||||
export const HttpsProxyAgent: typeof _HttpsProxyAgent;
|
||||
export {};
|
||||
}
|
||||
export = createHttpsProxyAgent;
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
Returns the type that is wrapped inside a `Promise` type.
|
||||
If the type is a nested Promise, it is unwrapped recursively until a non-Promise type is obtained.
|
||||
If the type is not a `Promise`, the type itself is returned.
|
||||
|
||||
@example
|
||||
```
|
||||
import {PromiseValue} from 'type-fest';
|
||||
|
||||
type AsyncData = Promise<string>;
|
||||
let asyncData: PromiseValue<AsyncData> = Promise.resolve('ABC');
|
||||
|
||||
type Data = PromiseValue<AsyncData>;
|
||||
let data: Data = await asyncData;
|
||||
|
||||
// Here's an example that shows how this type reacts to non-Promise types.
|
||||
type SyncData = PromiseValue<string>;
|
||||
let syncData: SyncData = getSyncData();
|
||||
|
||||
// Here's an example that shows how this type reacts to recursive Promise types.
|
||||
type RecursiveAsyncData = Promise<Promise<string> >;
|
||||
let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = Promise.resolve(Promise.resolve('ABC'));
|
||||
```
|
||||
|
||||
@category Utilities
|
||||
*/
|
||||
export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
|
||||
? { 0: PromiseValue<Value>; 1: Value }[PromiseType extends Promise<unknown> ? 0 : 1]
|
||||
: Otherwise;
|
||||
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
var isNegativeZero = require('is-negative-zero');
|
||||
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
|
||||
var Type = require('../Type');
|
||||
var NumberSameValueZero = require('./sameValueZero');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-numeric-types-number-sameValue
|
||||
|
||||
module.exports = function NumberSameValue(x, y) {
|
||||
if (Type(x) !== 'Number' || Type(y) !== 'Number') {
|
||||
throw new $TypeError('Assertion failed: `x` and `y` arguments must be Numbers');
|
||||
}
|
||||
if (x === 0 && y === 0) {
|
||||
return !(isNegativeZero(x) ^ isNegativeZero(y));
|
||||
}
|
||||
return NumberSameValueZero(x, y);
|
||||
};
|
||||
@@ -0,0 +1,314 @@
|
||||
<h1 align="center">
|
||||
<br>
|
||||
<br>
|
||||
<img width="320" src="media/logo.svg" alt="Chalk">
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
</h1>
|
||||
|
||||
> Terminal string styling done right
|
||||
|
||||
[](https://travis-ci.org/chalk/chalk) [](https://coveralls.io/github/chalk/chalk?branch=master) [](https://www.youtube.com/watch?v=9auOCbH5Ns4) [](https://github.com/xojs/xo) [](https://github.com/sindresorhus/awesome-nodejs)
|
||||
|
||||
### [See what's new in Chalk 2](https://github.com/chalk/chalk/releases/tag/v2.0.0)
|
||||
|
||||
<img src="https://cdn.rawgit.com/chalk/ansi-styles/8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" alt="" width="900">
|
||||
|
||||
|
||||
## Highlights
|
||||
|
||||
- Expressive API
|
||||
- Highly performant
|
||||
- Ability to nest styles
|
||||
- [256/Truecolor color support](#256-and-truecolor-color-support)
|
||||
- Auto-detects color support
|
||||
- Doesn't extend `String.prototype`
|
||||
- Clean and focused
|
||||
- Actively maintained
|
||||
- [Used by ~23,000 packages](https://www.npmjs.com/browse/depended/chalk) as of December 31, 2017
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```console
|
||||
$ npm install chalk
|
||||
```
|
||||
|
||||
<a href="https://www.patreon.com/sindresorhus">
|
||||
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
|
||||
</a>
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const chalk = require('chalk');
|
||||
|
||||
console.log(chalk.blue('Hello world!'));
|
||||
```
|
||||
|
||||
Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
|
||||
|
||||
```js
|
||||
const chalk = require('chalk');
|
||||
const log = console.log;
|
||||
|
||||
// Combine styled and normal strings
|
||||
log(chalk.blue('Hello') + ' World' + chalk.red('!'));
|
||||
|
||||
// Compose multiple styles using the chainable API
|
||||
log(chalk.blue.bgRed.bold('Hello world!'));
|
||||
|
||||
// Pass in multiple arguments
|
||||
log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
|
||||
|
||||
// Nest styles
|
||||
log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
|
||||
|
||||
// Nest styles of the same type even (color, underline, background)
|
||||
log(chalk.green(
|
||||
'I am a green line ' +
|
||||
chalk.blue.underline.bold('with a blue substring') +
|
||||
' that becomes green again!'
|
||||
));
|
||||
|
||||
// ES2015 template literal
|
||||
log(`
|
||||
CPU: ${chalk.red('90%')}
|
||||
RAM: ${chalk.green('40%')}
|
||||
DISK: ${chalk.yellow('70%')}
|
||||
`);
|
||||
|
||||
// ES2015 tagged template literal
|
||||
log(chalk`
|
||||
CPU: {red ${cpu.totalPercent}%}
|
||||
RAM: {green ${ram.used / ram.total * 100}%}
|
||||
DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
|
||||
`);
|
||||
|
||||
// Use RGB colors in terminal emulators that support it.
|
||||
log(chalk.keyword('orange')('Yay for orange colored text!'));
|
||||
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
|
||||
log(chalk.hex('#DEADED').bold('Bold gray!'));
|
||||
```
|
||||
|
||||
Easily define your own themes:
|
||||
|
||||
```js
|
||||
const chalk = require('chalk');
|
||||
|
||||
const error = chalk.bold.red;
|
||||
const warning = chalk.keyword('orange');
|
||||
|
||||
console.log(error('Error!'));
|
||||
console.log(warning('Warning!'));
|
||||
```
|
||||
|
||||
Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args):
|
||||
|
||||
```js
|
||||
const name = 'Sindre';
|
||||
console.log(chalk.green('Hello %s'), name);
|
||||
//=> 'Hello Sindre'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### chalk.`<style>[.<style>...](string, [string...])`
|
||||
|
||||
Example: `chalk.red.bold.underline('Hello', 'world');`
|
||||
|
||||
Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
|
||||
|
||||
Multiple arguments will be separated by space.
|
||||
|
||||
### chalk.enabled
|
||||
|
||||
Color support is automatically detected, as is the level (see `chalk.level`). However, if you'd like to simply enable/disable Chalk, you can do so via the `.enabled` property.
|
||||
|
||||
Chalk is enabled by default unless explicitly disabled via the constructor or `chalk.level` is `0`.
|
||||
|
||||
If you need to change this in a reusable module, create a new instance:
|
||||
|
||||
```js
|
||||
const ctx = new chalk.constructor({enabled: false});
|
||||
```
|
||||
|
||||
### chalk.level
|
||||
|
||||
Color support is automatically detected, but you can override it by setting the `level` property. You should however only do this in your own code as it applies globally to all Chalk consumers.
|
||||
|
||||
If you need to change this in a reusable module, create a new instance:
|
||||
|
||||
```js
|
||||
const ctx = new chalk.constructor({level: 0});
|
||||
```
|
||||
|
||||
Levels are as follows:
|
||||
|
||||
0. All colors disabled
|
||||
1. Basic color support (16 colors)
|
||||
2. 256 color support
|
||||
3. Truecolor support (16 million colors)
|
||||
|
||||
### chalk.supportsColor
|
||||
|
||||
Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
|
||||
|
||||
Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add the environment variable `FORCE_COLOR=1` to forcefully enable color or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
|
||||
|
||||
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
|
||||
|
||||
|
||||
## Styles
|
||||
|
||||
### Modifiers
|
||||
|
||||
- `reset`
|
||||
- `bold`
|
||||
- `dim`
|
||||
- `italic` *(Not widely supported)*
|
||||
- `underline`
|
||||
- `inverse`
|
||||
- `hidden`
|
||||
- `strikethrough` *(Not widely supported)*
|
||||
- `visible` (Text is emitted only if enabled)
|
||||
|
||||
### Colors
|
||||
|
||||
- `black`
|
||||
- `red`
|
||||
- `green`
|
||||
- `yellow`
|
||||
- `blue` *(On Windows the bright version is used since normal blue is illegible)*
|
||||
- `magenta`
|
||||
- `cyan`
|
||||
- `white`
|
||||
- `gray` ("bright black")
|
||||
- `redBright`
|
||||
- `greenBright`
|
||||
- `yellowBright`
|
||||
- `blueBright`
|
||||
- `magentaBright`
|
||||
- `cyanBright`
|
||||
- `whiteBright`
|
||||
|
||||
### Background colors
|
||||
|
||||
- `bgBlack`
|
||||
- `bgRed`
|
||||
- `bgGreen`
|
||||
- `bgYellow`
|
||||
- `bgBlue`
|
||||
- `bgMagenta`
|
||||
- `bgCyan`
|
||||
- `bgWhite`
|
||||
- `bgBlackBright`
|
||||
- `bgRedBright`
|
||||
- `bgGreenBright`
|
||||
- `bgYellowBright`
|
||||
- `bgBlueBright`
|
||||
- `bgMagentaBright`
|
||||
- `bgCyanBright`
|
||||
- `bgWhiteBright`
|
||||
|
||||
|
||||
## Tagged template literal
|
||||
|
||||
Chalk can be used as a [tagged template literal](http://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
|
||||
|
||||
```js
|
||||
const chalk = require('chalk');
|
||||
|
||||
const miles = 18;
|
||||
const calculateFeet = miles => miles * 5280;
|
||||
|
||||
console.log(chalk`
|
||||
There are {bold 5280 feet} in a mile.
|
||||
In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.
|
||||
`);
|
||||
```
|
||||
|
||||
Blocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).
|
||||
|
||||
Template styles are chained exactly like normal Chalk styles. The following two statements are equivalent:
|
||||
|
||||
```js
|
||||
console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
|
||||
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
|
||||
```
|
||||
|
||||
Note that function styles (`rgb()`, `hsl()`, `keyword()`, etc.) may not contain spaces between parameters.
|
||||
|
||||
All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
|
||||
|
||||
|
||||
## 256 and Truecolor color support
|
||||
|
||||
Chalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.
|
||||
|
||||
Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying `{level: n}` as a Chalk option). For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).
|
||||
|
||||
Examples:
|
||||
|
||||
- `chalk.hex('#DEADED').underline('Hello, world!')`
|
||||
- `chalk.keyword('orange')('Some orange text')`
|
||||
- `chalk.rgb(15, 100, 204).inverse('Hello!')`
|
||||
|
||||
Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `keyword` for foreground colors and `bgKeyword` for background colors).
|
||||
|
||||
- `chalk.bgHex('#DEADED').underline('Hello, world!')`
|
||||
- `chalk.bgKeyword('orange')('Some orange text')`
|
||||
- `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
|
||||
|
||||
The following color models can be used:
|
||||
|
||||
- [`rgb`](https://en.wikipedia.org/wiki/RGB_color_model) - Example: `chalk.rgb(255, 136, 0).bold('Orange!')`
|
||||
- [`hex`](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) - Example: `chalk.hex('#FF8800').bold('Orange!')`
|
||||
- [`keyword`](https://www.w3.org/wiki/CSS/Properties/color/keywords) (CSS keywords) - Example: `chalk.keyword('orange').bold('Orange!')`
|
||||
- [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')`
|
||||
- [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsv(32, 100, 100).bold('Orange!')`
|
||||
- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hwb(32, 0, 50).bold('Orange!')`
|
||||
- `ansi16`
|
||||
- `ansi256`
|
||||
|
||||
|
||||
## Windows
|
||||
|
||||
If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) instead of `cmd.exe`.
|
||||
|
||||
|
||||
## Origin story
|
||||
|
||||
[colors.js](https://github.com/Marak/colors.js) used to be the most popular string styling module, but it has serious deficiencies like extending `String.prototype` which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68) and the package is unmaintained. Although there are other packages, they either do too much or not enough. Chalk is a clean and focused alternative.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
|
||||
- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
|
||||
- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
|
||||
- [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
|
||||
- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Strip ANSI escape codes from a stream
|
||||
- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
|
||||
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
|
||||
- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
|
||||
- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
|
||||
- [color-convert](https://github.com/qix-/color-convert) - Converts colors between different models
|
||||
- [chalk-animation](https://github.com/bokub/chalk-animation) - Animate strings in the terminal
|
||||
- [gradient-string](https://github.com/bokub/gradient-string) - Apply color gradients to strings
|
||||
- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
|
||||
- [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal
|
||||
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Josh Junon](https://github.com/qix-)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"bufferWhen.d.ts","sourceRoot":"","sources":["../../../../src/internal/operators/bufferWhen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAM7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAgDnG"}
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"is-set","version":"2.0.2","files":{".eslintignore":{"checkedAt":1678883671537,"integrity":"sha512-VLhEcqup3IHXtZJPt07ZYoA9JNRjy1jhU/NU41Yw4E8mEyea/z+6bw5hL3lhCO09pji9E0BH2Q3aDXdc3i9zBg==","mode":420,"size":10},".nycrc":{"checkedAt":1678883671537,"integrity":"sha512-42sgwWzusJB1Dzhl78jX/Zg65Oi0HDDMOGXS/Uklv1kCYn4fHtRsD/JFPwdu+d40vome9XdUspzRWEQAcTGEeQ==","mode":420,"size":216},".editorconfig":{"checkedAt":1678883671904,"integrity":"sha512-EfglD8RrTnjtZ2q5HL0nkylOeED9bGeGjum405wtJB5wftOXyKDubHruyUm4yPsMpMtywRmqyPiR7zGKNImhWw==","mode":420,"size":231},".eslintrc":{"checkedAt":1678883671904,"integrity":"sha512-iNOkLDjSOflWx+gt8IfCZ1/jN5QRspbEMElVf5HoQbWoP9Aw+wRSirZi3GeyXRd5W4Is+Q4WWcntlUCJd+y1dQ==","mode":420,"size":162},".gitattributes":{"checkedAt":1678883671904,"integrity":"sha512-DXomms2sviS9F4bmidCOamSsDhLno7TVvrpH9f7IgaHcUwkhPkrdIXAMHYJdsFHW25Nyx1XXTY3RUIR9pDZyKw==","mode":420,"size":12},"LICENSE":{"checkedAt":1678883671904,"integrity":"sha512-MhC2ouUwYbb45JeIJX0d4ULwmtY3oOFi36RC0eoiJCQXhddI1K2UX0Ff+/tdNw2gLzmJqFZCuegpEH+10gofDA==","mode":420,"size":1067},"index.js":{"checkedAt":1678883671904,"integrity":"sha512-fsWxC/fOGxRnce4F8dmXtvu/B8MenIOomoSE2h54/yAzuoxJtPDEFJW4cvDPICubrE2uyM3gKJDwQTn3Uh8D/g==","mode":420,"size":904},"test/index.js":{"checkedAt":1678883671904,"integrity":"sha512-olKfZBtgkwnOm9F9OLVEL+MOKpBXhg9WPAAxo8pzJO9ToO7sJnqoSFijNRoVGPq9Jpas7822HAqxRZ3x8jALQg==","mode":420,"size":1102},"package.json":{"checkedAt":1678883671904,"integrity":"sha512-cZxUkFLbcG5BeMw5HPoSAlvZi5cAf+/uPGoYGfce/ghuJhHsd31UAHPf6dDmZIQZittYum6GbtmmqkVZaO0u7Q==","mode":420,"size":1759},"CHANGELOG.md":{"checkedAt":1678883671908,"integrity":"sha512-oaFvQ3hQG+ZjIGv1NCNwgQBQwx6P16/orgA5QbL+xirqhh4NL//FJJ2H3icwvwkJneOk6p7iQXgJz2KhrVhqfw==","mode":420,"size":4876},"README.md":{"checkedAt":1678883671908,"integrity":"sha512-f9QXyXxpeOvApVnMV7Y0m0dMbe20vevjhsk0ZWyZtmXwCr+yWD/VyDYxDa529Dqxk+B1y+H2+pECIksBBq6cuA==","mode":420,"size":1374},".github/FUNDING.yml":{"checkedAt":1678883671908,"integrity":"sha512-UfvldzwxgtQsLKSC5OQuKu7JpkTIi4SoKnVEcqXTL4A36XiRmGorI7Mtptw9cRwgO20rTdTdpPctHX0sBltdOA==","mode":420,"size":577}}}
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
lazyPostcss: ()=>lazyPostcss,
|
||||
lazyPostcssImport: ()=>lazyPostcssImport,
|
||||
lazyAutoprefixer: ()=>lazyAutoprefixer,
|
||||
lazyCssnano: ()=>lazyCssnano
|
||||
});
|
||||
function lazyPostcss() {
|
||||
return require("postcss");
|
||||
}
|
||||
function lazyPostcssImport() {
|
||||
return require("postcss-import");
|
||||
}
|
||||
function lazyAutoprefixer() {
|
||||
return require("autoprefixer");
|
||||
}
|
||||
function lazyCssnano() {
|
||||
return require("cssnano");
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var common = require('./common');
|
||||
var glob = require('glob');
|
||||
|
||||
var globPatternRecursive = path.sep + '**';
|
||||
|
||||
common.register('ls', _ls, {
|
||||
cmdOptions: {
|
||||
'R': 'recursive',
|
||||
'A': 'all',
|
||||
'L': 'link',
|
||||
'a': 'all_deprecated',
|
||||
'd': 'directory',
|
||||
'l': 'long',
|
||||
},
|
||||
});
|
||||
|
||||
//@
|
||||
//@ ### ls([options,] [path, ...])
|
||||
//@ ### ls([options,] path_array)
|
||||
//@
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-R`: recursive
|
||||
//@ + `-A`: all files (include files beginning with `.`, except for `.` and `..`)
|
||||
//@ + `-L`: follow symlinks
|
||||
//@ + `-d`: list directories themselves, not their contents
|
||||
//@ + `-l`: list objects representing each file, each with fields containing `ls
|
||||
//@ -l` output fields. See
|
||||
//@ [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
||||
//@ for more info
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ ls('projs/*.js');
|
||||
//@ ls('-R', '/users/me', '/tmp');
|
||||
//@ ls('-R', ['/users/me', '/tmp']); // same as above
|
||||
//@ ls('-l', 'file.txt'); // { name: 'file.txt', mode: 33188, nlink: 1, ...}
|
||||
//@ ```
|
||||
//@
|
||||
//@ Returns array of files in the given `path`, or files in
|
||||
//@ the current directory if no `path` is provided.
|
||||
function _ls(options, paths) {
|
||||
if (options.all_deprecated) {
|
||||
// We won't support the -a option as it's hard to image why it's useful
|
||||
// (it includes '.' and '..' in addition to '.*' files)
|
||||
// For backwards compatibility we'll dump a deprecated message and proceed as before
|
||||
common.log('ls: Option -a is deprecated. Use -A instead');
|
||||
options.all = true;
|
||||
}
|
||||
|
||||
if (!paths) {
|
||||
paths = ['.'];
|
||||
} else {
|
||||
paths = [].slice.call(arguments, 1);
|
||||
}
|
||||
|
||||
var list = [];
|
||||
|
||||
function pushFile(abs, relName, stat) {
|
||||
if (process.platform === 'win32') {
|
||||
relName = relName.replace(/\\/g, '/');
|
||||
}
|
||||
if (options.long) {
|
||||
stat = stat || (options.link ? common.statFollowLinks(abs) : common.statNoFollowLinks(abs));
|
||||
list.push(addLsAttributes(relName, stat));
|
||||
} else {
|
||||
// list.push(path.relative(rel || '.', file));
|
||||
list.push(relName);
|
||||
}
|
||||
}
|
||||
|
||||
paths.forEach(function (p) {
|
||||
var stat;
|
||||
|
||||
try {
|
||||
stat = options.link ? common.statFollowLinks(p) : common.statNoFollowLinks(p);
|
||||
// follow links to directories by default
|
||||
if (stat.isSymbolicLink()) {
|
||||
/* istanbul ignore next */
|
||||
// workaround for https://github.com/shelljs/shelljs/issues/795
|
||||
// codecov seems to have a bug that miscalculate this block as uncovered.
|
||||
// but according to nyc report this block does get covered.
|
||||
try {
|
||||
var _stat = common.statFollowLinks(p);
|
||||
if (_stat.isDirectory()) {
|
||||
stat = _stat;
|
||||
}
|
||||
} catch (_) {} // bad symlink, treat it like a file
|
||||
}
|
||||
} catch (e) {
|
||||
common.error('no such file or directory: ' + p, 2, { continue: true });
|
||||
return;
|
||||
}
|
||||
|
||||
// If the stat succeeded
|
||||
if (stat.isDirectory() && !options.directory) {
|
||||
if (options.recursive) {
|
||||
// use glob, because it's simple
|
||||
glob.sync(p + globPatternRecursive, { dot: options.all, follow: options.link })
|
||||
.forEach(function (item) {
|
||||
// Glob pattern returns the directory itself and needs to be filtered out.
|
||||
if (path.relative(p, item)) {
|
||||
pushFile(item, path.relative(p, item));
|
||||
}
|
||||
});
|
||||
} else if (options.all) {
|
||||
// use fs.readdirSync, because it's fast
|
||||
fs.readdirSync(p).forEach(function (item) {
|
||||
pushFile(path.join(p, item), item);
|
||||
});
|
||||
} else {
|
||||
// use fs.readdirSync and then filter out secret files
|
||||
fs.readdirSync(p).forEach(function (item) {
|
||||
if (item[0] !== '.') {
|
||||
pushFile(path.join(p, item), item);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
pushFile(p, p, stat);
|
||||
}
|
||||
});
|
||||
|
||||
// Add methods, to make this more compatible with ShellStrings
|
||||
return list;
|
||||
}
|
||||
|
||||
function addLsAttributes(pathName, stats) {
|
||||
// Note: this object will contain more information than .toString() returns
|
||||
stats.name = pathName;
|
||||
stats.toString = function () {
|
||||
// Return a string resembling unix's `ls -l` format
|
||||
return [this.mode, this.nlink, this.uid, this.gid, this.size, this.mtime, this.name].join(' ');
|
||||
};
|
||||
return stats;
|
||||
}
|
||||
|
||||
module.exports = _ls;
|
||||
@@ -0,0 +1,14 @@
|
||||
import { operate } from '../util/lift';
|
||||
import { createOperatorSubscriber } from './OperatorSubscriber';
|
||||
export function isEmpty() {
|
||||
return operate(function (source, subscriber) {
|
||||
source.subscribe(createOperatorSubscriber(subscriber, function () {
|
||||
subscriber.next(false);
|
||||
subscriber.complete();
|
||||
}, function () {
|
||||
subscriber.next(true);
|
||||
subscriber.complete();
|
||||
}));
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=isEmpty.js.map
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"J D E F A B CC"},B:{"1":"C K L G M N O P Q R S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H"},C:{"1":"0 1 2 3 4 5 6 7 8 9 G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H xB yB","2":"DC tB I v J D E F A B C K L EC FC"},D:{"1":"NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H xB yB GC","2":"0 1 2 3 4 5 6 7 8 9 I v J D E F A B C K L G M N O w g x y z AB BB CB DB EB FB GB HB IB JB","194":"KB LB MB"},E:{"1":"A B C K L G 0B qB rB 1B MC NC 2B 3B 4B 5B sB 6B 7B 8B 9B OC","2":"I v J D E F HC zB IC JC KC LC"},F:{"1":"AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d e","2":"0 1 2 3 4 5 6 F B C G M N O w g x y z PC QC RC SC qB AC TC rB","194":"7 8 9"},G:{"1":"bC cC dC eC fC gC hC iC jC kC lC mC nC 2B 3B 4B 5B sB 6B 7B 8B 9B","2":"E zB UC BC VC WC XC YC ZC aC"},H:{"2":"oC"},I:{"1":"f","2":"tB I pC qC rC sC BC tC uC"},J:{"2":"D A"},K:{"1":"h","2":"A B C qB AC rB"},L:{"1":"H"},M:{"1":"H"},N:{"2":"A B"},O:{"1":"vC"},P:{"1":"g wC xC yC zC 0C 0B 1C 2C 3C 4C 5C sB 6C 7C 8C","2":"I"},Q:{"1":"1B"},R:{"1":"9C"},S:{"1":"AD BD"}},B:6,C:"Rest parameters"};
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
module.exports = function(det, rec, confidence, name, lang) {
|
||||
this.confidence = confidence;
|
||||
this.name = name || rec.name(det);
|
||||
this.lang = lang;
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0.00132,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0.00132,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0.00132,"98":0,"99":0,"100":0,"101":0,"102":0.00132,"103":0,"104":0,"105":0.00132,"106":0.00132,"107":0.00132,"108":0.00396,"109":0.08184,"110":0.04356,"111":0,"112":0,"3.5":0,"3.6":0},D:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0.00132,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0.00264,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0.00132,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0.00396,"80":0,"81":0.00132,"83":0.00132,"84":0.00132,"85":0.00132,"86":0.00132,"87":0.00264,"88":0.00132,"89":0,"90":0.00132,"91":0,"92":0.00132,"93":0,"94":0,"95":0,"96":0.00132,"97":0.00132,"98":0.00132,"99":0.00132,"100":0.00264,"101":0.00132,"102":0.00132,"103":0.00396,"104":0.00264,"105":0.00528,"106":0.00396,"107":0.0066,"108":0.0264,"109":0.7656,"110":0.37356,"111":0,"112":0,"113":0},F:{"9":0,"11":0,"12":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"60":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0.00132,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0.00132,"94":0.01716,"95":0.01452,"9.5-9.6":0,"10.0-10.1":0,"10.5":0,"10.6":0,"11.1":0,"11.5":0,"11.6":0,"12.1":0},B:{"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"79":0,"80":0,"81":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0.00132,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0.00132,"108":0.00396,"109":0.04224,"110":0.05016},E:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0.00132,"15":0.00132,_:"0","3.1":0,"3.2":0,"5.1":0,"6.1":0,"7.1":0,"9.1":0,"10.1":0,"11.1":0,"12.1":0,"13.1":0.00396,"14.1":0.00264,"15.1":0.00264,"15.2-15.3":0.00132,"15.4":0.00528,"15.5":0.00924,"15.6":0.03564,"16.0":0.00396,"16.1":0.01584,"16.2":0.033,"16.3":0.04224,"16.4":0},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0,"5.0-5.1":0,"6.0-6.1":0,"7.0-7.1":0.0492,"8.1-8.4":0,"9.0-9.2":0,"9.3":0.0246,"10.0-10.2":0.00984,"10.3":0.08365,"11.0-11.2":0.01476,"11.3-11.4":0.00984,"12.0-12.1":0.0246,"12.2-12.5":1.14645,"13.0-13.1":0.0246,"13.2":0.03444,"13.3":0.07873,"13.4-13.7":0.27554,"14.0-14.4":0.81678,"14.5-14.8":2.77018,"15.0-15.1":0.29522,"15.2-15.3":0.49696,"15.4":0.76758,"15.5":1.47612,"15.6":5.75193,"16.0":5.17133,"16.1":10.2098,"16.2":9.88014,"16.3":5.28942,"16.4":0.0246},P:{"4":0.11048,"20":0.75326,"5.0-5.4":0,"6.2-6.4":0,"7.2-7.4":0.0703,"8.2":0,"9.2":0.01004,"10.1":0,"11.1-11.2":0.04017,"12.0":0.01004,"13.0":0.05022,"14.0":0.04017,"15.0":0.06026,"16.0":0.06026,"17.0":0.05022,"18.0":0.06026,"19.0":1.30566},I:{"0":0,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0.00616,"4.2-4.3":0.00308,"4.4":0,"4.4.3-4.4.4":0.02001},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"6":0,"7":0,"8":0,"9":0,"10":0,"11":0.00132,"5.5":0},N:{"10":0,"11":0},S:{"2.5":0,_:"3.0-3.1"},J:{"7":0,"10":0},O:{"0":0.00868},H:{"0":0.07396},L:{"0":50.34328},R:{_:"0"},M:{"0":0.11284},Q:{"13.1":0}};
|
||||
@@ -0,0 +1,118 @@
|
||||
import assert from './_assert.js';
|
||||
import { Hash, createView, Input, toBytes } from './utils.js';
|
||||
|
||||
// Polyfill for Safari 14
|
||||
function setBigUint64(view: DataView, byteOffset: number, value: bigint, isLE: boolean): void {
|
||||
if (typeof view.setBigUint64 === 'function') return view.setBigUint64(byteOffset, value, isLE);
|
||||
const _32n = BigInt(32);
|
||||
const _u32_max = BigInt(0xffffffff);
|
||||
const wh = Number((value >> _32n) & _u32_max);
|
||||
const wl = Number(value & _u32_max);
|
||||
const h = isLE ? 4 : 0;
|
||||
const l = isLE ? 0 : 4;
|
||||
view.setUint32(byteOffset + h, wh, isLE);
|
||||
view.setUint32(byteOffset + l, wl, isLE);
|
||||
}
|
||||
|
||||
// Base SHA2 class (RFC 6234)
|
||||
export abstract class SHA2<T extends SHA2<T>> extends Hash<T> {
|
||||
protected abstract process(buf: DataView, offset: number): void;
|
||||
protected abstract get(): number[];
|
||||
protected abstract set(...args: number[]): void;
|
||||
abstract destroy(): void;
|
||||
protected abstract roundClean(): void;
|
||||
// For partial updates less than block size
|
||||
protected buffer: Uint8Array;
|
||||
protected view: DataView;
|
||||
protected finished = false;
|
||||
protected length = 0;
|
||||
protected pos = 0;
|
||||
protected destroyed = false;
|
||||
|
||||
constructor(
|
||||
readonly blockLen: number,
|
||||
public outputLen: number,
|
||||
readonly padOffset: number,
|
||||
readonly isLE: boolean
|
||||
) {
|
||||
super();
|
||||
this.buffer = new Uint8Array(blockLen);
|
||||
this.view = createView(this.buffer);
|
||||
}
|
||||
update(data: Input): this {
|
||||
assert.exists(this);
|
||||
const { view, buffer, blockLen } = this;
|
||||
data = toBytes(data);
|
||||
const len = data.length;
|
||||
for (let pos = 0; pos < len; ) {
|
||||
const take = Math.min(blockLen - this.pos, len - pos);
|
||||
// Fast path: we have at least one block in input, cast it to view and process
|
||||
if (take === blockLen) {
|
||||
const dataView = createView(data);
|
||||
for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
|
||||
continue;
|
||||
}
|
||||
buffer.set(data.subarray(pos, pos + take), this.pos);
|
||||
this.pos += take;
|
||||
pos += take;
|
||||
if (this.pos === blockLen) {
|
||||
this.process(view, 0);
|
||||
this.pos = 0;
|
||||
}
|
||||
}
|
||||
this.length += data.length;
|
||||
this.roundClean();
|
||||
return this;
|
||||
}
|
||||
digestInto(out: Uint8Array) {
|
||||
assert.exists(this);
|
||||
assert.output(out, this);
|
||||
this.finished = true;
|
||||
// Padding
|
||||
// We can avoid allocation of buffer for padding completely if it
|
||||
// was previously not allocated here. But it won't change performance.
|
||||
const { buffer, view, blockLen, isLE } = this;
|
||||
let { pos } = this;
|
||||
// append the bit '1' to the message
|
||||
buffer[pos++] = 0b10000000;
|
||||
this.buffer.subarray(pos).fill(0);
|
||||
// we have less than padOffset left in buffer, so we cannot put length in current block, need process it and pad again
|
||||
if (this.padOffset > blockLen - pos) {
|
||||
this.process(view, 0);
|
||||
pos = 0;
|
||||
}
|
||||
// Pad until full block byte with zeros
|
||||
for (let i = pos; i < blockLen; i++) buffer[i] = 0;
|
||||
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
||||
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
||||
// So we just write lowest 64 bits of that value.
|
||||
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
||||
this.process(view, 0);
|
||||
const oview = createView(out);
|
||||
const len = this.outputLen;
|
||||
// NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
|
||||
if (len % 4) throw new Error('_sha2: outputLen should be aligned to 32bit');
|
||||
const outLen = len / 4;
|
||||
const state = this.get();
|
||||
if (outLen > state.length) throw new Error('_sha2: outputLen bigger than state');
|
||||
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
|
||||
}
|
||||
digest() {
|
||||
const { buffer, outputLen } = this;
|
||||
this.digestInto(buffer);
|
||||
const res = buffer.slice(0, outputLen);
|
||||
this.destroy();
|
||||
return res;
|
||||
}
|
||||
_cloneInto(to?: T): T {
|
||||
to ||= new (this.constructor as any)() as T;
|
||||
to.set(...this.get());
|
||||
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
||||
to.length = length;
|
||||
to.pos = pos;
|
||||
to.finished = finished;
|
||||
to.destroyed = destroyed;
|
||||
if (length % blockLen) to.buffer.set(buffer);
|
||||
return to;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
var REMOTE_RESOURCE_PATTERN = /^(\w+:\/\/|\/\/)/;
|
||||
|
||||
function isRemoteResource(uri) {
|
||||
return REMOTE_RESOURCE_PATTERN.test(uri);
|
||||
}
|
||||
|
||||
module.exports = isRemoteResource;
|
||||
@@ -0,0 +1,8 @@
|
||||
const logSymbols = {
|
||||
info: 'ℹ️',
|
||||
success: '✅',
|
||||
warning: '⚠️',
|
||||
error: '❌️',
|
||||
};
|
||||
|
||||
export default logSymbols;
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
var isPrototype = require("../prototype/is");
|
||||
|
||||
// In theory we could rely on Symbol.toStringTag directly,
|
||||
// still early native implementation (e.g. in FF) predated symbols
|
||||
var objectToString = Object.prototype.toString, objectTaggedString = objectToString.call(new Map());
|
||||
|
||||
module.exports = function (value) {
|
||||
if (!value) return false;
|
||||
|
||||
// Sanity check (reject objects which do not expose common Promise interface)
|
||||
try {
|
||||
if (typeof value.set !== "function") return false;
|
||||
if (typeof value.get !== "function") return false;
|
||||
if (typeof value.has !== "function") return false;
|
||||
if (typeof value.clear !== "function") return false;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure its native Promise object (has [[MapData]] slot)
|
||||
// Note: it's not 100% precise as string tag may be overriden
|
||||
// and other objects could be hacked to expose it
|
||||
if (objectToString.call(value) !== objectTaggedString) return false;
|
||||
|
||||
return !isPrototype(value);
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
# define-properties <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||
|
||||
[![github actions][actions-image]][actions-url]
|
||||
[![coverage][codecov-image]][codecov-url]
|
||||
[![dependency status][deps-svg]][deps-url]
|
||||
[![dev dependency status][dev-deps-svg]][dev-deps-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
[![npm badge][npm-badge-png]][package-url]
|
||||
|
||||
Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.
|
||||
Existing properties are not overridden. Accepts a map of property names to a predicate that, when true, force-overrides.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var define = require('define-properties');
|
||||
var assert = require('assert');
|
||||
|
||||
var obj = define({ a: 1, b: 2 }, {
|
||||
a: 10,
|
||||
b: 20,
|
||||
c: 30
|
||||
});
|
||||
assert(obj.a === 1);
|
||||
assert(obj.b === 2);
|
||||
assert(obj.c === 30);
|
||||
if (define.supportsDescriptors) {
|
||||
assert.deepEqual(Object.keys(obj), ['a', 'b']);
|
||||
assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'c'), {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
value: 30,
|
||||
writable: false
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
Then, with predicates:
|
||||
```js
|
||||
var define = require('define-properties');
|
||||
var assert = require('assert');
|
||||
|
||||
var obj = define({ a: 1, b: 2, c: 3 }, {
|
||||
a: 10,
|
||||
b: 20,
|
||||
c: 30
|
||||
}, {
|
||||
a: function () { return false; },
|
||||
b: function () { return true; }
|
||||
});
|
||||
assert(obj.a === 1);
|
||||
assert(obj.b === 20);
|
||||
assert(obj.c === 3);
|
||||
if (define.supportsDescriptors) {
|
||||
assert.deepEqual(Object.keys(obj), ['a', 'c']);
|
||||
assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'b'), {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
value: 20,
|
||||
writable: false
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Tests
|
||||
Simply clone the repo, `npm install`, and run `npm test`
|
||||
|
||||
[package-url]: https://npmjs.org/package/define-properties
|
||||
[npm-version-svg]: https://versionbadg.es/ljharb/define-properties.svg
|
||||
[deps-svg]: https://david-dm.org/ljharb/define-properties.svg
|
||||
[deps-url]: https://david-dm.org/ljharb/define-properties
|
||||
[dev-deps-svg]: https://david-dm.org/ljharb/define-properties/dev-status.svg
|
||||
[dev-deps-url]: https://david-dm.org/ljharb/define-properties#info=devDependencies
|
||||
[npm-badge-png]: https://nodei.co/npm/define-properties.png?downloads=true&stars=true
|
||||
[license-image]: https://img.shields.io/npm/l/define-properties.svg
|
||||
[license-url]: LICENSE
|
||||
[downloads-image]: https://img.shields.io/npm/dm/define-properties.svg
|
||||
[downloads-url]: https://npm-stat.com/charts.html?package=define-properties
|
||||
[codecov-image]: https://codecov.io/gh/ljharb/define-properties/branch/main/graphs/badge.svg
|
||||
[codecov-url]: https://app.codecov.io/gh/ljharb/define-properties/
|
||||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/define-properties
|
||||
[actions-url]: https://github.com/ljharb/define-properties/actions
|
||||
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var abs = require('./abs');
|
||||
var floor = require('./floor');
|
||||
var Type = require('./Type');
|
||||
|
||||
var $isNaN = require('../helpers/isNaN');
|
||||
var $isFinite = require('../helpers/isFinite');
|
||||
|
||||
// https://tc39.es/ecma262/#sec-isintegralnumber
|
||||
|
||||
module.exports = function IsIntegralNumber(argument) {
|
||||
if (Type(argument) !== 'Number' || $isNaN(argument) || !$isFinite(argument)) {
|
||||
return false;
|
||||
}
|
||||
var absValue = abs(argument);
|
||||
return floor(absValue) === absValue;
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
var callBind = require('../');
|
||||
var bind = require('function-bind');
|
||||
|
||||
var test = require('tape');
|
||||
|
||||
/*
|
||||
* older engines have length nonconfigurable
|
||||
* in io.js v3, it is configurable except on bound functions, hence the .bind()
|
||||
*/
|
||||
var functionsHaveConfigurableLengths = !!(
|
||||
Object.getOwnPropertyDescriptor
|
||||
&& Object.getOwnPropertyDescriptor(bind.call(function () {}), 'length').configurable
|
||||
);
|
||||
|
||||
test('callBind', function (t) {
|
||||
var sentinel = { sentinel: true };
|
||||
var func = function (a, b) {
|
||||
// eslint-disable-next-line no-invalid-this
|
||||
return [this, a, b];
|
||||
};
|
||||
t.equal(func.length, 2, 'original function length is 2');
|
||||
t.deepEqual(func(), [undefined, undefined, undefined], 'unbound func with too few args');
|
||||
t.deepEqual(func(1, 2), [undefined, 1, 2], 'unbound func with right args');
|
||||
t.deepEqual(func(1, 2, 3), [undefined, 1, 2], 'unbound func with too many args');
|
||||
|
||||
var bound = callBind(func);
|
||||
t.equal(bound.length, func.length + 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
|
||||
t.deepEqual(bound(), [undefined, undefined, undefined], 'bound func with too few args');
|
||||
t.deepEqual(bound(1, 2), [1, 2, undefined], 'bound func with right args');
|
||||
t.deepEqual(bound(1, 2, 3), [1, 2, 3], 'bound func with too many args');
|
||||
|
||||
var boundR = callBind(func, sentinel);
|
||||
t.equal(boundR.length, func.length, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
|
||||
t.deepEqual(boundR(), [sentinel, undefined, undefined], 'bound func with receiver, with too few args');
|
||||
t.deepEqual(boundR(1, 2), [sentinel, 1, 2], 'bound func with receiver, with right args');
|
||||
t.deepEqual(boundR(1, 2, 3), [sentinel, 1, 2], 'bound func with receiver, with too many args');
|
||||
|
||||
var boundArg = callBind(func, sentinel, 1);
|
||||
t.equal(boundArg.length, func.length - 1, 'function length is preserved', { skip: !functionsHaveConfigurableLengths });
|
||||
t.deepEqual(boundArg(), [sentinel, 1, undefined], 'bound func with receiver and arg, with too few args');
|
||||
t.deepEqual(boundArg(2), [sentinel, 1, 2], 'bound func with receiver and arg, with right arg');
|
||||
t.deepEqual(boundArg(2, 3), [sentinel, 1, 2], 'bound func with receiver and arg, with too many args');
|
||||
|
||||
t.test('callBind.apply', function (st) {
|
||||
var aBound = callBind.apply(func);
|
||||
st.deepEqual(aBound(sentinel), [sentinel, undefined, undefined], 'apply-bound func with no args');
|
||||
st.deepEqual(aBound(sentinel, [1], 4), [sentinel, 1, undefined], 'apply-bound func with too few args');
|
||||
st.deepEqual(aBound(sentinel, [1, 2], 4), [sentinel, 1, 2], 'apply-bound func with right args');
|
||||
|
||||
var aBoundArg = callBind.apply(func);
|
||||
st.deepEqual(aBoundArg(sentinel, [1, 2, 3], 4), [sentinel, 1, 2], 'apply-bound func with too many args');
|
||||
st.deepEqual(aBoundArg(sentinel, [1, 2], 4), [sentinel, 1, 2], 'apply-bound func with right args');
|
||||
st.deepEqual(aBoundArg(sentinel, [1], 4), [sentinel, 1, undefined], 'apply-bound func with too few args');
|
||||
|
||||
var aBoundR = callBind.apply(func, sentinel);
|
||||
st.deepEqual(aBoundR([1, 2, 3], 4), [sentinel, 1, 2], 'apply-bound func with receiver and too many args');
|
||||
st.deepEqual(aBoundR([1, 2], 4), [sentinel, 1, 2], 'apply-bound func with receiver and right args');
|
||||
st.deepEqual(aBoundR([1], 4), [sentinel, 1, undefined], 'apply-bound func with receiver and too few args');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
||||
if(typeof cptable === 'undefined') cptable = {};
|
||||
cptable[20105] = (function(){ var d = "<22><>\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#¤%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}‾∇<E280BE><E28887><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d.charAt(i)] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })();
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
if (!require("./is-implemented")()) {
|
||||
Object.defineProperty(Array.prototype, "keys", {
|
||||
value: require("./shim"),
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./async').reject;
|
||||
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
const aliases = ['stdin', 'stdout', 'stderr'];
|
||||
|
||||
const hasAlias = options => aliases.some(alias => options[alias] !== undefined);
|
||||
|
||||
const normalizeStdio = options => {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {stdio} = options;
|
||||
|
||||
if (stdio === undefined) {
|
||||
return aliases.map(alias => options[alias]);
|
||||
}
|
||||
|
||||
if (hasAlias(options)) {
|
||||
throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);
|
||||
}
|
||||
|
||||
if (typeof stdio === 'string') {
|
||||
return stdio;
|
||||
}
|
||||
|
||||
if (!Array.isArray(stdio)) {
|
||||
throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
|
||||
}
|
||||
|
||||
const length = Math.max(stdio.length, aliases.length);
|
||||
return Array.from({length}, (value, index) => stdio[index]);
|
||||
};
|
||||
|
||||
module.exports = normalizeStdio;
|
||||
|
||||
// `ipc` is pushed unless it is already present
|
||||
module.exports.node = options => {
|
||||
const stdio = normalizeStdio(options);
|
||||
|
||||
if (stdio === 'ipc') {
|
||||
return 'ipc';
|
||||
}
|
||||
|
||||
if (stdio === undefined || typeof stdio === 'string') {
|
||||
return [stdio, stdio, stdio, 'ipc'];
|
||||
}
|
||||
|
||||
if (stdio.includes('ipc')) {
|
||||
return stdio;
|
||||
}
|
||||
|
||||
return [...stdio, 'ipc'];
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
import { asyncScheduler } from '../scheduler/async';
|
||||
import { delayWhen } from './delayWhen';
|
||||
import { timer } from '../observable/timer';
|
||||
export function delay(due, scheduler = asyncScheduler) {
|
||||
const duration = timer(due, scheduler);
|
||||
return delayWhen(() => duration);
|
||||
}
|
||||
//# sourceMappingURL=delay.js.map
|
||||
@@ -0,0 +1,32 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import { Context } from 'vm';
|
||||
import { CompileOptions } from 'degenerator';
|
||||
/**
|
||||
* Returns an asynchronous `FindProxyForURL()` function
|
||||
* from the given JS string (from a PAC file).
|
||||
*
|
||||
* @param {String} str JS string
|
||||
* @param {Object} opts optional "options" object
|
||||
* @return {Function} async resolver function
|
||||
*/
|
||||
declare function createPacResolver(_str: string | Buffer, _opts?: createPacResolver.PacResolverOptions): {
|
||||
(url: string, host?: string): Promise<string>;
|
||||
(url: string, callback: createPacResolver.FindProxyForURLCallback): void;
|
||||
(url: string, host: string, callback: createPacResolver.FindProxyForURLCallback): void;
|
||||
};
|
||||
declare namespace createPacResolver {
|
||||
type GMT = 'GMT';
|
||||
type Hour = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23;
|
||||
type Day = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31;
|
||||
type Weekday = 'SUN' | 'MON' | 'TUE' | 'WED' | 'THU' | 'FRI' | 'SAT';
|
||||
type Month = 'JAN' | 'FEB' | 'MAR' | 'APR' | 'MAY' | 'JUN' | 'JUL' | 'AUG' | 'SEP' | 'OCT' | 'NOV' | 'DEC';
|
||||
interface PacResolverOptions extends CompileOptions {
|
||||
}
|
||||
interface FindProxyForURLCallback {
|
||||
(err?: Error | null, result?: string): void;
|
||||
}
|
||||
type FindProxyForURL = ReturnType<typeof createPacResolver>;
|
||||
const sandbox: Readonly<Context>;
|
||||
}
|
||||
export = createPacResolver;
|
||||
@@ -0,0 +1,5 @@
|
||||
var convert = require('./convert'),
|
||||
func = convert('camelCase', require('../camelCase'), require('./_falseOptions'));
|
||||
|
||||
func.placeholder = require('./placeholder');
|
||||
module.exports = func;
|
||||
@@ -0,0 +1,33 @@
|
||||
var test = require('tape');
|
||||
var wordwrap = require('../');
|
||||
|
||||
var fs = require('fs');
|
||||
var idleness = fs.readFileSync(__dirname + '/idleness.txt', 'utf8');
|
||||
|
||||
test('stop80', function (t) {
|
||||
var lines = wordwrap(80)(idleness).split(/\n/);
|
||||
var words = idleness.split(/\s+/);
|
||||
|
||||
lines.forEach(function (line) {
|
||||
t.ok(line.length <= 80, 'line > 80 columns');
|
||||
var chunks = line.match(/\S/) ? line.split(/\s+/) : [];
|
||||
t.deepEqual(chunks, words.splice(0, chunks.length));
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('start20stop60', function (t) {
|
||||
var lines = wordwrap(20, 100)(idleness).split(/\n/);
|
||||
var words = idleness.split(/\s+/);
|
||||
|
||||
lines.forEach(function (line) {
|
||||
t.ok(line.length <= 100, 'line > 100 columns');
|
||||
var chunks = line
|
||||
.split(/\s+/)
|
||||
.filter(function (x) { return x.match(/\S/) })
|
||||
;
|
||||
t.deepEqual(chunks, words.splice(0, chunks.length));
|
||||
t.deepEqual(line.slice(0, 20), new Array(20 + 1).join(' '));
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"Commands:": "命令:",
|
||||
"Options:": "选项:",
|
||||
"Examples:": "示例:",
|
||||
"boolean": "布尔",
|
||||
"count": "计数",
|
||||
"string": "字符串",
|
||||
"number": "数字",
|
||||
"array": "数组",
|
||||
"required": "必需",
|
||||
"default": "默认值",
|
||||
"default:": "默认值:",
|
||||
"choices:": "可选值:",
|
||||
"generated-value": "生成的值",
|
||||
"Not enough non-option arguments: got %s, need at least %s": {
|
||||
"one": "缺少 non-option 参数:传入了 %s 个, 至少需要 %s 个",
|
||||
"other": "缺少 non-option 参数:传入了 %s 个, 至少需要 %s 个"
|
||||
},
|
||||
"Too many non-option arguments: got %s, maximum of %s": {
|
||||
"one": "non-option 参数过多:传入了 %s 个, 最大允许 %s 个",
|
||||
"other": "non-option 参数过多:传入了 %s 个, 最大允许 %s 个"
|
||||
},
|
||||
"Missing argument value: %s": {
|
||||
"one": "没有给此选项指定值:%s",
|
||||
"other": "没有给这些选项指定值:%s"
|
||||
},
|
||||
"Missing required argument: %s": {
|
||||
"one": "缺少必须的选项:%s",
|
||||
"other": "缺少这些必须的选项:%s"
|
||||
},
|
||||
"Unknown argument: %s": {
|
||||
"one": "无法识别的选项:%s",
|
||||
"other": "无法识别这些选项:%s"
|
||||
},
|
||||
"Invalid values:": "无效的选项值:",
|
||||
"Argument: %s, Given: %s, Choices: %s": "选项名称: %s, 传入的值: %s, 可选的值:%s",
|
||||
"Argument check failed: %s": "选项值验证失败:%s",
|
||||
"Implications failed:": "缺少依赖的选项:",
|
||||
"Not enough arguments following: %s": "没有提供足够的值给此选项:%s",
|
||||
"Invalid JSON config file: %s": "无效的 JSON 配置文件:%s",
|
||||
"Path to JSON config file": "JSON 配置文件的路径",
|
||||
"Show help": "显示帮助信息",
|
||||
"Show version number": "显示版本号",
|
||||
"Did you mean %s?": "是指 %s?",
|
||||
"Arguments %s and %s are mutually exclusive" : "选项 %s 和 %s 是互斥的",
|
||||
"Positionals:": "位置:",
|
||||
"command": "命令"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
console.log('API usage not implemented yet...');
|
||||
@@ -0,0 +1,37 @@
|
||||
import * as base from './handlebars/base';
|
||||
|
||||
// Each of these augment the Handlebars object. No need to setup here.
|
||||
// (This is done to easily share code between commonjs and browse envs)
|
||||
import SafeString from './handlebars/safe-string';
|
||||
import Exception from './handlebars/exception';
|
||||
import * as Utils from './handlebars/utils';
|
||||
import * as runtime from './handlebars/runtime';
|
||||
|
||||
import noConflict from './handlebars/no-conflict';
|
||||
|
||||
// For compatibility and usage outside of module systems, make the Handlebars object a namespace
|
||||
function create() {
|
||||
let hb = new base.HandlebarsEnvironment();
|
||||
|
||||
Utils.extend(hb, base);
|
||||
hb.SafeString = SafeString;
|
||||
hb.Exception = Exception;
|
||||
hb.Utils = Utils;
|
||||
hb.escapeExpression = Utils.escapeExpression;
|
||||
|
||||
hb.VM = runtime;
|
||||
hb.template = function(spec) {
|
||||
return runtime.template(spec, hb);
|
||||
};
|
||||
|
||||
return hb;
|
||||
}
|
||||
|
||||
let inst = create();
|
||||
inst.create = create;
|
||||
|
||||
noConflict(inst);
|
||||
|
||||
inst['default'] = inst;
|
||||
|
||||
export default inst;
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mergeScan.d.ts","sourceRoot":"","sources":["../../../../src/internal/operators/mergeScan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAI7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,eAAe,CAAC,CAAC,CAAC,EACpE,IAAI,EAAE,CAAC,EACP,UAAU,SAAW,GACpB,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAkBxB"}
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference types="node" resolution-mode="require"/>
|
||||
import type { EventEmitter } from 'node:events';
|
||||
type Origin = EventEmitter;
|
||||
type Event = string | symbol;
|
||||
type Fn = (...args: any[]) => void;
|
||||
type Unhandler = {
|
||||
once: (origin: Origin, event: Event, fn: Fn) => void;
|
||||
unhandleAll: () => void;
|
||||
};
|
||||
export default function unhandle(): Unhandler;
|
||||
export {};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0.02444,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0.11611,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0.00611,"89":0,"90":0,"91":0.00611,"92":0,"93":0,"94":0,"95":0,"96":0.00611,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0.03056,"103":0,"104":0.00611,"105":0.00611,"106":0.00611,"107":0.02444,"108":0.055,"109":1.19165,"110":0.8861,"111":0.03667,"112":0.00611,"3.5":0,"3.6":0},D:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0.01222,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0.00611,"66":0.00611,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0.01222,"77":0,"78":0,"79":0.23833,"80":0,"81":0.00611,"83":0,"84":0,"85":0,"86":0,"87":0.06111,"88":0,"89":0,"90":0,"91":0,"92":0.00611,"93":0,"94":0,"95":0,"96":0,"97":0.00611,"98":0.00611,"99":0,"100":0.03667,"101":0,"102":0.00611,"103":0.03056,"104":0.09167,"105":0.48888,"106":0.01833,"107":0.00611,"108":0.165,"109":14.6114,"110":10.57203,"111":0,"112":0,"113":0},F:{"9":0,"11":0,"12":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"60":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0.06722,"90":0,"91":0,"92":0,"93":0.23222,"94":0.29333,"95":0.04889,"9.5-9.6":0,"10.0-10.1":0,"10.5":0,"10.6":0,"11.1":0,"11.5":0,"11.6":0,"12.1":0},B:{"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"79":0,"80":0,"81":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0.01222,"109":1.59497,"110":1.99219},E:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0.00611,"14":0.26888,"15":0.01222,_:"0","3.1":0,"3.2":0,"5.1":0,"6.1":0,"7.1":0,"9.1":0,"10.1":0,"11.1":0,"12.1":0.03056,"13.1":0.07333,"14.1":0.25055,"15.1":0,"15.2-15.3":0.02444,"15.4":0.02444,"15.5":0.25055,"15.6":0.40333,"16.0":0.17111,"16.1":0.22,"16.2":0.87387,"16.3":1.0022,"16.4":0},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0,"5.0-5.1":0,"6.0-6.1":0,"7.0-7.1":0,"8.1-8.4":0,"9.0-9.2":0.06657,"9.3":0.01712,"10.0-10.2":0,"10.3":0.02853,"11.0-11.2":0.01141,"11.3-11.4":0,"12.0-12.1":0.02853,"12.2-12.5":0.47359,"13.0-13.1":0.01141,"13.2":0.01712,"13.3":0,"13.4-13.7":0,"14.0-14.4":0.87109,"14.5-14.8":0.60292,"15.0-15.1":0.16737,"15.2-15.3":0.18449,"15.4":0.12743,"15.5":0.24535,"15.6":1.29333,"16.0":2.55432,"16.1":4.28889,"16.2":4.31172,"16.3":3.14012,"16.4":0},P:{"4":0.05112,"20":1.20644,"5.0-5.4":0,"6.2-6.4":0,"7.2-7.4":0,"8.2":0,"9.2":0,"10.1":0,"11.1-11.2":0,"12.0":0,"13.0":0,"14.0":0,"15.0":0,"16.0":0,"17.0":0,"18.0":0.02045,"19.0":1.61541},I:{"0":0,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00202,"4.4":0,"4.4.3-4.4.4":0.19965},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"6":0,"7":0,"8":0,"9":0,"10":0,"11":0.01222,"5.5":0},N:{"10":0,"11":0},S:{"2.5":0,_:"3.0-3.1"},J:{"7":0,"10":0},O:{"0":0},H:{"0":0.0405},L:{"0":39.08209},R:{_:"0"},M:{"0":0.34612},Q:{"13.1":0}};
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Observable } from '../Observable';
|
||||
import { ObservableInput, SchedulerLike, ObservedValueOf } from '../types';
|
||||
export declare function from<O extends ObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>;
|
||||
/** @deprecated The `scheduler` parameter will be removed in v8. Use `scheduled`. Details: https://rxjs.dev/deprecations/scheduler-argument */
|
||||
export declare function from<O extends ObservableInput<any>>(input: O, scheduler: SchedulerLike | undefined): Observable<ObservedValueOf<O>>;
|
||||
//# sourceMappingURL=from.d.ts.map
|
||||
@@ -0,0 +1,264 @@
|
||||
# deepmerge
|
||||
|
||||
Merges the enumerable properties of two or more objects deeply.
|
||||
|
||||
> UMD bundle is 723B minified+gzipped
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Example Usage
|
||||
<!--js
|
||||
const merge = require('./')
|
||||
-->
|
||||
|
||||
```js
|
||||
const x = {
|
||||
foo: { bar: 3 },
|
||||
array: [{
|
||||
does: 'work',
|
||||
too: [ 1, 2, 3 ]
|
||||
}]
|
||||
}
|
||||
|
||||
const y = {
|
||||
foo: { baz: 4 },
|
||||
quux: 5,
|
||||
array: [{
|
||||
does: 'work',
|
||||
too: [ 4, 5, 6 ]
|
||||
}, {
|
||||
really: 'yes'
|
||||
}]
|
||||
}
|
||||
|
||||
const output = {
|
||||
foo: {
|
||||
bar: 3,
|
||||
baz: 4
|
||||
},
|
||||
array: [{
|
||||
does: 'work',
|
||||
too: [ 1, 2, 3 ]
|
||||
}, {
|
||||
does: 'work',
|
||||
too: [ 4, 5, 6 ]
|
||||
}, {
|
||||
really: 'yes'
|
||||
}],
|
||||
quux: 5
|
||||
}
|
||||
|
||||
merge(x, y) // => output
|
||||
```
|
||||
|
||||
|
||||
### Installation
|
||||
|
||||
With [npm](http://npmjs.org) do:
|
||||
|
||||
```sh
|
||||
npm install deepmerge
|
||||
```
|
||||
|
||||
deepmerge can be used directly in the browser without the use of package managers/bundlers as well: [UMD version from unpkg.com](https://unpkg.com/deepmerge/dist/umd.js).
|
||||
|
||||
|
||||
### Include
|
||||
|
||||
deepmerge exposes a CommonJS entry point:
|
||||
|
||||
```
|
||||
const merge = require('deepmerge')
|
||||
```
|
||||
|
||||
The ESM entry point was dropped due to a [Webpack bug](https://github.com/webpack/webpack/issues/6584).
|
||||
|
||||
# API
|
||||
|
||||
|
||||
## `merge(x, y, [options])`
|
||||
|
||||
Merge two objects `x` and `y` deeply, returning a new merged object with the
|
||||
elements from both `x` and `y`.
|
||||
|
||||
If an element at the same key is present for both `x` and `y`, the value from
|
||||
`y` will appear in the result.
|
||||
|
||||
Merging creates a new object, so that neither `x` or `y` is modified.
|
||||
|
||||
**Note:** By default, arrays are merged by concatenating them.
|
||||
|
||||
## `merge.all(arrayOfObjects, [options])`
|
||||
|
||||
Merges any number of objects into a single result object.
|
||||
|
||||
```js
|
||||
const foobar = { foo: { bar: 3 } }
|
||||
const foobaz = { foo: { baz: 4 } }
|
||||
const bar = { bar: 'yay!' }
|
||||
|
||||
merge.all([ foobar, foobaz, bar ]) // => { foo: { bar: 3, baz: 4 }, bar: 'yay!' }
|
||||
```
|
||||
|
||||
|
||||
## Options
|
||||
|
||||
### `arrayMerge`
|
||||
|
||||
There are multiple ways to merge two arrays, below are a few examples but you can also create your own custom function.
|
||||
|
||||
Your `arrayMerge` function will be called with three arguments: a `target` array, the `source` array, and an `options` object with these properties:
|
||||
|
||||
- `isMergeableObject(value)`
|
||||
- `cloneUnlessOtherwiseSpecified(value, options)`
|
||||
|
||||
#### `arrayMerge` example: overwrite target array
|
||||
|
||||
Overwrites the existing array values completely rather than concatenating them:
|
||||
|
||||
```js
|
||||
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray
|
||||
|
||||
merge(
|
||||
[1, 2, 3],
|
||||
[3, 2, 1],
|
||||
{ arrayMerge: overwriteMerge }
|
||||
) // => [3, 2, 1]
|
||||
```
|
||||
|
||||
#### `arrayMerge` example: combine arrays
|
||||
|
||||
Combines objects at the same index in the two arrays.
|
||||
|
||||
This was the default array merging algorithm pre-version-2.0.0.
|
||||
|
||||
```js
|
||||
const combineMerge = (target, source, options) => {
|
||||
const destination = target.slice()
|
||||
|
||||
source.forEach((item, index) => {
|
||||
if (typeof destination[index] === 'undefined') {
|
||||
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options)
|
||||
} else if (options.isMergeableObject(item)) {
|
||||
destination[index] = merge(target[index], item, options)
|
||||
} else if (target.indexOf(item) === -1) {
|
||||
destination.push(item)
|
||||
}
|
||||
})
|
||||
return destination
|
||||
}
|
||||
|
||||
merge(
|
||||
[{ a: true }],
|
||||
[{ b: true }, 'ah yup'],
|
||||
{ arrayMerge: combineMerge }
|
||||
) // => [{ a: true, b: true }, 'ah yup']
|
||||
```
|
||||
|
||||
### `isMergeableObject`
|
||||
|
||||
By default, deepmerge clones every property from almost every kind of object.
|
||||
|
||||
You may not want this, if your objects are of special types, and you want to copy the whole object instead of just copying its properties.
|
||||
|
||||
You can accomplish this by passing in a function for the `isMergeableObject` option.
|
||||
|
||||
If you only want to clone properties of plain objects, and ignore all "special" kinds of instantiated objects, you probably want to drop in [`is-plain-object`](https://github.com/jonschlinkert/is-plain-object).
|
||||
|
||||
```js
|
||||
const isPlainObject = require('is-plain-object')
|
||||
|
||||
function SuperSpecial() {
|
||||
this.special = 'oh yeah man totally'
|
||||
}
|
||||
|
||||
const instantiatedSpecialObject = new SuperSpecial()
|
||||
|
||||
const target = {
|
||||
someProperty: {
|
||||
cool: 'oh for sure'
|
||||
}
|
||||
}
|
||||
|
||||
const source = {
|
||||
someProperty: instantiatedSpecialObject
|
||||
}
|
||||
|
||||
const defaultOutput = merge(target, source)
|
||||
|
||||
defaultOutput.someProperty.cool // => 'oh for sure'
|
||||
defaultOutput.someProperty.special // => 'oh yeah man totally'
|
||||
defaultOutput.someProperty instanceof SuperSpecial // => false
|
||||
|
||||
const customMergeOutput = merge(target, source, {
|
||||
isMergeableObject: isPlainObject
|
||||
})
|
||||
|
||||
customMergeOutput.someProperty.cool // => undefined
|
||||
customMergeOutput.someProperty.special // => 'oh yeah man totally'
|
||||
customMergeOutput.someProperty instanceof SuperSpecial // => true
|
||||
```
|
||||
|
||||
### `customMerge`
|
||||
|
||||
Specifies a function which can be used to override the default merge behavior for a property, based on the property name.
|
||||
|
||||
The `customMerge` function will be passed the key for each property, and should return the function which should be used to merge the values for that property.
|
||||
|
||||
It may also return undefined, in which case the default merge behaviour will be used.
|
||||
|
||||
```js
|
||||
const alex = {
|
||||
name: {
|
||||
first: 'Alex',
|
||||
last: 'Alexson'
|
||||
},
|
||||
pets: ['Cat', 'Parrot']
|
||||
}
|
||||
|
||||
const tony = {
|
||||
name: {
|
||||
first: 'Tony',
|
||||
last: 'Tonison'
|
||||
},
|
||||
pets: ['Dog']
|
||||
}
|
||||
|
||||
const mergeNames = (nameA, nameB) => `${nameA.first} and ${nameB.first}`
|
||||
|
||||
const options = {
|
||||
customMerge: (key) => {
|
||||
if (key === 'name') {
|
||||
return mergeNames
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const result = merge(alex, tony, options)
|
||||
|
||||
result.name // => 'Alex and Tony'
|
||||
result.pets // => ['Cat', 'Parrot', 'Dog']
|
||||
```
|
||||
|
||||
|
||||
### `clone`
|
||||
|
||||
*Deprecated.*
|
||||
|
||||
Defaults to `true`.
|
||||
|
||||
If `clone` is `false` then child objects will be copied directly instead of being cloned. This was the default behavior before version 2.x.
|
||||
|
||||
|
||||
# Testing
|
||||
|
||||
With [npm](http://npmjs.org) do:
|
||||
|
||||
```sh
|
||||
npm test
|
||||
```
|
||||
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
||||
@@ -0,0 +1,39 @@
|
||||
var createPadding = require('./_createPadding'),
|
||||
stringSize = require('./_stringSize'),
|
||||
toInteger = require('./toInteger'),
|
||||
toString = require('./toString');
|
||||
|
||||
/**
|
||||
* Pads `string` on the right side if it's shorter than `length`. Padding
|
||||
* characters are truncated if they exceed `length`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @category String
|
||||
* @param {string} [string=''] The string to pad.
|
||||
* @param {number} [length=0] The padding length.
|
||||
* @param {string} [chars=' '] The string used as padding.
|
||||
* @returns {string} Returns the padded string.
|
||||
* @example
|
||||
*
|
||||
* _.padEnd('abc', 6);
|
||||
* // => 'abc '
|
||||
*
|
||||
* _.padEnd('abc', 6, '_-');
|
||||
* // => 'abc_-_'
|
||||
*
|
||||
* _.padEnd('abc', 3);
|
||||
* // => 'abc'
|
||||
*/
|
||||
function padEnd(string, length, chars) {
|
||||
string = toString(string);
|
||||
length = toInteger(length);
|
||||
|
||||
var strLength = length ? stringSize(string) : 0;
|
||||
return (length && strLength < length)
|
||||
? (string + createPadding(length - strLength, chars))
|
||||
: string;
|
||||
}
|
||||
|
||||
module.exports = padEnd;
|
||||
Reference in New Issue
Block a user