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 0.1.1 to 1.0.0

LICENSE

49

cjs/index.js
'use strict';
module.exports = typeof Promise === 'function' ? Promise : function (fn) {
let queue = [], resolved = 0, value;
fn($ => {
value = $;
resolved = 1;
queue.splice(0).forEach(then);
});
return {then};
function then(fn) {
return (resolved ? setTimeout(fn, 0, value) : queue.push(fn)), this;
class Lie {
/** @type {unknown} */
#value;
/**
* @param {unknown} value
*/
constructor(value) {
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>}
*/
then(success, _) {
return lie(success(this.#value));
}
/**
* It ignores the `failure` callback and returns `this` lie.
* @param {function} _ ignored `failure` callback
* @returns
*/
catch(_) {
return this;
}
}
/**
*
* @param {Promise<unknown> | unknown} value
* @returns {Promise<unknown> | Lie<unknown>}
*/
const lie = value => value instanceof Promise ? value : new Lie(value);
module.exports = lie;

@@ -1,12 +0,39 @@

export default typeof Promise === 'function' ? Promise : function (fn) {
let queue = [], resolved = 0, value;
fn($ => {
value = $;
resolved = 1;
queue.splice(0).forEach(then);
});
return {then};
function then(fn) {
return (resolved ? setTimeout(fn, 0, value) : queue.push(fn)), this;
class Lie {
/** @type {unknown} */
#value;
/**
* @param {unknown} value
*/
constructor(value) {
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>}
*/
then(success, _) {
return lie(success(this.#value));
}
/**
* It ignores the `failure` callback and returns `this` lie.
* @param {function} _ ignored `failure` callback
* @returns
*/
catch(_) {
return this;
}
}
/**
*
* @param {Promise<unknown> | unknown} value
* @returns {Promise<unknown> | Lie<unknown>}
*/
const lie = value => value instanceof Promise ? value : new Lie(value);
export default lie;
{
"name": "@webreflection/lie",
"version": "0.1.1",
"description": "A badly implemented Promise",
"version": "1.0.0",
"description": "An optionally sync promise that directly passes along its value",
"main": "./cjs/index.js",
"scripts": {
"build": "ascjs --no-default esm cjs"
"build": "ascjs --no-default esm cjs && npm test",
"test": "node test/index.js"
},
"keywords": [
"Promise"
"Promise",
"lie",
"direct",
"sync"
],
"author": "Andrea Giammarchi",
"license": "ISC",
"license": "MIT",
"devDependencies": {
"ascjs": "^4.0.1"
"ascjs": "^6.0.3"
},

@@ -23,3 +27,2 @@ "module": "./esm/index.js",

},
"unpkg": "es.js",
"repository": {

@@ -26,0 +29,0 @@ "type": "git",

# Lie
A badly implemented Promise
An optionally sync promise that directly passes along its value, particularly useful for any *API* that handles both synchronous and asynchronous use cases through explicit `.then(...)` invocation.
```js
import Lie from '@webreflection/lie';
lie(123)
// invoked synchronously
.then(value => {
console.log('sync #1', value);
return value * 2;
})
// invoked synchronously
// because the result is an async function
// the returned value will be a Promise this time
.then(async value => {
console.log('sync #2', value);
return value * 2;
})
// this time is a Promise
.then(value => {
console.log('async #1', value);
})
;
const lie = new Lie(resolve => {
// resolve only ...
}).then(() => {
// ... and no catch method
});
console.log('sync #1 and #2 already logged');
// async #1 going to be logged after
```
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