@webreflection/lie
Advanced tools
Comparing version 1.0.1 to 1.0.2
'use strict'; | ||
/** | ||
* @template T | ||
* @typedef {T extends PromiseLike ? T : T extends Lie ? T : Lie<T>} Thenable | ||
*/ | ||
/** | ||
* @template V | ||
* @satisfies {PromiseLike} | ||
*/ | ||
class Lie { | ||
/** @type {unknown} */ | ||
/** @type {V} */ | ||
#value; | ||
/** | ||
* @param {unknown} value | ||
*/ | ||
/** @param {V} value */ | ||
constructor(value) { | ||
@@ -14,6 +21,6 @@ this.#value = value; | ||
/** | ||
* Directly invoke the `success` callback with the non-`Promise` value. | ||
* @param {(value: unknown) => unknown} success | ||
* @param {function} [_] ignored `failure` callback | ||
* @returns {Promise<unknown> | Lie<unknown>} | ||
* @template T | ||
* @param {(value: V) => T} success | ||
* @param {() => never} [_] ignored `failure` callback | ||
* @returns {Thenable<T>} | ||
*/ | ||
@@ -24,7 +31,3 @@ then(success, _) { | ||
/** | ||
* It ignores the `failure` callback and returns `this` lie. | ||
* @param {function} _ ignored `failure` callback | ||
* @returns | ||
*/ | ||
/** @param {() => never} _ */ | ||
catch(_) { | ||
@@ -36,8 +39,12 @@ return this; | ||
/** | ||
* Returns the `Promise<unknown>` or a `Lie<unknown>` if the `value` is not a `Promise`. | ||
* @param {Promise<unknown> | unknown} value | ||
* @returns {Promise<unknown> | Lie<unknown>} | ||
* Returns the `value:T` itself if "thenable", otherwise returns a `Lie<T>`. | ||
* @template T | ||
* @param {T} value | ||
* @returns {Thenable<T>} | ||
*/ | ||
const lie = value => value instanceof Promise ? value : new Lie(value); | ||
const lie = value => | ||
(value && typeof value === 'object' && 'then' in value) ? | ||
value : | ||
new Lie(value); | ||
module.exports = lie; |
@@ -0,8 +1,15 @@ | ||
/** | ||
* @template T | ||
* @typedef {T extends PromiseLike ? T : T extends Lie ? T : Lie<T>} Thenable | ||
*/ | ||
/** | ||
* @template V | ||
* @satisfies {PromiseLike} | ||
*/ | ||
class Lie { | ||
/** @type {unknown} */ | ||
/** @type {V} */ | ||
#value; | ||
/** | ||
* @param {unknown} value | ||
*/ | ||
/** @param {V} value */ | ||
constructor(value) { | ||
@@ -13,6 +20,6 @@ this.#value = value; | ||
/** | ||
* Directly invoke the `success` callback with the non-`Promise` value. | ||
* @param {(value: unknown) => unknown} success | ||
* @param {function} [_] ignored `failure` callback | ||
* @returns {Promise<unknown> | Lie<unknown>} | ||
* @template T | ||
* @param {(value: V) => T} success | ||
* @param {() => never} [_] ignored `failure` callback | ||
* @returns {Thenable<T>} | ||
*/ | ||
@@ -23,7 +30,3 @@ then(success, _) { | ||
/** | ||
* It ignores the `failure` callback and returns `this` lie. | ||
* @param {function} _ ignored `failure` callback | ||
* @returns | ||
*/ | ||
/** @param {() => never} _ */ | ||
catch(_) { | ||
@@ -35,8 +38,12 @@ return this; | ||
/** | ||
* Returns the `Promise<unknown>` or a `Lie<unknown>` if the `value` is not a `Promise`. | ||
* @param {Promise<unknown> | unknown} value | ||
* @returns {Promise<unknown> | Lie<unknown>} | ||
* Returns the `value:T` itself if "thenable", otherwise returns a `Lie<T>`. | ||
* @template T | ||
* @param {T} value | ||
* @returns {Thenable<T>} | ||
*/ | ||
const lie = value => value instanceof Promise ? value : new Lie(value); | ||
const lie = value => | ||
(value && typeof value === 'object' && 'then' in value) ? | ||
value : | ||
new Lie(value); | ||
export default lie; |
{ | ||
"name": "@webreflection/lie", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "An optionally sync promise that directly passes along its value", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81
4404