Socket
Socket
Sign inDemoInstall

@js-bits/xpromise

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@js-bits/xpromise - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

34

dist/index.d.ts
export default ExtendablePromise;
export type ErrorsEnum = {
InstantiationError: 'ExtendablePromise|InstantiationError';
ExecutionError: 'ExtendablePromise|ExecutionError';
};
export type Resolve<T> = (value: T | PromiseLike<T>, ...rest: unknown[]) => void;

@@ -16,2 +12,4 @@ export type Reject = (reason?: Error) => void;

/**
* Allows extension of JavaScript's standard, built-in `Promise` class.
* Decouples an asynchronous operation that ties an outcome to a promise from the constructor.
* @template T

@@ -21,15 +19,28 @@ * @extends {Promise<T>}

declare class ExtendablePromise<T> extends Promise<T> {
static InstantiationError: "ExtendablePromise|InstantiationError";
static ExecutionError: "ExtendablePromise|ExecutionError";
/**
* @param {(resolve:Resolve<T>, reject:Reject, ...rest:unknown[]) => void} executor
* @type {'ExtendablePromise|InstantiationError'}
* @readonly
*/
static readonly InstantiationError: 'ExtendablePromise|InstantiationError';
/**
* @type {'ExtendablePromise|ExecutionError'}
* @readonly
*/
static readonly ExecutionError: 'ExtendablePromise|ExecutionError';
/**
* Creates new `ExtendablePromise` instance.
* @param {(resolve:Resolve<T>, reject:Reject, ...rest:unknown[]) => void} executor - A function to be executed by the `.execute()` method
* @throws {typeof ExtendablePromise.InstantiationError}
*/
constructor(executor: (resolve: Resolve<T>, reject: Reject, ...rest: unknown[]) => void);
/**
* @param {...unknown} args
* Executes `executor` function provided to `ExtendablePromise` constructor.
* All arguments will be passed through to `executor` function.
* @returns {ExtendablePromise<T>}
* @throws {typeof ExtendablePromise.ExecutionError}
*/
execute(...args: unknown[]): ExtendablePromise<T>;
execute(...args: unknown[][]): ExtendablePromise<T>;
/**
* @param {T} result
* Resolves `ExtendablePromise`
* @param result
* @returns {ExtendablePromise<T>}

@@ -39,3 +50,4 @@ */

/**
* @param {Error} reason
* Rejects `ExtendablePromise`
* @param reason
* @returns {ExtendablePromise<T>}

@@ -42,0 +54,0 @@ */

@@ -13,10 +13,2 @@ import enumerate from '@js-bits/enumerate';

/**
* @typedef {{
* InstantiationError: 'ExtendablePromise|InstantiationError',
* ExecutionError: 'ExtendablePromise|ExecutionError'
* }} ErrorsEnum
*/
/** @type {ErrorsEnum} */
const ERRORS = enumerate.ts(

@@ -40,2 +32,4 @@ `

/**
* Allows extension of JavaScript's standard, built-in `Promise` class.
* Decouples an asynchronous operation that ties an outcome to a promise from the constructor.
* @template T

@@ -45,8 +39,18 @@ * @extends {Promise<T>}

class ExtendablePromise extends Promise {
/**
* @type {'ExtendablePromise|InstantiationError'}
* @readonly
*/
static InstantiationError = ERRORS.InstantiationError;
/**
* @type {'ExtendablePromise|ExecutionError'}
* @readonly
*/
static ExecutionError = ERRORS.ExecutionError;
/**
* @param {(resolve:Resolve<T>, reject:Reject, ...rest:unknown[]) => void} executor
* Creates new `ExtendablePromise` instance.
* @param {(resolve:Resolve<T>, reject:Reject, ...rest:unknown[]) => void} executor - A function to be executed by the `.execute()` method
* @throws {typeof ExtendablePromise.InstantiationError}
*/

@@ -80,6 +84,8 @@ constructor(executor) {

/**
* @param {...unknown} args
* Executes `executor` function provided to `ExtendablePromise` constructor.
* All arguments will be passed through to `executor` function.
* @returns {ExtendablePromise<T>}
* @throws {typeof ExtendablePromise.ExecutionError}
*/
execute(...args) {
execute(/** @type {...unknown[]} */ ...args) {
if (this[ø.executor]) {

@@ -100,6 +106,7 @@ try {

/**
* @param {T} result
* Resolves `ExtendablePromise`
* @param result
* @returns {ExtendablePromise<T>}
*/
resolve(result) {
resolve(/** @type {T} */ result) {
this[ø.resolve](result);

@@ -110,6 +117,7 @@ return this;

/**
* @param {Error} reason
* Rejects `ExtendablePromise`
* @param reason
* @returns {ExtendablePromise<T>}
*/
reject(reason) {
reject(/** @type {Error} */ reason) {
this[ø.reject](reason);

@@ -116,0 +124,0 @@ return this;

{
"name": "@js-bits/xpromise",
"version": "1.0.0",
"version": "1.0.1",
"description": "Extendable Promise",
"keywords": [
"javascript",
"typescript",
"extend",

@@ -8,0 +9,0 @@ "extendable",

Sorry, the diff of this file is not supported yet

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