promise

Utilities for Promise management.

Functions

Function
Description
Example

check

Check if value is a Promise

dphelper.promise.check(value)

Description

Promise utility functions:

  • Type Check - Detect if value is a Promise

  • Cross-Environment - Works in browser and Node.js

  • Extended Support - Checks for Promise-like objects (thenables)

Usage Examples

Check if Value is Promise

// Standard Promise
const promise = fetch('https://api.example.com/data');
console.log(dphelper.promise.check(promise));
// true

// Promise created with Promise.resolve
const resolved = Promise.resolve('data');
console.log(dphelper.promise.check(resolved));
// true

// Thenable (Promise-like object)
const thenable = { then: (resolve) => resolve('data') };
console.log(dphelper.promise.check(thenable));
// true

// Regular value
console.log(dphelper.promise.check('hello'));
// false

console.log(dphelper.promise.check(123));
// false

console.log(dphelper.promise.check({}));
// false

Safe Promise Handling

Type Guard for TypeScript

Details

  • Author: Dario Passariello

  • Version: 0.0.2

  • Creation Date: 20210101

  • Last Modified: 20260220

  • Environment: both (browser + Node.js)


Automatically generated document

Last updated