new license file version [CI SKIP]
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
// TODO: consolidate on using a helpers file at some point in the future, which
|
||||
// is the approach currently used to export Parser and applyExtends for ESM:
|
||||
import pkg from './build/index.cjs';
|
||||
const {applyExtends, cjsPlatformShim, Parser, processArgv, Yargs} = pkg;
|
||||
Yargs.applyExtends = (config, cwd, mergeExtends) => {
|
||||
return applyExtends(config, cwd, mergeExtends, cjsPlatformShim);
|
||||
};
|
||||
Yargs.hideBin = processArgv.hideBin;
|
||||
Yargs.Parser = Parser;
|
||||
export default Yargs;
|
||||
@@ -0,0 +1,5 @@
|
||||
var convert = require('./convert'),
|
||||
func = convert('without', require('../without'));
|
||||
|
||||
func.placeholder = require('./placeholder');
|
||||
module.exports = func;
|
||||
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Kevin Mårtensson <kevinmartensson@gmail.com> (github.com/kevva)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,670 @@
|
||||
# is
|
||||
|
||||
> Type check values
|
||||
|
||||
For example, `is.string('🦄') //=> true`
|
||||
|
||||
<img src="header.gif" width="182" align="right">
|
||||
|
||||
## Highlights
|
||||
|
||||
- Written in TypeScript
|
||||
- [Extensive use of type guards](#type-guards)
|
||||
- [Supports type assertions](#type-assertions)
|
||||
- [Aware of generic type parameters](#generic-type-parameters) (use with caution)
|
||||
- Actively maintained
|
||||
- 
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install @sindresorhus/is
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import is from '@sindresorhus/is';
|
||||
|
||||
is('🦄');
|
||||
//=> 'string'
|
||||
|
||||
is(new Map());
|
||||
//=> 'Map'
|
||||
|
||||
is.number(6);
|
||||
//=> true
|
||||
```
|
||||
|
||||
[Assertions](#type-assertions) perform the same type checks, but throw an error if the type does not match.
|
||||
|
||||
```js
|
||||
import {assert} from '@sindresorhus/is';
|
||||
|
||||
assert.string(2);
|
||||
//=> Error: Expected value which is `string`, received value of type `number`.
|
||||
```
|
||||
|
||||
And with TypeScript:
|
||||
|
||||
```ts
|
||||
import {assert} from '@sindresorhus/is';
|
||||
|
||||
assert.string(foo);
|
||||
// `foo` is now typed as a `string`.
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### is(value)
|
||||
|
||||
Returns the type of `value`.
|
||||
|
||||
Primitives are lowercase and object types are camelcase.
|
||||
|
||||
Example:
|
||||
|
||||
- `'undefined'`
|
||||
- `'null'`
|
||||
- `'string'`
|
||||
- `'symbol'`
|
||||
- `'Array'`
|
||||
- `'Function'`
|
||||
- `'Object'`
|
||||
|
||||
Note: It will throw an error if you try to feed it object-wrapped primitives, as that's a bad practice. For example `new String('foo')`.
|
||||
|
||||
### is.{method}
|
||||
|
||||
All the below methods accept a value and returns a boolean for whether the value is of the desired type.
|
||||
|
||||
#### Primitives
|
||||
|
||||
##### .undefined(value)
|
||||
##### .null(value)
|
||||
|
||||
**Note:** TypeScript users must use `.null_()` because of a TypeScript naming limitation.
|
||||
|
||||
##### .string(value)
|
||||
##### .number(value)
|
||||
|
||||
Note: `is.number(NaN)` returns `false`. This intentionally deviates from `typeof` behavior to increase user-friendliness of `is` type checks.
|
||||
|
||||
##### .boolean(value)
|
||||
##### .symbol(value)
|
||||
##### .bigint(value)
|
||||
|
||||
#### Built-in types
|
||||
|
||||
##### .array(value, assertion?)
|
||||
|
||||
Returns true if `value` is an array and all of its items match the assertion (if provided).
|
||||
|
||||
```js
|
||||
is.array(value); // Validate `value` is an array.
|
||||
is.array(value, is.number); // Validate `value` is an array and all of its items are numbers.
|
||||
```
|
||||
|
||||
##### .function(value)
|
||||
|
||||
**Note:** TypeScript users must use `.function_()` because of a TypeScript naming limitation.
|
||||
|
||||
##### .buffer(value)
|
||||
##### .blob(value)
|
||||
##### .object(value)
|
||||
|
||||
Keep in mind that [functions are objects too](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions).
|
||||
|
||||
##### .numericString(value)
|
||||
|
||||
Returns `true` for a string that represents a number satisfying `is.number`, for example, `'42'` and `'-8.3'`.
|
||||
|
||||
Note: `'NaN'` returns `false`, but `'Infinity'` and `'-Infinity'` return `true`.
|
||||
|
||||
##### .regExp(value)
|
||||
##### .date(value)
|
||||
##### .error(value)
|
||||
##### .nativePromise(value)
|
||||
##### .promise(value)
|
||||
|
||||
Returns `true` for any object with a `.then()` and `.catch()` method. Prefer this one over `.nativePromise()` as you usually want to allow userland promise implementations too.
|
||||
|
||||
##### .generator(value)
|
||||
|
||||
Returns `true` for any object that implements its own `.next()` and `.throw()` methods and has a function definition for `Symbol.iterator`.
|
||||
|
||||
##### .generatorFunction(value)
|
||||
|
||||
##### .asyncFunction(value)
|
||||
|
||||
Returns `true` for any `async` function that can be called with the `await` operator.
|
||||
|
||||
```js
|
||||
is.asyncFunction(async () => {});
|
||||
//=> true
|
||||
|
||||
is.asyncFunction(() => {});
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .asyncGenerator(value)
|
||||
|
||||
```js
|
||||
is.asyncGenerator(
|
||||
(async function * () {
|
||||
yield 4;
|
||||
})()
|
||||
);
|
||||
//=> true
|
||||
|
||||
is.asyncGenerator(
|
||||
(function * () {
|
||||
yield 4;
|
||||
})()
|
||||
);
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .asyncGeneratorFunction(value)
|
||||
|
||||
```js
|
||||
is.asyncGeneratorFunction(async function * () {
|
||||
yield 4;
|
||||
});
|
||||
//=> true
|
||||
|
||||
is.asyncGeneratorFunction(function * () {
|
||||
yield 4;
|
||||
});
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .boundFunction(value)
|
||||
|
||||
Returns `true` for any `bound` function.
|
||||
|
||||
```js
|
||||
is.boundFunction(() => {});
|
||||
//=> true
|
||||
|
||||
is.boundFunction(function () {}.bind(null));
|
||||
//=> true
|
||||
|
||||
is.boundFunction(function () {});
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .map(value)
|
||||
##### .set(value)
|
||||
##### .weakMap(value)
|
||||
##### .weakSet(value)
|
||||
##### .weakRef(value)
|
||||
|
||||
#### Typed arrays
|
||||
|
||||
##### .int8Array(value)
|
||||
##### .uint8Array(value)
|
||||
##### .uint8ClampedArray(value)
|
||||
##### .int16Array(value)
|
||||
##### .uint16Array(value)
|
||||
##### .int32Array(value)
|
||||
##### .uint32Array(value)
|
||||
##### .float32Array(value)
|
||||
##### .float64Array(value)
|
||||
##### .bigInt64Array(value)
|
||||
##### .bigUint64Array(value)
|
||||
|
||||
#### Structured data
|
||||
|
||||
##### .arrayBuffer(value)
|
||||
##### .sharedArrayBuffer(value)
|
||||
##### .dataView(value)
|
||||
|
||||
##### .enumCase(value, enum)
|
||||
|
||||
TypeScript-only. Returns `true` if `value` is a member of `enum`.
|
||||
|
||||
```ts
|
||||
enum Direction {
|
||||
Ascending = 'ascending',
|
||||
Descending = 'descending'
|
||||
}
|
||||
|
||||
is.enumCase('ascending', Direction);
|
||||
//=> true
|
||||
|
||||
is.enumCase('other', Direction);
|
||||
//=> false
|
||||
```
|
||||
|
||||
#### Emptiness
|
||||
|
||||
##### .emptyString(value)
|
||||
|
||||
Returns `true` if the value is a `string` and the `.length` is 0.
|
||||
|
||||
##### .emptyStringOrWhitespace(value)
|
||||
|
||||
Returns `true` if `is.emptyString(value)` or if it's a `string` that is all whitespace.
|
||||
|
||||
##### .nonEmptyString(value)
|
||||
|
||||
Returns `true` if the value is a `string` and the `.length` is more than 0.
|
||||
|
||||
##### .nonEmptyStringAndNotWhitespace(value)
|
||||
|
||||
Returns `true` if the value is a `string` that is not empty and not whitespace.
|
||||
|
||||
```js
|
||||
const values = ['property1', '', null, 'property2', ' ', undefined];
|
||||
|
||||
values.filter(is.nonEmptyStringAndNotWhitespace);
|
||||
//=> ['property1', 'property2']
|
||||
```
|
||||
|
||||
##### .emptyArray(value)
|
||||
|
||||
Returns `true` if the value is an `Array` and the `.length` is 0.
|
||||
|
||||
##### .nonEmptyArray(value)
|
||||
|
||||
Returns `true` if the value is an `Array` and the `.length` is more than 0.
|
||||
|
||||
##### .emptyObject(value)
|
||||
|
||||
Returns `true` if the value is an `Object` and `Object.keys(value).length` is 0.
|
||||
|
||||
Please note that `Object.keys` returns only own enumerable properties. Hence something like this can happen:
|
||||
|
||||
```js
|
||||
const object1 = {};
|
||||
|
||||
Object.defineProperty(object1, 'property1', {
|
||||
value: 42,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
is.emptyObject(object1);
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .nonEmptyObject(value)
|
||||
|
||||
Returns `true` if the value is an `Object` and `Object.keys(value).length` is more than 0.
|
||||
|
||||
##### .emptySet(value)
|
||||
|
||||
Returns `true` if the value is a `Set` and the `.size` is 0.
|
||||
|
||||
##### .nonEmptySet(Value)
|
||||
|
||||
Returns `true` if the value is a `Set` and the `.size` is more than 0.
|
||||
|
||||
##### .emptyMap(value)
|
||||
|
||||
Returns `true` if the value is a `Map` and the `.size` is 0.
|
||||
|
||||
##### .nonEmptyMap(value)
|
||||
|
||||
Returns `true` if the value is a `Map` and the `.size` is more than 0.
|
||||
|
||||
#### Miscellaneous
|
||||
|
||||
##### .directInstanceOf(value, class)
|
||||
|
||||
Returns `true` if `value` is a direct instance of `class`.
|
||||
|
||||
```js
|
||||
is.directInstanceOf(new Error(), Error);
|
||||
//=> true
|
||||
|
||||
class UnicornError extends Error {}
|
||||
|
||||
is.directInstanceOf(new UnicornError(), Error);
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .urlInstance(value)
|
||||
|
||||
Returns `true` if `value` is an instance of the [`URL` class](https://developer.mozilla.org/en-US/docs/Web/API/URL).
|
||||
|
||||
```js
|
||||
const url = new URL('https://example.com');
|
||||
|
||||
is.urlInstance(url);
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .urlString(value)
|
||||
|
||||
Returns `true` if `value` is a URL string.
|
||||
|
||||
Note: this only does basic checking using the [`URL` class](https://developer.mozilla.org/en-US/docs/Web/API/URL) constructor.
|
||||
|
||||
```js
|
||||
const url = 'https://example.com';
|
||||
|
||||
is.urlString(url);
|
||||
//=> true
|
||||
|
||||
is.urlString(new URL(url));
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .truthy(value)
|
||||
|
||||
Returns `true` for all values that evaluate to true in a boolean context:
|
||||
|
||||
```js
|
||||
is.truthy('🦄');
|
||||
//=> true
|
||||
|
||||
is.truthy(undefined);
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .falsy(value)
|
||||
|
||||
Returns `true` if `value` is one of: `false`, `0`, `''`, `null`, `undefined`, `NaN`.
|
||||
|
||||
##### .nan(value)
|
||||
##### .nullOrUndefined(value)
|
||||
##### .primitive(value)
|
||||
|
||||
JavaScript primitives are as follows: `null`, `undefined`, `string`, `number`, `boolean`, `symbol`.
|
||||
|
||||
##### .integer(value)
|
||||
|
||||
##### .safeInteger(value)
|
||||
|
||||
Returns `true` if `value` is a [safe integer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger).
|
||||
|
||||
##### .plainObject(value)
|
||||
|
||||
An object is plain if it's created by either `{}`, `new Object()`, or `Object.create(null)`.
|
||||
|
||||
##### .iterable(value)
|
||||
##### .asyncIterable(value)
|
||||
##### .class(value)
|
||||
|
||||
Returns `true` for instances created by a class.
|
||||
|
||||
**Note:** TypeScript users must use `.class_()` because of a TypeScript naming limitation.
|
||||
|
||||
##### .typedArray(value)
|
||||
|
||||
##### .arrayLike(value)
|
||||
|
||||
A `value` is array-like if it is not a function and has a `value.length` that is a safe integer greater than or equal to 0.
|
||||
|
||||
```js
|
||||
is.arrayLike(document.forms);
|
||||
//=> true
|
||||
|
||||
function foo() {
|
||||
is.arrayLike(arguments);
|
||||
//=> true
|
||||
}
|
||||
foo();
|
||||
```
|
||||
|
||||
##### .inRange(value, range)
|
||||
|
||||
Check if `value` (number) is in the given `range`. The range is an array of two values, lower bound and upper bound, in no specific order.
|
||||
|
||||
```js
|
||||
is.inRange(3, [0, 5]);
|
||||
is.inRange(3, [5, 0]);
|
||||
is.inRange(0, [-2, 2]);
|
||||
```
|
||||
|
||||
##### .inRange(value, upperBound)
|
||||
|
||||
Check if `value` (number) is in the range of `0` to `upperBound`.
|
||||
|
||||
```js
|
||||
is.inRange(3, 10);
|
||||
```
|
||||
|
||||
##### .domElement(value)
|
||||
|
||||
Returns `true` if `value` is a DOM Element.
|
||||
|
||||
##### .nodeStream(value)
|
||||
|
||||
Returns `true` if `value` is a Node.js [stream](https://nodejs.org/api/stream.html).
|
||||
|
||||
```js
|
||||
import fs from 'node:fs';
|
||||
|
||||
is.nodeStream(fs.createReadStream('unicorn.png'));
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .observable(value)
|
||||
|
||||
Returns `true` if `value` is an `Observable`.
|
||||
|
||||
```js
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
is.observable(new Observable());
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .infinite(value)
|
||||
|
||||
Check if `value` is `Infinity` or `-Infinity`.
|
||||
|
||||
##### .evenInteger(value)
|
||||
|
||||
Returns `true` if `value` is an even integer.
|
||||
|
||||
##### .oddInteger(value)
|
||||
|
||||
Returns `true` if `value` is an odd integer.
|
||||
|
||||
##### .propertyKey(value)
|
||||
|
||||
Returns `true` if `value` can be used as an object property key (either `string`, `number`, or `symbol`).
|
||||
|
||||
##### .formData(value)
|
||||
|
||||
Returns `true` if `value` is an instance of the [`FormData` class](https://developer.mozilla.org/en-US/docs/Web/API/FormData).
|
||||
|
||||
```js
|
||||
const data = new FormData();
|
||||
|
||||
is.formData(data);
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .urlSearchParams(value)
|
||||
|
||||
Returns `true` if `value` is an instance of the [`URLSearchParams` class](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).
|
||||
|
||||
```js
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
is.urlSearchParams(searchParams);
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .any(predicate | predicate[], ...values)
|
||||
|
||||
Using a single `predicate` argument, returns `true` if **any** of the input `values` returns true in the `predicate`:
|
||||
|
||||
```js
|
||||
is.any(is.string, {}, true, '🦄');
|
||||
//=> true
|
||||
|
||||
is.any(is.boolean, 'unicorns', [], new Map());
|
||||
//=> false
|
||||
```
|
||||
|
||||
Using an array of `predicate[]`, returns `true` if **any** of the input `values` returns true for **any** of the `predicates` provided in an array:
|
||||
|
||||
```js
|
||||
is.any([is.string, is.number], {}, true, '🦄');
|
||||
//=> true
|
||||
|
||||
is.any([is.boolean, is.number], 'unicorns', [], new Map());
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .all(predicate, ...values)
|
||||
|
||||
Returns `true` if **all** of the input `values` returns true in the `predicate`:
|
||||
|
||||
```js
|
||||
is.all(is.object, {}, new Map(), new Set());
|
||||
//=> true
|
||||
|
||||
is.all(is.string, '🦄', [], 'unicorns');
|
||||
//=> false
|
||||
```
|
||||
|
||||
## Type guards
|
||||
|
||||
When using `is` together with TypeScript, [type guards](http://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types) are being used extensively to infer the correct type inside if-else statements.
|
||||
|
||||
```ts
|
||||
import is from '@sindresorhus/is';
|
||||
|
||||
const padLeft = (value: string, padding: string | number) => {
|
||||
if (is.number(padding)) {
|
||||
// `padding` is typed as `number`
|
||||
return Array(padding + 1).join(' ') + value;
|
||||
}
|
||||
|
||||
if (is.string(padding)) {
|
||||
// `padding` is typed as `string`
|
||||
return padding + value;
|
||||
}
|
||||
|
||||
throw new TypeError(`Expected 'padding' to be of type 'string' or 'number', got '${is(padding)}'.`);
|
||||
}
|
||||
|
||||
padLeft('🦄', 3);
|
||||
//=> ' 🦄'
|
||||
|
||||
padLeft('🦄', '🌈');
|
||||
//=> '🌈🦄'
|
||||
```
|
||||
|
||||
## Type assertions
|
||||
|
||||
The type guards are also available as [type assertions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions), which throw an error for unexpected types. It is a convenient one-line version of the often repetitive "if-not-expected-type-throw" pattern.
|
||||
|
||||
```ts
|
||||
import {assert} from '@sindresorhus/is';
|
||||
|
||||
const handleMovieRatingApiResponse = (response: unknown) => {
|
||||
assert.plainObject(response);
|
||||
// `response` is now typed as a plain `object` with `unknown` properties.
|
||||
|
||||
assert.number(response.rating);
|
||||
// `response.rating` is now typed as a `number`.
|
||||
|
||||
assert.string(response.title);
|
||||
// `response.title` is now typed as a `string`.
|
||||
|
||||
return `${response.title} (${response.rating * 10})`;
|
||||
};
|
||||
|
||||
handleMovieRatingApiResponse({rating: 0.87, title: 'The Matrix'});
|
||||
//=> 'The Matrix (8.7)'
|
||||
|
||||
// This throws an error.
|
||||
handleMovieRatingApiResponse({rating: '🦄'});
|
||||
```
|
||||
|
||||
## Generic type parameters
|
||||
|
||||
The type guards and type assertions are aware of [generic type parameters](https://www.typescriptlang.org/docs/handbook/generics.html), such as `Promise<T>` and `Map<Key, Value>`. The default is `unknown` for most cases, since `is` cannot check them at runtime. If the generic type is known at compile-time, either implicitly (inferred) or explicitly (provided), `is` propagates the type so it can be used later.
|
||||
|
||||
Use generic type parameters with caution. They are only checked by the TypeScript compiler, and not checked by `is` at runtime. This can lead to unexpected behavior, where the generic type is _assumed_ at compile-time, but actually is something completely different at runtime. It is best to use `unknown` (default) and type-check the value of the generic type parameter at runtime with `is` or `assert`.
|
||||
|
||||
```ts
|
||||
import {assert} from '@sindresorhus/is';
|
||||
|
||||
async function badNumberAssumption(input: unknown) {
|
||||
// Bad assumption about the generic type parameter fools the compile-time type system.
|
||||
assert.promise<number>(input);
|
||||
// `input` is a `Promise` but only assumed to be `Promise<number>`.
|
||||
|
||||
const resolved = await input;
|
||||
// `resolved` is typed as `number` but was not actually checked at runtime.
|
||||
|
||||
// Multiplication will return NaN if the input promise did not actually contain a number.
|
||||
return 2 * resolved;
|
||||
}
|
||||
|
||||
async function goodNumberAssertion(input: unknown) {
|
||||
assert.promise(input);
|
||||
// `input` is typed as `Promise<unknown>`
|
||||
|
||||
const resolved = await input;
|
||||
// `resolved` is typed as `unknown`
|
||||
|
||||
assert.number(resolved);
|
||||
// `resolved` is typed as `number`
|
||||
|
||||
// Uses runtime checks so only numbers will reach the multiplication.
|
||||
return 2 * resolved;
|
||||
}
|
||||
|
||||
badNumberAssumption(Promise.resolve('An unexpected string'));
|
||||
//=> NaN
|
||||
|
||||
// This correctly throws an error because of the unexpected string value.
|
||||
goodNumberAssertion(Promise.resolve('An unexpected string'));
|
||||
```
|
||||
|
||||
## FAQ
|
||||
|
||||
### Why yet another type checking module?
|
||||
|
||||
There are hundreds of type checking modules on npm, unfortunately, I couldn't find any that fit my needs:
|
||||
|
||||
- Includes both type methods and ability to get the type
|
||||
- Types of primitives returned as lowercase and object types as camelcase
|
||||
- Covers all built-ins
|
||||
- Unsurprising behavior
|
||||
- Well-maintained
|
||||
- Comprehensive test suite
|
||||
|
||||
For the ones I found, pick 3 of these.
|
||||
|
||||
The most common mistakes I noticed in these modules was using `instanceof` for type checking, forgetting that functions are objects, and omitting `symbol` as a primitive.
|
||||
|
||||
### Why not just use `instanceof` instead of this package?
|
||||
|
||||
`instanceof` does not work correctly for all types and it does not work across [realms](https://stackoverflow.com/a/49832343/64949). Examples of realms are iframes, windows, web workers, and the `vm` module in Node.js.
|
||||
|
||||
## For enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription.
|
||||
|
||||
The maintainers of @sindresorhus/is and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-sindresorhus-is?utm_source=npm-sindresorhus-is&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
|
||||
## Related
|
||||
|
||||
- [ow](https://github.com/sindresorhus/ow) - Function argument validation for humans
|
||||
- [is-stream](https://github.com/sindresorhus/is-stream) - Check if something is a Node.js stream
|
||||
- [is-observable](https://github.com/sindresorhus/is-observable) - Check if a value is an Observable
|
||||
- [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array
|
||||
- [is-ip](https://github.com/sindresorhus/is-ip) - Check if a string is an IP address
|
||||
- [is-array-sorted](https://github.com/sindresorhus/is-array-sorted) - Check if an Array is sorted
|
||||
- [is-error-constructor](https://github.com/sindresorhus/is-error-constructor) - Check if a value is an error constructor
|
||||
- [is-empty-iterable](https://github.com/sindresorhus/is-empty-iterable) - Check if an Iterable is empty
|
||||
- [is-blob](https://github.com/sindresorhus/is-blob) - Check if a value is a Blob - File-like object of immutable, raw data
|
||||
- [has-emoji](https://github.com/sindresorhus/has-emoji) - Check whether a string has any emoji
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Giora Guttsait](https://github.com/gioragutt)
|
||||
- [Brandon Smith](https://github.com/brandon93s)
|
||||
@@ -0,0 +1,27 @@
|
||||
export function union(types) {
|
||||
return [...new Set(types)].join(' | ')
|
||||
}
|
||||
|
||||
export function unionValues(values) {
|
||||
return union(values.map(forValue))
|
||||
}
|
||||
|
||||
export function forKeys(value) {
|
||||
return union(Object.keys(value).map((key) => `'${key}'`))
|
||||
}
|
||||
|
||||
export function forValue(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return `(${unionValues(value)})[]`
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
return `Record<${forKeys(value)}, ${unionValues(Object.values(value))}>`
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
return `string`
|
||||
}
|
||||
|
||||
return `any`
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
var convert = require('./convert'),
|
||||
func = convert('fromPairs', require('../fromPairs'));
|
||||
|
||||
func.placeholder = require('./placeholder');
|
||||
module.exports = func;
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../../src/internal/operators/throttle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAKrE,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,qBAAqB,EAAE,cAGnC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,gBAAgB,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,eAAe,CAAC,GAAG,CAAC,EACpD,MAAM,GAAE,cAAsC,GAC7C,wBAAwB,CAAC,CAAC,CAAC,CA2D7B"}
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"@types/relateurl","version":"0.2.29","files":{"LICENSE":{"checkedAt":1678883669855,"integrity":"sha512-HQaIQk9pwOcyKutyDk4o2a87WnotwYuLGYFW43emGm4FvIJFKPyg+OYaw5sTegKAKf+C5SKa1ACjzCLivbaHrQ==","mode":511,"size":1141},"README.md":{"checkedAt":1678883669855,"integrity":"sha512-IV4fes/5Uw904cunyGaLq2q87stkLTS8fH1DYjoXaAc5MmSPE2GBGR1GowcZghqmLep0dfB7iaXfhGayx8igSw==","mode":511,"size":504},"index.d.ts":{"checkedAt":1678883669855,"integrity":"sha512-ZWZeI8Jo/K/MNEMWADOeloCmfnTaV5cndvbu6eYQoVtItvAoOvuFzXcGBVY1qgQeLT/Bgso7CEeuU0/zmgBiYg==","mode":511,"size":4310},"package.json":{"checkedAt":1678883669855,"integrity":"sha512-Ds7mmwJ1/j2tysmA0LtadNZTqTZyvx09VMB6aRLAXCPFgOu6OE9iR7+YSQQ0m1wGJ9dpfbycNqaw9OXGuhFN+g==","mode":511,"size":797}}}
|
||||
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
|
||||
var assert = require("chai").assert
|
||||
, isError = require("../../error/is");
|
||||
|
||||
describe("error/is", function () {
|
||||
it("Should return true on error", function () { assert.equal(isError(new Error()), true); });
|
||||
|
||||
it("Should return false on native error with no common API exposed", function () {
|
||||
var value = new Error();
|
||||
value.message = null;
|
||||
assert.equal(isError(value), false);
|
||||
});
|
||||
it("Should return false on Error.prototype", function () {
|
||||
assert.equal(isError(Error.prototype), false);
|
||||
});
|
||||
|
||||
if (typeof Object.create === "function") {
|
||||
it("Should return true on custom built ES5 era error", function () {
|
||||
var CustomEs5Error = function () { Error.call(this); };
|
||||
CustomEs5Error.prototype = Object.create(Error.prototype);
|
||||
assert.equal(isError(new CustomEs5Error()), true);
|
||||
});
|
||||
|
||||
it("Should return false on object with no prototype", function () {
|
||||
assert.equal(isError(Object.create(null)), false);
|
||||
});
|
||||
}
|
||||
|
||||
it("Should return false on plain object", function () { assert.equal(isError({}), false); });
|
||||
it("Should return false on function", function () {
|
||||
assert.equal(isError(function () { return true; }), false);
|
||||
});
|
||||
|
||||
it("Should return false on array", function () { assert.equal(isError([]), false); });
|
||||
|
||||
it("Should return false on string", function () { assert.equal(isError("foo"), false); });
|
||||
it("Should return false on empty string", function () { assert.equal(isError(""), false); });
|
||||
it("Should return false on number", function () { assert.equal(isError(123), false); });
|
||||
it("Should return false on NaN", function () { assert.equal(isError(NaN), false); });
|
||||
it("Should return false on boolean", function () { assert.equal(isError(true), false); });
|
||||
if (typeof Symbol === "function") {
|
||||
it("Should return false on symbol", function () {
|
||||
assert.equal(isError(Symbol("foo")), false);
|
||||
});
|
||||
}
|
||||
|
||||
it("Should return false on null", function () { assert.equal(isError(null), false); });
|
||||
it("Should return false on undefined", function () { assert.equal(isError(void 0), false); });
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"CC","8":"J D E F A","129":"B"},B:{"1":"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","129":"C K L G M N O"},C:{"1":"0 1 2 3 4 5 6 7 8 9 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 EC FC","129":"I v J D E F A B C K L G M N O w g x y z"},D:{"1":"9 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","2":"I v J D","129":"0 1 2 3 4 5 6 7 8 E F A B C K L G M N O w g x y z"},E:{"1":"E F A B C K L G LC 0B qB rB 1B MC NC 2B 3B 4B 5B sB 6B 7B 8B 9B OC","2":"I v HC zB","129":"J D IC JC KC"},F:{"1":"0 1 2 3 4 5 6 7 8 9 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","2":"F B PC QC RC SC qB AC TC","129":"C G M N O rB"},G:{"1":"E YC ZC aC bC cC dC eC fC gC hC iC jC kC lC mC nC 2B 3B 4B 5B sB 6B 7B 8B 9B","2":"zB UC BC VC WC XC"},H:{"2":"oC"},I:{"1":"f","2":"tB I pC qC rC sC BC tC uC"},J:{"1":"A","2":"D"},K:{"1":"C h rB","2":"A B qB AC"},L:{"1":"H"},M:{"1":"H"},N:{"8":"A","129":"B"},O:{"1":"vC"},P:{"1":"I g wC xC yC zC 0C 0B 1C 2C 3C 4C 5C sB 6C 7C 8C"},Q:{"1":"1B"},R:{"1":"9C"},S:{"1":"BD","129":"AD"}},B:6,C:"WebGL - 3D Canvas graphics"};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../../../../packages/icu-messageformat-parser/printer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EAoBpB,gBAAgB,EAEjB,MAAM,SAAS,CAAA;AAEhB,wBAAgB,QAAQ,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAE5D;AAED,wBAAgB,UAAU,CACxB,GAAG,EAAE,oBAAoB,EAAE,EAC3B,UAAU,EAAE,OAAO,GAClB,MAAM,CA8BR;AA4CD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAErE"}
|
||||
@@ -0,0 +1,283 @@
|
||||
var understandable = require('./properties/understandable');
|
||||
|
||||
function animationIterationCount(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isAnimationIterationCountKeyword(value2) || validator.isPositiveNumber(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isAnimationIterationCountKeyword(value2) || validator.isPositiveNumber(value2);
|
||||
}
|
||||
|
||||
function animationName(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isAnimationNameKeyword(value2) || validator.isIdentifier(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isAnimationNameKeyword(value2) || validator.isIdentifier(value2);
|
||||
}
|
||||
|
||||
function areSameFunction(validator, value1, value2) {
|
||||
if (!validator.isFunction(value1) || !validator.isFunction(value2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var function1Name = value1.substring(0, value1.indexOf('('));
|
||||
var function2Name = value2.substring(0, value2.indexOf('('));
|
||||
|
||||
return function1Name === function2Name;
|
||||
}
|
||||
|
||||
function backgroundPosition(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isBackgroundPositionKeyword(value2) || validator.isGlobal(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
} else if (validator.isBackgroundPositionKeyword(value2) || validator.isGlobal(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return unit(validator, value1, value2);
|
||||
}
|
||||
|
||||
function backgroundSize(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isBackgroundSizeKeyword(value2) || validator.isGlobal(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
} else if (validator.isBackgroundSizeKeyword(value2) || validator.isGlobal(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return unit(validator, value1, value2);
|
||||
}
|
||||
|
||||
function color(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !validator.isColor(value2)) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
} else if (!validator.colorOpacity && (validator.isRgbColor(value1) || validator.isHslColor(value1))) {
|
||||
return false;
|
||||
} else if (!validator.colorOpacity && (validator.isRgbColor(value2) || validator.isHslColor(value2))) {
|
||||
return false;
|
||||
} else if (validator.isColor(value1) && validator.isColor(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return sameFunctionOrValue(validator, value1, value2);
|
||||
}
|
||||
|
||||
function components(overrideCheckers) {
|
||||
return function (validator, value1, value2, position) {
|
||||
return overrideCheckers[position](validator, value1, value2);
|
||||
};
|
||||
}
|
||||
|
||||
function fontFamily(validator, value1, value2) {
|
||||
return understandable(validator, value1, value2, 0, true);
|
||||
}
|
||||
|
||||
function image(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !validator.isImage(value2)) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
} else if (validator.isImage(value2)) {
|
||||
return true;
|
||||
} else if (validator.isImage(value1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sameFunctionOrValue(validator, value1, value2);
|
||||
}
|
||||
|
||||
function keyword(propertyName) {
|
||||
return function(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !validator.isKeyword(propertyName)(value2)) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isKeyword(propertyName)(value2);
|
||||
};
|
||||
}
|
||||
|
||||
function keywordWithGlobal(propertyName) {
|
||||
return function(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isKeyword(propertyName)(value2) || validator.isGlobal(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isKeyword(propertyName)(value2) || validator.isGlobal(value2);
|
||||
};
|
||||
}
|
||||
|
||||
function propertyName(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !validator.isIdentifier(value2)) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isIdentifier(value2);
|
||||
}
|
||||
|
||||
function sameFunctionOrValue(validator, value1, value2) {
|
||||
return areSameFunction(validator, value1, value2) ?
|
||||
true :
|
||||
value1 === value2;
|
||||
}
|
||||
|
||||
function textShadow(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isUnit(value2) || validator.isColor(value2) || validator.isGlobal(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isUnit(value2) || validator.isColor(value2) || validator.isGlobal(value2);
|
||||
}
|
||||
|
||||
function time(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !validator.isTime(value2)) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
} else if (validator.isTime(value1) && !validator.isTime(value2)) {
|
||||
return false;
|
||||
} else if (validator.isTime(value2)) {
|
||||
return true;
|
||||
} else if (validator.isTime(value1)) {
|
||||
return false;
|
||||
} else if (validator.isFunction(value1) && !validator.isPrefixed(value1) && validator.isFunction(value2) && !validator.isPrefixed(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return sameFunctionOrValue(validator, value1, value2);
|
||||
}
|
||||
|
||||
function timingFunction(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isTimingFunction(value2) || validator.isGlobal(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isTimingFunction(value2) || validator.isGlobal(value2);
|
||||
}
|
||||
|
||||
function unit(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !validator.isUnit(value2)) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
} else if (validator.isUnit(value1) && !validator.isUnit(value2)) {
|
||||
return false;
|
||||
} else if (validator.isUnit(value2)) {
|
||||
return true;
|
||||
} else if (validator.isUnit(value1)) {
|
||||
return false;
|
||||
} else if (validator.isFunction(value1) && !validator.isPrefixed(value1) && validator.isFunction(value2) && !validator.isPrefixed(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return sameFunctionOrValue(validator, value1, value2);
|
||||
}
|
||||
|
||||
function unitOrKeywordWithGlobal(propertyName) {
|
||||
var byKeyword = keywordWithGlobal(propertyName);
|
||||
|
||||
return function(validator, value1, value2) {
|
||||
return unit(validator, value1, value2) || byKeyword(validator, value1, value2);
|
||||
};
|
||||
}
|
||||
|
||||
function unitOrNumber(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isUnit(value2) || validator.isNumber(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
} else if ((validator.isUnit(value1) || validator.isNumber(value1)) && !(validator.isUnit(value2) || validator.isNumber(value2))) {
|
||||
return false;
|
||||
} else if (validator.isUnit(value2) || validator.isNumber(value2)) {
|
||||
return true;
|
||||
} else if (validator.isUnit(value1) || validator.isNumber(value1)) {
|
||||
return false;
|
||||
} else if (validator.isFunction(value1) && !validator.isPrefixed(value1) && validator.isFunction(value2) && !validator.isPrefixed(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return sameFunctionOrValue(validator, value1, value2);
|
||||
}
|
||||
|
||||
function zIndex(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !validator.isZIndex(value2)) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isZIndex(value2);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generic: {
|
||||
color: color,
|
||||
components: components,
|
||||
image: image,
|
||||
propertyName: propertyName,
|
||||
time: time,
|
||||
timingFunction: timingFunction,
|
||||
unit: unit,
|
||||
unitOrNumber: unitOrNumber
|
||||
},
|
||||
property: {
|
||||
animationDirection: keywordWithGlobal('animation-direction'),
|
||||
animationFillMode: keyword('animation-fill-mode'),
|
||||
animationIterationCount: animationIterationCount,
|
||||
animationName: animationName,
|
||||
animationPlayState: keywordWithGlobal('animation-play-state'),
|
||||
backgroundAttachment: keyword('background-attachment'),
|
||||
backgroundClip: keywordWithGlobal('background-clip'),
|
||||
backgroundOrigin: keyword('background-origin'),
|
||||
backgroundPosition: backgroundPosition,
|
||||
backgroundRepeat: keyword('background-repeat'),
|
||||
backgroundSize: backgroundSize,
|
||||
bottom: unitOrKeywordWithGlobal('bottom'),
|
||||
borderCollapse: keyword('border-collapse'),
|
||||
borderStyle: keywordWithGlobal('*-style'),
|
||||
clear: keywordWithGlobal('clear'),
|
||||
cursor: keywordWithGlobal('cursor'),
|
||||
display: keywordWithGlobal('display'),
|
||||
float: keywordWithGlobal('float'),
|
||||
left: unitOrKeywordWithGlobal('left'),
|
||||
fontFamily: fontFamily,
|
||||
fontStretch: keywordWithGlobal('font-stretch'),
|
||||
fontStyle: keywordWithGlobal('font-style'),
|
||||
fontVariant: keywordWithGlobal('font-variant'),
|
||||
fontWeight: keywordWithGlobal('font-weight'),
|
||||
listStyleType: keywordWithGlobal('list-style-type'),
|
||||
listStylePosition: keywordWithGlobal('list-style-position'),
|
||||
outlineStyle: keywordWithGlobal('*-style'),
|
||||
overflow: keywordWithGlobal('overflow'),
|
||||
position: keywordWithGlobal('position'),
|
||||
right: unitOrKeywordWithGlobal('right'),
|
||||
textAlign: keywordWithGlobal('text-align'),
|
||||
textDecoration: keywordWithGlobal('text-decoration'),
|
||||
textOverflow: keywordWithGlobal('text-overflow'),
|
||||
textShadow: textShadow,
|
||||
top: unitOrKeywordWithGlobal('top'),
|
||||
transform: sameFunctionOrValue,
|
||||
verticalAlign: unitOrKeywordWithGlobal('vertical-align'),
|
||||
visibility: keywordWithGlobal('visibility'),
|
||||
whiteSpace: keywordWithGlobal('white-space'),
|
||||
zIndex: zIndex
|
||||
}
|
||||
};
|
||||
@@ -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,"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.05264,"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,"90":0.15386,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0.05264,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0,"109":0.05264,"110":0,"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,"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,"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.05264,"72":0,"73":0,"74":0,"75":0.05264,"76":0,"77":0,"78":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.2065,"99":0,"100":7.73359,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0,"109":0.83005,"110":0.62355,"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.10527,"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.46564,"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.05264,"95":0.10527,"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.05264,"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.31177,"109":0.67618,"110":1.29973},E:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,_:"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,"14.1":0,"15.1":0,"15.2-15.3":0,"15.4":0,"15.5":0,"15.6":0.25914,"16.0":0,"16.1":0.05264,"16.2":0.41705,"16.3":0.98796,"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,"9.3":0,"10.0-10.2":0,"10.3":0,"11.0-11.2":0.0966,"11.3-11.4":0,"12.0-12.1":0,"12.2-12.5":0.19319,"13.0-13.1":0,"13.2":0,"13.3":0,"13.4-13.7":0,"14.0-14.4":0.0966,"14.5-14.8":0,"15.0-15.1":0,"15.2-15.3":0.0966,"15.4":1.73435,"15.5":20.79898,"15.6":1.73435,"16.0":2.21294,"16.1":8.57074,"16.2":5.87482,"16.3":1.63775,"16.4":0},P:{"4":0,"20":0,"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,"19.0":0},I:{"0":0,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0,"4.4":0,"4.4.3-4.4.4":0},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"5.5":0},N:{"10":0,"11":0},S:{"2.5":0,_:"3.0-3.1"},J:{"7":0,"10":0},O:{"0":27.76142},H:{"0":0},L:{"0":0.18356},R:{_:"0"},M:{"0":0},Q:{"13.1":0}};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"expand.js","sourceRoot":"","sources":["../../../../src/internal/operators/expand.ts"],"names":[],"mappings":";;;AACA,qCAAuC;AACvC,mDAAkD;AAuElD,SAAgB,MAAM,CACpB,OAAuC,EACvC,UAAqB,EACrB,SAAyB;IADzB,2BAAA,EAAA,qBAAqB;IAGrB,UAAU,GAAG,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC;IAC3D,OAAO,cAAO,CAAC,UAAC,MAAM,EAAE,UAAU;QAChC,OAAA,+BAAc,CAEZ,MAAM,EACN,UAAU,EACV,OAAO,EACP,UAAU,EAGV,SAAS,EAGT,IAAI,EACJ,SAAS,CACV;IAbD,CAaC,CACF,CAAC;AACJ,CAAC;AAtBD,wBAsBC"}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $species = GetIntrinsic('%Symbol.species%', true);
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
|
||||
var IsConstructor = require('./IsConstructor');
|
||||
var Type = require('./Type');
|
||||
|
||||
// https://262.ecma-international.org/6.0/#sec-speciesconstructor
|
||||
|
||||
module.exports = function SpeciesConstructor(O, defaultConstructor) {
|
||||
if (Type(O) !== 'Object') {
|
||||
throw new $TypeError('Assertion failed: Type(O) is not Object');
|
||||
}
|
||||
var C = O.constructor;
|
||||
if (typeof C === 'undefined') {
|
||||
return defaultConstructor;
|
||||
}
|
||||
if (Type(C) !== 'Object') {
|
||||
throw new $TypeError('O.constructor is not an Object');
|
||||
}
|
||||
var S = $species ? C[$species] : void 0;
|
||||
if (S == null) {
|
||||
return defaultConstructor;
|
||||
}
|
||||
if (IsConstructor(S)) {
|
||||
return S;
|
||||
}
|
||||
throw new $TypeError('no constructor found');
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
var baseFindKey = require('./_baseFindKey'),
|
||||
baseForOwnRight = require('./_baseForOwnRight'),
|
||||
baseIteratee = require('./_baseIteratee');
|
||||
|
||||
/**
|
||||
* This method is like `_.findKey` except that it iterates over elements of
|
||||
* a collection in the opposite order.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 2.0.0
|
||||
* @category Object
|
||||
* @param {Object} object The object to inspect.
|
||||
* @param {Function} [predicate=_.identity] The function invoked per iteration.
|
||||
* @returns {string|undefined} Returns the key of the matched element,
|
||||
* else `undefined`.
|
||||
* @example
|
||||
*
|
||||
* var users = {
|
||||
* 'barney': { 'age': 36, 'active': true },
|
||||
* 'fred': { 'age': 40, 'active': false },
|
||||
* 'pebbles': { 'age': 1, 'active': true }
|
||||
* };
|
||||
*
|
||||
* _.findLastKey(users, function(o) { return o.age < 40; });
|
||||
* // => returns 'pebbles' assuming `_.findKey` returns 'barney'
|
||||
*
|
||||
* // The `_.matches` iteratee shorthand.
|
||||
* _.findLastKey(users, { 'age': 36, 'active': true });
|
||||
* // => 'barney'
|
||||
*
|
||||
* // The `_.matchesProperty` iteratee shorthand.
|
||||
* _.findLastKey(users, ['active', false]);
|
||||
* // => 'fred'
|
||||
*
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.findLastKey(users, 'active');
|
||||
* // => 'pebbles'
|
||||
*/
|
||||
function findLastKey(object, predicate) {
|
||||
return baseFindKey(object, baseIteratee(predicate, 3), baseForOwnRight);
|
||||
}
|
||||
|
||||
module.exports = findLastKey;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
if (!require("./is-implemented")()) {
|
||||
Object.defineProperty(Array.prototype, "entries", {
|
||||
value: require("./shim"),
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { ClientRequest } from 'node:http';
|
||||
declare const reentry: unique symbol;
|
||||
type TimedOutOptions = {
|
||||
host?: string;
|
||||
hostname?: string;
|
||||
protocol?: string;
|
||||
};
|
||||
export type Delays = {
|
||||
lookup?: number;
|
||||
socket?: number;
|
||||
connect?: number;
|
||||
secureConnect?: number;
|
||||
send?: number;
|
||||
response?: number;
|
||||
read?: number;
|
||||
request?: number;
|
||||
};
|
||||
export type ErrorCode = 'ETIMEDOUT' | 'ECONNRESET' | 'EADDRINUSE' | 'ECONNREFUSED' | 'EPIPE' | 'ENOTFOUND' | 'ENETUNREACH' | 'EAI_AGAIN';
|
||||
export declare class TimeoutError extends Error {
|
||||
event: string;
|
||||
code: ErrorCode;
|
||||
constructor(threshold: number, event: string);
|
||||
}
|
||||
export default function timedOut(request: ClientRequest, delays: Delays, options: TimedOutOptions): () => void;
|
||||
declare module 'http' {
|
||||
interface ClientRequest {
|
||||
[reentry]?: boolean;
|
||||
}
|
||||
}
|
||||
export {};
|
||||
@@ -0,0 +1,5 @@
|
||||
import Renderer, { RenderOptions } from '../Renderer';
|
||||
import SlotTemplate from '../../nodes/SlotTemplate';
|
||||
export default function (node: SlotTemplate, renderer: Renderer, options: RenderOptions & {
|
||||
slot_scopes: Map<any, any>;
|
||||
}): void;
|
||||
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.iif = void 0;
|
||||
var defer_1 = require("./defer");
|
||||
function iif(condition, trueResult, falseResult) {
|
||||
return defer_1.defer(function () { return (condition() ? trueResult : falseResult); });
|
||||
}
|
||||
exports.iif = iif;
|
||||
//# sourceMappingURL=iif.js.map
|
||||
@@ -0,0 +1,136 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Code coverage report for csv2json/testNew</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="../../prettify.css" />
|
||||
<link rel="stylesheet" href="../../base.css" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style type='text/css'>
|
||||
.coverage-summary .sorter {
|
||||
background-image: url(../../sort-arrow-sprite.png);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='wrapper'>
|
||||
<div class='pad1'>
|
||||
<h1>
|
||||
<a href="../../index.html">All files</a> csv2json/testNew
|
||||
</h1>
|
||||
<div class='clearfix'>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">98.58% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>208/211</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>1/1</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>22/22</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">98.58% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>208/211</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
</div>
|
||||
<div class='status-line high'></div>
|
||||
<div class="pad1">
|
||||
<table class="coverage-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
|
||||
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
|
||||
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
|
||||
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
|
||||
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
|
||||
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
|
||||
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td class="file high" data-value="testCSVConverter.ts"><a href="testCSVConverter.ts.html">testCSVConverter.ts</a></td>
|
||||
<td data-value="98.95" class="pic high"><div class="chart"><div class="cover-fill" style="width: 98%;"></div><div class="cover-empty" style="width:2%;"></div></div></td>
|
||||
<td data-value="98.95" class="pct high">98.95%</td>
|
||||
<td data-value="95" class="abs high">94/95</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="1" class="abs high">1/1</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="5" class="abs high">5/5</td>
|
||||
<td data-value="98.95" class="pct high">98.95%</td>
|
||||
<td data-value="95" class="abs high">94/95</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="file high" data-value="testCSVConverter2.ts"><a href="testCSVConverter2.ts.html">testCSVConverter2.ts</a></td>
|
||||
<td data-value="98" class="pic high"><div class="chart"><div class="cover-fill" style="width: 98%;"></div><div class="cover-empty" style="width:2%;"></div></div></td>
|
||||
<td data-value="98" class="pct high">98%</td>
|
||||
<td data-value="100" class="abs high">98/100</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="0" class="abs high">0/0</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="15" class="abs high">15/15</td>
|
||||
<td data-value="98" class="pct high">98%</td>
|
||||
<td data-value="100" class="abs high">98/100</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="file high" data-value="testCSVConverter3.ts"><a href="testCSVConverter3.ts.html">testCSVConverter3.ts</a></td>
|
||||
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="4" class="abs high">4/4</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="0" class="abs high">0/0</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="0" class="abs high">0/0</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="4" class="abs high">4/4</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="file high" data-value="testErrorHandle.ts"><a href="testErrorHandle.ts.html">testErrorHandle.ts</a></td>
|
||||
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="12" class="abs high">12/12</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="0" class="abs high">0/0</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="2" class="abs high">2/2</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="12" class="abs high">12/12</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div><div class='push'></div><!-- for sticky footer -->
|
||||
</div><!-- /wrapper -->
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage
|
||||
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Fri May 11 2018 21:20:20 GMT+0100 (IST)
|
||||
</div>
|
||||
</div>
|
||||
<script src="../../prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
if (typeof prettyPrint === 'function') {
|
||||
prettyPrint();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script src="../../sorter.js"></script>
|
||||
<script src="../../block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,584 @@
|
||||
# safe-buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
|
||||
|
||||
[travis-image]: https://img.shields.io/travis/feross/safe-buffer/master.svg
|
||||
[travis-url]: https://travis-ci.org/feross/safe-buffer
|
||||
[npm-image]: https://img.shields.io/npm/v/safe-buffer.svg
|
||||
[npm-url]: https://npmjs.org/package/safe-buffer
|
||||
[downloads-image]: https://img.shields.io/npm/dm/safe-buffer.svg
|
||||
[downloads-url]: https://npmjs.org/package/safe-buffer
|
||||
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
|
||||
[standard-url]: https://standardjs.com
|
||||
|
||||
#### Safer Node.js Buffer API
|
||||
|
||||
**Use the new Node.js Buffer APIs (`Buffer.from`, `Buffer.alloc`,
|
||||
`Buffer.allocUnsafe`, `Buffer.allocUnsafeSlow`) in all versions of Node.js.**
|
||||
|
||||
**Uses the built-in implementation when available.**
|
||||
|
||||
## install
|
||||
|
||||
```
|
||||
npm install safe-buffer
|
||||
```
|
||||
|
||||
## usage
|
||||
|
||||
The goal of this package is to provide a safe replacement for the node.js `Buffer`.
|
||||
|
||||
It's a drop-in replacement for `Buffer`. You can use it by adding one `require` line to
|
||||
the top of your node.js modules:
|
||||
|
||||
```js
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
|
||||
// Existing buffer code will continue to work without issues:
|
||||
|
||||
new Buffer('hey', 'utf8')
|
||||
new Buffer([1, 2, 3], 'utf8')
|
||||
new Buffer(obj)
|
||||
new Buffer(16) // create an uninitialized buffer (potentially unsafe)
|
||||
|
||||
// But you can use these new explicit APIs to make clear what you want:
|
||||
|
||||
Buffer.from('hey', 'utf8') // convert from many types to a Buffer
|
||||
Buffer.alloc(16) // create a zero-filled buffer (safe)
|
||||
Buffer.allocUnsafe(16) // create an uninitialized buffer (potentially unsafe)
|
||||
```
|
||||
|
||||
## api
|
||||
|
||||
### Class Method: Buffer.from(array)
|
||||
<!-- YAML
|
||||
added: v3.0.0
|
||||
-->
|
||||
|
||||
* `array` {Array}
|
||||
|
||||
Allocates a new `Buffer` using an `array` of octets.
|
||||
|
||||
```js
|
||||
const buf = Buffer.from([0x62,0x75,0x66,0x66,0x65,0x72]);
|
||||
// creates a new Buffer containing ASCII bytes
|
||||
// ['b','u','f','f','e','r']
|
||||
```
|
||||
|
||||
A `TypeError` will be thrown if `array` is not an `Array`.
|
||||
|
||||
### Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
|
||||
<!-- YAML
|
||||
added: v5.10.0
|
||||
-->
|
||||
|
||||
* `arrayBuffer` {ArrayBuffer} The `.buffer` property of a `TypedArray` or
|
||||
a `new ArrayBuffer()`
|
||||
* `byteOffset` {Number} Default: `0`
|
||||
* `length` {Number} Default: `arrayBuffer.length - byteOffset`
|
||||
|
||||
When passed a reference to the `.buffer` property of a `TypedArray` instance,
|
||||
the newly created `Buffer` will share the same allocated memory as the
|
||||
TypedArray.
|
||||
|
||||
```js
|
||||
const arr = new Uint16Array(2);
|
||||
arr[0] = 5000;
|
||||
arr[1] = 4000;
|
||||
|
||||
const buf = Buffer.from(arr.buffer); // shares the memory with arr;
|
||||
|
||||
console.log(buf);
|
||||
// Prints: <Buffer 88 13 a0 0f>
|
||||
|
||||
// changing the TypedArray changes the Buffer also
|
||||
arr[1] = 6000;
|
||||
|
||||
console.log(buf);
|
||||
// Prints: <Buffer 88 13 70 17>
|
||||
```
|
||||
|
||||
The optional `byteOffset` and `length` arguments specify a memory range within
|
||||
the `arrayBuffer` that will be shared by the `Buffer`.
|
||||
|
||||
```js
|
||||
const ab = new ArrayBuffer(10);
|
||||
const buf = Buffer.from(ab, 0, 2);
|
||||
console.log(buf.length);
|
||||
// Prints: 2
|
||||
```
|
||||
|
||||
A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer`.
|
||||
|
||||
### Class Method: Buffer.from(buffer)
|
||||
<!-- YAML
|
||||
added: v3.0.0
|
||||
-->
|
||||
|
||||
* `buffer` {Buffer}
|
||||
|
||||
Copies the passed `buffer` data onto a new `Buffer` instance.
|
||||
|
||||
```js
|
||||
const buf1 = Buffer.from('buffer');
|
||||
const buf2 = Buffer.from(buf1);
|
||||
|
||||
buf1[0] = 0x61;
|
||||
console.log(buf1.toString());
|
||||
// 'auffer'
|
||||
console.log(buf2.toString());
|
||||
// 'buffer' (copy is not changed)
|
||||
```
|
||||
|
||||
A `TypeError` will be thrown if `buffer` is not a `Buffer`.
|
||||
|
||||
### Class Method: Buffer.from(str[, encoding])
|
||||
<!-- YAML
|
||||
added: v5.10.0
|
||||
-->
|
||||
|
||||
* `str` {String} String to encode.
|
||||
* `encoding` {String} Encoding to use, Default: `'utf8'`
|
||||
|
||||
Creates a new `Buffer` containing the given JavaScript string `str`. If
|
||||
provided, the `encoding` parameter identifies the character encoding.
|
||||
If not provided, `encoding` defaults to `'utf8'`.
|
||||
|
||||
```js
|
||||
const buf1 = Buffer.from('this is a tést');
|
||||
console.log(buf1.toString());
|
||||
// prints: this is a tést
|
||||
console.log(buf1.toString('ascii'));
|
||||
// prints: this is a tC)st
|
||||
|
||||
const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');
|
||||
console.log(buf2.toString());
|
||||
// prints: this is a tést
|
||||
```
|
||||
|
||||
A `TypeError` will be thrown if `str` is not a string.
|
||||
|
||||
### Class Method: Buffer.alloc(size[, fill[, encoding]])
|
||||
<!-- YAML
|
||||
added: v5.10.0
|
||||
-->
|
||||
|
||||
* `size` {Number}
|
||||
* `fill` {Value} Default: `undefined`
|
||||
* `encoding` {String} Default: `utf8`
|
||||
|
||||
Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the
|
||||
`Buffer` will be *zero-filled*.
|
||||
|
||||
```js
|
||||
const buf = Buffer.alloc(5);
|
||||
console.log(buf);
|
||||
// <Buffer 00 00 00 00 00>
|
||||
```
|
||||
|
||||
The `size` must be less than or equal to the value of
|
||||
`require('buffer').kMaxLength` (on 64-bit architectures, `kMaxLength` is
|
||||
`(2^31)-1`). Otherwise, a [`RangeError`][] is thrown. A zero-length Buffer will
|
||||
be created if a `size` less than or equal to 0 is specified.
|
||||
|
||||
If `fill` is specified, the allocated `Buffer` will be initialized by calling
|
||||
`buf.fill(fill)`. See [`buf.fill()`][] for more information.
|
||||
|
||||
```js
|
||||
const buf = Buffer.alloc(5, 'a');
|
||||
console.log(buf);
|
||||
// <Buffer 61 61 61 61 61>
|
||||
```
|
||||
|
||||
If both `fill` and `encoding` are specified, the allocated `Buffer` will be
|
||||
initialized by calling `buf.fill(fill, encoding)`. For example:
|
||||
|
||||
```js
|
||||
const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
|
||||
console.log(buf);
|
||||
// <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
|
||||
```
|
||||
|
||||
Calling `Buffer.alloc(size)` can be significantly slower than the alternative
|
||||
`Buffer.allocUnsafe(size)` but ensures that the newly created `Buffer` instance
|
||||
contents will *never contain sensitive data*.
|
||||
|
||||
A `TypeError` will be thrown if `size` is not a number.
|
||||
|
||||
### Class Method: Buffer.allocUnsafe(size)
|
||||
<!-- YAML
|
||||
added: v5.10.0
|
||||
-->
|
||||
|
||||
* `size` {Number}
|
||||
|
||||
Allocates a new *non-zero-filled* `Buffer` of `size` bytes. The `size` must
|
||||
be less than or equal to the value of `require('buffer').kMaxLength` (on 64-bit
|
||||
architectures, `kMaxLength` is `(2^31)-1`). Otherwise, a [`RangeError`][] is
|
||||
thrown. A zero-length Buffer will be created if a `size` less than or equal to
|
||||
0 is specified.
|
||||
|
||||
The underlying memory for `Buffer` instances created in this way is *not
|
||||
initialized*. The contents of the newly created `Buffer` are unknown and
|
||||
*may contain sensitive data*. Use [`buf.fill(0)`][] to initialize such
|
||||
`Buffer` instances to zeroes.
|
||||
|
||||
```js
|
||||
const buf = Buffer.allocUnsafe(5);
|
||||
console.log(buf);
|
||||
// <Buffer 78 e0 82 02 01>
|
||||
// (octets will be different, every time)
|
||||
buf.fill(0);
|
||||
console.log(buf);
|
||||
// <Buffer 00 00 00 00 00>
|
||||
```
|
||||
|
||||
A `TypeError` will be thrown if `size` is not a number.
|
||||
|
||||
Note that the `Buffer` module pre-allocates an internal `Buffer` instance of
|
||||
size `Buffer.poolSize` that is used as a pool for the fast allocation of new
|
||||
`Buffer` instances created using `Buffer.allocUnsafe(size)` (and the deprecated
|
||||
`new Buffer(size)` constructor) only when `size` is less than or equal to
|
||||
`Buffer.poolSize >> 1` (floor of `Buffer.poolSize` divided by two). The default
|
||||
value of `Buffer.poolSize` is `8192` but can be modified.
|
||||
|
||||
Use of this pre-allocated internal memory pool is a key difference between
|
||||
calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
|
||||
Specifically, `Buffer.alloc(size, fill)` will *never* use the internal Buffer
|
||||
pool, while `Buffer.allocUnsafe(size).fill(fill)` *will* use the internal
|
||||
Buffer pool if `size` is less than or equal to half `Buffer.poolSize`. The
|
||||
difference is subtle but can be important when an application requires the
|
||||
additional performance that `Buffer.allocUnsafe(size)` provides.
|
||||
|
||||
### Class Method: Buffer.allocUnsafeSlow(size)
|
||||
<!-- YAML
|
||||
added: v5.10.0
|
||||
-->
|
||||
|
||||
* `size` {Number}
|
||||
|
||||
Allocates a new *non-zero-filled* and non-pooled `Buffer` of `size` bytes. The
|
||||
`size` must be less than or equal to the value of
|
||||
`require('buffer').kMaxLength` (on 64-bit architectures, `kMaxLength` is
|
||||
`(2^31)-1`). Otherwise, a [`RangeError`][] is thrown. A zero-length Buffer will
|
||||
be created if a `size` less than or equal to 0 is specified.
|
||||
|
||||
The underlying memory for `Buffer` instances created in this way is *not
|
||||
initialized*. The contents of the newly created `Buffer` are unknown and
|
||||
*may contain sensitive data*. Use [`buf.fill(0)`][] to initialize such
|
||||
`Buffer` instances to zeroes.
|
||||
|
||||
When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
|
||||
allocations under 4KB are, by default, sliced from a single pre-allocated
|
||||
`Buffer`. This allows applications to avoid the garbage collection overhead of
|
||||
creating many individually allocated Buffers. This approach improves both
|
||||
performance and memory usage by eliminating the need to track and cleanup as
|
||||
many `Persistent` objects.
|
||||
|
||||
However, in the case where a developer may need to retain a small chunk of
|
||||
memory from a pool for an indeterminate amount of time, it may be appropriate
|
||||
to create an un-pooled Buffer instance using `Buffer.allocUnsafeSlow()` then
|
||||
copy out the relevant bits.
|
||||
|
||||
```js
|
||||
// need to keep around a few small chunks of memory
|
||||
const store = [];
|
||||
|
||||
socket.on('readable', () => {
|
||||
const data = socket.read();
|
||||
// allocate for retained data
|
||||
const sb = Buffer.allocUnsafeSlow(10);
|
||||
// copy the data into the new allocation
|
||||
data.copy(sb, 0, 0, 10);
|
||||
store.push(sb);
|
||||
});
|
||||
```
|
||||
|
||||
Use of `Buffer.allocUnsafeSlow()` should be used only as a last resort *after*
|
||||
a developer has observed undue memory retention in their applications.
|
||||
|
||||
A `TypeError` will be thrown if `size` is not a number.
|
||||
|
||||
### All the Rest
|
||||
|
||||
The rest of the `Buffer` API is exactly the same as in node.js.
|
||||
[See the docs](https://nodejs.org/api/buffer.html).
|
||||
|
||||
|
||||
## Related links
|
||||
|
||||
- [Node.js issue: Buffer(number) is unsafe](https://github.com/nodejs/node/issues/4660)
|
||||
- [Node.js Enhancement Proposal: Buffer.from/Buffer.alloc/Buffer.zalloc/Buffer() soft-deprecate](https://github.com/nodejs/node-eps/pull/4)
|
||||
|
||||
## Why is `Buffer` unsafe?
|
||||
|
||||
Today, the node.js `Buffer` constructor is overloaded to handle many different argument
|
||||
types like `String`, `Array`, `Object`, `TypedArrayView` (`Uint8Array`, etc.),
|
||||
`ArrayBuffer`, and also `Number`.
|
||||
|
||||
The API is optimized for convenience: you can throw any type at it, and it will try to do
|
||||
what you want.
|
||||
|
||||
Because the Buffer constructor is so powerful, you often see code like this:
|
||||
|
||||
```js
|
||||
// Convert UTF-8 strings to hex
|
||||
function toHex (str) {
|
||||
return new Buffer(str).toString('hex')
|
||||
}
|
||||
```
|
||||
|
||||
***But what happens if `toHex` is called with a `Number` argument?***
|
||||
|
||||
### Remote Memory Disclosure
|
||||
|
||||
If an attacker can make your program call the `Buffer` constructor with a `Number`
|
||||
argument, then they can make it allocate uninitialized memory from the node.js process.
|
||||
This could potentially disclose TLS private keys, user data, or database passwords.
|
||||
|
||||
When the `Buffer` constructor is passed a `Number` argument, it returns an
|
||||
**UNINITIALIZED** block of memory of the specified `size`. When you create a `Buffer` like
|
||||
this, you **MUST** overwrite the contents before returning it to the user.
|
||||
|
||||
From the [node.js docs](https://nodejs.org/api/buffer.html#buffer_new_buffer_size):
|
||||
|
||||
> `new Buffer(size)`
|
||||
>
|
||||
> - `size` Number
|
||||
>
|
||||
> The underlying memory for `Buffer` instances created in this way is not initialized.
|
||||
> **The contents of a newly created `Buffer` are unknown and could contain sensitive
|
||||
> data.** Use `buf.fill(0)` to initialize a Buffer to zeroes.
|
||||
|
||||
(Emphasis our own.)
|
||||
|
||||
Whenever the programmer intended to create an uninitialized `Buffer` you often see code
|
||||
like this:
|
||||
|
||||
```js
|
||||
var buf = new Buffer(16)
|
||||
|
||||
// Immediately overwrite the uninitialized buffer with data from another buffer
|
||||
for (var i = 0; i < buf.length; i++) {
|
||||
buf[i] = otherBuf[i]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Would this ever be a problem in real code?
|
||||
|
||||
Yes. It's surprisingly common to forget to check the type of your variables in a
|
||||
dynamically-typed language like JavaScript.
|
||||
|
||||
Usually the consequences of assuming the wrong type is that your program crashes with an
|
||||
uncaught exception. But the failure mode for forgetting to check the type of arguments to
|
||||
the `Buffer` constructor is more catastrophic.
|
||||
|
||||
Here's an example of a vulnerable service that takes a JSON payload and converts it to
|
||||
hex:
|
||||
|
||||
```js
|
||||
// Take a JSON payload {str: "some string"} and convert it to hex
|
||||
var server = http.createServer(function (req, res) {
|
||||
var data = ''
|
||||
req.setEncoding('utf8')
|
||||
req.on('data', function (chunk) {
|
||||
data += chunk
|
||||
})
|
||||
req.on('end', function () {
|
||||
var body = JSON.parse(data)
|
||||
res.end(new Buffer(body.str).toString('hex'))
|
||||
})
|
||||
})
|
||||
|
||||
server.listen(8080)
|
||||
```
|
||||
|
||||
In this example, an http client just has to send:
|
||||
|
||||
```json
|
||||
{
|
||||
"str": 1000
|
||||
}
|
||||
```
|
||||
|
||||
and it will get back 1,000 bytes of uninitialized memory from the server.
|
||||
|
||||
This is a very serious bug. It's similar in severity to the
|
||||
[the Heartbleed bug](http://heartbleed.com/) that allowed disclosure of OpenSSL process
|
||||
memory by remote attackers.
|
||||
|
||||
|
||||
### Which real-world packages were vulnerable?
|
||||
|
||||
#### [`bittorrent-dht`](https://www.npmjs.com/package/bittorrent-dht)
|
||||
|
||||
[Mathias Buus](https://github.com/mafintosh) and I
|
||||
([Feross Aboukhadijeh](http://feross.org/)) found this issue in one of our own packages,
|
||||
[`bittorrent-dht`](https://www.npmjs.com/package/bittorrent-dht). The bug would allow
|
||||
anyone on the internet to send a series of messages to a user of `bittorrent-dht` and get
|
||||
them to reveal 20 bytes at a time of uninitialized memory from the node.js process.
|
||||
|
||||
Here's
|
||||
[the commit](https://github.com/feross/bittorrent-dht/commit/6c7da04025d5633699800a99ec3fbadf70ad35b8)
|
||||
that fixed it. We released a new fixed version, created a
|
||||
[Node Security Project disclosure](https://nodesecurity.io/advisories/68), and deprecated all
|
||||
vulnerable versions on npm so users will get a warning to upgrade to a newer version.
|
||||
|
||||
#### [`ws`](https://www.npmjs.com/package/ws)
|
||||
|
||||
That got us wondering if there were other vulnerable packages. Sure enough, within a short
|
||||
period of time, we found the same issue in [`ws`](https://www.npmjs.com/package/ws), the
|
||||
most popular WebSocket implementation in node.js.
|
||||
|
||||
If certain APIs were called with `Number` parameters instead of `String` or `Buffer` as
|
||||
expected, then uninitialized server memory would be disclosed to the remote peer.
|
||||
|
||||
These were the vulnerable methods:
|
||||
|
||||
```js
|
||||
socket.send(number)
|
||||
socket.ping(number)
|
||||
socket.pong(number)
|
||||
```
|
||||
|
||||
Here's a vulnerable socket server with some echo functionality:
|
||||
|
||||
```js
|
||||
server.on('connection', function (socket) {
|
||||
socket.on('message', function (message) {
|
||||
message = JSON.parse(message)
|
||||
if (message.type === 'echo') {
|
||||
socket.send(message.data) // send back the user's message
|
||||
}
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
`socket.send(number)` called on the server, will disclose server memory.
|
||||
|
||||
Here's [the release](https://github.com/websockets/ws/releases/tag/1.0.1) where the issue
|
||||
was fixed, with a more detailed explanation. Props to
|
||||
[Arnout Kazemier](https://github.com/3rd-Eden) for the quick fix. Here's the
|
||||
[Node Security Project disclosure](https://nodesecurity.io/advisories/67).
|
||||
|
||||
|
||||
### What's the solution?
|
||||
|
||||
It's important that node.js offers a fast way to get memory otherwise performance-critical
|
||||
applications would needlessly get a lot slower.
|
||||
|
||||
But we need a better way to *signal our intent* as programmers. **When we want
|
||||
uninitialized memory, we should request it explicitly.**
|
||||
|
||||
Sensitive functionality should not be packed into a developer-friendly API that loosely
|
||||
accepts many different types. This type of API encourages the lazy practice of passing
|
||||
variables in without checking the type very carefully.
|
||||
|
||||
#### A new API: `Buffer.allocUnsafe(number)`
|
||||
|
||||
The functionality of creating buffers with uninitialized memory should be part of another
|
||||
API. We propose `Buffer.allocUnsafe(number)`. This way, it's not part of an API that
|
||||
frequently gets user input of all sorts of different types passed into it.
|
||||
|
||||
```js
|
||||
var buf = Buffer.allocUnsafe(16) // careful, uninitialized memory!
|
||||
|
||||
// Immediately overwrite the uninitialized buffer with data from another buffer
|
||||
for (var i = 0; i < buf.length; i++) {
|
||||
buf[i] = otherBuf[i]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### How do we fix node.js core?
|
||||
|
||||
We sent [a PR to node.js core](https://github.com/nodejs/node/pull/4514) (merged as
|
||||
`semver-major`) which defends against one case:
|
||||
|
||||
```js
|
||||
var str = 16
|
||||
new Buffer(str, 'utf8')
|
||||
```
|
||||
|
||||
In this situation, it's implied that the programmer intended the first argument to be a
|
||||
string, since they passed an encoding as a second argument. Today, node.js will allocate
|
||||
uninitialized memory in the case of `new Buffer(number, encoding)`, which is probably not
|
||||
what the programmer intended.
|
||||
|
||||
But this is only a partial solution, since if the programmer does `new Buffer(variable)`
|
||||
(without an `encoding` parameter) there's no way to know what they intended. If `variable`
|
||||
is sometimes a number, then uninitialized memory will sometimes be returned.
|
||||
|
||||
### What's the real long-term fix?
|
||||
|
||||
We could deprecate and remove `new Buffer(number)` and use `Buffer.allocUnsafe(number)` when
|
||||
we need uninitialized memory. But that would break 1000s of packages.
|
||||
|
||||
~~We believe the best solution is to:~~
|
||||
|
||||
~~1. Change `new Buffer(number)` to return safe, zeroed-out memory~~
|
||||
|
||||
~~2. Create a new API for creating uninitialized Buffers. We propose: `Buffer.allocUnsafe(number)`~~
|
||||
|
||||
#### Update
|
||||
|
||||
We now support adding three new APIs:
|
||||
|
||||
- `Buffer.from(value)` - convert from any type to a buffer
|
||||
- `Buffer.alloc(size)` - create a zero-filled buffer
|
||||
- `Buffer.allocUnsafe(size)` - create an uninitialized buffer with given size
|
||||
|
||||
This solves the core problem that affected `ws` and `bittorrent-dht` which is
|
||||
`Buffer(variable)` getting tricked into taking a number argument.
|
||||
|
||||
This way, existing code continues working and the impact on the npm ecosystem will be
|
||||
minimal. Over time, npm maintainers can migrate performance-critical code to use
|
||||
`Buffer.allocUnsafe(number)` instead of `new Buffer(number)`.
|
||||
|
||||
|
||||
### Conclusion
|
||||
|
||||
We think there's a serious design issue with the `Buffer` API as it exists today. It
|
||||
promotes insecure software by putting high-risk functionality into a convenient API
|
||||
with friendly "developer ergonomics".
|
||||
|
||||
This wasn't merely a theoretical exercise because we found the issue in some of the
|
||||
most popular npm packages.
|
||||
|
||||
Fortunately, there's an easy fix that can be applied today. Use `safe-buffer` in place of
|
||||
`buffer`.
|
||||
|
||||
```js
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
```
|
||||
|
||||
Eventually, we hope that node.js core can switch to this new, safer behavior. We believe
|
||||
the impact on the ecosystem would be minimal since it's not a breaking change.
|
||||
Well-maintained, popular packages would be updated to use `Buffer.alloc` quickly, while
|
||||
older, insecure packages would magically become safe from this attack vector.
|
||||
|
||||
|
||||
## links
|
||||
|
||||
- [Node.js PR: buffer: throw if both length and enc are passed](https://github.com/nodejs/node/pull/4514)
|
||||
- [Node Security Project disclosure for `ws`](https://nodesecurity.io/advisories/67)
|
||||
- [Node Security Project disclosure for`bittorrent-dht`](https://nodesecurity.io/advisories/68)
|
||||
|
||||
|
||||
## credit
|
||||
|
||||
The original issues in `bittorrent-dht`
|
||||
([disclosure](https://nodesecurity.io/advisories/68)) and
|
||||
`ws` ([disclosure](https://nodesecurity.io/advisories/67)) were discovered by
|
||||
[Mathias Buus](https://github.com/mafintosh) and
|
||||
[Feross Aboukhadijeh](http://feross.org/).
|
||||
|
||||
Thanks to [Adam Baldwin](https://github.com/evilpacket) for helping disclose these issues
|
||||
and for his work running the [Node Security Project](https://nodesecurity.io/).
|
||||
|
||||
Thanks to [John Hiesey](https://github.com/jhiesey) for proofreading this README and
|
||||
auditing the code.
|
||||
|
||||
|
||||
## license
|
||||
|
||||
MIT. Copyright (C) [Feross Aboukhadijeh](http://feross.org)
|
||||
@@ -0,0 +1,67 @@
|
||||
module.exports = {
|
||||
'chunk': require('./chunk'),
|
||||
'compact': require('./compact'),
|
||||
'concat': require('./concat'),
|
||||
'difference': require('./difference'),
|
||||
'differenceBy': require('./differenceBy'),
|
||||
'differenceWith': require('./differenceWith'),
|
||||
'drop': require('./drop'),
|
||||
'dropRight': require('./dropRight'),
|
||||
'dropRightWhile': require('./dropRightWhile'),
|
||||
'dropWhile': require('./dropWhile'),
|
||||
'fill': require('./fill'),
|
||||
'findIndex': require('./findIndex'),
|
||||
'findLastIndex': require('./findLastIndex'),
|
||||
'first': require('./first'),
|
||||
'flatten': require('./flatten'),
|
||||
'flattenDeep': require('./flattenDeep'),
|
||||
'flattenDepth': require('./flattenDepth'),
|
||||
'fromPairs': require('./fromPairs'),
|
||||
'head': require('./head'),
|
||||
'indexOf': require('./indexOf'),
|
||||
'initial': require('./initial'),
|
||||
'intersection': require('./intersection'),
|
||||
'intersectionBy': require('./intersectionBy'),
|
||||
'intersectionWith': require('./intersectionWith'),
|
||||
'join': require('./join'),
|
||||
'last': require('./last'),
|
||||
'lastIndexOf': require('./lastIndexOf'),
|
||||
'nth': require('./nth'),
|
||||
'pull': require('./pull'),
|
||||
'pullAll': require('./pullAll'),
|
||||
'pullAllBy': require('./pullAllBy'),
|
||||
'pullAllWith': require('./pullAllWith'),
|
||||
'pullAt': require('./pullAt'),
|
||||
'remove': require('./remove'),
|
||||
'reverse': require('./reverse'),
|
||||
'slice': require('./slice'),
|
||||
'sortedIndex': require('./sortedIndex'),
|
||||
'sortedIndexBy': require('./sortedIndexBy'),
|
||||
'sortedIndexOf': require('./sortedIndexOf'),
|
||||
'sortedLastIndex': require('./sortedLastIndex'),
|
||||
'sortedLastIndexBy': require('./sortedLastIndexBy'),
|
||||
'sortedLastIndexOf': require('./sortedLastIndexOf'),
|
||||
'sortedUniq': require('./sortedUniq'),
|
||||
'sortedUniqBy': require('./sortedUniqBy'),
|
||||
'tail': require('./tail'),
|
||||
'take': require('./take'),
|
||||
'takeRight': require('./takeRight'),
|
||||
'takeRightWhile': require('./takeRightWhile'),
|
||||
'takeWhile': require('./takeWhile'),
|
||||
'union': require('./union'),
|
||||
'unionBy': require('./unionBy'),
|
||||
'unionWith': require('./unionWith'),
|
||||
'uniq': require('./uniq'),
|
||||
'uniqBy': require('./uniqBy'),
|
||||
'uniqWith': require('./uniqWith'),
|
||||
'unzip': require('./unzip'),
|
||||
'unzipWith': require('./unzipWith'),
|
||||
'without': require('./without'),
|
||||
'xor': require('./xor'),
|
||||
'xorBy': require('./xorBy'),
|
||||
'xorWith': require('./xorWith'),
|
||||
'zip': require('./zip'),
|
||||
'zipObject': require('./zipObject'),
|
||||
'zipObjectDeep': require('./zipObjectDeep'),
|
||||
'zipWith': require('./zipWith')
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright 2010 James Halliday (mail@substack.net); Modified work Copyright 2014 Contributors (ben@npmjs.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,58 @@
|
||||
import { observeNotification } from '../Notification';
|
||||
import { OperatorFunction, ObservableNotification, ValueFromNotification } from '../types';
|
||||
import { operate } from '../util/lift';
|
||||
import { createOperatorSubscriber } from './OperatorSubscriber';
|
||||
|
||||
/**
|
||||
* Converts an Observable of {@link ObservableNotification} objects into the emissions
|
||||
* that they represent.
|
||||
*
|
||||
* <span class="informal">Unwraps {@link ObservableNotification} objects as actual `next`,
|
||||
* `error` and `complete` emissions. The opposite of {@link materialize}.</span>
|
||||
*
|
||||
* 
|
||||
*
|
||||
* `dematerialize` is assumed to operate an Observable that only emits
|
||||
* {@link ObservableNotification} objects as `next` emissions, and does not emit any
|
||||
* `error`. Such Observable is the output of a `materialize` operation. Those
|
||||
* notifications are then unwrapped using the metadata they contain, and emitted
|
||||
* as `next`, `error`, and `complete` on the output Observable.
|
||||
*
|
||||
* Use this operator in conjunction with {@link materialize}.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* Convert an Observable of Notifications to an actual Observable
|
||||
*
|
||||
* ```ts
|
||||
* import { NextNotification, ErrorNotification, of, dematerialize } from 'rxjs';
|
||||
*
|
||||
* const notifA: NextNotification<string> = { kind: 'N', value: 'A' };
|
||||
* const notifB: NextNotification<string> = { kind: 'N', value: 'B' };
|
||||
* const notifE: ErrorNotification = { kind: 'E', error: new TypeError('x.toUpperCase is not a function') };
|
||||
*
|
||||
* const materialized = of(notifA, notifB, notifE);
|
||||
*
|
||||
* const upperCase = materialized.pipe(dematerialize());
|
||||
* upperCase.subscribe({
|
||||
* next: x => console.log(x),
|
||||
* error: e => console.error(e)
|
||||
* });
|
||||
*
|
||||
* // Results in:
|
||||
* // A
|
||||
* // B
|
||||
* // TypeError: x.toUpperCase is not a function
|
||||
* ```
|
||||
*
|
||||
* @see {@link materialize}
|
||||
*
|
||||
* @return A function that returns an Observable that emits items and
|
||||
* notifications embedded in Notification objects emitted by the source
|
||||
* Observable.
|
||||
*/
|
||||
export function dematerialize<N extends ObservableNotification<any>>(): OperatorFunction<N, ValueFromNotification<N>> {
|
||||
return operate((source, subscriber) => {
|
||||
source.subscribe(createOperatorSubscriber(subscriber, (notification) => observeNotification(notification, subscriber)));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import assertString from './util/assertString';
|
||||
var hslComma = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(,(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}(,((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?))?\)$/i;
|
||||
var hslSpace = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(\s(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s?(\/\s((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s?)?\)$/i;
|
||||
export default function isHSL(str) {
|
||||
assertString(str); // Strip duplicate spaces before calling the validation regex (See #1598 for more info)
|
||||
|
||||
var strippedStr = str.replace(/\s+/g, ' ').replace(/\s?(hsla?\(|\)|,)\s?/ig, '$1');
|
||||
|
||||
if (strippedStr.indexOf(',') !== -1) {
|
||||
return hslComma.test(strippedStr);
|
||||
}
|
||||
|
||||
return hslSpace.test(strippedStr);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = isISSN;
|
||||
|
||||
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var issn = '^\\d{4}-?\\d{3}[\\dX]$';
|
||||
|
||||
function isISSN(str) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
(0, _assertString.default)(str);
|
||||
var testIssn = issn;
|
||||
testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn;
|
||||
testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i');
|
||||
|
||||
if (!testIssn.test(str)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var digits = str.replace('-', '').toUpperCase();
|
||||
var checksum = 0;
|
||||
|
||||
for (var i = 0; i < digits.length; i++) {
|
||||
var digit = digits[i];
|
||||
checksum += (digit === 'X' ? 10 : +digit) * (8 - i);
|
||||
}
|
||||
|
||||
return checksum % 11 === 0;
|
||||
}
|
||||
|
||||
module.exports = exports.default;
|
||||
module.exports.default = exports.default;
|
||||
@@ -0,0 +1,5 @@
|
||||
var convert = require('./convert'),
|
||||
func = convert('curryRight', require('../curryRight'));
|
||||
|
||||
func.placeholder = require('./placeholder');
|
||||
module.exports = func;
|
||||
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./async').log;
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = 2.220446049250313e-16;
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"52":0.04106,"78":0.01026,"102":0.02053,"107":0.01026,"108":0.0154,"109":1.10338,"110":0.57478,_:"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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 103 104 105 106 111 112 3.5 3.6"},D:{"44":0.00513,"49":0.02053,"65":0.02053,"70":0.00513,"72":0.00513,"76":0.00513,"77":0.02566,"79":0.02566,"80":0.02053,"81":0.00513,"83":0.02053,"85":0.02566,"86":0.02566,"87":0.04619,"89":0.00513,"92":0.0154,"93":0.29252,"95":0.01026,"98":0.02053,"99":0.25147,"100":0.03592,"101":0.02566,"102":0.01026,"103":0.13343,"104":0.02053,"105":0.4003,"106":0.11804,"107":0.22068,"108":1.01614,"109":21.9239,"110":12.08586,"111":0.02053,_:"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 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 66 67 68 69 71 73 74 75 78 84 88 90 91 94 96 97 112 113"},F:{"28":0.02053,"46":0.01026,"93":0.1129,"94":0.89297,"95":0.32845,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 9.5-9.6 10.5 10.6 11.1 11.5 11.6 12.1","10.0-10.1":0},B:{"92":0.01026,"104":0.01026,"107":0.02566,"108":0.06672,"109":2.83286,"110":3.16131,_:"12 13 14 15 16 17 18 79 80 81 83 84 85 86 87 88 89 90 91 93 94 95 96 97 98 99 100 101 102 103 105 106"},E:{"4":0,"13":0.01026,"14":0.21554,"15":0.02566,_:"0 5 6 7 8 9 10 11 12 3.1 3.2 5.1 6.1 7.1 9.1 10.1 16.4","11.1":0.00513,"12.1":0.01026,"13.1":0.10777,"14.1":0.27713,"15.1":0.06672,"15.2-15.3":0.02566,"15.4":0.06672,"15.5":0.22068,"15.6":0.73388,"16.0":0.10264,"16.1":0.40543,"16.2":0.69282,"16.3":0.59531},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0,"5.0-5.1":0.00315,"6.0-6.1":0.00315,"7.0-7.1":0.0063,"8.1-8.4":0.00315,"9.0-9.2":0,"9.3":0.0252,"10.0-10.2":0,"10.3":0.27877,"11.0-11.2":0.0063,"11.3-11.4":0.01102,"12.0-12.1":0.02047,"12.2-12.5":0.1512,"13.0-13.1":0.00157,"13.2":0,"13.3":0.00787,"13.4-13.7":0.0189,"14.0-14.4":0.1953,"14.5-14.8":0.38272,"15.0-15.1":0.05827,"15.2-15.3":0.12285,"15.4":0.19057,"15.5":0.34335,"15.6":1.19226,"16.0":2.08371,"16.1":3.84297,"16.2":4.09969,"16.3":2.05851,"16.4":0.00787},P:{"4":0.05278,"20":0.93952,"5.0-5.4":0.01042,"6.2-6.4":0.01025,"7.2-7.4":0.03167,"8.2":0.02044,"9.2":0.01042,"10.1":0.0217,"11.1-11.2":0.01056,"12.0":0.02048,"13.0":0.02111,"14.0":0.06252,"15.0":0.05278,"16.0":0.01056,"17.0":0.02111,"18.0":0.03167,"19.0":1.64681},I:{"0":0,"3":0,"4":0.00365,"2.1":0,"2.2":0,"2.3":0.00365,"4.1":0.00365,"4.2-4.3":0.0073,"4.4":0,"4.4.3-4.4.4":0.09858},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"8":0.03079,"9":0.00513,"11":0.28739,_:"6 7 10 5.5"},N:{"10":0.02102,"11":0.02035},S:{"2.5":0,_:"3.0-3.1"},J:{"7":0,"10":0},O:{"0":0.10223},H:{"0":0.212},L:{"0":30.63275},R:{_:"0"},M:{"0":0.18012},Q:{"13.1":0}};
|
||||
@@ -0,0 +1,6 @@
|
||||
module.exports = isPromise;
|
||||
module.exports.default = isPromise;
|
||||
|
||||
function isPromise(obj) {
|
||||
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v1.1.1](https://github.com/inspect-js/is-arguments/compare/v1.1.0...v1.1.1) - 2021-08-05
|
||||
|
||||
### Commits
|
||||
|
||||
- [actions] use `node/install` instead of `node/run`; use `codecov` action [`dd28b30`](https://github.com/inspect-js/is-arguments/commit/dd28b30f4237fac722f2ce05b0c1d7e63c4a81e4)
|
||||
- [meta] do not publish github action workflow files [`87e489c`](https://github.com/inspect-js/is-arguments/commit/87e489cc77b709b96e73aaf9f9b2cd6da48f4960)
|
||||
- [readme] fix repo URLs [`e2c2c6e`](https://github.com/inspect-js/is-arguments/commit/e2c2c6ee34ca21be4b19d282d96dd7ab75b63ae3)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape` [`b9ae62b`](https://github.com/inspect-js/is-arguments/commit/b9ae62b3a08a5fe84519865192e6287d5b6966f7)
|
||||
- [readme] add github actions/codecov badges [`504c0a5`](https://github.com/inspect-js/is-arguments/commit/504c0a508dc313eae5942b1e35b2d031948de143)
|
||||
- [Fix] use `has-tostringtag` to behave correctly in the presence of symbol shams [`dc29e52`](https://github.com/inspect-js/is-arguments/commit/dc29e521d71da420414110919a1e0fde8ec6eba3)
|
||||
- [Dev Deps] update `auto-changelog`, `eslint`, `tape` [`a966d25`](https://github.com/inspect-js/is-arguments/commit/a966d25535c5f050ca5ce43a1559f93698a7130b)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape` [`1218944`](https://github.com/inspect-js/is-arguments/commit/12189445a195558fdccebe099c699272d2082aa8)
|
||||
- [meta] use `prepublishOnly` script for npm 7+ [`757dbee`](https://github.com/inspect-js/is-arguments/commit/757dbee3ec6f6225d4c7c91582e045cc1183dbd8)
|
||||
- [Deps] update `call-bind` [`b206f05`](https://github.com/inspect-js/is-arguments/commit/b206f059571c430375c632e40dd29249fa76a8fd)
|
||||
- [actions] update workflows [`b89b2f1`](https://github.com/inspect-js/is-arguments/commit/b89b2f1ab98bedebdf97d2397246030a1132c84e)
|
||||
|
||||
## [v1.1.0](https://github.com/inspect-js/is-arguments/compare/v1.0.4...v1.1.0) - 2020-12-04
|
||||
|
||||
### Commits
|
||||
|
||||
- [Tests] use shared travis-ci configs [`fd59a37`](https://github.com/inspect-js/is-arguments/commit/fd59a3779f004f36ea8e5ac90b0de9b97ff60755)
|
||||
- [Tests] migrate tests to Github Actions [`982a0d6`](https://github.com/inspect-js/is-arguments/commit/982a0d68495b68e2b6ca8f4caa9f8a909ec56755)
|
||||
- [Tests] remove `jscs` [`927d4b5`](https://github.com/inspect-js/is-arguments/commit/927d4b5c17b12c40f445491e52a11d5bed311ef6)
|
||||
- [meta] add `auto-changelog` [`ef0634b`](https://github.com/inspect-js/is-arguments/commit/ef0634b0c07a12d9144c4db168cb79963326ec6d)
|
||||
- [Tests] up to `node` `v12.10`, `v11.15`, `v10.16`, `v8.16`, `v6.17` [`1689f8b`](https://github.com/inspect-js/is-arguments/commit/1689f8bf533c8ab8cd95caf953905e3a204c0cdc)
|
||||
- [Tests] up to `node` `v11.7`, `v10.15`, `v8.15`, `v6.16` [`145aaeb`](https://github.com/inspect-js/is-arguments/commit/145aaeb5a35e7abd3a8a5c9ec87c6e37f16ed068)
|
||||
- [readme] fix repo URLs, remove defunct badges [`cc484a3`](https://github.com/inspect-js/is-arguments/commit/cc484a3ae787125eccc30a05c63b7ff6a1581591)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `tape` [`c888738`](https://github.com/inspect-js/is-arguments/commit/c888738ef1cf84b973169bbe6219b795de4acfc2)
|
||||
- [Tests] run `nyc` on all tests [`0de8efb`](https://github.com/inspect-js/is-arguments/commit/0de8efb8091a3dd5708812cd26ad541f7dca773a)
|
||||
- [actions] add automatic rebasing / merge commit blocking [`818775a`](https://github.com/inspect-js/is-arguments/commit/818775aa0c66064965517be554c3bcc57ec0d721)
|
||||
- [Robustness] use `call-bind` [`31d0199`](https://github.com/inspect-js/is-arguments/commit/31d0199c1a560f113ff099a2f43068cdfe0af79e)
|
||||
- [actions] add "Allow Edits" workflow [`0c55f7d`](https://github.com/inspect-js/is-arguments/commit/0c55f7d254ff335291d9cee39501b247f7248fb9)
|
||||
- [meta] create FUNDING.yml [`ca7ed59`](https://github.com/inspect-js/is-arguments/commit/ca7ed597bac29790ac6233ff1bdff7704b870e96)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog` [`1ae5053`](https://github.com/inspect-js/is-arguments/commit/1ae505390efff099c50d0bc786a3ecc8d5303b04)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`; add `safe-publish-latest` [`433f4a5`](https://github.com/inspect-js/is-arguments/commit/433f4a5573810fe689c5e56ad9fe69b6a2229b8c)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `covert`, `tape` [`78ea4e8`](https://github.com/inspect-js/is-arguments/commit/78ea4e8261bc326c1ae7e9e50bb655e8bf128c6b)
|
||||
- [Tests] use `npm audit` instead of `nsp` [`07fb85b`](https://github.com/inspect-js/is-arguments/commit/07fb85bf396880648c2d4285273968d478df4711)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape` [`2204add`](https://github.com/inspect-js/is-arguments/commit/2204add22fcc15b1ee6aaae90578595b4f6d9647)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `safe-publish-latest` [`ce150c0`](https://github.com/inspect-js/is-arguments/commit/ce150c0c47504779ce812b1aefe044fcad1286af)
|
||||
- [Tests] fix tests from 0de8efb [`ee45fc3`](https://github.com/inspect-js/is-arguments/commit/ee45fc387b655de6feac101c478af111d488e144)
|
||||
- [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops [`03a312c`](https://github.com/inspect-js/is-arguments/commit/03a312cdae0aa058cfd094c996acb2af4e785484)
|
||||
- [actions] switch Automatic Rebase workflow to `pull_request_target` event [`25d2ef8`](https://github.com/inspect-js/is-arguments/commit/25d2ef8da0b90c834d1fa6b83410205832e271d4)
|
||||
- [Dev Deps] update `auto-changelog`, `tape` [`0fe60b7`](https://github.com/inspect-js/is-arguments/commit/0fe60b74b7f1254c386e14d0ea6d9cc074fdf12c)
|
||||
- [Dev Deps] update `@ljharb/eslint-config`, `tape` [`4a9cbd0`](https://github.com/inspect-js/is-arguments/commit/4a9cbd0c91fd945ccc97c219d34e0840b0965586)
|
||||
- [Dev Deps] update `auto-changelog`; add `aud` [`d9ff7d5`](https://github.com/inspect-js/is-arguments/commit/d9ff7d5f521eec5942019b1d7b38ace475da142f)
|
||||
- [meta] add `funding` field [`adec2d2`](https://github.com/inspect-js/is-arguments/commit/adec2d293022ee3ec87479eaeae81bfec1ea1b18)
|
||||
- [Tests] only audit prod deps [`f474960`](https://github.com/inspect-js/is-arguments/commit/f474960795eeb6087fc79eed8b787aa067b22ab1)
|
||||
|
||||
## [v1.0.4](https://github.com/inspect-js/is-arguments/compare/v1.0.3...v1.0.4) - 2018-11-05
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] Fix errors about `in` operator. [`4d12e23`](https://github.com/inspect-js/is-arguments/commit/4d12e23fab8701207b7715fe7502db35c6edd3dd)
|
||||
|
||||
## [v1.0.3](https://github.com/inspect-js/is-arguments/compare/v1.0.2...v1.0.3) - 2018-11-02
|
||||
|
||||
### Fixed
|
||||
|
||||
- [Fix] add awareness of Symbol.toStringTag [`#20`](https://github.com/inspect-js/is-arguments/issues/20)
|
||||
|
||||
### Commits
|
||||
|
||||
- [Tests] up to `node` `v8.1`; `v7.10`, `v6.11`, `v4.8`; improve matrix; newer npm fails on older node [`ea5f23c`](https://github.com/inspect-js/is-arguments/commit/ea5f23c322234e18248b0acafe0f45333d5d78ec)
|
||||
- [Tests] up to `node` `v9.1`, `v8.9`, `v6.12`; use `nvm install-latest-npm`; pin included builds to LTS. [`697a0a1`](https://github.com/inspect-js/is-arguments/commit/697a0a143d3b82f84956e4cca407c7eea228526b)
|
||||
- [Tests] up to `node` `v10.0`, `v9.11`, `v8.11`, `v6.14`, `v4.9` [`40045c5`](https://github.com/inspect-js/is-arguments/commit/40045c5fe6ebb86f96125da96f7bfb9637579ce4)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `jscs`, `tape` [`08abc0d`](https://github.com/inspect-js/is-arguments/commit/08abc0d2e31c34514a58711f6203e41d06c3b81f)
|
||||
- [Tests] up to `node` `v11.1`, `v10.13`, `v8.12` [`bf8d275`](https://github.com/inspect-js/is-arguments/commit/bf8d275ecf855c40c9c3f9c3ccf76874d4ce2497)
|
||||
- [Tests] up to `node` `v7.0`, `v6.9`, `v4.6`; improve test matrix [`f813d86`](https://github.com/inspect-js/is-arguments/commit/f813d86b38f10d2e1f495597ca2a58d25a21339e)
|
||||
- [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`e4f9aee`](https://github.com/inspect-js/is-arguments/commit/e4f9aee64f0f7f2f9d8132992b81d133b5d3c9c7)
|
||||
- [Dev Deps] update `jscs`, `eslint`, `@ljharb/eslint-config` [`6c98d11`](https://github.com/inspect-js/is-arguments/commit/6c98d1171a043a4ab21d70b813379a4162ac3702)
|
||||
- [Dev Deps] update `jscs`, `eslint`, `@ljharb/eslint-config` [`8e3178d`](https://github.com/inspect-js/is-arguments/commit/8e3178db172bc3ac889343aa3e38c24cc92aed08)
|
||||
- package.json: use object form of "author", add "contributors" [`decc4fe`](https://github.com/inspect-js/is-arguments/commit/decc4feb9b31bd9f68b7a5f67aed39d32c9a6ab3)
|
||||
- [Dev Deps] update `jscs`, `eslint`, `@ljharb/eslint-config` [`514902a`](https://github.com/inspect-js/is-arguments/commit/514902abde6b7d9397c9dbcd90f19fd78b70725a)
|
||||
- [Tests] up to `node` `v5.6`, `v4.3` [`f11f47c`](https://github.com/inspect-js/is-arguments/commit/f11f47c5c1dae8adfda7ba1319de3b6e03db7925)
|
||||
- [Dev Deps] add `npm run security` [`4adf82c`](https://github.com/inspect-js/is-arguments/commit/4adf82c0c9259eb81db18848a314b36db1c48d36)
|
||||
- [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`f587aeb`](https://github.com/inspect-js/is-arguments/commit/f587aeb3ec04f2d22c2a8fd7686a2153d0fd50d2)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `nsp`, `tape` [`4f587bb`](https://github.com/inspect-js/is-arguments/commit/4f587bb7a2c499b1aa2e2aea60da8c0ee91c9df2)
|
||||
- [Tests] up to `node` `v6.2`, `v5.11` [`36939c5`](https://github.com/inspect-js/is-arguments/commit/36939c5e1d8ce56c356a3f2144983839d86b3ae8)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `nsp`, `tape` [`d779cc8`](https://github.com/inspect-js/is-arguments/commit/d779cc875bd6fa15d861a134065d629159051331)
|
||||
- Only apps should have lockfiles [`f50ce65`](https://github.com/inspect-js/is-arguments/commit/f50ce65fe94728b6f127a0c11f2efc6473f56cf3)
|
||||
- [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`3025559`](https://github.com/inspect-js/is-arguments/commit/30255597cf578068e5a28d7a6e29076355132c87)
|
||||
- [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`3b9ddee`](https://github.com/inspect-js/is-arguments/commit/3b9ddeef740608d84d2b825b9a90e4adf049c905)
|
||||
- [Tests] up to `v5.8`, `v4.4` [`d4902cf`](https://github.com/inspect-js/is-arguments/commit/d4902cfb07e0bfaa0788a7847fcaaba91c8e3435)
|
||||
- [Tests] fix npm upgrades for older nodes [`c617dd3`](https://github.com/inspect-js/is-arguments/commit/c617dd3a7b6a70162cbeb985009620acd69c029d)
|
||||
- [Tests] up to `node` `v5.3` [`cdd2a61`](https://github.com/inspect-js/is-arguments/commit/cdd2a617c3d1810149683596fe90024ae9dcc549)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape` [`7719172`](https://github.com/inspect-js/is-arguments/commit/77191721ef92ce9dc72fdae8e1cfdc2ec74317d9)
|
||||
- [Dev Deps] update `es5-shim`, `tape`, `nsp`, `eslint` [`6a5f82b`](https://github.com/inspect-js/is-arguments/commit/6a5f82bc6d9407e64fc4c7794d546e4db8ab61ed)
|
||||
- [Dev Deps] update `tape`, `eslint`, `@ljharb/eslint-config` [`c896c1c`](https://github.com/inspect-js/is-arguments/commit/c896c1c4629ff3c8cda25e0c3e607d2950ff4ba9)
|
||||
- [Tests] Use `pretest` for running the linter. [`83db117`](https://github.com/inspect-js/is-arguments/commit/83db1173fde93c2d8a490663ce850321b018eab2)
|
||||
- [Dev Deps] update `@ljharb/eslint-config`, `eslint` [`57fdc63`](https://github.com/inspect-js/is-arguments/commit/57fdc636dea2f5c641e2d0c0dfbe0ac589acb69a)
|
||||
- [Tests] up to `node` `v7.2` [`aa3eacf`](https://github.com/inspect-js/is-arguments/commit/aa3eacf27001a92aab4874f7d29f693ed6221b4a)
|
||||
- [Tests] up to `node` `v5.10` [`94ff6d7`](https://github.com/inspect-js/is-arguments/commit/94ff6d72c095cae00a4df06043976dc3e414f49b)
|
||||
- [Tests] on `node` `v4.2` [`cdb1fb5`](https://github.com/inspect-js/is-arguments/commit/cdb1fb5babe08c845570cbae218c0b96753c1152)
|
||||
|
||||
## [v1.0.2](https://github.com/inspect-js/is-arguments/compare/v1.0.1...v1.0.2) - 2015-09-21
|
||||
|
||||
### Commits
|
||||
|
||||
- Update `eslint`, use my personal shared config. [`8e211f4`](https://github.com/inspect-js/is-arguments/commit/8e211f46b17ae8d89aa5484b4b3b853d3d1b3fa9)
|
||||
- In modern engines, only export the "is standard arguments" check. [`e8aa23f`](https://github.com/inspect-js/is-arguments/commit/e8aa23fc19f6d1c3c952174391a4903d90fcd622)
|
||||
- Update `jscs`, `eslint`, `@ljharb/eslint-config` [`8a90bca`](https://github.com/inspect-js/is-arguments/commit/8a90bcad88025736a7c127123f1473af35bae6f7)
|
||||
- Update `eslint` [`2214b5d`](https://github.com/inspect-js/is-arguments/commit/2214b5dac911e1eb949179f9034aa37ba7c079d7)
|
||||
- Update `eslint` [`ca97c5b`](https://github.com/inspect-js/is-arguments/commit/ca97c5b22e7cf4f30d90ee1519988ecd4bf36887)
|
||||
- [Dev Deps] update `jscs` [`ca6a477`](https://github.com/inspect-js/is-arguments/commit/ca6a477c16c70c0e5f29d56713237703ab610fdf)
|
||||
- Update `covert`, `jscs`, `eslint` [`232d92a`](https://github.com/inspect-js/is-arguments/commit/232d92ab1dff7b0ad64024726cda437b32ce1906)
|
||||
- [Tests] up to `io.js` `v3.3`, `node` `v4.1` [`460d700`](https://github.com/inspect-js/is-arguments/commit/460d700bdb5d8b261995e3d8f3e6b3eda4f91bcf)
|
||||
- Test up to `io.js` `v2.3` [`7ef2293`](https://github.com/inspect-js/is-arguments/commit/7ef229388819ae1f1c1d55dbe741c90977cc3a3f)
|
||||
- [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`29f3d71`](https://github.com/inspect-js/is-arguments/commit/29f3d71eb516326409bd24bc7e6d4ebb6a872d01)
|
||||
- [Dev Deps] update `tape`, `eslint`, `@ljharb/eslint-config` [`1c79a85`](https://github.com/inspect-js/is-arguments/commit/1c79a85d670d8dc5dbb1831ee0de0c8858a94775)
|
||||
- `toString` as a variable name breaks in some older browsers. [`1e59f2b`](https://github.com/inspect-js/is-arguments/commit/1e59f2bf79454188145de5275a64996eafc94420)
|
||||
- Update `tape`, `eslint` [`1efbefd`](https://github.com/inspect-js/is-arguments/commit/1efbefd84df6ae802245ebe6371cd15255ee23e7)
|
||||
- Test up to `io.js` `v2.5` [`0760acc`](https://github.com/inspect-js/is-arguments/commit/0760acc3139d1930efebc4321c1f96ba1406e2de)
|
||||
- Test up to `io.js` `v2.1` [`4c2245f`](https://github.com/inspect-js/is-arguments/commit/4c2245f3deccdb3ec70e4f79e5e8aac697f35d08)
|
||||
- [Dev Deps] update `tape` [`348980e`](https://github.com/inspect-js/is-arguments/commit/348980e1666b66724e37c9df63d18d540a51d5fe)
|
||||
- Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG. [`91d8c4f`](https://github.com/inspect-js/is-arguments/commit/91d8c4fd4516aae483fa2dd9c4a5b44c48e773f0)
|
||||
- Update `tape` [`ec9b92a`](https://github.com/inspect-js/is-arguments/commit/ec9b92a244f7a077fe1df58af89f56a39d4d2600)
|
||||
- Update `tape` [`6bc8969`](https://github.com/inspect-js/is-arguments/commit/6bc8969c40b2b2cd1c767933b7ef3d8ff65bf67f)
|
||||
- Test on `io.js` `v3.0` [`33d9578`](https://github.com/inspect-js/is-arguments/commit/33d957814d515855583e98e652624e5920cc9496)
|
||||
|
||||
## [v1.0.1](https://github.com/inspect-js/is-arguments/compare/v1.0.0...v1.0.1) - 2015-04-29
|
||||
|
||||
### Commits
|
||||
|
||||
- Update `jscs`, add `npm run eslint` [`13a5f01`](https://github.com/inspect-js/is-arguments/commit/13a5f015aa67cb2402b5fdb21c68180ff7036a14)
|
||||
- Using my standard jscs.json file [`d669fc4`](https://github.com/inspect-js/is-arguments/commit/d669fc49c0db56457eb55a77a2f9c40916ad6361)
|
||||
- Adding `npm run lint` [`ece5d05`](https://github.com/inspect-js/is-arguments/commit/ece5d0581fadcff99b181d67b54eacb4869cfb98)
|
||||
- Test on latest `io.js` [`908b092`](https://github.com/inspect-js/is-arguments/commit/908b092912fa9c89c20a41fdd117b21e857bfc84)
|
||||
- Adding license and downloads badges [`05fd28b`](https://github.com/inspect-js/is-arguments/commit/05fd28b28d857ecb2220d0ac6267f36ec1e65eae)
|
||||
- Make sure old and unstable nodes don't break Travis [`16ee7ea`](https://github.com/inspect-js/is-arguments/commit/16ee7eae70015864a8b3f2fe03463ecb4d707451)
|
||||
- All grade A-supported `node`/`iojs` versions now ship with an `npm` that understands `^`. [`9846c79`](https://github.com/inspect-js/is-arguments/commit/9846c79d1999432538ea757c0dbf61ab3f0d54cd)
|
||||
- Run `travis-ci` tests on `iojs` and `node` v0.12; speed up builds; allow 0.8 failures. [`27c014d`](https://github.com/inspect-js/is-arguments/commit/27c014d217d41d33b0bb1735e38184b871d86311)
|
||||
- Use SVG instead of PNG badges [`ea01e68`](https://github.com/inspect-js/is-arguments/commit/ea01e68896722351c63912e37cc37541f9b78780)
|
||||
- Remove unused links in README [`f5baaff`](https://github.com/inspect-js/is-arguments/commit/f5baaff1931bb9d48b20270a94d99121a3176dba)
|
||||
- Test on latest `io.js` versions [`293e2c4`](https://github.com/inspect-js/is-arguments/commit/293e2c4d1edfdf9c6db88663314599ecde08a945)
|
||||
- Update `tape`, `jscs` [`d72ab08`](https://github.com/inspect-js/is-arguments/commit/d72ab08147ab5256e1efd61c01b719796699faf0)
|
||||
- Update `jscs` [`5f6e6d4`](https://github.com/inspect-js/is-arguments/commit/5f6e6d42645845b5663b5fef716e2963686aad8d)
|
||||
- Update `tape`, `jscs` [`39ae55b`](https://github.com/inspect-js/is-arguments/commit/39ae55b6ef0c3d6206116bd7500bc601485d8698)
|
||||
- Update `tape`, `jscs` [`594d928`](https://github.com/inspect-js/is-arguments/commit/594d92852cf7a4d93c8ff5ac157fdae9dbefc133)
|
||||
- Updating dependencies [`183ac15`](https://github.com/inspect-js/is-arguments/commit/183ac151d27032fce4aaf3fa095cce9b086eb651)
|
||||
- Update `tape` [`77b9cea`](https://github.com/inspect-js/is-arguments/commit/77b9ceae8dcb2c2e73d85f512d0d0309427c4011)
|
||||
- Lock covert to v1.0.0. [`28d9052`](https://github.com/inspect-js/is-arguments/commit/28d9052eaa99f36ca5c61f35645b5e14ddf6f8f9)
|
||||
- Updating tape [`d9ee2ac`](https://github.com/inspect-js/is-arguments/commit/d9ee2ac24045fa81ffed356410cfc2d878bc8b4b)
|
||||
- Updating jscs [`c0cab8f`](https://github.com/inspect-js/is-arguments/commit/c0cab8fd6c0509153142a3cc79a7a4dceba322be)
|
||||
- Updating jscs [`c59352a`](https://github.com/inspect-js/is-arguments/commit/c59352ae99c0d813168c19b9c888182ea11ae17a)
|
||||
- Run linter as part of tests [`8b8154e`](https://github.com/inspect-js/is-arguments/commit/8b8154ef5b2566250baed70807affdbba93c3bcf)
|
||||
- Oops, properly running code coverage checks during tests. [`cc441d0`](https://github.com/inspect-js/is-arguments/commit/cc441d0c488486c688e513f7d129f4f8ea2ee323)
|
||||
- Updating covert. [`142db90`](https://github.com/inspect-js/is-arguments/commit/142db90aa3448995232c419419523b67a953b012)
|
||||
- Updating tape [`265fd0f`](https://github.com/inspect-js/is-arguments/commit/265fd0ff3ee71ab8aa3d2d90be74066c1aa7c9c0)
|
||||
- Updating tape [`7e9aec6`](https://github.com/inspect-js/is-arguments/commit/7e9aec654b8f5fe0bb2f8c940c84da8ec29a2102)
|
||||
- Updating covert [`d96860a`](https://github.com/inspect-js/is-arguments/commit/d96860ab520ae62a37e80ad259b936ace09954d9)
|
||||
- Updating tape [`1ec32a0`](https://github.com/inspect-js/is-arguments/commit/1ec32a0c02f53192a94521d63d4cf8fbb567fc84)
|
||||
- Run code coverage as part of tests [`155ab22`](https://github.com/inspect-js/is-arguments/commit/155ab227902287c5eec653c25bec2cc4b530e635)
|
||||
- Coverage does not work currently on node 0.6. [`9acf696`](https://github.com/inspect-js/is-arguments/commit/9acf696a1f3e202990fea494615377b40a380b79)
|
||||
- Testing node 0.6 again [`a23ca07`](https://github.com/inspect-js/is-arguments/commit/a23ca07427cf3801b82e6a93d9a8904f392f4b20)
|
||||
|
||||
## [v1.0.0](https://github.com/inspect-js/is-arguments/compare/v0.1.0...v1.0.0) - 2014-01-07
|
||||
|
||||
### Commits
|
||||
|
||||
- :metal: 1.0.0 [`fc08874`](https://github.com/inspect-js/is-arguments/commit/fc08874107ac74fca91bd678843dbf7ea3a4c54a)
|
||||
|
||||
## v0.1.0 - 2014-01-07
|
||||
|
||||
### Commits
|
||||
|
||||
- package.json [`c547055`](https://github.com/inspect-js/is-arguments/commit/c54705585e907f1ef22473bff656904e49d22db2)
|
||||
- read me! [`72ed639`](https://github.com/inspect-js/is-arguments/commit/72ed639c5db9c8732073ec1d30f14b493bb976da)
|
||||
- Initial commit [`d2e0264`](https://github.com/inspect-js/is-arguments/commit/d2e0264bed7948b6c4f7bfde12ab351bffbf4cc1)
|
||||
- Tests. [`032ed16`](https://github.com/inspect-js/is-arguments/commit/032ed16abf54466a75333e1da2ceef780fb58c1e)
|
||||
- Implementation. [`71c312d`](https://github.com/inspect-js/is-arguments/commit/71c312d76d3b4b99cf7a1e0b442e9492069fba2b)
|
||||
- Travis CI [`5500a66`](https://github.com/inspect-js/is-arguments/commit/5500a664de6b4484850f02b74641baa6e7d74c50)
|
||||
- Running code coverage as part of tests. [`88ad34a`](https://github.com/inspect-js/is-arguments/commit/88ad34a133188cea28aa26a9f583653ea3a0260e)
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2007-2012 Steven Levithan <http://xregexp.com/>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "@types/pug",
|
||||
"version": "2.0.6",
|
||||
"description": "TypeScript definitions for pug",
|
||||
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/pug",
|
||||
"license": "MIT",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "TonyYang",
|
||||
"url": "https://github.com/TonyPythoneer",
|
||||
"githubUsername": "TonyPythoneer"
|
||||
}
|
||||
],
|
||||
"main": "",
|
||||
"types": "index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
||||
"directory": "types/pug"
|
||||
},
|
||||
"scripts": {},
|
||||
"dependencies": {},
|
||||
"typesPublisherContentHash": "9109540393ac30fc3ac3057f8f68afa8a7b5b81d8d13fae50596e012b993951d",
|
||||
"typeScriptVersion": "3.8"
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var toPrimitive = require('../es2015');
|
||||
var is = require('object-is');
|
||||
var forEach = require('foreach');
|
||||
var functionName = require('function.prototype.name');
|
||||
var debug = require('object-inspect');
|
||||
|
||||
var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';
|
||||
var hasSymbolToPrimitive = hasSymbols && typeof Symbol.toPrimitive === 'symbol';
|
||||
|
||||
test('function properties', function (t) {
|
||||
t.equal(toPrimitive.length, 1, 'length is 1');
|
||||
t.equal(functionName(toPrimitive), 'ToPrimitive', 'name is ToPrimitive');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
var primitives = [null, undefined, true, false, 0, -0, 42, NaN, Infinity, -Infinity, '', 'abc'];
|
||||
|
||||
test('primitives', function (t) {
|
||||
forEach(primitives, function (i) {
|
||||
t.ok(is(toPrimitive(i), i), 'toPrimitive(' + debug(i) + ') returns the same value');
|
||||
t.ok(is(toPrimitive(i, String), i), 'toPrimitive(' + debug(i) + ', String) returns the same value');
|
||||
t.ok(is(toPrimitive(i, Number), i), 'toPrimitive(' + debug(i) + ', Number) returns the same value');
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Symbols', { skip: !hasSymbols }, function (t) {
|
||||
var symbols = [
|
||||
Symbol('foo'),
|
||||
Symbol.iterator,
|
||||
Symbol['for']('foo') // eslint-disable-line no-restricted-properties
|
||||
];
|
||||
forEach(symbols, function (sym) {
|
||||
t.equal(toPrimitive(sym), sym, 'toPrimitive(' + debug(sym) + ') returns the same value');
|
||||
t.equal(toPrimitive(sym, String), sym, 'toPrimitive(' + debug(sym) + ', String) returns the same value');
|
||||
t.equal(toPrimitive(sym, Number), sym, 'toPrimitive(' + debug(sym) + ', Number) returns the same value');
|
||||
});
|
||||
|
||||
var primitiveSym = Symbol('primitiveSym');
|
||||
var objectSym = Object(primitiveSym);
|
||||
t.equal(toPrimitive(objectSym), primitiveSym, 'toPrimitive(' + debug(objectSym) + ') returns ' + debug(primitiveSym));
|
||||
t.equal(toPrimitive(objectSym, String), primitiveSym, 'toPrimitive(' + debug(objectSym) + ', String) returns ' + debug(primitiveSym));
|
||||
t.equal(toPrimitive(objectSym, Number), primitiveSym, 'toPrimitive(' + debug(objectSym) + ', Number) returns ' + debug(primitiveSym));
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Arrays', function (t) {
|
||||
var arrays = [[], ['a', 'b'], [1, 2]];
|
||||
forEach(arrays, function (arr) {
|
||||
t.equal(toPrimitive(arr), String(arr), 'toPrimitive(' + debug(arr) + ') returns the string version of the array');
|
||||
t.equal(toPrimitive(arr, String), String(arr), 'toPrimitive(' + debug(arr) + ') returns the string version of the array');
|
||||
t.equal(toPrimitive(arr, Number), String(arr), 'toPrimitive(' + debug(arr) + ') returns the string version of the array');
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Dates', function (t) {
|
||||
var dates = [new Date(), new Date(0), new Date(NaN)];
|
||||
forEach(dates, function (date) {
|
||||
t.equal(toPrimitive(date), String(date), 'toPrimitive(' + debug(date) + ') returns the string version of the date');
|
||||
t.equal(toPrimitive(date, String), String(date), 'toPrimitive(' + debug(date) + ') returns the string version of the date');
|
||||
t.ok(is(toPrimitive(date, Number), Number(date)), 'toPrimitive(' + debug(date) + ') returns the number version of the date');
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } };
|
||||
var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } };
|
||||
var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } };
|
||||
var coercibleFnObject = {
|
||||
valueOf: function () { return function valueOfFn() {}; },
|
||||
toString: function () { return 42; }
|
||||
};
|
||||
var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } };
|
||||
var uncoercibleFnObject = {
|
||||
valueOf: function () { return function valueOfFn() {}; },
|
||||
toString: function () { return function toStrFn() {}; }
|
||||
};
|
||||
|
||||
test('Objects', function (t) {
|
||||
t.equal(toPrimitive(coercibleObject), coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf');
|
||||
t.equal(toPrimitive(coercibleObject, Number), coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
|
||||
t.equal(toPrimitive(coercibleObject, String), coercibleObject.toString(), 'coercibleObject with hint String coerces to non-stringified toString');
|
||||
|
||||
t.equal(toPrimitive(coercibleFnObject), coercibleFnObject.toString(), 'coercibleFnObject coerces to non-stringified toString');
|
||||
t.equal(toPrimitive(coercibleFnObject, Number), coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to non-stringified toString');
|
||||
t.equal(toPrimitive(coercibleFnObject, String), coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to non-stringified toString');
|
||||
|
||||
t.equal(toPrimitive({}), '[object Object]', '{} with no hint coerces to Object#toString');
|
||||
t.equal(toPrimitive({}, Number), '[object Object]', '{} with hint Number coerces to Object#toString');
|
||||
t.equal(toPrimitive({}, String), '[object Object]', '{} with hint String coerces to Object#toString');
|
||||
|
||||
t.equal(toPrimitive(toStringOnlyObject), toStringOnlyObject.toString(), 'toStringOnlyObject returns non-stringified toString');
|
||||
t.equal(toPrimitive(toStringOnlyObject, Number), toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns non-stringified toString');
|
||||
t.equal(toPrimitive(toStringOnlyObject, String), toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns non-stringified toString');
|
||||
|
||||
t.equal(toPrimitive(valueOfOnlyObject), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
|
||||
t.equal(toPrimitive(valueOfOnlyObject, Number), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');
|
||||
t.equal(toPrimitive(valueOfOnlyObject, String), valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns non-stringified valueOf');
|
||||
|
||||
t.test('Symbol.toPrimitive', { skip: !hasSymbolToPrimitive }, function (st) {
|
||||
var overriddenObject = { toString: st.fail, valueOf: st.fail };
|
||||
overriddenObject[Symbol.toPrimitive] = function (hint) { return String(hint); };
|
||||
|
||||
st.equal(toPrimitive(overriddenObject), 'default', 'object with Symbol.toPrimitive + no hint invokes that');
|
||||
st.equal(toPrimitive(overriddenObject, Number), 'number', 'object with Symbol.toPrimitive + hint Number invokes that');
|
||||
st.equal(toPrimitive(overriddenObject, String), 'string', 'object with Symbol.toPrimitive + hint String invokes that');
|
||||
|
||||
var nullToPrimitive = { toString: coercibleObject.toString, valueOf: coercibleObject.valueOf };
|
||||
nullToPrimitive[Symbol.toPrimitive] = null;
|
||||
st.equal(toPrimitive(nullToPrimitive), toPrimitive(coercibleObject), 'object with no hint + null Symbol.toPrimitive ignores it');
|
||||
st.equal(toPrimitive(nullToPrimitive, Number), toPrimitive(coercibleObject, Number), 'object with hint Number + null Symbol.toPrimitive ignores it');
|
||||
st.equal(toPrimitive(nullToPrimitive, String), toPrimitive(coercibleObject, String), 'object with hint String + null Symbol.toPrimitive ignores it');
|
||||
|
||||
st.test('exceptions', function (sst) {
|
||||
var nonFunctionToPrimitive = { toString: sst.fail, valueOf: sst.fail };
|
||||
nonFunctionToPrimitive[Symbol.toPrimitive] = {};
|
||||
sst['throws'](toPrimitive.bind(null, nonFunctionToPrimitive), TypeError, 'Symbol.toPrimitive returning a non-function throws');
|
||||
|
||||
var uncoercibleToPrimitive = { toString: sst.fail, valueOf: sst.fail };
|
||||
uncoercibleToPrimitive[Symbol.toPrimitive] = function (hint) {
|
||||
return { toString: function () { return hint; } };
|
||||
};
|
||||
sst['throws'](toPrimitive.bind(null, uncoercibleToPrimitive), TypeError, 'Symbol.toPrimitive returning an object throws');
|
||||
|
||||
var throwingToPrimitive = { toString: sst.fail, valueOf: sst.fail };
|
||||
throwingToPrimitive[Symbol.toPrimitive] = function (hint) { throw new RangeError(hint); };
|
||||
sst['throws'](toPrimitive.bind(null, throwingToPrimitive), RangeError, 'Symbol.toPrimitive throwing throws');
|
||||
|
||||
sst.end();
|
||||
});
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('exceptions', function (st) {
|
||||
st['throws'](toPrimitive.bind(null, uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');
|
||||
st['throws'](toPrimitive.bind(null, uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');
|
||||
st['throws'](toPrimitive.bind(null, uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');
|
||||
|
||||
st['throws'](toPrimitive.bind(null, uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');
|
||||
st['throws'](toPrimitive.bind(null, uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');
|
||||
st['throws'](toPrimitive.bind(null, uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');
|
||||
st.end();
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Parse Date time skeleton into Intl.DateTimeFormatOptions
|
||||
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
||||
* @public
|
||||
* @param skeleton skeleton string
|
||||
*/
|
||||
export declare function parseDateTimeSkeleton(skeleton: string): Intl.DateTimeFormatOptions;
|
||||
//# sourceMappingURL=date-time.d.ts.map
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "no-case",
|
||||
"version": "2.3.2",
|
||||
"description": "Remove case from a string",
|
||||
"main": "no-case.js",
|
||||
"typings": "no-case.d.ts",
|
||||
"files": [
|
||||
"no-case.js",
|
||||
"no-case.d.ts",
|
||||
"vendor",
|
||||
"LICENSE"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "standard",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec --bail",
|
||||
"test": "npm run lint && npm run test-cov",
|
||||
"build": "node build.js"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"coverage/**"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/blakeembrey/no-case.git"
|
||||
},
|
||||
"keywords": [
|
||||
"no",
|
||||
"case",
|
||||
"space",
|
||||
"lower",
|
||||
"trim"
|
||||
],
|
||||
"author": {
|
||||
"name": "Blake Embrey",
|
||||
"email": "hello@blakeembrey.com",
|
||||
"url": "http://blakeembrey.me"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/blakeembrey/no-case/issues"
|
||||
},
|
||||
"homepage": "https://github.com/blakeembrey/no-case",
|
||||
"devDependencies": {
|
||||
"chai": "^4.0.2",
|
||||
"istanbul": "^0.4.3",
|
||||
"jsesc": "^2.2.0",
|
||||
"mocha": "^3.0.0",
|
||||
"standard": "^10.0.2",
|
||||
"xregexp": "^3.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"lower-case": "^1.1.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
export declare let current_component: any;
|
||||
export declare function set_current_component(component: any): void;
|
||||
export declare function get_current_component(): any;
|
||||
/**
|
||||
* Schedules a callback to run immediately before the component is updated after any state change.
|
||||
*
|
||||
* The first time the callback runs will be before the initial `onMount`
|
||||
*
|
||||
* https://svelte.dev/docs#run-time-svelte-beforeupdate
|
||||
*/
|
||||
export declare function beforeUpdate(fn: () => any): void;
|
||||
/**
|
||||
* The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM.
|
||||
* It must be called during the component's initialisation (but doesn't need to live *inside* the component;
|
||||
* it can be called from an external module).
|
||||
*
|
||||
* `onMount` does not run inside a [server-side component](/docs#run-time-server-side-component-api).
|
||||
*
|
||||
* https://svelte.dev/docs#run-time-svelte-onmount
|
||||
*/
|
||||
export declare function onMount(fn: () => any): void;
|
||||
/**
|
||||
* Schedules a callback to run immediately after the component has been updated.
|
||||
*
|
||||
* The first time the callback runs will be after the initial `onMount`
|
||||
*/
|
||||
export declare function afterUpdate(fn: () => any): void;
|
||||
/**
|
||||
* Schedules a callback to run immediately before the component is unmounted.
|
||||
*
|
||||
* Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the
|
||||
* only one that runs inside a server-side component.
|
||||
*
|
||||
* https://svelte.dev/docs#run-time-svelte-ondestroy
|
||||
*/
|
||||
export declare function onDestroy(fn: () => any): void;
|
||||
export interface DispatchOptions {
|
||||
cancelable?: boolean;
|
||||
}
|
||||
/**
|
||||
* Creates an event dispatcher that can be used to dispatch [component events](/docs#template-syntax-component-directives-on-eventname).
|
||||
* Event dispatchers are functions that can take two arguments: `name` and `detail`.
|
||||
*
|
||||
* Component events created with `createEventDispatcher` create a
|
||||
* [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent).
|
||||
* These events do not [bubble](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture).
|
||||
* The `detail` argument corresponds to the [CustomEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail)
|
||||
* property and can contain any type of data.
|
||||
*
|
||||
* https://svelte.dev/docs#run-time-svelte-createeventdispatcher
|
||||
*/
|
||||
export declare function createEventDispatcher<EventMap extends {} = any>(): <EventKey extends Extract<keyof EventMap, string>>(type: EventKey, detail?: EventMap[EventKey], options?: DispatchOptions) => boolean;
|
||||
/**
|
||||
* Associates an arbitrary `context` object with the current component and the specified `key`
|
||||
* and returns that object. The context is then available to children of the component
|
||||
* (including slotted content) with `getContext`.
|
||||
*
|
||||
* Like lifecycle functions, this must be called during component initialisation.
|
||||
*
|
||||
* https://svelte.dev/docs#run-time-svelte-setcontext
|
||||
*/
|
||||
export declare function setContext<T>(key: any, context: T): T;
|
||||
/**
|
||||
* Retrieves the context that belongs to the closest parent component with the specified `key`.
|
||||
* Must be called during component initialisation.
|
||||
*
|
||||
* https://svelte.dev/docs#run-time-svelte-getcontext
|
||||
*/
|
||||
export declare function getContext<T>(key: any): T;
|
||||
/**
|
||||
* Retrieves the whole context map that belongs to the closest parent component.
|
||||
* Must be called during component initialisation. Useful, for example, if you
|
||||
* programmatically create a component and want to pass the existing context to it.
|
||||
*
|
||||
* https://svelte.dev/docs#run-time-svelte-getallcontexts
|
||||
*/
|
||||
export declare function getAllContexts<T extends Map<any, any> = Map<any, any>>(): T;
|
||||
/**
|
||||
* Checks whether a given `key` has been set in the context of a parent component.
|
||||
* Must be called during component initialisation.
|
||||
*
|
||||
* https://svelte.dev/docs#run-time-svelte-hascontext
|
||||
*/
|
||||
export declare function hasContext(key: any): boolean;
|
||||
export declare function bubble(component: any, event: any): void;
|
||||
@@ -0,0 +1,47 @@
|
||||
import Attribute from '../../../nodes/Attribute';
|
||||
import Block from '../../Block';
|
||||
import ElementWrapper from './index';
|
||||
import { Identifier, Node } from 'estree';
|
||||
export declare class BaseAttributeWrapper {
|
||||
node: Attribute;
|
||||
parent: ElementWrapper;
|
||||
constructor(parent: ElementWrapper, block: Block, node: Attribute);
|
||||
render(_block: Block): void;
|
||||
}
|
||||
export default class AttributeWrapper extends BaseAttributeWrapper {
|
||||
node: Attribute;
|
||||
parent: ElementWrapper;
|
||||
metadata: any;
|
||||
name: string;
|
||||
property_name: string;
|
||||
is_indirectly_bound_value: boolean;
|
||||
is_src: boolean;
|
||||
is_select_value_attribute: boolean;
|
||||
is_input_value: boolean;
|
||||
should_cache: boolean;
|
||||
last: Identifier;
|
||||
constructor(parent: ElementWrapper, block: Block, node: Attribute);
|
||||
render(block: Block): void;
|
||||
get_init(block: Block, value: any): any;
|
||||
get_dom_update_conditions(block: Block, dependency_condition: Node): Node;
|
||||
get_dependencies(): string[];
|
||||
get_metadata(): AttributeMetadata;
|
||||
get_value(block: Block): import("estree").Property | import("estree").CatchClause | import("estree").ClassDeclaration | import("estree").ClassExpression | import("estree").ClassBody | import("estree").ArrayExpression | import("estree").ArrowFunctionExpression | import("estree").AssignmentExpression | import("estree").AwaitExpression | import("estree").BinaryExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").ChainExpression | import("estree").ConditionalExpression | import("estree").FunctionExpression | Identifier | import("estree").ImportExpression | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").BigIntLiteral | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").MetaProperty | import("estree").ObjectExpression | import("estree").SequenceExpression | import("estree").TaggedTemplateExpression | import("estree").TemplateLiteral | import("estree").ThisExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").YieldExpression | import("estree").FunctionDeclaration | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").PrivateIdentifier | import("estree").Program | import("estree").PropertyDefinition | import("estree").SpreadElement | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").StaticBlock | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").Super | import("estree").SwitchCase | import("estree").TemplateElement | import("estree").VariableDeclarator | {
|
||||
type: string;
|
||||
value: string;
|
||||
};
|
||||
get_class_name_text(block: Block): import("estree").Property | import("estree").CatchClause | import("estree").ClassDeclaration | import("estree").ClassExpression | import("estree").ClassBody | import("estree").ArrayExpression | import("estree").ArrowFunctionExpression | import("estree").AssignmentExpression | import("estree").AwaitExpression | import("estree").BinaryExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").ChainExpression | import("estree").ConditionalExpression | import("estree").FunctionExpression | Identifier | import("estree").ImportExpression | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").BigIntLiteral | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").MetaProperty | import("estree").ObjectExpression | import("estree").SequenceExpression | import("estree").TaggedTemplateExpression | import("estree").TemplateLiteral | import("estree").ThisExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").YieldExpression | import("estree").FunctionDeclaration | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").PrivateIdentifier | import("estree").Program | import("estree").PropertyDefinition | import("estree").SpreadElement | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").StaticBlock | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").Super | import("estree").SwitchCase | import("estree").TemplateElement | import("estree").VariableDeclarator | {
|
||||
type: string;
|
||||
value: string;
|
||||
};
|
||||
render_chunks(block: Block): (import("estree").Property | import("estree").CatchClause | import("estree").ClassDeclaration | import("estree").ClassExpression | import("estree").ClassBody | import("estree").ArrayExpression | import("estree").ArrowFunctionExpression | import("estree").AssignmentExpression | import("estree").AwaitExpression | import("estree").BinaryExpression | import("estree").SimpleCallExpression | import("estree").NewExpression | import("estree").ChainExpression | import("estree").ConditionalExpression | import("estree").FunctionExpression | Identifier | import("estree").ImportExpression | import("estree").SimpleLiteral | import("estree").RegExpLiteral | import("estree").BigIntLiteral | import("estree").LogicalExpression | import("estree").MemberExpression | import("estree").MetaProperty | import("estree").ObjectExpression | import("estree").SequenceExpression | import("estree").TaggedTemplateExpression | import("estree").TemplateLiteral | import("estree").ThisExpression | import("estree").UnaryExpression | import("estree").UpdateExpression | import("estree").YieldExpression | import("estree").FunctionDeclaration | import("estree").MethodDefinition | import("estree").ImportDeclaration | import("estree").ExportNamedDeclaration | import("estree").ExportDefaultDeclaration | import("estree").ExportAllDeclaration | import("estree").ImportSpecifier | import("estree").ImportDefaultSpecifier | import("estree").ImportNamespaceSpecifier | import("estree").ExportSpecifier | import("estree").ObjectPattern | import("estree").ArrayPattern | import("estree").RestElement | import("estree").AssignmentPattern | import("estree").PrivateIdentifier | import("estree").Program | import("estree").PropertyDefinition | import("estree").SpreadElement | import("estree").ExpressionStatement | import("estree").BlockStatement | import("estree").StaticBlock | import("estree").EmptyStatement | import("estree").DebuggerStatement | import("estree").WithStatement | import("estree").ReturnStatement | import("estree").LabeledStatement | import("estree").BreakStatement | import("estree").ContinueStatement | import("estree").IfStatement | import("estree").SwitchStatement | import("estree").ThrowStatement | import("estree").TryStatement | import("estree").WhileStatement | import("estree").DoWhileStatement | import("estree").ForStatement | import("estree").ForInStatement | import("estree").ForOfStatement | import("estree").VariableDeclaration | import("estree").Super | import("estree").SwitchCase | import("estree").TemplateElement | import("estree").VariableDeclarator | {
|
||||
type: string;
|
||||
value: string;
|
||||
})[];
|
||||
stringify(): string;
|
||||
}
|
||||
declare type AttributeMetadata = {
|
||||
property_name?: string;
|
||||
applies_to?: string[];
|
||||
};
|
||||
export {};
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"color-convert","version":"1.9.3","files":{"CHANGELOG.md":{"checkedAt":1678883669302,"integrity":"sha512-kFk6gSlqT4SNzRMC7qUx+Ej7V0Iy3CiSMMQwKuU1VSrmQ3vaBoTKWVhX5I3F/kbsq9grq2OSWgXGOycK9KhCNg==","mode":420,"size":1417},"LICENSE":{"checkedAt":1678883669302,"integrity":"sha512-RJ+994iKW5CItfhKptGkLPlReCoGIHn2P+Xh55fnCe1HN8PhkwDQqYoBATQx5zZSxbgUOJE7qVL/H7Y7zkYOWw==","mode":420,"size":1087},"README.md":{"checkedAt":1678883669302,"integrity":"sha512-7q6ZuyOSyojh49/C0jlgw8XDs4hwdzxabhv86I3iuJibL6Gw7PaKJuBstMnEbv6EDIa+eLYrv1wqvKICO6f1Ng==","mode":420,"size":2853},"package.json":{"checkedAt":1678883670570,"integrity":"sha512-MkZ9qgi+tXA92Wo1Cdv644Gu4SbkwBvtvMcDrFoaIOpuo5xm/ZkwfC8WMf204jof6HywIop3wOej6mgtbREVCQ==","mode":420,"size":805},"index.js":{"checkedAt":1678883670574,"integrity":"sha512-TH1wx6629YrdZjwwYc8uKX/VfzgW/u0wE18w5BNLKP5OqNn9+ebDsgjUjIu+KusU351vlFZb91gmdaE9XnEB6A==","mode":420,"size":1725},"conversions.js":{"checkedAt":1678883670574,"integrity":"sha512-Sx/HGl4Hmh+6e2/nIG/0sK7pJwQ4RKeyqmUa75tdVVcaIVsN625dXNe+79PvdjS+eT5G2cFGTnucNG3HwU5ssg==","mode":420,"size":16850},"route.js":{"checkedAt":1678883670574,"integrity":"sha512-mLbRoZbksU8MNdaRwaIrfDufrvmdIilO3CuqB3Bia8WHjIqaNExArsxmYNcPIMA80lzcpHOLJKnP/CePlYUrEg==","mode":420,"size":2227}}}
|
||||
@@ -0,0 +1 @@
|
||||
export const VERSION = "4.2.0";
|
||||
@@ -0,0 +1,205 @@
|
||||
/**
|
||||
* `list` type prompt
|
||||
*/
|
||||
|
||||
import chalk from 'chalk';
|
||||
import figures from 'figures';
|
||||
import cliCursor from 'cli-cursor';
|
||||
import runAsync from 'run-async';
|
||||
import { flatMap, map, take, takeUntil } from 'rxjs';
|
||||
import Base from './base.js';
|
||||
import observe from '../utils/events.js';
|
||||
import Paginator from '../utils/paginator.js';
|
||||
import incrementListIndex from '../utils/incrementListIndex.js';
|
||||
|
||||
export default class ListPrompt extends Base {
|
||||
constructor(questions, rl, answers) {
|
||||
super(questions, rl, answers);
|
||||
|
||||
if (!this.opt.choices) {
|
||||
this.throwParamError('choices');
|
||||
}
|
||||
|
||||
this.firstRender = true;
|
||||
this.selected = 0;
|
||||
|
||||
const def = this.opt.default;
|
||||
|
||||
// If def is a Number, then use as index. Otherwise, check for value.
|
||||
if (typeof def === 'number' && def >= 0 && def < this.opt.choices.realLength) {
|
||||
this.selected = def;
|
||||
} else if (typeof def !== 'number' && def != null) {
|
||||
const index = this.opt.choices.realChoices.findIndex(({ value }) => value === def);
|
||||
this.selected = Math.max(index, 0);
|
||||
}
|
||||
|
||||
// Make sure no default is set (so it won't be printed)
|
||||
this.opt.default = null;
|
||||
|
||||
const shouldLoop = this.opt.loop === undefined ? true : this.opt.loop;
|
||||
this.paginator = new Paginator(this.screen, { isInfinite: shouldLoop });
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the Inquiry session
|
||||
* @param {Function} cb Callback when prompt is done
|
||||
* @return {this}
|
||||
*/
|
||||
|
||||
_run(cb) {
|
||||
this.done = cb;
|
||||
|
||||
const self = this;
|
||||
|
||||
const events = observe(this.rl);
|
||||
events.normalizedUpKey.pipe(takeUntil(events.line)).forEach(this.onUpKey.bind(this));
|
||||
events.normalizedDownKey
|
||||
.pipe(takeUntil(events.line))
|
||||
.forEach(this.onDownKey.bind(this));
|
||||
events.numberKey.pipe(takeUntil(events.line)).forEach(this.onNumberKey.bind(this));
|
||||
events.line
|
||||
.pipe(
|
||||
take(1),
|
||||
map(this.getCurrentValue.bind(this)),
|
||||
flatMap((value) =>
|
||||
runAsync(self.opt.filter)(value, self.answers).catch((err) => err)
|
||||
)
|
||||
)
|
||||
.forEach(this.onSubmit.bind(this));
|
||||
|
||||
// Init the prompt
|
||||
cliCursor.hide();
|
||||
this.render();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the prompt to screen
|
||||
* @return {ListPrompt} self
|
||||
*/
|
||||
|
||||
render() {
|
||||
// Render question
|
||||
let message = this.getQuestion();
|
||||
|
||||
if (this.firstRender) {
|
||||
message += chalk.dim('(Use arrow keys)');
|
||||
}
|
||||
|
||||
// Render choices or answer depending on the state
|
||||
if (this.status === 'answered') {
|
||||
message += chalk.cyan(this.opt.choices.getChoice(this.selected).short);
|
||||
} else {
|
||||
const choicesStr = listRender(this.opt.choices, this.selected);
|
||||
const indexPosition = this.opt.choices.indexOf(
|
||||
this.opt.choices.getChoice(this.selected)
|
||||
);
|
||||
const realIndexPosition =
|
||||
this.opt.choices.reduce((acc, value, i) => {
|
||||
// Dont count lines past the choice we are looking at
|
||||
if (i > indexPosition) {
|
||||
return acc;
|
||||
}
|
||||
// Add line if it's a separator
|
||||
if (value.type === 'separator') {
|
||||
return acc + 1;
|
||||
}
|
||||
|
||||
let l = value.name;
|
||||
// Non-strings take up one line
|
||||
if (typeof l !== 'string') {
|
||||
return acc + 1;
|
||||
}
|
||||
|
||||
// Calculate lines taken up by string
|
||||
l = l.split('\n');
|
||||
return acc + l.length;
|
||||
}, 0) - 1;
|
||||
message +=
|
||||
'\n' + this.paginator.paginate(choicesStr, realIndexPosition, this.opt.pageSize);
|
||||
}
|
||||
|
||||
this.firstRender = false;
|
||||
|
||||
this.screen.render(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* When user press `enter` key
|
||||
*/
|
||||
|
||||
onSubmit(value) {
|
||||
this.status = 'answered';
|
||||
|
||||
// Rerender prompt
|
||||
this.render();
|
||||
|
||||
this.screen.done();
|
||||
cliCursor.show();
|
||||
this.done(value);
|
||||
}
|
||||
|
||||
getCurrentValue() {
|
||||
return this.opt.choices.getChoice(this.selected).value;
|
||||
}
|
||||
|
||||
/**
|
||||
* When user press a key
|
||||
*/
|
||||
onUpKey() {
|
||||
this.selected = incrementListIndex(this.selected, 'up', this.opt);
|
||||
this.render();
|
||||
}
|
||||
|
||||
onDownKey() {
|
||||
this.selected = incrementListIndex(this.selected, 'down', this.opt);
|
||||
this.render();
|
||||
}
|
||||
|
||||
onNumberKey(input) {
|
||||
if (input <= this.opt.choices.realLength) {
|
||||
this.selected = input - 1;
|
||||
}
|
||||
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for rendering list choices
|
||||
* @param {Number} pointer Position of the pointer
|
||||
* @return {String} Rendered content
|
||||
*/
|
||||
function listRender(choices, pointer) {
|
||||
let output = '';
|
||||
let separatorOffset = 0;
|
||||
|
||||
choices.forEach((choice, i) => {
|
||||
if (choice.type === 'separator') {
|
||||
separatorOffset++;
|
||||
output += ' ' + choice + '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
if (choice.disabled) {
|
||||
separatorOffset++;
|
||||
output += ' - ' + choice.name;
|
||||
output += ` (${
|
||||
typeof choice.disabled === 'string' ? choice.disabled : 'Disabled'
|
||||
})`;
|
||||
output += '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
const isSelected = i - separatorOffset === pointer;
|
||||
let line = (isSelected ? figures.pointer + ' ' : ' ') + choice.name;
|
||||
if (isSelected) {
|
||||
line = chalk.cyan(line);
|
||||
}
|
||||
|
||||
output += line + ' \n';
|
||||
});
|
||||
|
||||
return output.replace(/\n$/, '');
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const u = require('universalify').fromCallback
|
||||
module.exports = {
|
||||
copy: u(require('./copy'))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"scanInternals.d.ts","sourceRoot":"","sources":["../../../../src/internal/operators/scanInternals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C;;;;;;;GAOG;AAEH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACnC,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,EAC3D,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,OAAO,EACnB,kBAAkB,CAAC,EAAE,SAAS,GAAG,IAAI,YAErB,WAAW,CAAC,CAAC,cAAc,WAAW,GAAG,CAAC,UAyC3D"}
|
||||
Reference in New Issue
Block a user