already
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -115,3 +115,3 @@ declare const _default: { | ||
export declare function once<T, R>(fn: OnceRunnee<T, R>): OnceRunnee<T, R>; | ||
export declare function retry<R>(times: number, fn: () => R, retryable?: (err: Error) => boolean): R; | ||
export declare function retry<R>(times: number, fn: () => R, retryable?: (err: unknown) => boolean): R; | ||
export interface Deferred<T> { | ||
@@ -118,0 +118,0 @@ resolve: (t: T | PromiseLike<T>) => void; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deferSet = exports.OrderedAsynchrony = exports.funnel = exports.wrapFunction = exports.rethrow = exports.specific = exports.deferInspectable = exports.inspect = exports.reflect = exports.defer = exports.retry = exports.once = exports.some = exports.eachImpl = exports.each = exports.reduce = exports.map = exports.filter = exports.props = exports.tap = exports.delayChain = exports.delay = exports.concurrent = void 0; | ||
exports.default = { | ||
export default { | ||
defer, | ||
@@ -31,3 +28,3 @@ deferSet, | ||
} | ||
function concurrent(size, fn) { | ||
export function concurrent(size, fn) { | ||
const queue = makeQueue(size); | ||
@@ -41,3 +38,2 @@ if (size < 1) | ||
} | ||
exports.concurrent = concurrent; | ||
function makeQueue(size) { | ||
@@ -74,3 +70,3 @@ const queue = { | ||
} | ||
function delay(milliseconds, t) { | ||
export function delay(milliseconds, t) { | ||
return new Promise(resolve => { | ||
@@ -80,8 +76,6 @@ setTimeout(() => resolve(t), milliseconds); | ||
} | ||
exports.delay = delay; | ||
function delayChain(milliseconds) { | ||
export function delayChain(milliseconds) { | ||
return tap(() => delay(milliseconds)); | ||
} | ||
exports.delayChain = delayChain; | ||
function tap(fn) { | ||
export function tap(fn) { | ||
return async (t) => { | ||
@@ -92,4 +86,3 @@ await fn(t); | ||
} | ||
exports.tap = tap; | ||
function props(obj) { | ||
export function props(obj) { | ||
const ret = {}; | ||
@@ -102,5 +95,4 @@ const awaiters = []; | ||
} | ||
exports.props = props; | ||
const defaultFilterMapOptions = { concurrency: Infinity }; | ||
function filter(arr, opts, filterFn) { | ||
export function filter(arr, opts, filterFn) { | ||
if (Array.isArray(arr)) { | ||
@@ -128,4 +120,3 @@ if (typeof opts === "function") { | ||
} | ||
exports.filter = filter; | ||
function map(arr, opts, mapFn) { | ||
export function map(arr, opts, mapFn) { | ||
if (Array.isArray(arr)) { | ||
@@ -153,4 +144,3 @@ if (typeof opts === "function") { | ||
} | ||
exports.map = map; | ||
function reduce(input, reducer, initialValue) { | ||
export function reduce(input, reducer, initialValue) { | ||
if (typeof input === "function") { | ||
@@ -165,3 +155,2 @@ initialValue = reducer; | ||
} | ||
exports.reduce = reduce; | ||
async function reduceImpl(input, reducer, initialValue) { | ||
@@ -183,3 +172,3 @@ const _input = Array.from(await input); | ||
} | ||
function each(arr, eachFn) { | ||
export function each(arr, eachFn) { | ||
if (Array.isArray(arr)) | ||
@@ -189,4 +178,3 @@ return eachImpl(eachFn)(arr); | ||
} | ||
exports.each = each; | ||
function eachImpl(eachFn) { | ||
export function eachImpl(eachFn) { | ||
return async (arr) => { | ||
@@ -201,4 +189,3 @@ const length = arr.length; | ||
} | ||
exports.eachImpl = eachImpl; | ||
function some(list, fn) { | ||
export function some(list, fn) { | ||
if (typeof list === "function") { | ||
@@ -210,3 +197,2 @@ fn = list; | ||
} | ||
exports.some = some; | ||
async function someImpl(list, fn) { | ||
@@ -221,3 +207,3 @@ const _list = toReadonlyArray(await list); | ||
} | ||
function once(fn) { | ||
export function once(fn) { | ||
if (fn) { | ||
@@ -230,3 +216,2 @@ const _once = onceDynamic(); | ||
} | ||
exports.once = once; | ||
function onceDynamic() { | ||
@@ -259,3 +244,3 @@ const state = new WeakMap(); | ||
} | ||
function retry(times, fn, retryable = () => true) { | ||
export function retry(times, fn, retryable = () => true) { | ||
const retryAsync = (promise) => promise | ||
@@ -295,4 +280,3 @@ .catch((err) => { | ||
} | ||
exports.retry = retry; | ||
function defer() { | ||
export function defer() { | ||
var _a; | ||
@@ -314,4 +298,3 @@ const deferred = {}; | ||
} | ||
exports.defer = defer; | ||
function reflect(promise) { | ||
export function reflect(promise) { | ||
const inspection = inspect(promise); | ||
@@ -335,4 +318,3 @@ function handleResolution(value) { | ||
} | ||
exports.reflect = reflect; | ||
function inspect(promise) { | ||
export function inspect(promise) { | ||
const inspectable = { | ||
@@ -356,4 +338,3 @@ isPending: true, | ||
} | ||
exports.inspect = inspect; | ||
function deferInspectable() { | ||
export function deferInspectable() { | ||
const deferred = defer(); | ||
@@ -384,3 +365,2 @@ const ret = { | ||
} | ||
exports.deferInspectable = deferInspectable; | ||
// This logic is taken from Bluebird | ||
@@ -413,3 +393,3 @@ function catchFilter(filters, err) { | ||
} | ||
function specific(filters, handler) { | ||
export function specific(filters, handler) { | ||
return (err) => { | ||
@@ -421,4 +401,3 @@ if (!catchFilter(filters, err)) | ||
} | ||
exports.specific = specific; | ||
function rethrow(fn) { | ||
export function rethrow(fn) { | ||
return async (err) => { | ||
@@ -429,4 +408,3 @@ await fn(err); | ||
} | ||
exports.rethrow = rethrow; | ||
function wrapFunction(wrap) { | ||
export function wrapFunction(wrap) { | ||
// tslint:disable-next-line | ||
@@ -497,4 +475,3 @@ return function (t, cb) { | ||
} | ||
exports.wrapFunction = wrapFunction; | ||
function funnel(opts = {}) { | ||
export function funnel(opts = {}) { | ||
const { onEmpty, concurrency = 1 } = (opts || {}); | ||
@@ -587,4 +564,3 @@ let FunnelState; | ||
} | ||
exports.funnel = funnel; | ||
class OrderedAsynchrony { | ||
export class OrderedAsynchrony { | ||
constructor() { | ||
@@ -653,6 +629,4 @@ this.deferrals = []; | ||
} | ||
exports.OrderedAsynchrony = OrderedAsynchrony; | ||
function deferSet() { | ||
export function deferSet() { | ||
return new OrderedAsynchrony(); | ||
} | ||
exports.deferSet = deferSet; |
{ | ||
"name": "already", | ||
"description": "Promise extensions; finally, map, filter, etc", | ||
"description": "Promise extensions; map, filter, etc", | ||
"license": "MIT", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"author": "Gustaf Räntilä <g.rantila@gmail.com>", | ||
@@ -11,19 +11,15 @@ "repository": { | ||
}, | ||
"engines": { | ||
"node": ">=12.20" | ||
}, | ||
"type": "module", | ||
"files": [ | ||
"dist", | ||
"dist-mjs" | ||
"dist" | ||
], | ||
"main": "./dist/index.js", | ||
"exports": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"import": "./dist-mjs/index.js", | ||
"require": "./dist/index.js" | ||
}, | ||
"scripts": { | ||
"build:dist": "scripts/build.sh dist ./tsconfig.prod.json --module CommonJS -t ES2019", | ||
"build:dist-mjs": "scripts/build.sh dist-mjs ./tsconfig.prod.json --module ESNext -t ES2019", | ||
"build:test-out": "scripts/build.sh test-out ./tsconfig.test.json", | ||
"build:test-out-mjs": "scripts/build.sh test-out-mjs ./tsconfig.test.json --module CommonJS -t esnext && scripts/rewrite-mjs-test.js", | ||
"build:lib": "concurrently 'yarn build:dist' 'yarn build:dist-mjs'", | ||
"build:test": "concurrently 'yarn build:test-out' 'yarn build:test-out-mjs'", | ||
"build:lib": "scripts/build.sh dist ./tsconfig.prod.json", | ||
"build:test": "scripts/build.sh test-out ./tsconfig.test.json", | ||
"build": "yarn build:lib && yarn build:test", | ||
@@ -56,7 +52,7 @@ "lint": "true", | ||
"@babel/plugin-syntax-optional-chaining": "^7.8.3", | ||
"@babel/plugin-transform-modules-commonjs": "^7.12.1", | ||
"@babel/preset-typescript": "^7.12.7", | ||
"@babel/plugin-transform-modules-commonjs": "^7.15.4", | ||
"@babel/preset-typescript": "^7.15.0", | ||
"@types/jest": "^26.0.15", | ||
"commitizen": "^4.2.2", | ||
"concurrently": "^6.2.0", | ||
"concurrently": "^6.2.1", | ||
"cz-conventional-changelog": "^3.3.0", | ||
@@ -69,3 +65,3 @@ "jest": "^26.6.3", | ||
"tslint": "6.1.3", | ||
"typescript": "4.3.4" | ||
"typescript": "4.4.3" | ||
}, | ||
@@ -72,0 +68,0 @@ "dependencies": {}, |
@@ -14,3 +14,3 @@ [![npm version][npm-image]][npm-url] | ||
The library is written in TypeScript, so typings are provided. Apart from being exported as JavaScript (ES2019), it's also exported as an *ES module*, if imported in platforms (and bundlers) supporting this. | ||
The library is written in TypeScript, so typings are provided. It is exported only as an [ESM package](esm-package)! | ||
@@ -21,2 +21,3 @@ | ||
* Since version 2, `Finally` and `Try` are removed. They should be replaced with `Promise.prototype.finally` and async functions. | ||
* Since version 3, it's only exported as an [ESM package](esm-package). | ||
@@ -175,9 +176,7 @@ | ||
To always delay a chain, regardless of whether it was resolved or rejected, use `finallyDelay`. **Note the triple dots**, and read more about `Finally` below... | ||
To always delay a chain, regardless of whether it was resolved or rejected, use: | ||
```ts | ||
import { finallyDelay } from 'already' | ||
somePromise | ||
.then( ...finallyDelay( 100 ) ) | ||
.finally( delayChain( 100 ) ) | ||
``` | ||
@@ -894,1 +893,2 @@ | ||
[lgtm-url]: https://lgtm.com/projects/g/grantila/already/context:javascript | ||
[esm-package]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c |
Yes
66376
5
796