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

@webreflection/lie

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

@webreflection/lie - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

41

cjs/index.js
'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",

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