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

safe-errors

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safe-errors - npm Package Compare versions

Comparing version 0.0.3 to 0.2.0

20

lib/safecb.js
'use strict';
const Promise = require('bluebird');
var Promise = require('bluebird');
function safecb(fn, ctx) {
return function () {
let args = [].slice.call(arguments);
return new Promise(resolve => {
let done = function () {
let doneArgs = [].slice.call(arguments);
let error = doneArgs.shift();
var args = [].slice.call(arguments);
return new Promise(function (resolve) {
var done = function done() {
var doneArgs = [].slice.call(arguments);
var error = doneArgs.shift();

@@ -16,3 +16,3 @@ if (error) {

success: false,
error
error: error
});

@@ -31,6 +31,6 @@ return;

fn.apply(ctx, args);
}).catch(error => {
}).catch(function (error) {
return {
success: false,
error
error: error
};

@@ -42,3 +42,3 @@ });

module.exports = {
safecb
safecb: safecb
};
'use strict';
const { safecb } = require('./safecb');
const deep = require('assert').deepEqual;
var _require = require('./safecb');
describe('safe callback', () => {
it('should convert a callback to a promise', () => {
let cb = (a, b, done) => {
var safecb = _require.safecb;
var deep = require('assert').deepEqual;
describe('safe callback', function () {
it('should convert a callback to a promise', function () {
var cb = function cb(a, b, done) {
done(null, '1');
};
return safecb(cb)('a', 'b').then(result => {
return safecb(cb)('a', 'b').then(function (result) {
deep(result.success, true);

@@ -19,8 +22,8 @@ deep(result.payload, '1');

it('should convert a callback to a promise and handle no arguments', () => {
let cb = done => {
it('should convert a callback to a promise and handle no arguments', function () {
var cb = function cb(done) {
done(null, 'a');
};
return safecb(cb)().then(result => {
return safecb(cb)().then(function (result) {
deep(result.success, true);

@@ -31,9 +34,9 @@ deep(result.payload[0], 'a');

it('should convert a callback to a promise and handle errors', () => {
let error = new Error('error in cb');
let cb = (a, b, done) => {
it('should convert a callback to a promise and handle errors', function () {
var error = new Error('error in cb');
var cb = function cb(a, b, done) {
done(error);
};
return safecb(cb)('a', 'b').then(result => {
return safecb(cb)('a', 'b').then(function (result) {
deep(result.success, false);

@@ -44,10 +47,10 @@ deep(result.error, error);

it('should convert a callback to a promise and catch errors', () => {
let error = new Error('error thrown in cb');
it('should convert a callback to a promise and catch errors', function () {
var error = new Error('error thrown in cb');
let cb = (a, b, done) => {
var cb = function cb(a, b, done) {
throw error;
};
return safecb(cb)('a', 'b').then(result => {
return safecb(cb)('a', 'b').then(function (result) {
deep(result.success, false);

@@ -54,0 +57,0 @@ deep(result.error, error);

@@ -5,11 +5,11 @@ "use strict";

return function () {
return p.apply(ctx, arguments).then(payload => {
return p.apply(ctx, arguments).then(function (payload) {
return {
success: true,
payload
payload: payload
};
}).catch(error => {
}).catch(function (error) {
return {
success: false,
error
error: error
};

@@ -21,3 +21,3 @@ });

module.exports = {
safep
safep: safep
};
'use strict';
const { safep } = require('./safep');
const deep = require('assert').deepEqual;
var _require = require('./safep');
describe('safe promise', () => {
it('should convert a promise to a safe promise', () => {
let p = () => {
var safep = _require.safep;
var deep = require('assert').deepEqual;
describe('safe promise', function () {
it('should convert a promise to a safe promise', function () {
var p = function p() {
return Promise.resolve('a');
};
return safep(p)().then(result => {
return safep(p)().then(function (result) {
deep(result.success, true);

@@ -18,9 +21,9 @@ deep(result.payload, 'a');

it('should return reject promise result', () => {
let error = new Error('something bad!');
let p = () => {
it('should return reject promise result', function () {
var error = new Error('something bad!');
var p = function p() {
return Promise.reject(error);
};
return safep(p)().then(result => {
return safep(p)().then(function (result) {
deep(result.success, false);

@@ -27,0 +30,0 @@ deep(result.error, error);

{
"name": "safe-errors",
"version": "0.0.3",
"version": "0.2.0",
"description": "",

@@ -14,2 +14,5 @@ "main": "index.js",

"bluebird": "^3.4.6",
"babel-core": "^6.14.0",
"babel-preset-es2015": "^6.14.0",
"body-parser": "^1.15.2",
"mocha": "^3.0.2"

@@ -16,0 +19,0 @@ },

@@ -65,3 +65,3 @@ # Safe Errors

if (result.success === false) {
log(result.error)
log(result.success === false)
// maybe return a default

@@ -68,0 +68,0 @@ return {}

Sorry, the diff of this file is not supported yet

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