new license file version [CI SKIP]
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { SvelteComponentTyped } from "svelte";
|
||||
import type { DataHandler } from './core';
|
||||
declare const __propDef: {
|
||||
props: {
|
||||
handler: DataHandler;
|
||||
};
|
||||
events: {
|
||||
[evt: string]: CustomEvent<any>;
|
||||
};
|
||||
slots: {};
|
||||
};
|
||||
export type SearchProps = typeof __propDef.props;
|
||||
export type SearchEvents = typeof __propDef.events;
|
||||
export type SearchSlots = typeof __propDef.slots;
|
||||
export default class Search extends SvelteComponentTyped<SearchProps, SearchEvents, SearchSlots> {
|
||||
}
|
||||
export {};
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createDirentFromStats = void 0;
|
||||
class DirentFromStats {
|
||||
constructor(name, stats) {
|
||||
this.name = name;
|
||||
this.isBlockDevice = stats.isBlockDevice.bind(stats);
|
||||
this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
|
||||
this.isDirectory = stats.isDirectory.bind(stats);
|
||||
this.isFIFO = stats.isFIFO.bind(stats);
|
||||
this.isFile = stats.isFile.bind(stats);
|
||||
this.isSocket = stats.isSocket.bind(stats);
|
||||
this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
|
||||
}
|
||||
}
|
||||
function createDirentFromStats(name, stats) {
|
||||
return new DirentFromStats(name, stats);
|
||||
}
|
||||
exports.createDirentFromStats = createDirentFromStats;
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Object whose keys are signal names and values are signal objects.
|
||||
*/
|
||||
export declare const signalsByName: { [signalName: string]: Signal }
|
||||
/**
|
||||
* Object whose keys are signal numbers and values are signal objects.
|
||||
*/
|
||||
export declare const signalsByNumber: { [signalNumber: string]: Signal }
|
||||
|
||||
export declare type SignalAction =
|
||||
| 'terminate'
|
||||
| 'core'
|
||||
| 'ignore'
|
||||
| 'pause'
|
||||
| 'unpause'
|
||||
export declare type SignalStandard =
|
||||
| 'ansi'
|
||||
| 'posix'
|
||||
| 'bsd'
|
||||
| 'systemv'
|
||||
| 'other'
|
||||
|
||||
export declare type Signal = {
|
||||
/**
|
||||
* Standard name of the signal, for example 'SIGINT'.
|
||||
*/
|
||||
name: string
|
||||
/**
|
||||
* Code number of the signal, for example 2. While most number are cross-platform, some are different between different OS.
|
||||
*/
|
||||
number: number
|
||||
/**
|
||||
* Human-friendly description for the signal, for example 'User interruption with CTRL-C'.
|
||||
*/
|
||||
description: string
|
||||
/**
|
||||
* Whether the current OS can handle this signal in Node.js using process.on(name, handler). The list of supported signals is OS-specific.
|
||||
*/
|
||||
supported: boolean
|
||||
/**
|
||||
* What is the default action for this signal when it is not handled.
|
||||
*/
|
||||
action: SignalAction
|
||||
/**
|
||||
* Whether the signal's default action cannot be prevented. This is true for SIGTERM, SIGKILL and SIGSTOP.
|
||||
*/
|
||||
forced: boolean
|
||||
/**
|
||||
* Which standard defined that signal.
|
||||
*/
|
||||
standard: SignalStandard
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
|
||||
let isDocker;
|
||||
|
||||
function hasDockerEnv() {
|
||||
try {
|
||||
fs.statSync('/.dockerenv');
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function hasDockerCGroup() {
|
||||
try {
|
||||
return fs.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = () => {
|
||||
if (isDocker === undefined) {
|
||||
isDocker = hasDockerEnv() || hasDockerCGroup();
|
||||
}
|
||||
|
||||
return isDocker;
|
||||
};
|
||||
@@ -0,0 +1,351 @@
|
||||
import { diff, unmount, applyRef } from './index';
|
||||
import { createVNode, Fragment } from '../create-element';
|
||||
import { EMPTY_OBJ, EMPTY_ARR } from '../constants';
|
||||
import { getDomSibling } from '../component';
|
||||
|
||||
/**
|
||||
* Diff the children of a virtual node
|
||||
* @param {import('../internal').PreactElement} parentDom The DOM element whose
|
||||
* children are being diffed
|
||||
* @param {import('../internal').ComponentChildren[]} renderResult
|
||||
* @param {import('../internal').VNode} newParentVNode The new virtual
|
||||
* node whose children should be diff'ed against oldParentVNode
|
||||
* @param {import('../internal').VNode} oldParentVNode The old virtual
|
||||
* node whose children should be diff'ed against newParentVNode
|
||||
* @param {object} globalContext The current context object - modified by getChildContext
|
||||
* @param {boolean} isSvg Whether or not this DOM node is an SVG node
|
||||
* @param {Array<import('../internal').PreactElement>} excessDomChildren
|
||||
* @param {Array<import('../internal').Component>} commitQueue List of components
|
||||
* which have callbacks to invoke in commitRoot
|
||||
* @param {import('../internal').PreactElement} oldDom The current attached DOM
|
||||
* element any new dom elements should be placed around. Likely `null` on first
|
||||
* render (except when hydrating). Can be a sibling DOM element when diffing
|
||||
* Fragments that have siblings. In most cases, it starts out as `oldChildren[0]._dom`.
|
||||
* @param {boolean} isHydrating Whether or not we are in hydration
|
||||
*/
|
||||
export function diffChildren(
|
||||
parentDom,
|
||||
renderResult,
|
||||
newParentVNode,
|
||||
oldParentVNode,
|
||||
globalContext,
|
||||
isSvg,
|
||||
excessDomChildren,
|
||||
commitQueue,
|
||||
oldDom,
|
||||
isHydrating
|
||||
) {
|
||||
let i, j, oldVNode, childVNode, newDom, firstChildDom, refs;
|
||||
|
||||
// This is a compression of oldParentVNode!=null && oldParentVNode != EMPTY_OBJ && oldParentVNode._children || EMPTY_ARR
|
||||
// as EMPTY_OBJ._children should be `undefined`.
|
||||
let oldChildren = (oldParentVNode && oldParentVNode._children) || EMPTY_ARR;
|
||||
|
||||
let oldChildrenLength = oldChildren.length;
|
||||
|
||||
newParentVNode._children = [];
|
||||
for (i = 0; i < renderResult.length; i++) {
|
||||
childVNode = renderResult[i];
|
||||
|
||||
if (childVNode == null || typeof childVNode == 'boolean') {
|
||||
childVNode = newParentVNode._children[i] = null;
|
||||
}
|
||||
// If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
|
||||
// or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
|
||||
// it's own DOM & etc. pointers
|
||||
else if (
|
||||
typeof childVNode == 'string' ||
|
||||
typeof childVNode == 'number' ||
|
||||
// eslint-disable-next-line valid-typeof
|
||||
typeof childVNode == 'bigint'
|
||||
) {
|
||||
childVNode = newParentVNode._children[i] = createVNode(
|
||||
null,
|
||||
childVNode,
|
||||
null,
|
||||
null,
|
||||
childVNode
|
||||
);
|
||||
} else if (Array.isArray(childVNode)) {
|
||||
childVNode = newParentVNode._children[i] = createVNode(
|
||||
Fragment,
|
||||
{ children: childVNode },
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
} else if (childVNode._depth > 0) {
|
||||
// VNode is already in use, clone it. This can happen in the following
|
||||
// scenario:
|
||||
// const reuse = <div />
|
||||
// <div>{reuse}<span />{reuse}</div>
|
||||
childVNode = newParentVNode._children[i] = createVNode(
|
||||
childVNode.type,
|
||||
childVNode.props,
|
||||
childVNode.key,
|
||||
childVNode.ref ? childVNode.ref : null,
|
||||
childVNode._original
|
||||
);
|
||||
} else {
|
||||
childVNode = newParentVNode._children[i] = childVNode;
|
||||
}
|
||||
|
||||
// Terser removes the `continue` here and wraps the loop body
|
||||
// in a `if (childVNode) { ... } condition
|
||||
if (childVNode == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
childVNode._parent = newParentVNode;
|
||||
childVNode._depth = newParentVNode._depth + 1;
|
||||
|
||||
// Check if we find a corresponding element in oldChildren.
|
||||
// If found, delete the array item by setting to `undefined`.
|
||||
// We use `undefined`, as `null` is reserved for empty placeholders
|
||||
// (holes).
|
||||
oldVNode = oldChildren[i];
|
||||
|
||||
if (
|
||||
oldVNode === null ||
|
||||
(oldVNode &&
|
||||
childVNode.key == oldVNode.key &&
|
||||
childVNode.type === oldVNode.type)
|
||||
) {
|
||||
oldChildren[i] = undefined;
|
||||
} else {
|
||||
// Either oldVNode === undefined or oldChildrenLength > 0,
|
||||
// so after this loop oldVNode == null or oldVNode is a valid value.
|
||||
for (j = 0; j < oldChildrenLength; j++) {
|
||||
oldVNode = oldChildren[j];
|
||||
// If childVNode is unkeyed, we only match similarly unkeyed nodes, otherwise we match by key.
|
||||
// We always match by type (in either case).
|
||||
if (
|
||||
oldVNode &&
|
||||
childVNode.key == oldVNode.key &&
|
||||
childVNode.type === oldVNode.type
|
||||
) {
|
||||
oldChildren[j] = undefined;
|
||||
break;
|
||||
}
|
||||
oldVNode = null;
|
||||
}
|
||||
}
|
||||
|
||||
oldVNode = oldVNode || EMPTY_OBJ;
|
||||
|
||||
// Morph the old element into the new one, but don't append it to the dom yet
|
||||
diff(
|
||||
parentDom,
|
||||
childVNode,
|
||||
oldVNode,
|
||||
globalContext,
|
||||
isSvg,
|
||||
excessDomChildren,
|
||||
commitQueue,
|
||||
oldDom,
|
||||
isHydrating
|
||||
);
|
||||
|
||||
newDom = childVNode._dom;
|
||||
|
||||
if ((j = childVNode.ref) && oldVNode.ref != j) {
|
||||
if (!refs) refs = [];
|
||||
if (oldVNode.ref) refs.push(oldVNode.ref, null, childVNode);
|
||||
refs.push(j, childVNode._component || newDom, childVNode);
|
||||
}
|
||||
|
||||
if (newDom != null) {
|
||||
if (firstChildDom == null) {
|
||||
firstChildDom = newDom;
|
||||
}
|
||||
|
||||
if (
|
||||
typeof childVNode.type == 'function' &&
|
||||
childVNode._children === oldVNode._children
|
||||
) {
|
||||
childVNode._nextDom = oldDom = reorderChildren(
|
||||
childVNode,
|
||||
oldDom,
|
||||
parentDom
|
||||
);
|
||||
} else {
|
||||
oldDom = placeChild(
|
||||
parentDom,
|
||||
childVNode,
|
||||
oldVNode,
|
||||
oldChildren,
|
||||
newDom,
|
||||
oldDom
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof newParentVNode.type == 'function') {
|
||||
// Because the newParentVNode is Fragment-like, we need to set it's
|
||||
// _nextDom property to the nextSibling of its last child DOM node.
|
||||
//
|
||||
// `oldDom` contains the correct value here because if the last child
|
||||
// is a Fragment-like, then oldDom has already been set to that child's _nextDom.
|
||||
// If the last child is a DOM VNode, then oldDom will be set to that DOM
|
||||
// node's nextSibling.
|
||||
newParentVNode._nextDom = oldDom;
|
||||
}
|
||||
} else if (
|
||||
oldDom &&
|
||||
oldVNode._dom == oldDom &&
|
||||
oldDom.parentNode != parentDom
|
||||
) {
|
||||
// The above condition is to handle null placeholders. See test in placeholder.test.js:
|
||||
// `efficiently replace null placeholders in parent rerenders`
|
||||
oldDom = getDomSibling(oldVNode);
|
||||
}
|
||||
}
|
||||
|
||||
newParentVNode._dom = firstChildDom;
|
||||
|
||||
// Remove remaining oldChildren if there are any.
|
||||
for (i = oldChildrenLength; i--; ) {
|
||||
if (oldChildren[i] != null) {
|
||||
if (
|
||||
typeof newParentVNode.type == 'function' &&
|
||||
oldChildren[i]._dom != null &&
|
||||
oldChildren[i]._dom == newParentVNode._nextDom
|
||||
) {
|
||||
// If the newParentVNode.__nextDom points to a dom node that is about to
|
||||
// be unmounted, then get the next sibling of that vnode and set
|
||||
// _nextDom to it
|
||||
newParentVNode._nextDom = getLastDom(oldParentVNode).nextSibling;
|
||||
}
|
||||
|
||||
unmount(oldChildren[i], oldChildren[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Set refs only after unmount
|
||||
if (refs) {
|
||||
for (i = 0; i < refs.length; i++) {
|
||||
applyRef(refs[i], refs[++i], refs[++i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reorderChildren(childVNode, oldDom, parentDom) {
|
||||
// Note: VNodes in nested suspended trees may be missing _children.
|
||||
let c = childVNode._children;
|
||||
let tmp = 0;
|
||||
for (; c && tmp < c.length; tmp++) {
|
||||
let vnode = c[tmp];
|
||||
if (vnode) {
|
||||
// We typically enter this code path on sCU bailout, where we copy
|
||||
// oldVNode._children to newVNode._children. If that is the case, we need
|
||||
// to update the old children's _parent pointer to point to the newVNode
|
||||
// (childVNode here).
|
||||
vnode._parent = childVNode;
|
||||
|
||||
if (typeof vnode.type == 'function') {
|
||||
oldDom = reorderChildren(vnode, oldDom, parentDom);
|
||||
} else {
|
||||
oldDom = placeChild(parentDom, vnode, vnode, c, vnode._dom, oldDom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return oldDom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten and loop through the children of a virtual node
|
||||
* @param {import('../index').ComponentChildren} children The unflattened
|
||||
* children of a virtual node
|
||||
* @returns {import('../internal').VNode[]}
|
||||
*/
|
||||
export function toChildArray(children, out) {
|
||||
out = out || [];
|
||||
if (children == null || typeof children == 'boolean') {
|
||||
} else if (Array.isArray(children)) {
|
||||
children.some(child => {
|
||||
toChildArray(child, out);
|
||||
});
|
||||
} else {
|
||||
out.push(children);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function placeChild(
|
||||
parentDom,
|
||||
childVNode,
|
||||
oldVNode,
|
||||
oldChildren,
|
||||
newDom,
|
||||
oldDom
|
||||
) {
|
||||
let nextDom;
|
||||
if (childVNode._nextDom !== undefined) {
|
||||
// Only Fragments or components that return Fragment like VNodes will
|
||||
// have a non-undefined _nextDom. Continue the diff from the sibling
|
||||
// of last DOM child of this child VNode
|
||||
nextDom = childVNode._nextDom;
|
||||
|
||||
// Eagerly cleanup _nextDom. We don't need to persist the value because
|
||||
// it is only used by `diffChildren` to determine where to resume the diff after
|
||||
// diffing Components and Fragments. Once we store it the nextDOM local var, we
|
||||
// can clean up the property
|
||||
childVNode._nextDom = undefined;
|
||||
} else if (
|
||||
oldVNode == null ||
|
||||
newDom != oldDom ||
|
||||
newDom.parentNode == null
|
||||
) {
|
||||
outer: if (oldDom == null || oldDom.parentNode !== parentDom) {
|
||||
parentDom.appendChild(newDom);
|
||||
nextDom = null;
|
||||
} else {
|
||||
// `j<oldChildrenLength; j+=2` is an alternative to `j++<oldChildrenLength/2`
|
||||
for (
|
||||
let sibDom = oldDom, j = 0;
|
||||
(sibDom = sibDom.nextSibling) && j < oldChildren.length;
|
||||
j += 1
|
||||
) {
|
||||
if (sibDom == newDom) {
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
parentDom.insertBefore(newDom, oldDom);
|
||||
nextDom = oldDom;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have pre-calculated the nextDOM node, use it. Else calculate it now
|
||||
// Strictly check for `undefined` here cuz `null` is a valid value of `nextDom`.
|
||||
// See more detail in create-element.js:createVNode
|
||||
if (nextDom !== undefined) {
|
||||
oldDom = nextDom;
|
||||
} else {
|
||||
oldDom = newDom.nextSibling;
|
||||
}
|
||||
|
||||
return oldDom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('../internal').VNode} vnode
|
||||
*/
|
||||
function getLastDom(vnode) {
|
||||
if (vnode.type == null || typeof vnode.type === 'string') {
|
||||
return vnode._dom;
|
||||
}
|
||||
|
||||
if (vnode._children) {
|
||||
for (let i = vnode._children.length - 1; i >= 0; i--) {
|
||||
let child = vnode._children[i];
|
||||
if (child) {
|
||||
let lastDom = getLastDom(child);
|
||||
if (lastDom) {
|
||||
return lastDom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var implementation = require('../implementation');
|
||||
var callBind = require('call-bind');
|
||||
var test = require('tape');
|
||||
var hasStrictMode = require('has-strict-mode')();
|
||||
var runTests = require('./tests');
|
||||
|
||||
test('as a function', function (t) {
|
||||
t.test('bad first arg/receiver', { skip: !hasStrictMode }, function (st) {
|
||||
st['throws'](function () { implementation(undefined); }, TypeError, 'undefined is not an object');
|
||||
st['throws'](function () { implementation(null); }, TypeError, 'null is not an object');
|
||||
st.end();
|
||||
});
|
||||
|
||||
runTests(callBind(implementation, Object), t);
|
||||
|
||||
t.end();
|
||||
});
|
||||
@@ -0,0 +1,69 @@
|
||||
# mimic-fn [](https://travis-ci.org/sindresorhus/mimic-fn)
|
||||
|
||||
> Make a function mimic another one
|
||||
|
||||
Useful when you wrap a function in another function and like to preserve the original name and other properties.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install mimic-fn
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const mimicFn = require('mimic-fn');
|
||||
|
||||
function foo() {}
|
||||
foo.unicorn = '🦄';
|
||||
|
||||
function wrapper() {
|
||||
return foo();
|
||||
}
|
||||
|
||||
console.log(wrapper.name);
|
||||
//=> 'wrapper'
|
||||
|
||||
mimicFn(wrapper, foo);
|
||||
|
||||
console.log(wrapper.name);
|
||||
//=> 'foo'
|
||||
|
||||
console.log(wrapper.unicorn);
|
||||
//=> '🦄'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
It will copy over the properties `name`, `length`, `displayName`, and any custom properties you may have set.
|
||||
|
||||
### mimicFn(to, from)
|
||||
|
||||
Modifies the `to` function and returns it.
|
||||
|
||||
#### to
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Mimicking function.
|
||||
|
||||
#### from
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Function to mimic.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function
|
||||
- [keep-func-props](https://github.com/ehmicky/keep-func-props) - Wrap a function without changing its name, length and other properties
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"isFunction.js","sourceRoot":"","sources":["../../../../src/internal/util/isFunction.ts"],"names":[],"mappings":";;;AAIA,SAAgB,UAAU,CAAC,KAAU;IACnC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAFD,gCAEC"}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require('./at');
|
||||
@@ -0,0 +1,18 @@
|
||||
declare namespace cuid2 {
|
||||
export function getConstants(): {
|
||||
defaultLength: number
|
||||
bigLength: number
|
||||
}
|
||||
|
||||
export function init(options?: {
|
||||
counter?: () => number
|
||||
length?: number
|
||||
fingerprint?: string
|
||||
}): () => string
|
||||
|
||||
export function isCuid(id: string): boolean
|
||||
|
||||
export function createId(): string
|
||||
}
|
||||
|
||||
export = cuid2;
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"reduce.js","sourceRoot":"","sources":["../../../../src/internal/operators/reduce.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAEhD,qCAAuC;AAyDvC,SAAgB,MAAM,CAAO,WAAuD,EAAE,IAAU;IAC9F,OAAO,cAAO,CAAC,6BAAa,CAAC,WAAW,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AACvF,CAAC;AAFD,wBAEC"}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { Subscription } from '../Subscription';
|
||||
|
||||
import { MonoTypeOperatorFunction, ObservableInput } from '../types';
|
||||
import { operate } from '../util/lift';
|
||||
import { createOperatorSubscriber } from './OperatorSubscriber';
|
||||
import { innerFrom } from '../observable/innerFrom';
|
||||
|
||||
export interface ThrottleConfig {
|
||||
leading?: boolean;
|
||||
trailing?: boolean;
|
||||
}
|
||||
|
||||
export const defaultThrottleConfig: ThrottleConfig = {
|
||||
leading: true,
|
||||
trailing: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* Emits a value from the source Observable, then ignores subsequent source
|
||||
* values for a duration determined by another Observable, then repeats this
|
||||
* process.
|
||||
*
|
||||
* <span class="informal">It's like {@link throttleTime}, but the silencing
|
||||
* duration is determined by a second Observable.</span>
|
||||
*
|
||||
* 
|
||||
*
|
||||
* `throttle` emits the source Observable values on the output Observable
|
||||
* when its internal timer is disabled, and ignores source values when the timer
|
||||
* is enabled. Initially, the timer is disabled. As soon as the first source
|
||||
* value arrives, it is forwarded to the output Observable, and then the timer
|
||||
* is enabled by calling the `durationSelector` function with the source value,
|
||||
* which returns the "duration" Observable. When the duration Observable emits a
|
||||
* value, the timer is disabled, and this process repeats for the
|
||||
* next source value.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* Emit clicks at a rate of at most one click per second
|
||||
*
|
||||
* ```ts
|
||||
* import { fromEvent, throttle, interval } from 'rxjs';
|
||||
*
|
||||
* const clicks = fromEvent(document, 'click');
|
||||
* const result = clicks.pipe(throttle(() => interval(1000)));
|
||||
*
|
||||
* result.subscribe(x => console.log(x));
|
||||
* ```
|
||||
*
|
||||
* @see {@link audit}
|
||||
* @see {@link debounce}
|
||||
* @see {@link delayWhen}
|
||||
* @see {@link sample}
|
||||
* @see {@link throttleTime}
|
||||
*
|
||||
* @param durationSelector A function
|
||||
* that receives a value from the source Observable, for computing the silencing
|
||||
* duration for each source value, returned as an Observable or a Promise.
|
||||
* @param config a configuration object to define `leading` and `trailing` behavior. Defaults
|
||||
* to `{ leading: true, trailing: false }`.
|
||||
* @return A function that returns an Observable that performs the throttle
|
||||
* operation to limit the rate of emissions from the source.
|
||||
*/
|
||||
export function throttle<T>(
|
||||
durationSelector: (value: T) => ObservableInput<any>,
|
||||
config: ThrottleConfig = defaultThrottleConfig
|
||||
): MonoTypeOperatorFunction<T> {
|
||||
return operate((source, subscriber) => {
|
||||
const { leading, trailing } = config;
|
||||
let hasValue = false;
|
||||
let sendValue: T | null = null;
|
||||
let throttled: Subscription | null = null;
|
||||
let isComplete = false;
|
||||
|
||||
const endThrottling = () => {
|
||||
throttled?.unsubscribe();
|
||||
throttled = null;
|
||||
if (trailing) {
|
||||
send();
|
||||
isComplete && subscriber.complete();
|
||||
}
|
||||
};
|
||||
|
||||
const cleanupThrottling = () => {
|
||||
throttled = null;
|
||||
isComplete && subscriber.complete();
|
||||
};
|
||||
|
||||
const startThrottle = (value: T) =>
|
||||
(throttled = innerFrom(durationSelector(value)).subscribe(createOperatorSubscriber(subscriber, endThrottling, cleanupThrottling)));
|
||||
|
||||
const send = () => {
|
||||
if (hasValue) {
|
||||
// Ensure we clear out our value and hasValue flag
|
||||
// before we emit, otherwise reentrant code can cause
|
||||
// issues here.
|
||||
hasValue = false;
|
||||
const value = sendValue!;
|
||||
sendValue = null;
|
||||
// Emit the value.
|
||||
subscriber.next(value);
|
||||
!isComplete && startThrottle(value);
|
||||
}
|
||||
};
|
||||
|
||||
source.subscribe(
|
||||
createOperatorSubscriber(
|
||||
subscriber,
|
||||
// Regarding the presence of throttled.closed in the following
|
||||
// conditions, if a synchronous duration selector is specified - weird,
|
||||
// but legal - an already-closed subscription will be assigned to
|
||||
// throttled, so the subscription's closed property needs to be checked,
|
||||
// too.
|
||||
(value) => {
|
||||
hasValue = true;
|
||||
sendValue = value;
|
||||
!(throttled && !throttled.closed) && (leading ? send() : startThrottle(value));
|
||||
},
|
||||
() => {
|
||||
isComplete = true;
|
||||
!(trailing && hasValue && throttled && !throttled.closed) && subscriber.complete();
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
|
||||
var callBound = require('call-bind/callBound');
|
||||
|
||||
var $push = callBound('Array.prototype.push');
|
||||
|
||||
var CodePointAt = require('./CodePointAt');
|
||||
var Type = require('./Type');
|
||||
|
||||
// https://262.ecma-international.org/11.0/#sec-utf16decodestring
|
||||
|
||||
module.exports = function UTF16DecodeString(string) {
|
||||
if (Type(string) !== 'String') {
|
||||
throw new $TypeError('Assertion failed: `string` must be a String');
|
||||
}
|
||||
var codePoints = [];
|
||||
var size = string.length;
|
||||
var position = 0;
|
||||
while (position < size) {
|
||||
var cp = CodePointAt(string, position);
|
||||
$push(codePoints, cp['[[CodePoint]]']);
|
||||
position += cp['[[CodeUnitCount]]'];
|
||||
}
|
||||
return codePoints;
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "package-json",
|
||||
"version": "8.1.0",
|
||||
"description": "Get metadata of a package from the npm registry",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/package-json",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=14.16"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"npm",
|
||||
"registry",
|
||||
"package",
|
||||
"pkg",
|
||||
"package.json",
|
||||
"json",
|
||||
"module",
|
||||
"scope",
|
||||
"scoped"
|
||||
],
|
||||
"dependencies": {
|
||||
"got": "^12.1.0",
|
||||
"registry-auth-token": "^5.0.1",
|
||||
"registry-url": "^6.0.0",
|
||||
"semver": "^7.3.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.40",
|
||||
"ava": "^4.3.0",
|
||||
"mock-private-registry": "^1.1.2",
|
||||
"tsd": "^0.20.0",
|
||||
"xo": "^0.49.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
var baseAssignValue = require('./_baseAssignValue'),
|
||||
createAggregator = require('./_createAggregator');
|
||||
|
||||
/** Used for built-in method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Creates an object composed of keys generated from the results of running
|
||||
* each element of `collection` thru `iteratee`. The corresponding value of
|
||||
* each key is the number of times the key was returned by `iteratee`. The
|
||||
* iteratee is invoked with one argument: (value).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 0.5.0
|
||||
* @category Collection
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {Function} [iteratee=_.identity] The iteratee to transform keys.
|
||||
* @returns {Object} Returns the composed aggregate object.
|
||||
* @example
|
||||
*
|
||||
* _.countBy([6.1, 4.2, 6.3], Math.floor);
|
||||
* // => { '4': 1, '6': 2 }
|
||||
*
|
||||
* // The `_.property` iteratee shorthand.
|
||||
* _.countBy(['one', 'two', 'three'], 'length');
|
||||
* // => { '3': 2, '5': 1 }
|
||||
*/
|
||||
var countBy = createAggregator(function(result, value, key) {
|
||||
if (hasOwnProperty.call(result, key)) {
|
||||
++result[key];
|
||||
} else {
|
||||
baseAssignValue(result, key, 1);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = countBy;
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"52":0.05446,"59":0.01167,"60":0.00389,"67":0.01167,"68":0.00778,"78":0.04279,"83":0.00389,"88":0.01556,"89":0.00389,"91":0.01556,"93":0.01167,"94":0.01945,"95":0.00389,"97":0.00389,"99":0.00389,"100":0.00778,"101":0.00778,"102":0.08947,"103":0.00778,"104":0.01167,"105":0.01945,"106":0.01167,"107":0.01945,"108":0.04668,"109":1.42374,"110":0.94527,_:"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 61 62 63 64 65 66 69 70 71 72 73 74 75 76 77 79 80 81 82 84 85 86 87 90 92 96 98 111 112 3.5 3.6"},D:{"38":0.00778,"49":0.07391,"60":0.01167,"64":0.00389,"65":0.00778,"66":0.04668,"67":0.00389,"68":0.00778,"69":0.00389,"70":0.00778,"71":0.00778,"72":0.00778,"73":0.00389,"74":0.01167,"75":0.02334,"76":0.01167,"77":0.00778,"78":0.01167,"79":0.10892,"80":0.01556,"81":0.01945,"83":0.02334,"84":0.02334,"85":0.02723,"86":0.02723,"87":0.08947,"88":0.01945,"89":0.02334,"90":0.03112,"91":0.04279,"92":0.0389,"93":0.03112,"94":0.05835,"95":0.0389,"96":0.03112,"97":0.02723,"98":0.09336,"99":0.03112,"100":0.04668,"101":0.02334,"102":0.04279,"103":0.24118,"104":0.03112,"105":0.08169,"106":0.05446,"107":0.13615,"108":0.8169,"109":14.12848,"110":8.99368,"111":0.00778,"112":0.00389,_:"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 39 40 41 42 43 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 61 62 63 113"},F:{"28":0.00778,"46":0.00389,"89":0.00778,"92":0.01945,"93":0.12448,"94":0.99584,"95":0.46291,_:"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 90 91 9.5-9.6 10.5 10.6 11.1 11.5 11.6 12.1","10.0-10.1":0},B:{"17":0.00778,"18":0.00778,"90":0.00778,"92":0.00778,"97":0.00778,"100":0.00778,"101":0.00778,"103":0.00389,"104":0.00389,"105":0.00778,"106":0.00778,"107":0.03112,"108":0.08947,"109":1.40429,"110":1.9839,_:"12 13 14 15 16 79 80 81 83 84 85 86 87 88 89 91 93 94 95 96 98 99 102"},E:{"4":0,"13":0.01556,"14":0.10503,"15":0.02723,_:"0 5 6 7 8 9 10 11 12 3.1 3.2 5.1 6.1 7.1 10.1 16.4","9.1":0.02334,"11.1":0.01167,"12.1":0.03112,"13.1":0.12837,"14.1":0.23729,"15.1":0.0389,"15.2-15.3":0.03501,"15.4":0.08558,"15.5":0.17116,"15.6":0.61851,"16.0":0.07002,"16.1":0.24507,"16.2":0.71965,"16.3":0.49014},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0,"5.0-5.1":0.00124,"6.0-6.1":0,"7.0-7.1":0.00373,"8.1-8.4":0,"9.0-9.2":0,"9.3":0.05965,"10.0-10.2":0,"10.3":0.06586,"11.0-11.2":0.00746,"11.3-11.4":0.03355,"12.0-12.1":0.00994,"12.2-12.5":0.28207,"13.0-13.1":0.00994,"13.2":0.00373,"13.3":0.01615,"13.4-13.7":0.05965,"14.0-14.4":0.14663,"14.5-14.8":0.35042,"15.0-15.1":0.08201,"15.2-15.3":0.11805,"15.4":0.15657,"15.5":0.32308,"15.6":0.97669,"16.0":1.23889,"16.1":3.14754,"16.2":3.03819,"16.3":1.64646,"16.4":0.0087},P:{"4":0.12421,"20":0.9005,"5.0-5.4":0.03048,"6.2-6.4":0.04064,"7.2-7.4":0.26414,"8.2":0.01016,"9.2":0.02068,"10.1":0.03048,"11.1-11.2":0.03105,"12.0":0.01035,"13.0":0.0414,"14.0":0.0207,"15.0":0.0207,"16.0":0.05175,"17.0":0.0414,"18.0":0.0828,"19.0":1.44907},I:{"0":0,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0.01091,"4.2-4.3":0.00655,"4.4":0,"4.4.3-4.4.4":0.04364},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"8":0.00409,"11":0.1554,_:"6 7 9 10 5.5"},N:{"10":0.03712,"11":0.07423},S:{"2.5":0,_:"3.0-3.1"},J:{"7":0,"10":0},O:{"0":0.02444},H:{"0":0.20246},L:{"0":47.2477},R:{_:"0"},M:{"0":0.27495},Q:{"13.1":0}};
|
||||
@@ -0,0 +1,27 @@
|
||||
# Value
|
||||
|
||||
_Value_, any value that's neither `null` nor `undefined` .
|
||||
|
||||
## `value/is`
|
||||
|
||||
Confirms whether passed argument is a _value_
|
||||
|
||||
```javascript
|
||||
const isValue = require("type/value/is");
|
||||
|
||||
isValue({}); // true
|
||||
isValue(null); // false
|
||||
```
|
||||
|
||||
## `value/ensure`
|
||||
|
||||
Ensures if given argument is a _value_. If it's a value it is returned back, if not `TypeError` is thrown
|
||||
|
||||
```javascript
|
||||
const ensureValue = require("type/value/ensure");
|
||||
|
||||
const obj = {};
|
||||
|
||||
ensureValue(obj); // obj
|
||||
ensureValue(null); // Thrown TypeError: Cannot use null
|
||||
```
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sampleTime.js","sourceRoot":"","sources":["../../../../src/internal/operators/sampleTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AA6ClD,MAAM,UAAU,UAAU,CAAI,MAAc,EAAE,YAA2B,cAAc;IACrF,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAC7C,CAAC"}
|
||||
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) 2015, 2019 Elan Shanker, 2021 Blaine Bublitz <blaine.bublitz@gmail.com>, Eric Schoffstall <yo@contra.io> and other contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
@@ -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.00268,"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.00268,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0.00268,"100":0,"101":0,"102":0.01073,"103":0.00268,"104":0.00268,"105":0,"106":0.00268,"107":0.00268,"108":0.00805,"109":0.14483,"110":0.09923,"111":0.00536,"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.00268,"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.00268,"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.00268,"54":0,"55":0.00268,"56":0,"57":0,"58":0.00268,"59":0.00268,"60":0,"61":0,"62":0,"63":0.00268,"64":0.00268,"65":0,"66":0,"67":0,"68":0.00268,"69":0.00268,"70":0,"71":0,"72":0,"73":0,"74":0.00268,"75":0.00268,"76":0.00268,"77":0.00268,"78":0.01341,"79":0.00268,"80":0.00268,"81":0.00805,"83":0.00268,"84":0.00268,"85":0.00268,"86":0.00268,"87":0.00536,"88":0.00536,"89":0,"90":0.00268,"91":0,"92":0.00536,"93":0.00268,"94":0,"95":0.00536,"96":0.00536,"97":0.00268,"98":0.00268,"99":0.00536,"100":0.00268,"101":0.00805,"102":0.02146,"103":0.03755,"104":0.01073,"105":0.01341,"106":0.01341,"107":0.02682,"108":0.1046,"109":1.72721,"110":0.94406,"111":0.00268,"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.00268,"25":0,"26":0.00268,"27":0,"28":0.00536,"29":0,"30":0.00268,"31":0,"32":0.00268,"33":0,"34":0,"35":0.02682,"36":0,"37":0.00805,"38":0,"39":0,"40":0,"41":0,"42":0.00536,"43":0,"44":0,"45":0,"46":0,"47":0.00805,"48":0,"49":0,"50":0.01073,"51":0.07778,"52":0,"53":0,"54":0.00268,"55":0.00268,"56":0,"57":0.00536,"58":0.01073,"60":0.14215,"62":0,"63":0.16897,"64":0.06973,"65":0.04559,"66":0.22529,"67":0.51763,"68":0.00268,"69":0,"70":0,"71":0,"72":0.00536,"73":0.01609,"74":0.00268,"75":0,"76":0,"77":0,"78":0,"79":0.00805,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0.00268,"91":0,"92":0,"93":0.00268,"94":0.14215,"95":0.2092,"9.5-9.6":0,"10.0-10.1":0,"10.5":0,"10.6":0.00268,"11.1":0,"11.5":0,"11.6":0,"12.1":0.01877},B:{"12":0.01609,"13":0.00536,"14":0.00268,"15":0.00805,"16":0.00268,"17":0.00536,"18":0.02146,"79":0,"80":0,"81":0,"83":0,"84":0.00268,"85":0.00268,"86":0.00268,"87":0,"88":0,"89":0.00805,"90":0.00536,"91":0,"92":0.01877,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0.00268,"101":0.00268,"102":0,"103":0.00536,"104":0.00268,"105":0.00805,"106":0.00536,"107":0.02414,"108":0.03755,"109":0.33793,"110":0.39157},E:{"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0.00268,"15":0,_:"0","3.1":0,"3.2":0,"5.1":0.00536,"6.1":0,"7.1":0,"9.1":0,"10.1":0,"11.1":0,"12.1":0.00268,"13.1":0.00805,"14.1":0.01341,"15.1":0,"15.2-15.3":0,"15.4":0.00268,"15.5":0.01073,"15.6":0.02414,"16.0":0.00268,"16.1":0.01073,"16.2":0.01073,"16.3":0.01609,"16.4":0},G:{"8":0,"3.2":0,"4.0-4.1":0.00104,"4.2-4.3":0.00104,"5.0-5.1":0.00208,"6.0-6.1":0,"7.0-7.1":0.01662,"8.1-8.4":0.00104,"9.0-9.2":0.00104,"9.3":0.05298,"10.0-10.2":0,"10.3":0.04571,"11.0-11.2":0.01662,"11.3-11.4":0.00519,"12.0-12.1":0.03116,"12.2-12.5":1.85113,"13.0-13.1":0.02389,"13.2":0.00623,"13.3":0.02493,"13.4-13.7":0.13504,"14.0-14.4":0.37604,"14.5-14.8":0.42591,"15.0-15.1":0.44564,"15.2-15.3":0.25554,"15.4":0.24931,"15.5":0.36981,"15.6":0.71677,"16.0":0.76767,"16.1":1.28084,"16.2":1.03464,"16.3":0.97439,"16.4":0.00416},P:{"4":0.12458,"20":0.40487,"5.0-5.4":0,"6.2-6.4":0,"7.2-7.4":0.12458,"8.2":0,"9.2":0.02076,"10.1":0,"11.1-11.2":0.03114,"12.0":0,"13.0":0.06229,"14.0":0.01038,"15.0":0.01038,"16.0":0.05191,"17.0":0.04153,"18.0":0.09343,"19.0":0.80975},I:{"0":0,"3":0,"4":0.00225,"2.1":0,"2.2":0,"2.3":0,"4.1":0.0054,"4.2-4.3":0.00405,"4.4":0,"4.4.3-4.4.4":0.15781},K:{_:"0 10 11 12 11.1 11.5 12.1"},A:{"6":0,"7":0,"8":0,"9":0,"10":0.00298,"11":0.02384,"5.5":0},N:{"10":0,"11":0},S:{"2.5":0.01464,_:"3.0-3.1"},J:{"7":0,"10":0.00732},O:{"0":2.04904},H:{"0":11.81953},L:{"0":64.50685},R:{_:"0"},M:{"0":0.10977},Q:{"13.1":0.00732}};
|
||||
@@ -0,0 +1,40 @@
|
||||
var lowerCase = require('lower-case')
|
||||
|
||||
var NON_WORD_REGEXP = require('./vendor/non-word-regexp')
|
||||
var CAMEL_CASE_REGEXP = require('./vendor/camel-case-regexp')
|
||||
var CAMEL_CASE_UPPER_REGEXP = require('./vendor/camel-case-upper-regexp')
|
||||
|
||||
/**
|
||||
* Sentence case a string.
|
||||
*
|
||||
* @param {string} str
|
||||
* @param {string} locale
|
||||
* @param {string} replacement
|
||||
* @return {string}
|
||||
*/
|
||||
module.exports = function (str, locale, replacement) {
|
||||
if (str == null) {
|
||||
return ''
|
||||
}
|
||||
|
||||
replacement = typeof replacement !== 'string' ? ' ' : replacement
|
||||
|
||||
function replace (match, index, value) {
|
||||
if (index === 0 || index === (value.length - match.length)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return replacement
|
||||
}
|
||||
|
||||
str = String(str)
|
||||
// Support camel case ("camelCase" -> "camel Case").
|
||||
.replace(CAMEL_CASE_REGEXP, '$1 $2')
|
||||
// Support odd camel case ("CAMELCase" -> "CAMEL Case").
|
||||
.replace(CAMEL_CASE_UPPER_REGEXP, '$1 $2')
|
||||
// Remove all non-word characters and replace with a single space.
|
||||
.replace(NON_WORD_REGEXP, replace)
|
||||
|
||||
// Lower case the entire string.
|
||||
return lowerCase(str, locale)
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
import toDate from './lib/toDate';
|
||||
import toFloat from './lib/toFloat';
|
||||
import toInt from './lib/toInt';
|
||||
import toBoolean from './lib/toBoolean';
|
||||
import equals from './lib/equals';
|
||||
import contains from './lib/contains';
|
||||
import matches from './lib/matches';
|
||||
import isEmail from './lib/isEmail';
|
||||
import isURL from './lib/isURL';
|
||||
import isMACAddress from './lib/isMACAddress';
|
||||
import isIP from './lib/isIP';
|
||||
import isIPRange from './lib/isIPRange';
|
||||
import isFQDN from './lib/isFQDN';
|
||||
import isDate from './lib/isDate';
|
||||
import isTime from './lib/isTime';
|
||||
import isBoolean from './lib/isBoolean';
|
||||
import isLocale from './lib/isLocale';
|
||||
import isAlpha, { locales as isAlphaLocales } from './lib/isAlpha';
|
||||
import isAlphanumeric, { locales as isAlphanumericLocales } from './lib/isAlphanumeric';
|
||||
import isNumeric from './lib/isNumeric';
|
||||
import isPassportNumber from './lib/isPassportNumber';
|
||||
import isPort from './lib/isPort';
|
||||
import isLowercase from './lib/isLowercase';
|
||||
import isUppercase from './lib/isUppercase';
|
||||
import isIMEI from './lib/isIMEI';
|
||||
import isAscii from './lib/isAscii';
|
||||
import isFullWidth from './lib/isFullWidth';
|
||||
import isHalfWidth from './lib/isHalfWidth';
|
||||
import isVariableWidth from './lib/isVariableWidth';
|
||||
import isMultibyte from './lib/isMultibyte';
|
||||
import isSemVer from './lib/isSemVer';
|
||||
import isSurrogatePair from './lib/isSurrogatePair';
|
||||
import isInt from './lib/isInt';
|
||||
import isFloat, { locales as isFloatLocales } from './lib/isFloat';
|
||||
import isDecimal from './lib/isDecimal';
|
||||
import isHexadecimal from './lib/isHexadecimal';
|
||||
import isOctal from './lib/isOctal';
|
||||
import isDivisibleBy from './lib/isDivisibleBy';
|
||||
import isHexColor from './lib/isHexColor';
|
||||
import isRgbColor from './lib/isRgbColor';
|
||||
import isHSL from './lib/isHSL';
|
||||
import isISRC from './lib/isISRC';
|
||||
import isIBAN, { locales as ibanLocales } from './lib/isIBAN';
|
||||
import isBIC from './lib/isBIC';
|
||||
import isMD5 from './lib/isMD5';
|
||||
import isHash from './lib/isHash';
|
||||
import isJWT from './lib/isJWT';
|
||||
import isJSON from './lib/isJSON';
|
||||
import isEmpty from './lib/isEmpty';
|
||||
import isLength from './lib/isLength';
|
||||
import isByteLength from './lib/isByteLength';
|
||||
import isUUID from './lib/isUUID';
|
||||
import isMongoId from './lib/isMongoId';
|
||||
import isAfter from './lib/isAfter';
|
||||
import isBefore from './lib/isBefore';
|
||||
import isIn from './lib/isIn';
|
||||
import isLuhnNumber from './lib/isLuhnNumber';
|
||||
import isCreditCard from './lib/isCreditCard';
|
||||
import isIdentityCard from './lib/isIdentityCard';
|
||||
import isEAN from './lib/isEAN';
|
||||
import isISIN from './lib/isISIN';
|
||||
import isISBN from './lib/isISBN';
|
||||
import isISSN from './lib/isISSN';
|
||||
import isTaxID from './lib/isTaxID';
|
||||
import isMobilePhone, { locales as isMobilePhoneLocales } from './lib/isMobilePhone';
|
||||
import isEthereumAddress from './lib/isEthereumAddress';
|
||||
import isCurrency from './lib/isCurrency';
|
||||
import isBtcAddress from './lib/isBtcAddress';
|
||||
import isISO6391 from './lib/isISO6391';
|
||||
import isISO8601 from './lib/isISO8601';
|
||||
import isRFC3339 from './lib/isRFC3339';
|
||||
import isISO31661Alpha2 from './lib/isISO31661Alpha2';
|
||||
import isISO31661Alpha3 from './lib/isISO31661Alpha3';
|
||||
import isISO4217 from './lib/isISO4217';
|
||||
import isBase32 from './lib/isBase32';
|
||||
import isBase58 from './lib/isBase58';
|
||||
import isBase64 from './lib/isBase64';
|
||||
import isDataURI from './lib/isDataURI';
|
||||
import isMagnetURI from './lib/isMagnetURI';
|
||||
import isMimeType from './lib/isMimeType';
|
||||
import isLatLong from './lib/isLatLong';
|
||||
import isPostalCode, { locales as isPostalCodeLocales } from './lib/isPostalCode';
|
||||
import ltrim from './lib/ltrim';
|
||||
import rtrim from './lib/rtrim';
|
||||
import trim from './lib/trim';
|
||||
import escape from './lib/escape';
|
||||
import unescape from './lib/unescape';
|
||||
import stripLow from './lib/stripLow';
|
||||
import whitelist from './lib/whitelist';
|
||||
import blacklist from './lib/blacklist';
|
||||
import isWhitelisted from './lib/isWhitelisted';
|
||||
import normalizeEmail from './lib/normalizeEmail';
|
||||
import isSlug from './lib/isSlug';
|
||||
import isLicensePlate from './lib/isLicensePlate';
|
||||
import isStrongPassword from './lib/isStrongPassword';
|
||||
import isVAT from './lib/isVAT';
|
||||
var version = '13.9.0';
|
||||
var validator = {
|
||||
version: version,
|
||||
toDate: toDate,
|
||||
toFloat: toFloat,
|
||||
toInt: toInt,
|
||||
toBoolean: toBoolean,
|
||||
equals: equals,
|
||||
contains: contains,
|
||||
matches: matches,
|
||||
isEmail: isEmail,
|
||||
isURL: isURL,
|
||||
isMACAddress: isMACAddress,
|
||||
isIP: isIP,
|
||||
isIPRange: isIPRange,
|
||||
isFQDN: isFQDN,
|
||||
isBoolean: isBoolean,
|
||||
isIBAN: isIBAN,
|
||||
isBIC: isBIC,
|
||||
isAlpha: isAlpha,
|
||||
isAlphaLocales: isAlphaLocales,
|
||||
isAlphanumeric: isAlphanumeric,
|
||||
isAlphanumericLocales: isAlphanumericLocales,
|
||||
isNumeric: isNumeric,
|
||||
isPassportNumber: isPassportNumber,
|
||||
isPort: isPort,
|
||||
isLowercase: isLowercase,
|
||||
isUppercase: isUppercase,
|
||||
isAscii: isAscii,
|
||||
isFullWidth: isFullWidth,
|
||||
isHalfWidth: isHalfWidth,
|
||||
isVariableWidth: isVariableWidth,
|
||||
isMultibyte: isMultibyte,
|
||||
isSemVer: isSemVer,
|
||||
isSurrogatePair: isSurrogatePair,
|
||||
isInt: isInt,
|
||||
isIMEI: isIMEI,
|
||||
isFloat: isFloat,
|
||||
isFloatLocales: isFloatLocales,
|
||||
isDecimal: isDecimal,
|
||||
isHexadecimal: isHexadecimal,
|
||||
isOctal: isOctal,
|
||||
isDivisibleBy: isDivisibleBy,
|
||||
isHexColor: isHexColor,
|
||||
isRgbColor: isRgbColor,
|
||||
isHSL: isHSL,
|
||||
isISRC: isISRC,
|
||||
isMD5: isMD5,
|
||||
isHash: isHash,
|
||||
isJWT: isJWT,
|
||||
isJSON: isJSON,
|
||||
isEmpty: isEmpty,
|
||||
isLength: isLength,
|
||||
isLocale: isLocale,
|
||||
isByteLength: isByteLength,
|
||||
isUUID: isUUID,
|
||||
isMongoId: isMongoId,
|
||||
isAfter: isAfter,
|
||||
isBefore: isBefore,
|
||||
isIn: isIn,
|
||||
isLuhnNumber: isLuhnNumber,
|
||||
isCreditCard: isCreditCard,
|
||||
isIdentityCard: isIdentityCard,
|
||||
isEAN: isEAN,
|
||||
isISIN: isISIN,
|
||||
isISBN: isISBN,
|
||||
isISSN: isISSN,
|
||||
isMobilePhone: isMobilePhone,
|
||||
isMobilePhoneLocales: isMobilePhoneLocales,
|
||||
isPostalCode: isPostalCode,
|
||||
isPostalCodeLocales: isPostalCodeLocales,
|
||||
isEthereumAddress: isEthereumAddress,
|
||||
isCurrency: isCurrency,
|
||||
isBtcAddress: isBtcAddress,
|
||||
isISO6391: isISO6391,
|
||||
isISO8601: isISO8601,
|
||||
isRFC3339: isRFC3339,
|
||||
isISO31661Alpha2: isISO31661Alpha2,
|
||||
isISO31661Alpha3: isISO31661Alpha3,
|
||||
isISO4217: isISO4217,
|
||||
isBase32: isBase32,
|
||||
isBase58: isBase58,
|
||||
isBase64: isBase64,
|
||||
isDataURI: isDataURI,
|
||||
isMagnetURI: isMagnetURI,
|
||||
isMimeType: isMimeType,
|
||||
isLatLong: isLatLong,
|
||||
ltrim: ltrim,
|
||||
rtrim: rtrim,
|
||||
trim: trim,
|
||||
escape: escape,
|
||||
unescape: unescape,
|
||||
stripLow: stripLow,
|
||||
whitelist: whitelist,
|
||||
blacklist: blacklist,
|
||||
isWhitelisted: isWhitelisted,
|
||||
normalizeEmail: normalizeEmail,
|
||||
toString: toString,
|
||||
isSlug: isSlug,
|
||||
isStrongPassword: isStrongPassword,
|
||||
isTaxID: isTaxID,
|
||||
isDate: isDate,
|
||||
isTime: isTime,
|
||||
isLicensePlate: isLicensePlate,
|
||||
isVAT: isVAT,
|
||||
ibanLocales: ibanLocales
|
||||
};
|
||||
export default validator;
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Assign properties from `props` to `obj`
|
||||
* @template O, P The obj and props types
|
||||
* @param {O} obj The object to copy properties to
|
||||
* @param {P} props The object to copy properties from
|
||||
* @returns {O & P}
|
||||
*/
|
||||
export function assign(obj, props) {
|
||||
for (let i in props) obj[i] = props[i];
|
||||
return /** @type {O & P} */ (obj);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
var callBound = require('call-bind/callBound');
|
||||
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
|
||||
var IsInteger = require('./IsInteger');
|
||||
var Type = require('./Type');
|
||||
|
||||
var $charAt = callBound('String.prototype.charAt');
|
||||
|
||||
// https://262.ecma-international.org/6.0/#sec-splitmatch
|
||||
|
||||
module.exports = function SplitMatch(S, q, R) {
|
||||
if (Type(S) !== 'String') {
|
||||
throw new $TypeError('Assertion failed: `S` must be a String');
|
||||
}
|
||||
if (!IsInteger(q)) {
|
||||
throw new $TypeError('Assertion failed: `q` must be an integer');
|
||||
}
|
||||
if (Type(R) !== 'String') {
|
||||
throw new $TypeError('Assertion failed: `R` must be a String');
|
||||
}
|
||||
var r = R.length;
|
||||
var s = S.length;
|
||||
if (q + r > s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < r; i += 1) {
|
||||
if ($charAt(S, q + i) !== $charAt(R, i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return q + r;
|
||||
};
|
||||
@@ -0,0 +1,126 @@
|
||||
import { Observable } from '../Observable';
|
||||
import { SchedulerLike } from '../types';
|
||||
/**
|
||||
* Creates an observable that will wait for a specified time period, or exact date, before
|
||||
* emitting the number 0.
|
||||
*
|
||||
* <span class="informal">Used to emit a notification after a delay.</span>
|
||||
*
|
||||
* This observable is useful for creating delays in code, or racing against other values
|
||||
* for ad-hoc timeouts.
|
||||
*
|
||||
* The `delay` is specified by default in milliseconds, however providing a custom scheduler could
|
||||
* create a different behavior.
|
||||
*
|
||||
* ## Examples
|
||||
*
|
||||
* Wait 3 seconds and start another observable
|
||||
*
|
||||
* You might want to use `timer` to delay subscription to an
|
||||
* observable by a set amount of time. Here we use a timer with
|
||||
* {@link concatMapTo} or {@link concatMap} in order to wait
|
||||
* a few seconds and start a subscription to a source.
|
||||
*
|
||||
* ```ts
|
||||
* import { of, timer, concatMap } from 'rxjs';
|
||||
*
|
||||
* // This could be any observable
|
||||
* const source = of(1, 2, 3);
|
||||
*
|
||||
* timer(3000)
|
||||
* .pipe(concatMap(() => source))
|
||||
* .subscribe(console.log);
|
||||
* ```
|
||||
*
|
||||
* Take all values until the start of the next minute
|
||||
*
|
||||
* Using a `Date` as the trigger for the first emission, you can
|
||||
* do things like wait until midnight to fire an event, or in this case,
|
||||
* wait until a new minute starts (chosen so the example wouldn't take
|
||||
* too long to run) in order to stop watching a stream. Leveraging
|
||||
* {@link takeUntil}.
|
||||
*
|
||||
* ```ts
|
||||
* import { interval, takeUntil, timer } from 'rxjs';
|
||||
*
|
||||
* // Build a Date object that marks the
|
||||
* // next minute.
|
||||
* const currentDate = new Date();
|
||||
* const startOfNextMinute = new Date(
|
||||
* currentDate.getFullYear(),
|
||||
* currentDate.getMonth(),
|
||||
* currentDate.getDate(),
|
||||
* currentDate.getHours(),
|
||||
* currentDate.getMinutes() + 1
|
||||
* );
|
||||
*
|
||||
* // This could be any observable stream
|
||||
* const source = interval(1000);
|
||||
*
|
||||
* const result = source.pipe(
|
||||
* takeUntil(timer(startOfNextMinute))
|
||||
* );
|
||||
*
|
||||
* result.subscribe(console.log);
|
||||
* ```
|
||||
*
|
||||
* ### Known Limitations
|
||||
*
|
||||
* - The {@link asyncScheduler} uses `setTimeout` which has limitations for how far in the future it can be scheduled.
|
||||
*
|
||||
* - If a `scheduler` is provided that returns a timestamp other than an epoch from `now()`, and
|
||||
* a `Date` object is passed to the `dueTime` argument, the calculation for when the first emission
|
||||
* should occur will be incorrect. In this case, it would be best to do your own calculations
|
||||
* ahead of time, and pass a `number` in as the `dueTime`.
|
||||
*
|
||||
* @param due If a `number`, the amount of time in milliseconds to wait before emitting.
|
||||
* If a `Date`, the exact time at which to emit.
|
||||
* @param scheduler The scheduler to use to schedule the delay. Defaults to {@link asyncScheduler}.
|
||||
*/
|
||||
export declare function timer(due: number | Date, scheduler?: SchedulerLike): Observable<0>;
|
||||
/**
|
||||
* Creates an observable that starts an interval after a specified delay, emitting incrementing numbers -- starting at `0` --
|
||||
* on each interval after words.
|
||||
*
|
||||
* The `delay` and `intervalDuration` are specified by default in milliseconds, however providing a custom scheduler could
|
||||
* create a different behavior.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* ### Start an interval that starts right away
|
||||
*
|
||||
* Since {@link interval} waits for the passed delay before starting,
|
||||
* sometimes that's not ideal. You may want to start an interval immediately.
|
||||
* `timer` works well for this. Here we have both side-by-side so you can
|
||||
* see them in comparison.
|
||||
*
|
||||
* Note that this observable will never complete.
|
||||
*
|
||||
* ```ts
|
||||
* import { timer, interval } from 'rxjs';
|
||||
*
|
||||
* timer(0, 1000).subscribe(n => console.log('timer', n));
|
||||
* interval(1000).subscribe(n => console.log('interval', n));
|
||||
* ```
|
||||
*
|
||||
* ### Known Limitations
|
||||
*
|
||||
* - The {@link asyncScheduler} uses `setTimeout` which has limitations for how far in the future it can be scheduled.
|
||||
*
|
||||
* - If a `scheduler` is provided that returns a timestamp other than an epoch from `now()`, and
|
||||
* a `Date` object is passed to the `dueTime` argument, the calculation for when the first emission
|
||||
* should occur will be incorrect. In this case, it would be best to do your own calculations
|
||||
* ahead of time, and pass a `number` in as the `startDue`.
|
||||
* @param startDue If a `number`, is the time to wait before starting the interval.
|
||||
* If a `Date`, is the exact time at which to start the interval.
|
||||
* @param intervalDuration The delay between each value emitted in the interval. Passing a
|
||||
* negative number here will result in immediate completion after the first value is emitted, as though
|
||||
* no `intervalDuration` was passed at all.
|
||||
* @param scheduler The scheduler to use to schedule the delay. Defaults to {@link asyncScheduler}.
|
||||
*/
|
||||
export declare function timer(startDue: number | Date, intervalDuration: number, scheduler?: SchedulerLike): Observable<number>;
|
||||
/**
|
||||
* @deprecated The signature allowing `undefined` to be passed for `intervalDuration` will be removed in v8. Use the `timer(dueTime, scheduler?)` signature instead.
|
||||
*/
|
||||
export declare function timer(dueTime: number | Date, unused: undefined, scheduler?: SchedulerLike): Observable<0>;
|
||||
//# sourceMappingURL=timer.d.ts.map
|
||||
@@ -0,0 +1,190 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __values = (this && this.__values) || function(o) {
|
||||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||||
if (m) return m.call(o);
|
||||
if (o && typeof o.length === "number") return {
|
||||
next: function () {
|
||||
if (o && i >= o.length) o = void 0;
|
||||
return { value: o && o[i++], done: !o };
|
||||
}
|
||||
};
|
||||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AnonymousSubject = exports.Subject = void 0;
|
||||
var Observable_1 = require("./Observable");
|
||||
var Subscription_1 = require("./Subscription");
|
||||
var ObjectUnsubscribedError_1 = require("./util/ObjectUnsubscribedError");
|
||||
var arrRemove_1 = require("./util/arrRemove");
|
||||
var errorContext_1 = require("./util/errorContext");
|
||||
var Subject = (function (_super) {
|
||||
__extends(Subject, _super);
|
||||
function Subject() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.closed = false;
|
||||
_this.currentObservers = null;
|
||||
_this.observers = [];
|
||||
_this.isStopped = false;
|
||||
_this.hasError = false;
|
||||
_this.thrownError = null;
|
||||
return _this;
|
||||
}
|
||||
Subject.prototype.lift = function (operator) {
|
||||
var subject = new AnonymousSubject(this, this);
|
||||
subject.operator = operator;
|
||||
return subject;
|
||||
};
|
||||
Subject.prototype._throwIfClosed = function () {
|
||||
if (this.closed) {
|
||||
throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
|
||||
}
|
||||
};
|
||||
Subject.prototype.next = function (value) {
|
||||
var _this = this;
|
||||
errorContext_1.errorContext(function () {
|
||||
var e_1, _a;
|
||||
_this._throwIfClosed();
|
||||
if (!_this.isStopped) {
|
||||
if (!_this.currentObservers) {
|
||||
_this.currentObservers = Array.from(_this.observers);
|
||||
}
|
||||
try {
|
||||
for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||
var observer = _c.value;
|
||||
observer.next(value);
|
||||
}
|
||||
}
|
||||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||
}
|
||||
finally { if (e_1) throw e_1.error; }
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Subject.prototype.error = function (err) {
|
||||
var _this = this;
|
||||
errorContext_1.errorContext(function () {
|
||||
_this._throwIfClosed();
|
||||
if (!_this.isStopped) {
|
||||
_this.hasError = _this.isStopped = true;
|
||||
_this.thrownError = err;
|
||||
var observers = _this.observers;
|
||||
while (observers.length) {
|
||||
observers.shift().error(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Subject.prototype.complete = function () {
|
||||
var _this = this;
|
||||
errorContext_1.errorContext(function () {
|
||||
_this._throwIfClosed();
|
||||
if (!_this.isStopped) {
|
||||
_this.isStopped = true;
|
||||
var observers = _this.observers;
|
||||
while (observers.length) {
|
||||
observers.shift().complete();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Subject.prototype.unsubscribe = function () {
|
||||
this.isStopped = this.closed = true;
|
||||
this.observers = this.currentObservers = null;
|
||||
};
|
||||
Object.defineProperty(Subject.prototype, "observed", {
|
||||
get: function () {
|
||||
var _a;
|
||||
return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Subject.prototype._trySubscribe = function (subscriber) {
|
||||
this._throwIfClosed();
|
||||
return _super.prototype._trySubscribe.call(this, subscriber);
|
||||
};
|
||||
Subject.prototype._subscribe = function (subscriber) {
|
||||
this._throwIfClosed();
|
||||
this._checkFinalizedStatuses(subscriber);
|
||||
return this._innerSubscribe(subscriber);
|
||||
};
|
||||
Subject.prototype._innerSubscribe = function (subscriber) {
|
||||
var _this = this;
|
||||
var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
|
||||
if (hasError || isStopped) {
|
||||
return Subscription_1.EMPTY_SUBSCRIPTION;
|
||||
}
|
||||
this.currentObservers = null;
|
||||
observers.push(subscriber);
|
||||
return new Subscription_1.Subscription(function () {
|
||||
_this.currentObservers = null;
|
||||
arrRemove_1.arrRemove(observers, subscriber);
|
||||
});
|
||||
};
|
||||
Subject.prototype._checkFinalizedStatuses = function (subscriber) {
|
||||
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
|
||||
if (hasError) {
|
||||
subscriber.error(thrownError);
|
||||
}
|
||||
else if (isStopped) {
|
||||
subscriber.complete();
|
||||
}
|
||||
};
|
||||
Subject.prototype.asObservable = function () {
|
||||
var observable = new Observable_1.Observable();
|
||||
observable.source = this;
|
||||
return observable;
|
||||
};
|
||||
Subject.create = function (destination, source) {
|
||||
return new AnonymousSubject(destination, source);
|
||||
};
|
||||
return Subject;
|
||||
}(Observable_1.Observable));
|
||||
exports.Subject = Subject;
|
||||
var AnonymousSubject = (function (_super) {
|
||||
__extends(AnonymousSubject, _super);
|
||||
function AnonymousSubject(destination, source) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.destination = destination;
|
||||
_this.source = source;
|
||||
return _this;
|
||||
}
|
||||
AnonymousSubject.prototype.next = function (value) {
|
||||
var _a, _b;
|
||||
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
||||
};
|
||||
AnonymousSubject.prototype.error = function (err) {
|
||||
var _a, _b;
|
||||
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
|
||||
};
|
||||
AnonymousSubject.prototype.complete = function () {
|
||||
var _a, _b;
|
||||
(_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
||||
};
|
||||
AnonymousSubject.prototype._subscribe = function (subscriber) {
|
||||
var _a, _b;
|
||||
return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : Subscription_1.EMPTY_SUBSCRIPTION;
|
||||
};
|
||||
return AnonymousSubject;
|
||||
}(Subject));
|
||||
exports.AnonymousSubject = AnonymousSubject;
|
||||
//# sourceMappingURL=Subject.js.map
|
||||
@@ -0,0 +1,9 @@
|
||||
import { TColumn } from '../types';
|
||||
export declare function calculateRowColSpans(
|
||||
column: TColumn,
|
||||
rowIndex: number,
|
||||
totalRows: number,
|
||||
): {
|
||||
rowSpan: number;
|
||||
colSpan: number;
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
var convert = require('./convert'),
|
||||
func = convert('findLast', require('../findLast'));
|
||||
|
||||
func.placeholder = require('./placeholder');
|
||||
module.exports = func;
|
||||
@@ -0,0 +1,13 @@
|
||||
export type ResponseUser = {
|
||||
firstname: string;
|
||||
middlename: string;
|
||||
lastname: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
username: string;
|
||||
enabled: boolean;
|
||||
profilePic: string;
|
||||
groups?: Array<any>;
|
||||
permissions?: Array<any>;
|
||||
id: number;
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
# is-typedarray [](http://github.com/badges/stability-badges)
|
||||
|
||||
Detect whether or not an object is a
|
||||
[Typed Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays).
|
||||
|
||||
## Usage
|
||||
|
||||
[](https://nodei.co/npm/is-typedarray/)
|
||||
|
||||
### isTypedArray(array)
|
||||
|
||||
Returns `true` when array is a Typed Array, and `false` when it is not.
|
||||
|
||||
## License
|
||||
|
||||
MIT. See [LICENSE.md](http://github.com/hughsk/is-typedarray/blob/master/LICENSE.md) for details.
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"AsyncAction.js","sourceRoot":"","sources":["../../../../src/internal/scheduler/AsyncAction.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C;IAAoC,+BAAS;IAO3C,qBAAsB,SAAyB,EAAY,IAAmD;QAA9G,YACE,kBAAM,SAAS,EAAE,IAAI,CAAC,SACvB;QAFqB,eAAS,GAAT,SAAS,CAAgB;QAAY,UAAI,GAAJ,IAAI,CAA+C;QAFpG,aAAO,GAAY,KAAK,CAAC;;IAInC,CAAC;IAEM,8BAAQ,GAAf,UAAgB,KAAS,EAAE,KAAiB;;QAAjB,sBAAA,EAAA,SAAiB;QAC1C,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAO,IAAI,CAAC;SACb;QAGD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QACnB,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAuBjC,IAAI,EAAE,IAAI,IAAI,EAAE;YACd,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;SACrD;QAID,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAI,CAAC,EAAE,GAAG,MAAA,IAAI,CAAC,EAAE,mCAAI,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAEpE,OAAO,IAAI,CAAC;IACd,CAAC;IAES,oCAAc,GAAxB,UAAyB,SAAyB,EAAE,GAAiB,EAAE,KAAiB;QAAjB,sBAAA,EAAA,SAAiB;QACtF,OAAO,gBAAgB,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACpF,CAAC;IAES,oCAAc,GAAxB,UAAyB,UAA0B,EAAE,EAAgB,EAAE,KAAwB;QAAxB,sBAAA,EAAA,SAAwB;QAE7F,IAAI,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,EAAE;YACnE,OAAO,EAAE,CAAC;SACX;QAGD,IAAI,EAAE,IAAI,IAAI,EAAE;YACd,gBAAgB,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;SACpC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAMM,6BAAO,GAAd,UAAe,KAAQ,EAAE,KAAa;QACpC,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAO,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SAClD;QAED,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC1C,IAAI,KAAK,EAAE;YACT,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,EAAE;YAcpD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;SAC9D;IACH,CAAC;IAES,8BAAQ,GAAlB,UAAmB,KAAQ,EAAE,MAAc;QACzC,IAAI,OAAO,GAAY,KAAK,CAAC;QAC7B,IAAI,UAAe,CAAC;QACpB,IAAI;YACF,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAClB;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,GAAG,IAAI,CAAC;YAIf,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACtE;QACD,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO,UAAU,CAAC;SACnB;IACH,CAAC;IAED,iCAAW,GAAX;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACV,IAAA,KAAoB,IAAI,EAAtB,EAAE,QAAA,EAAE,SAAS,eAAS,CAAC;YACvB,IAAA,OAAO,GAAK,SAAS,QAAd,CAAe;YAE9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,GAAG,IAAK,CAAC;YAChD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YAErB,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACzB,IAAI,EAAE,IAAI,IAAI,EAAE;gBACd,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;aACpD;YAED,IAAI,CAAC,KAAK,GAAG,IAAK,CAAC;YACnB,iBAAM,WAAW,WAAE,CAAC;SACrB;IACH,CAAC;IACH,kBAAC;AAAD,CAAC,AA9ID,CAAoC,MAAM,GA8IzC"}
|
||||
@@ -0,0 +1,43 @@
|
||||
var root = require('./_root'),
|
||||
toString = require('./toString');
|
||||
|
||||
/** Used to match leading whitespace. */
|
||||
var reTrimStart = /^\s+/;
|
||||
|
||||
/* Built-in method references for those with the same name as other `lodash` methods. */
|
||||
var nativeParseInt = root.parseInt;
|
||||
|
||||
/**
|
||||
* Converts `string` to an integer of the specified radix. If `radix` is
|
||||
* `undefined` or `0`, a `radix` of `10` is used unless `value` is a
|
||||
* hexadecimal, in which case a `radix` of `16` is used.
|
||||
*
|
||||
* **Note:** This method aligns with the
|
||||
* [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 1.1.0
|
||||
* @category String
|
||||
* @param {string} string The string to convert.
|
||||
* @param {number} [radix=10] The radix to interpret `value` by.
|
||||
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||||
* @returns {number} Returns the converted integer.
|
||||
* @example
|
||||
*
|
||||
* _.parseInt('08');
|
||||
* // => 8
|
||||
*
|
||||
* _.map(['6', '08', '10'], _.parseInt);
|
||||
* // => [6, 8, 10]
|
||||
*/
|
||||
function parseInt(string, radix, guard) {
|
||||
if (guard || radix == null) {
|
||||
radix = 0;
|
||||
} else if (radix) {
|
||||
radix = +radix;
|
||||
}
|
||||
return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
|
||||
}
|
||||
|
||||
module.exports = parseInt;
|
||||
@@ -0,0 +1,7 @@
|
||||
import { ObservableNotification } from '../types';
|
||||
export interface TestMessage {
|
||||
frame: number;
|
||||
notification: ObservableNotification<any>;
|
||||
isGhost?: boolean;
|
||||
}
|
||||
//# sourceMappingURL=TestMessage.d.ts.map
|
||||
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.finalize = void 0;
|
||||
var lift_1 = require("../util/lift");
|
||||
function finalize(callback) {
|
||||
return lift_1.operate(function (source, subscriber) {
|
||||
try {
|
||||
source.subscribe(subscriber);
|
||||
}
|
||||
finally {
|
||||
subscriber.add(callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.finalize = finalize;
|
||||
//# sourceMappingURL=finalize.js.map
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = require("./is-implemented")() ? Number.isInteger : require("./shim");
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"UnicodeExtensionValue.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-localematcher/abstract/UnicodeExtensionValue.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,sBAoCnE"}
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Converts `map` to its key-value pairs.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} map The map to convert.
|
||||
* @returns {Array} Returns the key-value pairs.
|
||||
*/
|
||||
function mapToArray(map) {
|
||||
var index = -1,
|
||||
result = Array(map.size);
|
||||
|
||||
map.forEach(function(value, key) {
|
||||
result[++index] = [key, value];
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = mapToArray;
|
||||
@@ -0,0 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
let Stringifier = require('./stringifier')
|
||||
|
||||
function stringify(node, builder) {
|
||||
let str = new Stringifier(builder)
|
||||
str.stringify(node)
|
||||
}
|
||||
|
||||
module.exports = stringify
|
||||
stringify.default = stringify
|
||||
@@ -0,0 +1,13 @@
|
||||
type Options = {
|
||||
cwd?: string;
|
||||
dot?: boolean;
|
||||
absolute?: boolean;
|
||||
filesOnly?: boolean;
|
||||
flush?: boolean;
|
||||
};
|
||||
|
||||
type FilePath = string;
|
||||
|
||||
declare function glob(str: string, opts?: Options): Promise<FilePath[]>;
|
||||
|
||||
export = glob;
|
||||
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var floor = require('./floor');
|
||||
var modulo = require('./modulo');
|
||||
|
||||
var timeConstants = require('../helpers/timeConstants');
|
||||
var msPerHour = timeConstants.msPerHour;
|
||||
var HoursPerDay = timeConstants.HoursPerDay;
|
||||
|
||||
// https://262.ecma-international.org/5.1/#sec-15.9.1.10
|
||||
|
||||
module.exports = function HourFromTime(t) {
|
||||
return modulo(floor(t / msPerHour), HoursPerDay);
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
// Generated with `lib/make.js`
|
||||
'use strict';
|
||||
const path = require('path');
|
||||
const Stream = require('stream').Stream;
|
||||
const url = require('url');
|
||||
|
||||
const Umask = () => {};
|
||||
const getLocalAddresses = () => [];
|
||||
const semver = () => {};
|
||||
|
||||
exports.types = {
|
||||
access: [null, 'restricted', 'public'],
|
||||
'allow-same-version': Boolean,
|
||||
'always-auth': Boolean,
|
||||
also: [null, 'dev', 'development'],
|
||||
audit: Boolean,
|
||||
'auth-type': ['legacy', 'sso', 'saml', 'oauth'],
|
||||
'bin-links': Boolean,
|
||||
browser: [null, String],
|
||||
ca: [null, String, Array],
|
||||
cafile: path,
|
||||
cache: path,
|
||||
'cache-lock-stale': Number,
|
||||
'cache-lock-retries': Number,
|
||||
'cache-lock-wait': Number,
|
||||
'cache-max': Number,
|
||||
'cache-min': Number,
|
||||
cert: [null, String],
|
||||
cidr: [null, String, Array],
|
||||
color: ['always', Boolean],
|
||||
depth: Number,
|
||||
description: Boolean,
|
||||
dev: Boolean,
|
||||
'dry-run': Boolean,
|
||||
editor: String,
|
||||
'engine-strict': Boolean,
|
||||
force: Boolean,
|
||||
'fetch-retries': Number,
|
||||
'fetch-retry-factor': Number,
|
||||
'fetch-retry-mintimeout': Number,
|
||||
'fetch-retry-maxtimeout': Number,
|
||||
git: String,
|
||||
'git-tag-version': Boolean,
|
||||
'commit-hooks': Boolean,
|
||||
global: Boolean,
|
||||
globalconfig: path,
|
||||
'global-style': Boolean,
|
||||
group: [Number, String],
|
||||
'https-proxy': [null, url],
|
||||
'user-agent': String,
|
||||
'ham-it-up': Boolean,
|
||||
'heading': String,
|
||||
'if-present': Boolean,
|
||||
'ignore-prepublish': Boolean,
|
||||
'ignore-scripts': Boolean,
|
||||
'init-module': path,
|
||||
'init-author-name': String,
|
||||
'init-author-email': String,
|
||||
'init-author-url': ['', url],
|
||||
'init-license': String,
|
||||
'init-version': semver,
|
||||
json: Boolean,
|
||||
key: [null, String],
|
||||
'legacy-bundling': Boolean,
|
||||
link: Boolean,
|
||||
// local-address must be listed as an IP for a local network interface
|
||||
// must be IPv4 due to node bug
|
||||
'local-address': getLocalAddresses(),
|
||||
loglevel: ['silent', 'error', 'warn', 'notice', 'http', 'timing', 'info', 'verbose', 'silly'],
|
||||
logstream: Stream,
|
||||
'logs-max': Number,
|
||||
long: Boolean,
|
||||
maxsockets: Number,
|
||||
message: String,
|
||||
'metrics-registry': [null, String],
|
||||
'node-options': [null, String],
|
||||
'node-version': [null, semver],
|
||||
'no-proxy': [null, String, Array],
|
||||
offline: Boolean,
|
||||
'onload-script': [null, String],
|
||||
only: [null, 'dev', 'development', 'prod', 'production'],
|
||||
optional: Boolean,
|
||||
'package-lock': Boolean,
|
||||
otp: [null, String],
|
||||
'package-lock-only': Boolean,
|
||||
parseable: Boolean,
|
||||
'prefer-offline': Boolean,
|
||||
'prefer-online': Boolean,
|
||||
prefix: path,
|
||||
production: Boolean,
|
||||
progress: Boolean,
|
||||
proxy: [null, false, url],
|
||||
// allow proxy to be disabled explicitly
|
||||
'read-only': Boolean,
|
||||
'rebuild-bundle': Boolean,
|
||||
registry: [null, url],
|
||||
rollback: Boolean,
|
||||
save: Boolean,
|
||||
'save-bundle': Boolean,
|
||||
'save-dev': Boolean,
|
||||
'save-exact': Boolean,
|
||||
'save-optional': Boolean,
|
||||
'save-prefix': String,
|
||||
'save-prod': Boolean,
|
||||
scope: String,
|
||||
'script-shell': [null, String],
|
||||
'scripts-prepend-node-path': [false, true, 'auto', 'warn-only'],
|
||||
searchopts: String,
|
||||
searchexclude: [null, String],
|
||||
searchlimit: Number,
|
||||
searchstaleness: Number,
|
||||
'send-metrics': Boolean,
|
||||
shell: String,
|
||||
shrinkwrap: Boolean,
|
||||
'sign-git-tag': Boolean,
|
||||
'sso-poll-frequency': Number,
|
||||
'sso-type': [null, 'oauth', 'saml'],
|
||||
'strict-ssl': Boolean,
|
||||
tag: String,
|
||||
timing: Boolean,
|
||||
tmp: path,
|
||||
unicode: Boolean,
|
||||
'unsafe-perm': Boolean,
|
||||
usage: Boolean,
|
||||
user: [Number, String],
|
||||
userconfig: path,
|
||||
umask: Umask,
|
||||
version: Boolean,
|
||||
'tag-version-prefix': String,
|
||||
versions: Boolean,
|
||||
viewer: String,
|
||||
_exit: Boolean
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export type CreateStatsClient = {
|
||||
description?: string;
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require('./matchesProperty');
|
||||
@@ -0,0 +1,871 @@
|
||||
<div align="center">
|
||||
<img src="docs/media/Banner.svg" alt="Node Fetch"/>
|
||||
<br>
|
||||
<p>A light-weight module that brings <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch API</a> to Node.js.</p>
|
||||
<a href="https://github.com/node-fetch/node-fetch/actions"><img src="https://github.com/node-fetch/node-fetch/workflows/CI/badge.svg?branch=master" alt="Build status"></a>
|
||||
<a href="https://coveralls.io/github/node-fetch/node-fetch"><img src="https://img.shields.io/coveralls/github/node-fetch/node-fetch" alt="Coverage status"></a>
|
||||
<a href="https://packagephobia.now.sh/result?p=node-fetch"><img src="https://badgen.net/packagephobia/install/node-fetch" alt="Current version"></a>
|
||||
<a href="https://www.npmjs.com/package/node-fetch"><img src="https://img.shields.io/npm/v/node-fetch" alt="Install size"></a>
|
||||
<a href="https://github.com/sindresorhus/awesome-nodejs"><img src="https://awesome.re/mentioned-badge.svg" alt="Mentioned in Awesome Node.js"></a>
|
||||
<a href="https://discord.gg/Zxbndcm"><img src="https://img.shields.io/discord/619915844268326952?color=%237289DA&label=Discord" alt="Discord"></a>
|
||||
<br>
|
||||
<br>
|
||||
<b>Consider supporting us on our Open Collective:</b>
|
||||
<br>
|
||||
<br>
|
||||
<a href="https://opencollective.com/node-fetch"><img src="https://opencollective.com/node-fetch/donate/button.png?color=blue" alt="Open Collective"></a>
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
**You might be looking for the [v2 docs](https://github.com/node-fetch/node-fetch/tree/2.x#readme)**
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
- [Motivation](#motivation)
|
||||
- [Features](#features)
|
||||
- [Difference from client-side fetch](#difference-from-client-side-fetch)
|
||||
- [Installation](#installation)
|
||||
- [Loading and configuring the module](#loading-and-configuring-the-module)
|
||||
- [Upgrading](#upgrading)
|
||||
- [Common Usage](#common-usage)
|
||||
- [Plain text or HTML](#plain-text-or-html)
|
||||
- [JSON](#json)
|
||||
- [Simple Post](#simple-post)
|
||||
- [Post with JSON](#post-with-json)
|
||||
- [Post with form parameters](#post-with-form-parameters)
|
||||
- [Handling exceptions](#handling-exceptions)
|
||||
- [Handling client and server errors](#handling-client-and-server-errors)
|
||||
- [Handling cookies](#handling-cookies)
|
||||
- [Advanced Usage](#advanced-usage)
|
||||
- [Streams](#streams)
|
||||
- [Accessing Headers and other Metadata](#accessing-headers-and-other-metadata)
|
||||
- [Extract Set-Cookie Header](#extract-set-cookie-header)
|
||||
- [Post data using a file](#post-data-using-a-file)
|
||||
- [Request cancellation with AbortSignal](#request-cancellation-with-abortsignal)
|
||||
- [API](#api)
|
||||
- [fetch(url[, options])](#fetchurl-options)
|
||||
- [Options](#options)
|
||||
- [Default Headers](#default-headers)
|
||||
- [Custom Agent](#custom-agent)
|
||||
- [Custom highWaterMark](#custom-highwatermark)
|
||||
- [Insecure HTTP Parser](#insecure-http-parser)
|
||||
- [Class: Request](#class-request)
|
||||
- [new Request(input[, options])](#new-requestinput-options)
|
||||
- [Class: Response](#class-response)
|
||||
- [new Response([body[, options]])](#new-responsebody-options)
|
||||
- [response.ok](#responseok)
|
||||
- [response.redirected](#responseredirected)
|
||||
- [response.type](#responsetype)
|
||||
- [Class: Headers](#class-headers)
|
||||
- [new Headers([init])](#new-headersinit)
|
||||
- [Interface: Body](#interface-body)
|
||||
- [body.body](#bodybody)
|
||||
- [body.bodyUsed](#bodybodyused)
|
||||
- [body.arrayBuffer()](#bodyarraybuffer)
|
||||
- [body.blob()](#bodyblob)
|
||||
- [body.formData()](#formdata)
|
||||
- [body.json()](#bodyjson)
|
||||
- [body.text()](#bodytext)
|
||||
- [Class: FetchError](#class-fetcherror)
|
||||
- [Class: AbortError](#class-aborterror)
|
||||
- [TypeScript](#typescript)
|
||||
- [Acknowledgement](#acknowledgement)
|
||||
- [Team](#team)
|
||||
- [Former](#former)
|
||||
- [License](#license)
|
||||
|
||||
<!-- /TOC -->
|
||||
|
||||
## Motivation
|
||||
|
||||
Instead of implementing `XMLHttpRequest` in Node.js to run browser-specific [Fetch polyfill](https://github.com/github/fetch), why not go from native `http` to `fetch` API directly? Hence, `node-fetch`, minimal code for a `window.fetch` compatible API on Node.js runtime.
|
||||
|
||||
See Jason Miller's [isomorphic-unfetch](https://www.npmjs.com/package/isomorphic-unfetch) or Leonardo Quixada's [cross-fetch](https://github.com/lquixada/cross-fetch) for isomorphic usage (exports `node-fetch` for server-side, `whatwg-fetch` for client-side).
|
||||
|
||||
## Features
|
||||
|
||||
- Stay consistent with `window.fetch` API.
|
||||
- Make conscious trade-off when following [WHATWG fetch spec][whatwg-fetch] and [stream spec](https://streams.spec.whatwg.org/) implementation details, document known differences.
|
||||
- Use native promise and async functions.
|
||||
- Use native Node streams for body, on both request and response.
|
||||
- Decode content encoding (gzip/deflate/brotli) properly, and convert string output (such as `res.text()` and `res.json()`) to UTF-8 automatically.
|
||||
- Useful extensions such as redirect limit, response size limit, [explicit errors][error-handling.md] for troubleshooting.
|
||||
|
||||
## Difference from client-side fetch
|
||||
|
||||
- See known differences:
|
||||
- [As of v3.x](docs/v3-LIMITS.md)
|
||||
- [As of v2.x](docs/v2-LIMITS.md)
|
||||
- If you happen to use a missing feature that `window.fetch` offers, feel free to open an issue.
|
||||
- Pull requests are welcomed too!
|
||||
|
||||
## Installation
|
||||
|
||||
Current stable release (`3.x`) requires at least Node.js 12.20.0.
|
||||
|
||||
```sh
|
||||
npm install node-fetch
|
||||
```
|
||||
|
||||
## Loading and configuring the module
|
||||
|
||||
### ES Modules (ESM)
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
```
|
||||
|
||||
### CommonJS
|
||||
|
||||
`node-fetch` from v3 is an ESM-only module - you are not able to import it with `require()`.
|
||||
|
||||
If you cannot switch to ESM, please use v2 which remains compatible with CommonJS. Critical bug fixes will continue to be published for v2.
|
||||
|
||||
```sh
|
||||
npm install node-fetch@2
|
||||
```
|
||||
|
||||
Alternatively, you can use the async `import()` function from CommonJS to load `node-fetch` asynchronously:
|
||||
|
||||
```js
|
||||
// mod.cjs
|
||||
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||
```
|
||||
|
||||
### Providing global access
|
||||
|
||||
To use `fetch()` without importing it, you can patch the `global` object in node:
|
||||
|
||||
```js
|
||||
// fetch-polyfill.js
|
||||
import fetch, {
|
||||
Blob,
|
||||
blobFrom,
|
||||
blobFromSync,
|
||||
File,
|
||||
fileFrom,
|
||||
fileFromSync,
|
||||
FormData,
|
||||
Headers,
|
||||
Request,
|
||||
Response,
|
||||
} from 'node-fetch'
|
||||
|
||||
if (!globalThis.fetch) {
|
||||
globalThis.fetch = fetch
|
||||
globalThis.Headers = Headers
|
||||
globalThis.Request = Request
|
||||
globalThis.Response = Response
|
||||
}
|
||||
|
||||
// index.js
|
||||
import './fetch-polyfill'
|
||||
|
||||
// ...
|
||||
```
|
||||
|
||||
## Upgrading
|
||||
|
||||
Using an old version of node-fetch? Check out the following files:
|
||||
|
||||
- [2.x to 3.x upgrade guide](docs/v3-UPGRADE-GUIDE.md)
|
||||
- [1.x to 2.x upgrade guide](docs/v2-UPGRADE-GUIDE.md)
|
||||
- [Changelog](https://github.com/node-fetch/node-fetch/releases)
|
||||
|
||||
## Common Usage
|
||||
|
||||
NOTE: The documentation below is up-to-date with `3.x` releases, if you are using an older version, please check how to [upgrade](#upgrading).
|
||||
|
||||
### Plain text or HTML
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const response = await fetch('https://github.com/');
|
||||
const body = await response.text();
|
||||
|
||||
console.log(body);
|
||||
```
|
||||
|
||||
### JSON
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const response = await fetch('https://api.github.com/users/github');
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
```
|
||||
|
||||
### Simple Post
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const response = await fetch('https://httpbin.org/post', {method: 'POST', body: 'a=1'});
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
```
|
||||
|
||||
### Post with JSON
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const body = {a: 1};
|
||||
|
||||
const response = await fetch('https://httpbin.org/post', {
|
||||
method: 'post',
|
||||
body: JSON.stringify(body),
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
```
|
||||
|
||||
### Post with form parameters
|
||||
|
||||
`URLSearchParams` is available on the global object in Node.js as of v10.0.0. See [official documentation](https://nodejs.org/api/url.html#url_class_urlsearchparams) for more usage methods.
|
||||
|
||||
NOTE: The `Content-Type` header is only set automatically to `x-www-form-urlencoded` when an instance of `URLSearchParams` is given as such:
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.append('a', 1);
|
||||
|
||||
const response = await fetch('https://httpbin.org/post', {method: 'POST', body: params});
|
||||
const data = await response.json();
|
||||
|
||||
console.log(data);
|
||||
```
|
||||
|
||||
### Handling exceptions
|
||||
|
||||
NOTE: 3xx-5xx responses are _NOT_ exceptions, and should be handled in `then()`, see the next section.
|
||||
|
||||
Wrapping the fetch function into a `try/catch` block will catch _all_ exceptions, such as errors originating from node core libraries, like network errors, and operational errors which are instances of FetchError. See the [error handling document][error-handling.md] for more details.
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
try {
|
||||
await fetch('https://domain.invalid/');
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
```
|
||||
|
||||
### Handling client and server errors
|
||||
|
||||
It is common to create a helper function to check that the response contains no client (4xx) or server (5xx) error responses:
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
class HTTPResponseError extends Error {
|
||||
constructor(response) {
|
||||
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
|
||||
this.response = response;
|
||||
}
|
||||
}
|
||||
|
||||
const checkStatus = response => {
|
||||
if (response.ok) {
|
||||
// response.status >= 200 && response.status < 300
|
||||
return response;
|
||||
} else {
|
||||
throw new HTTPResponseError(response);
|
||||
}
|
||||
}
|
||||
|
||||
const response = await fetch('https://httpbin.org/status/400');
|
||||
|
||||
try {
|
||||
checkStatus(response);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
const errorBody = await error.response.text();
|
||||
console.error(`Error body: ${errorBody}`);
|
||||
}
|
||||
```
|
||||
|
||||
### Handling cookies
|
||||
|
||||
Cookies are not stored by default. However, cookies can be extracted and passed by manipulating request and response headers. See [Extract Set-Cookie Header](#extract-set-cookie-header) for details.
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
### Streams
|
||||
|
||||
The "Node.js way" is to use streams when possible. You can pipe `res.body` to another stream. This example uses [stream.pipeline](https://nodejs.org/api/stream.html#stream_stream_pipeline_streams_callback) to attach stream error handlers and wait for the download to complete.
|
||||
|
||||
```js
|
||||
import {createWriteStream} from 'node:fs';
|
||||
import {pipeline} from 'node:stream';
|
||||
import {promisify} from 'node:util'
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const streamPipeline = promisify(pipeline);
|
||||
|
||||
const response = await fetch('https://github.githubassets.com/images/modules/logos_page/Octocat.png');
|
||||
|
||||
if (!response.ok) throw new Error(`unexpected response ${response.statusText}`);
|
||||
|
||||
await streamPipeline(response.body, createWriteStream('./octocat.png'));
|
||||
```
|
||||
|
||||
In Node.js 14 you can also use async iterators to read `body`; however, be careful to catch
|
||||
errors -- the longer a response runs, the more likely it is to encounter an error.
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const response = await fetch('https://httpbin.org/stream/3');
|
||||
|
||||
try {
|
||||
for await (const chunk of response.body) {
|
||||
console.dir(JSON.parse(chunk.toString()));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
}
|
||||
```
|
||||
|
||||
In Node.js 12 you can also use async iterators to read `body`; however, async iterators with streams
|
||||
did not mature until Node.js 14, so you need to do some extra work to ensure you handle errors
|
||||
directly from the stream and wait on it response to fully close.
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const read = async body => {
|
||||
let error;
|
||||
body.on('error', err => {
|
||||
error = err;
|
||||
});
|
||||
|
||||
for await (const chunk of body) {
|
||||
console.dir(JSON.parse(chunk.toString()));
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
body.on('close', () => {
|
||||
error ? reject(error) : resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch('https://httpbin.org/stream/3');
|
||||
await read(response.body);
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
}
|
||||
```
|
||||
|
||||
### Accessing Headers and other Metadata
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const response = await fetch('https://github.com/');
|
||||
|
||||
console.log(response.ok);
|
||||
console.log(response.status);
|
||||
console.log(response.statusText);
|
||||
console.log(response.headers.raw());
|
||||
console.log(response.headers.get('content-type'));
|
||||
```
|
||||
|
||||
### Extract Set-Cookie Header
|
||||
|
||||
Unlike browsers, you can access raw `Set-Cookie` headers manually using `Headers.raw()`. This is a `node-fetch` only API.
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const response = await fetch('https://example.com');
|
||||
|
||||
// Returns an array of values, instead of a string of comma-separated values
|
||||
console.log(response.headers.raw()['set-cookie']);
|
||||
```
|
||||
|
||||
### Post data using a file
|
||||
|
||||
```js
|
||||
import fetch, {
|
||||
Blob,
|
||||
blobFrom,
|
||||
blobFromSync,
|
||||
File,
|
||||
fileFrom,
|
||||
fileFromSync,
|
||||
} from 'node-fetch'
|
||||
|
||||
const mimetype = 'text/plain'
|
||||
const blob = fileFromSync('./input.txt', mimetype)
|
||||
const url = 'https://httpbin.org/post'
|
||||
|
||||
const response = await fetch(url, { method: 'POST', body: blob })
|
||||
const data = await response.json()
|
||||
|
||||
console.log(data)
|
||||
```
|
||||
|
||||
node-fetch comes with a spec-compliant [FormData] implementations for posting
|
||||
multipart/form-data payloads
|
||||
|
||||
```js
|
||||
import fetch, { FormData, File, fileFrom } from 'node-fetch'
|
||||
|
||||
const httpbin = 'https://httpbin.org/post'
|
||||
const formData = new FormData()
|
||||
const binary = new Uint8Array([ 97, 98, 99 ])
|
||||
const abc = new File([binary], 'abc.txt', { type: 'text/plain' })
|
||||
|
||||
formData.set('greeting', 'Hello, world!')
|
||||
formData.set('file-upload', abc, 'new name.txt')
|
||||
|
||||
const response = await fetch(httpbin, { method: 'POST', body: formData })
|
||||
const data = await response.json()
|
||||
|
||||
console.log(data)
|
||||
```
|
||||
|
||||
If you for some reason need to post a stream coming from any arbitrary place,
|
||||
then you can append a [Blob] or a [File] look-a-like item.
|
||||
|
||||
The minimum requirement is that it has:
|
||||
1. A `Symbol.toStringTag` getter or property that is either `Blob` or `File`
|
||||
2. A known size.
|
||||
3. And either a `stream()` method or a `arrayBuffer()` method that returns a ArrayBuffer.
|
||||
|
||||
The `stream()` must return any async iterable object as long as it yields Uint8Array (or Buffer)
|
||||
so Node.Readable streams and whatwg streams works just fine.
|
||||
|
||||
```js
|
||||
formData.append('upload', {
|
||||
[Symbol.toStringTag]: 'Blob',
|
||||
size: 3,
|
||||
*stream() {
|
||||
yield new Uint8Array([97, 98, 99])
|
||||
},
|
||||
arrayBuffer() {
|
||||
return new Uint8Array([97, 98, 99]).buffer
|
||||
}
|
||||
}, 'abc.txt')
|
||||
```
|
||||
|
||||
### Request cancellation with AbortSignal
|
||||
|
||||
You may cancel requests with `AbortController`. A suggested implementation is [`abort-controller`](https://www.npmjs.com/package/abort-controller).
|
||||
|
||||
An example of timing out a request after 150ms could be achieved as the following:
|
||||
|
||||
```js
|
||||
import fetch, { AbortError } from 'node-fetch';
|
||||
|
||||
// AbortController was added in node v14.17.0 globally
|
||||
const AbortController = globalThis.AbortController || await import('abort-controller')
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => {
|
||||
controller.abort();
|
||||
}, 150);
|
||||
|
||||
try {
|
||||
const response = await fetch('https://example.com', {signal: controller.signal});
|
||||
const data = await response.json();
|
||||
} catch (error) {
|
||||
if (error instanceof AbortError) {
|
||||
console.log('request was aborted');
|
||||
}
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
```
|
||||
|
||||
See [test cases](https://github.com/node-fetch/node-fetch/blob/master/test/) for more examples.
|
||||
|
||||
## API
|
||||
|
||||
### fetch(url[, options])
|
||||
|
||||
- `url` A string representing the URL for fetching
|
||||
- `options` [Options](#fetch-options) for the HTTP(S) request
|
||||
- Returns: <code>Promise<[Response](#class-response)></code>
|
||||
|
||||
Perform an HTTP(S) fetch.
|
||||
|
||||
`url` should be an absolute URL, such as `https://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected `Promise`.
|
||||
|
||||
<a id="fetch-options"></a>
|
||||
|
||||
### Options
|
||||
|
||||
The default values are shown after each option key.
|
||||
|
||||
```js
|
||||
{
|
||||
// These properties are part of the Fetch Standard
|
||||
method: 'GET',
|
||||
headers: {}, // Request headers. format is the identical to that accepted by the Headers constructor (see below)
|
||||
body: null, // Request body. can be null, or a Node.js Readable stream
|
||||
redirect: 'follow', // Set to `manual` to extract redirect headers, `error` to reject redirect
|
||||
signal: null, // Pass an instance of AbortSignal to optionally abort requests
|
||||
|
||||
// The following properties are node-fetch extensions
|
||||
follow: 20, // maximum redirect count. 0 to not follow redirect
|
||||
compress: true, // support gzip/deflate content encoding. false to disable
|
||||
size: 0, // maximum response body size in bytes. 0 to disable
|
||||
agent: null, // http(s).Agent instance or function that returns an instance (see below)
|
||||
highWaterMark: 16384, // the maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource.
|
||||
insecureHTTPParser: false // Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
|
||||
}
|
||||
```
|
||||
|
||||
#### Default Headers
|
||||
|
||||
If no values are set, the following request headers will be sent automatically:
|
||||
|
||||
| Header | Value |
|
||||
| ------------------- | ------------------------------------------------------ |
|
||||
| `Accept-Encoding` | `gzip, deflate, br` (when `options.compress === true`) |
|
||||
| `Accept` | `*/*` |
|
||||
| `Connection` | `close` _(when no `options.agent` is present)_ |
|
||||
| `Content-Length` | _(automatically calculated, if possible)_ |
|
||||
| `Host` | _(host and port information from the target URI)_ |
|
||||
| `Transfer-Encoding` | `chunked` _(when `req.body` is a stream)_ |
|
||||
| `User-Agent` | `node-fetch` |
|
||||
|
||||
|
||||
Note: when `body` is a `Stream`, `Content-Length` is not set automatically.
|
||||
|
||||
#### Custom Agent
|
||||
|
||||
The `agent` option allows you to specify networking related options which are out of the scope of Fetch, including and not limited to the following:
|
||||
|
||||
- Support self-signed certificate
|
||||
- Use only IPv4 or IPv6
|
||||
- Custom DNS Lookup
|
||||
|
||||
See [`http.Agent`](https://nodejs.org/api/http.html#http_new_agent_options) for more information.
|
||||
|
||||
In addition, the `agent` option accepts a function that returns `http`(s)`.Agent` instance given current [URL](https://nodejs.org/api/url.html), this is useful during a redirection chain across HTTP and HTTPS protocol.
|
||||
|
||||
```js
|
||||
import http from 'node:http';
|
||||
import https from 'node:https';
|
||||
|
||||
const httpAgent = new http.Agent({
|
||||
keepAlive: true
|
||||
});
|
||||
const httpsAgent = new https.Agent({
|
||||
keepAlive: true
|
||||
});
|
||||
|
||||
const options = {
|
||||
agent: function(_parsedURL) {
|
||||
if (_parsedURL.protocol == 'http:') {
|
||||
return httpAgent;
|
||||
} else {
|
||||
return httpsAgent;
|
||||
}
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
<a id="custom-highWaterMark"></a>
|
||||
|
||||
#### Custom highWaterMark
|
||||
|
||||
Stream on Node.js have a smaller internal buffer size (16kB, aka `highWaterMark`) from client-side browsers (>1MB, not consistent across browsers). Because of that, when you are writing an isomorphic app and using `res.clone()`, it will hang with large response in Node.
|
||||
|
||||
The recommended way to fix this problem is to resolve cloned response in parallel:
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const response = await fetch('https://example.com');
|
||||
const r1 = response.clone();
|
||||
|
||||
const results = await Promise.all([response.json(), r1.text()]);
|
||||
|
||||
console.log(results[0]);
|
||||
console.log(results[1]);
|
||||
```
|
||||
|
||||
If for some reason you don't like the solution above, since `3.x` you are able to modify the `highWaterMark` option:
|
||||
|
||||
```js
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const response = await fetch('https://example.com', {
|
||||
// About 1MB
|
||||
highWaterMark: 1024 * 1024
|
||||
});
|
||||
|
||||
const result = await res.clone().arrayBuffer();
|
||||
console.dir(result);
|
||||
```
|
||||
|
||||
#### Insecure HTTP Parser
|
||||
|
||||
Passed through to the `insecureHTTPParser` option on http(s).request. See [`http.request`](https://nodejs.org/api/http.html#http_http_request_url_options_callback) for more information.
|
||||
|
||||
#### Manual Redirect
|
||||
|
||||
The `redirect: 'manual'` option for node-fetch is different from the browser & specification, which
|
||||
results in an [opaque-redirect filtered response](https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect).
|
||||
node-fetch gives you the typical [basic filtered response](https://fetch.spec.whatwg.org/#concept-filtered-response-basic) instead.
|
||||
|
||||
```js
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
const response = await fetch('https://httpbin.org/status/301', { redirect: 'manual' });
|
||||
|
||||
if (response.status === 301 || response.status === 302) {
|
||||
const locationURL = new URL(response.headers.get('location'), response.url);
|
||||
const response2 = await fetch(locationURL, { redirect: 'manual' });
|
||||
console.dir(response2);
|
||||
}
|
||||
```
|
||||
|
||||
<a id="class-request"></a>
|
||||
|
||||
### Class: Request
|
||||
|
||||
An HTTP(S) request containing information about URL, method, headers, and the body. This class implements the [Body](#iface-body) interface.
|
||||
|
||||
Due to the nature of Node.js, the following properties are not implemented at this moment:
|
||||
|
||||
- `type`
|
||||
- `destination`
|
||||
- `mode`
|
||||
- `credentials`
|
||||
- `cache`
|
||||
- `integrity`
|
||||
- `keepalive`
|
||||
|
||||
The following node-fetch extension properties are provided:
|
||||
|
||||
- `follow`
|
||||
- `compress`
|
||||
- `counter`
|
||||
- `agent`
|
||||
- `highWaterMark`
|
||||
|
||||
See [options](#fetch-options) for exact meaning of these extensions.
|
||||
|
||||
#### new Request(input[, options])
|
||||
|
||||
<small>_(spec-compliant)_</small>
|
||||
|
||||
- `input` A string representing a URL, or another `Request` (which will be cloned)
|
||||
- `options` [Options](#fetch-options) for the HTTP(S) request
|
||||
|
||||
Constructs a new `Request` object. The constructor is identical to that in the [browser](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request).
|
||||
|
||||
In most cases, directly `fetch(url, options)` is simpler than creating a `Request` object.
|
||||
|
||||
<a id="class-response"></a>
|
||||
|
||||
### Class: Response
|
||||
|
||||
An HTTP(S) response. This class implements the [Body](#iface-body) interface.
|
||||
|
||||
The following properties are not implemented in node-fetch at this moment:
|
||||
|
||||
- `trailer`
|
||||
|
||||
#### new Response([body[, options]])
|
||||
|
||||
<small>_(spec-compliant)_</small>
|
||||
|
||||
- `body` A `String` or [`Readable` stream][node-readable]
|
||||
- `options` A [`ResponseInit`][response-init] options dictionary
|
||||
|
||||
Constructs a new `Response` object. The constructor is identical to that in the [browser](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response).
|
||||
|
||||
Because Node.js does not implement service workers (for which this class was designed), one rarely has to construct a `Response` directly.
|
||||
|
||||
#### response.ok
|
||||
|
||||
<small>_(spec-compliant)_</small>
|
||||
|
||||
Convenience property representing if the request ended normally. Will evaluate to true if the response status was greater than or equal to 200 but smaller than 300.
|
||||
|
||||
#### response.redirected
|
||||
|
||||
<small>_(spec-compliant)_</small>
|
||||
|
||||
Convenience property representing if the request has been redirected at least once. Will evaluate to true if the internal redirect counter is greater than 0.
|
||||
|
||||
#### response.type
|
||||
|
||||
<small>_(deviation from spec)_</small>
|
||||
|
||||
Convenience property representing the response's type. node-fetch only supports `'default'` and `'error'` and does not make use of [filtered responses](https://fetch.spec.whatwg.org/#concept-filtered-response).
|
||||
|
||||
<a id="class-headers"></a>
|
||||
|
||||
### Class: Headers
|
||||
|
||||
This class allows manipulating and iterating over a set of HTTP headers. All methods specified in the [Fetch Standard][whatwg-fetch] are implemented.
|
||||
|
||||
#### new Headers([init])
|
||||
|
||||
<small>_(spec-compliant)_</small>
|
||||
|
||||
- `init` Optional argument to pre-fill the `Headers` object
|
||||
|
||||
Construct a new `Headers` object. `init` can be either `null`, a `Headers` object, an key-value map object or any iterable object.
|
||||
|
||||
```js
|
||||
// Example adapted from https://fetch.spec.whatwg.org/#example-headers-class
|
||||
import {Headers} from 'node-fetch';
|
||||
|
||||
const meta = {
|
||||
'Content-Type': 'text/xml'
|
||||
};
|
||||
const headers = new Headers(meta);
|
||||
|
||||
// The above is equivalent to
|
||||
const meta = [['Content-Type', 'text/xml']];
|
||||
const headers = new Headers(meta);
|
||||
|
||||
// You can in fact use any iterable objects, like a Map or even another Headers
|
||||
const meta = new Map();
|
||||
meta.set('Content-Type', 'text/xml');
|
||||
const headers = new Headers(meta);
|
||||
const copyOfHeaders = new Headers(headers);
|
||||
```
|
||||
|
||||
<a id="iface-body"></a>
|
||||
|
||||
### Interface: Body
|
||||
|
||||
`Body` is an abstract interface with methods that are applicable to both `Request` and `Response` classes.
|
||||
|
||||
#### body.body
|
||||
|
||||
<small>_(deviation from spec)_</small>
|
||||
|
||||
- Node.js [`Readable` stream][node-readable]
|
||||
|
||||
Data are encapsulated in the `Body` object. Note that while the [Fetch Standard][whatwg-fetch] requires the property to always be a WHATWG `ReadableStream`, in node-fetch it is a Node.js [`Readable` stream][node-readable].
|
||||
|
||||
#### body.bodyUsed
|
||||
|
||||
<small>_(spec-compliant)_</small>
|
||||
|
||||
- `Boolean`
|
||||
|
||||
A boolean property for if this body has been consumed. Per the specs, a consumed body cannot be used again.
|
||||
|
||||
#### body.arrayBuffer()
|
||||
|
||||
#### body.formData()
|
||||
|
||||
#### body.blob()
|
||||
|
||||
#### body.json()
|
||||
|
||||
#### body.text()
|
||||
|
||||
`fetch` comes with methods to parse `multipart/form-data` payloads as well as
|
||||
`x-www-form-urlencoded` bodies using `.formData()` this comes from the idea that
|
||||
Service Worker can intercept such messages before it's sent to the server to
|
||||
alter them. This is useful for anybody building a server so you can use it to
|
||||
parse & consume payloads.
|
||||
|
||||
<details>
|
||||
<summary>Code example</summary>
|
||||
|
||||
```js
|
||||
import http from 'node:http'
|
||||
import { Response } from 'node-fetch'
|
||||
|
||||
http.createServer(async function (req, res) {
|
||||
const formData = await new Response(req, {
|
||||
headers: req.headers // Pass along the boundary value
|
||||
}).formData()
|
||||
const allFields = [...formData]
|
||||
|
||||
const file = formData.get('uploaded-files')
|
||||
const arrayBuffer = await file.arrayBuffer()
|
||||
const text = await file.text()
|
||||
const whatwgReadableStream = file.stream()
|
||||
|
||||
// other was to consume the request could be to do:
|
||||
const json = await new Response(req).json()
|
||||
const text = await new Response(req).text()
|
||||
const arrayBuffer = await new Response(req).arrayBuffer()
|
||||
const blob = await new Response(req, {
|
||||
headers: req.headers // So that `type` inherits `Content-Type`
|
||||
}.blob()
|
||||
})
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<a id="class-fetcherror"></a>
|
||||
|
||||
### Class: FetchError
|
||||
|
||||
<small>_(node-fetch extension)_</small>
|
||||
|
||||
An operational error in the fetching process. See [ERROR-HANDLING.md][] for more info.
|
||||
|
||||
<a id="class-aborterror"></a>
|
||||
|
||||
### Class: AbortError
|
||||
|
||||
<small>_(node-fetch extension)_</small>
|
||||
|
||||
An Error thrown when the request is aborted in response to an `AbortSignal`'s `abort` event. It has a `name` property of `AbortError`. See [ERROR-HANDLING.MD][] for more info.
|
||||
|
||||
## TypeScript
|
||||
|
||||
**Since `3.x` types are bundled with `node-fetch`, so you don't need to install any additional packages.**
|
||||
|
||||
For older versions please use the type definitions from [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped):
|
||||
|
||||
```sh
|
||||
npm install --save-dev @types/node-fetch@2.x
|
||||
```
|
||||
|
||||
## Acknowledgement
|
||||
|
||||
Thanks to [github/fetch](https://github.com/github/fetch) for providing a solid implementation reference.
|
||||
|
||||
## Team
|
||||
|
||||
| [](https://github.com/bitinn) | [](https://github.com/jimmywarting) | [](https://github.com/xxczaki) | [](https://github.com/Richienb) | [](https://github.com/gr2m) |
|
||||
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------- |
|
||||
| [David Frank](https://bitinn.net/) | [Jimmy Wärting](https://jimmy.warting.se/) | [Antoni Kepinski](https://kepinski.ch) | [Richie Bendall](https://www.richie-bendall.ml/) | [Gregor Martynus](https://twitter.com/gr2m) |
|
||||
|
||||
###### Former
|
||||
|
||||
- [Timothy Gu](https://github.com/timothygu)
|
||||
- [Jared Kantrowitz](https://github.com/jkantr)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE.md)
|
||||
|
||||
[whatwg-fetch]: https://fetch.spec.whatwg.org/
|
||||
[response-init]: https://fetch.spec.whatwg.org/#responseinit
|
||||
[node-readable]: https://nodejs.org/api/stream.html#stream_readable_streams
|
||||
[mdn-headers]: https://developer.mozilla.org/en-US/docs/Web/API/Headers
|
||||
[error-handling.md]: https://github.com/node-fetch/node-fetch/blob/master/docs/ERROR-HANDLING.md
|
||||
[FormData]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
|
||||
[Blob]: https://developer.mozilla.org/en-US/docs/Web/API/Blob
|
||||
[File]: https://developer.mozilla.org/en-US/docs/Web/API/File
|
||||
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _namespace = _interopRequireDefault(require("./namespace"));
|
||||
|
||||
var _types = require("./types");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var Universal = /*#__PURE__*/function (_Namespace) {
|
||||
_inheritsLoose(Universal, _Namespace);
|
||||
|
||||
function Universal(opts) {
|
||||
var _this;
|
||||
|
||||
_this = _Namespace.call(this, opts) || this;
|
||||
_this.type = _types.UNIVERSAL;
|
||||
_this.value = '*';
|
||||
return _this;
|
||||
}
|
||||
|
||||
return Universal;
|
||||
}(_namespace["default"]);
|
||||
|
||||
exports["default"] = Universal;
|
||||
module.exports = exports.default;
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"J D E F A B CC"},B:{"1":"G M N O P Q R S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H","16":"C K L"},C:{"1":"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":"0 DC tB I v J D E F A B C K L G M N O w g x y z EC FC"},D:{"1":"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":"0 1 2 3 4 5 6 7 8 9 I v J D E F A B C K L G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB"},E:{"1":"E F A B C K L G KC LC 0B qB rB 1B MC NC 2B 3B 4B 5B sB 6B 7B 8B 9B OC","2":"I v J D HC zB IC JC"},F:{"1":"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 ZB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d e","2":"0 1 2 3 4 5 6 7 F B C G M N O w g x y z PC QC RC SC qB AC TC 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:{"2":"D","16":"A"},K:{"1":"h","2":"A B C qB AC rB"},L:{"1":"H"},M:{"1":"H"},N:{"2":"A B"},O:{"1":"vC"},P:{"1":"g wC xC yC zC 0C 0B 1C 2C 3C 4C 5C sB 6C 7C 8C","2":"I"},Q:{"1":"1B"},R:{"1":"9C"},S:{"1":"AD BD"}},B:6,C:"Array.prototype.find"};
|
||||
@@ -0,0 +1,35 @@
|
||||
var naiveFallback = function () {
|
||||
if (typeof self === "object" && self) return self;
|
||||
if (typeof window === "object" && window) return window;
|
||||
throw new Error("Unable to resolve global `this`");
|
||||
};
|
||||
|
||||
module.exports = (function () {
|
||||
if (this) return this;
|
||||
|
||||
// Unexpected strict mode (may happen if e.g. bundled into ESM module)
|
||||
|
||||
// Fallback to standard globalThis if available
|
||||
if (typeof globalThis === "object" && globalThis) return globalThis;
|
||||
|
||||
// Thanks @mathiasbynens -> https://mathiasbynens.be/notes/globalthis
|
||||
// In all ES5+ engines global object inherits from Object.prototype
|
||||
// (if you approached one that doesn't please report)
|
||||
try {
|
||||
Object.defineProperty(Object.prototype, "__global__", {
|
||||
get: function () { return this; },
|
||||
configurable: true
|
||||
});
|
||||
} catch (error) {
|
||||
// Unfortunate case of updates to Object.prototype being restricted
|
||||
// via preventExtensions, seal or freeze
|
||||
return naiveFallback();
|
||||
}
|
||||
try {
|
||||
// Safari case (window.__global__ works, but __global__ does not)
|
||||
if (!__global__) return naiveFallback();
|
||||
return __global__;
|
||||
} finally {
|
||||
delete Object.prototype.__global__;
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,13 @@
|
||||
// Bootstrap cliui with CommonJS dependencies:
|
||||
import { cliui } from './build/lib/index.js'
|
||||
import { wrap, stripAnsi } from './build/lib/string-utils.js'
|
||||
|
||||
export default function ui (opts) {
|
||||
return cliui(opts, {
|
||||
stringWidth: (str) => {
|
||||
return [...str].length
|
||||
},
|
||||
stripAnsi,
|
||||
wrap
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"J D E F A B CC"},B:{"2":"C K L G M N O","129":"P Q R S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H"},C:{"1":"0 1 2 3 4 5 6 7 8 9 tB I v J D E F A B C K L G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H xB yB EC FC","2":"DC"},D:{"2":"I v J D E F A B C","129":"0 1 2 3 4 5 6 7 8 9 K L G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB uB ZB vB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R S T U V W X Y Z a b c d e i j k l m n o p q r s t u f H xB yB GC"},E:{"2":"I v J D E F A B C K L G HC zB IC JC KC LC 0B qB rB 1B MC NC 2B 3B 4B 5B sB 6B 7B 8B 9B OC"},F:{"2":"F B PC QC RC SC qB AC","129":"0 1 2 3 4 5 6 7 8 9 C G M N O w g x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB PB QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB h lB mB nB oB pB P Q R wB S T U V W X Y Z a b c d e TC rB"},G:{"2":"E zB UC BC VC WC XC 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"},H:{"2":"oC"},I:{"2":"tB I f pC qC rC sC BC tC uC"},J:{"2":"D","129":"A"},K:{"2":"A B C h qB AC rB"},L:{"2":"H"},M:{"2":"H"},N:{"2":"A B"},O:{"2":"vC"},P:{"2":"I g wC xC yC zC 0C 0B 1C 2C 3C 4C 5C sB 6C 7C 8C"},Q:{"2":"1B"},R:{"2":"9C"},S:{"2":"AD BD"}},B:1,C:"Custom protocol handling"};
|
||||
@@ -0,0 +1,2 @@
|
||||
export type Callback = (directory: string, files: string[]) => string | false | void;
|
||||
export default function (directory: string, callback: Callback): string | void;
|
||||
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var resolveException = require("../lib/resolve-exception")
|
||||
, is = require("./is");
|
||||
|
||||
module.exports = function (value/*, options*/) {
|
||||
if (is(value)) return value;
|
||||
return resolveException(value, "Cannot use %v", arguments[1]);
|
||||
};
|
||||
Reference in New Issue
Block a user