New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

makepromise

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

makepromise - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

.eslingignore

2

.vscode/launch.json

@@ -14,3 +14,3 @@ {

"args": [
"test/spec/integration.js"
"test/spec/bound-functions.js"
],

@@ -17,0 +17,0 @@ "env": {

@@ -1,3 +0,9 @@

## 1.1.0 (29 December 2017)
## 29 December 2017
### 1.1.1
- [bugfix] fix throwing error when no arguments are passed
### 1.1.0
- [feature] es8 default standard, `/src/es5` available

@@ -7,4 +13,6 @@ - [chore] update wrote

## 1.0.0 (20 May 2017)
## 20 May 2017
### 1.0.0
- [feature] initial release

@@ -0,1 +1,3 @@

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var erotic = require('erotic/es5/src');

@@ -18,5 +20,7 @@

function makePromise(fn, args, resolveValue) {
return new Promise(function ($return, $error) {
var er, res;
var $args = arguments;return new Promise(function ($return, $error) {
var _arguments, er, fnLength, res;
_arguments = $args;
er = erotic();

@@ -26,5 +30,8 @@ if (typeof fn !== 'function') {

}
if (!fn.length) {
fnLength = fn.length;
if (!fnLength) {
return $error(new Error('Function does not accept any arguments'));
}
return Promise.resolve(new Promise(function (resolve, reject) {

@@ -38,13 +45,14 @@ var cb = function cb(err, res) {

};
var allArgs = Array.from({ length: fn.length });
allArgs[allArgs.length - 1] = cb;
var allArgs = [cb];
if (Array.isArray(args)) {
args.forEach(function (arg, i) {
checkArgumentIndex(allArgs.length, i);
allArgs[i] = arg;
checkArgumentIndex(fnLength, i);
});
} else {
checkArgumentIndex(allArgs.length, 0);
allArgs[0] = args;
allArgs = [].concat(_toConsumableArray(args), [cb]);
} else if (Array.from(_arguments).length > 1) {
// args passed as a single argument, not array
checkArgumentIndex(fnLength, 0);
allArgs = [args, cb];
}

@@ -51,0 +59,0 @@ fn.apply(fn.this, allArgs);

@@ -46,3 +46,3 @@ var _require = require('assert'),

fn = function fn(cb) {
cb();
return cb();
};

@@ -79,3 +79,3 @@ var $Try_2_Post = function () {

return new Promise(function ($return, $error) {
var fn, message;
var fn, message, stack;

@@ -94,2 +94,3 @@ fn = function fn(test, cb) {

message = _ref3.message;
stack = _ref3.stack;

@@ -96,0 +97,0 @@ equal(message, 'Function does not accept that many arguments');

{
"name": "makepromise",
"version": "1.1.0",
"version": "1.1.1",
"description": "Make a native Promise from a function with a callback",

@@ -5,0 +5,0 @@ "main": "src/index",

@@ -22,5 +22,7 @@ const erotic = require('erotic')

}
if (!fn.length) {
const { length: fnLength } = fn
if (!fnLength) {
throw new Error('Function does not accept any arguments')
}
const res = await new Promise((resolve, reject)=> {

@@ -34,13 +36,13 @@ const cb = (err, res) => {

}
const allArgs = Array.from({ length: fn.length })
allArgs[allArgs.length - 1] = cb
let allArgs = [cb]
if (Array.isArray(args)) {
args.forEach((arg, i) => {
checkArgumentIndex(allArgs.length, i)
allArgs[i] = arg
checkArgumentIndex(fnLength, i)
})
} else {
checkArgumentIndex(allArgs.length, 0)
allArgs[0] = args
allArgs = [...args, cb]
} else if (Array.from(arguments).length > 1) { // args passed as a single argument, not array
checkArgumentIndex(fnLength, 0)
allArgs = [args, cb]
}

@@ -47,0 +49,0 @@ fn.apply(fn.this, allArgs)

@@ -15,3 +15,3 @@ const { equal, deepEqual } = require('assert')

async 'passing arguments when none allowed'() {
const fn = (cb) => {cb()}
const fn = cb => cb()
try {

@@ -25,7 +25,7 @@ await makePromise(fn, 'hello-world')

async 'passing more arguments when allowed'() {
const fn = (test, cb) => {cb(null, test)}
const fn = (test, cb) => { cb(null, test) }
try {
await makePromise(fn, ['hello world', 'extra argument'])
throw new Error('should have thrown an error')
} catch ({ message }) {
} catch ({ message, stack }) {
equal(message, 'Function does not accept that many arguments')

@@ -32,0 +32,0 @@ }

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