Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@open-draft/until

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@open-draft/until - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

LICENSE

3

lib/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.until = void 0;
var until_1 = require("./until");
exports.until = until_1.until;
Object.defineProperty(exports, "until", { enumerable: true, get: function () { return until_1.until; } });

@@ -0,6 +1,13 @@

export declare type AsyncTuple<ErrorType extends any = Error, DataType extends any = unknown> = {
error: ErrorType;
data: null;
} | {
error: null;
data: DataType;
};
/**
* Gracefully handles a given Promise factory.
* @example
* cosnt [error, data] = await until(() => asyncAction())
* const [error, data] = await until(() => asyncAction())
*/
export declare const until: <DataType = unknown, ErrorType = Error>(promise: () => Promise<DataType>) => Promise<[ErrorType, DataType]>;
export declare const until: <ErrorType extends unknown = Error, DataType extends unknown = unknown>(promise: () => Promise<DataType>) => Promise<AsyncTuple<ErrorType, DataType>>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.until = void 0;
/**
* Gracefully handles a given Promise factory.
* @example
* cosnt [error, data] = await until(() => asyncAction())
* const [error, data] = await until(() => asyncAction())
*/
exports.until = async (promise) => {
const until = async (promise) => {
try {

@@ -13,7 +14,8 @@ const data = await promise().catch((error) => {

});
return [null, data];
return { error: null, data };
}
catch (error) {
return [error, null];
return { error, data: null };
}
};
exports.until = until;
{
"name": "@open-draft/until",
"version": "1.0.3",
"version": "2.0.0",
"description": "Gracefully handle a Promise using async/await.",

@@ -14,8 +14,9 @@ "main": "lib/index.js",

"devDependencies": {
"@types/jest": "^25.1.4",
"jest": "^25.1.0",
"ts-jest": "^25.2.1",
"typescript": "^3.8.3"
"@types/jest": "^26.0.22",
"jest": "^26.6.3",
"ts-jest": "^26.5.4",
"typescript": "^4.2.4"
},
"scripts": {
"start": "tsc -w",
"test": "jest",

@@ -22,0 +23,0 @@ "build": "tsc --build tsconfig.json",

@@ -0,1 +1,2 @@

[![Latest release](https://img.shields.io/npm/v/@open-draft/until.svg)](https://www.npmjs.com/package/@open-draft/until)
[![Build status](https://circleci.com/gh/open-draft/until.svg?style=shield)](https://circleci.com/gh/open-draft/until)

@@ -44,2 +45,4 @@

npm install @open-draft/until
# or
yarn add @open-draft/until
```

@@ -53,3 +56,3 @@

async function(id) {
const [error, user] = await until(() => fetchUser(id))
const { error, data } = await until(() => fetchUser(id))

@@ -60,3 +63,3 @@ if (error) {

return user
return data
}

@@ -81,3 +84,3 @@ ```

async function(id: string) {
const [error, user] = await until<User, UserFetchError>(() => fetchUser(id))
const { error, data } = await until<UserFetchError, User>(() => fetchUser(id))

@@ -88,3 +91,3 @@ if (error) {

return user.firstName
return data.firstName
}

@@ -95,2 +98,2 @@ ```

- [giuseppegurgone](https://twitter.com/giuseppegurgone) for discussing the original `until` API
- [giuseppegurgone](https://twitter.com/giuseppegurgone) for the discussion about the original `until` API.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc