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

@marcopeg/utils

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@marcopeg/utils - npm Package Compare versions

Comparing version 1.4.1 to 1.4.2

3

lib/cancel-event.js

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

"use strict";
const cancelEvent = evt => {
var cancelEvent = function cancelEvent(evt) {
evt.preventDefault();

@@ -4,0 +5,0 @@ evt.stopPropagation();

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

'use strict';
/**

@@ -9,25 +11,27 @@ * App Configuration

// const winston = require('winston')
const log = require('./logger/verbose');
var log = require('./logger/verbose');
const init = () => {};
var init = function init() {};
const get = (key, defaultValue) => {
var get = function get(key, defaultValue) {
if (process.env[key] === undefined) {
if (defaultValue) {
log(`${key}::default::${defaultValue}`);
log(key + '::default::' + defaultValue);
return defaultValue;
}
throw new Error(`Env "${key}" not defined`);
throw new Error('Env "' + key + '" not defined');
}
log(`${key}::${process.env[key]}`);
log(key + '::' + process.env[key]);
return process.env[key];
};
const isDev = () => get('NODE_ENV') === 'development';
var isDev = function isDev() {
return get('NODE_ENV') === 'development';
};
module.exports = {
init,
get,
isDev
init: init,
get: get,
isDev: isDev
};

@@ -0,6 +1,9 @@

'use strict';
function getErrorOrigin(errorStack) {
try {
const tokens = errorStack.split('\n').filter(item => item.indexOf('_callee') !== -1);
let origin = tokens.shift().trim();
var tokens = errorStack.split('\n').filter(function (item) {
return item.indexOf('_callee') !== -1;
});
var origin = tokens.shift().trim();
origin = origin.substring(origin.indexOf('_callee') + 10);

@@ -7,0 +10,0 @@ origin = origin.substring(0, origin.indexOf(')'));

@@ -0,1 +1,2 @@

'use strict';

@@ -2,0 +3,0 @@ function debug() {

@@ -0,1 +1,2 @@

'use strict';

@@ -2,0 +3,0 @@ function error() {

@@ -0,1 +1,2 @@

'use strict';

@@ -2,0 +3,0 @@ module.exports = {

@@ -0,1 +1,2 @@

'use strict';

@@ -2,0 +3,0 @@ function info() {

@@ -0,1 +1,2 @@

'use strict';

@@ -2,0 +3,0 @@ function verbose() {

@@ -0,15 +1,28 @@

"use strict";
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const pause = (() => {
var _ref = _asyncToGenerator(function* (time) {
return new Promise(function (resolve) {
return setTimeout(resolve, time);
});
});
var pause = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(time) {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", new Promise(function (resolve) {
return setTimeout(resolve, time);
}));
case 1:
case "end":
return _context.stop();
}
}
}, _callee, undefined);
}));
return function pause(_x) {
return _ref.apply(this, arguments);
};
})();
}();
module.exports = pause;

@@ -0,7 +1,11 @@

'use strict';
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/* global fetch */
const pause = require('./pause');
const { isDev } = require('./config');
var pause = require('./pause');
var _require = require('./config'),
isDev = _require.isDev;
// - this should be added at the app top level

@@ -11,5 +15,5 @@ // require('es6-promise').polyfill()

let devDelay = 0;
var devDelay = 0;
const setDevDelay = delay => {
var setDevDelay = function setDevDelay(delay) {
devDelay = delay;

@@ -19,13 +23,34 @@ };

// eslint-disable-next-line
const wrappedFetch = (() => {
var _ref = _asyncToGenerator(function* (url, config = {}) {
try {
if (isDev()) {
yield pause(devDelay);
var wrappedFetch = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(url) {
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
if (!isDev()) {
_context.next = 4;
break;
}
_context.next = 4;
return pause(devDelay);
case 4:
return _context.abrupt('return', fetch(url, config));
case 7:
_context.prev = 7;
_context.t0 = _context['catch'](0);
throw _context.t0;
case 10:
case 'end':
return _context.stop();
}
}
return fetch(url, config);
} catch (err) {
throw err;
}
});
}, _callee, undefined, [[0, 7]]);
}));

@@ -35,46 +60,85 @@ return function wrappedFetch(_x) {

};
})();
}();
const getJSON = (() => {
var _ref2 = _asyncToGenerator(function* (url, config = {}) {
try {
const headers = Object.assign({}, config.headers || {}, {
'content-type': 'application/json'
});
const options = Object.assign({}, config, {
method: 'GET',
headers: headers
});
const res = yield wrappedFetch(url, options);
var getJSON = function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(url) {
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var headers, options, res, errMsg, error;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
headers = Object.assign({}, config.headers || {}, {
'content-type': 'application/json'
});
options = Object.assign({}, config, {
method: 'GET',
headers: headers
});
_context2.next = 5;
return wrappedFetch(url, options);
// status code error handling
if (res.status !== 200) {
let errMsg;
try {
errMsg = yield res.text();
} catch (err) {
errMsg = res.statusText;
case 5:
res = _context2.sent;
if (!(res.status !== 200)) {
_context2.next = 20;
break;
}
errMsg = void 0;
_context2.prev = 8;
_context2.next = 11;
return res.text();
case 11:
errMsg = _context2.sent;
_context2.next = 17;
break;
case 14:
_context2.prev = 14;
_context2.t0 = _context2['catch'](8);
errMsg = res.statusText;
case 17:
error = new Error(res.status + ' - ' + errMsg);
error.response = res;
throw error;
case 20:
_context2.next = 22;
return res.json();
case 22:
return _context2.abrupt('return', _context2.sent);
case 25:
_context2.prev = 25;
_context2.t1 = _context2['catch'](0);
throw _context2.t1;
case 28:
case 'end':
return _context2.stop();
}
const error = new Error(`${res.status} - ${errMsg}`);
error.response = res;
throw error;
}
}, _callee2, undefined, [[0, 25], [8, 14]]);
}));
return yield res.json();
} catch (err) {
throw err;
}
});
return function getJSON(_x2) {
return function getJSON(_x3) {
return _ref2.apply(this, arguments);
};
})();
}();
const getJSONAuth = (url, token, config = {}) => {
const headers = Object.assign({}, config.headers || {}, {
Authorization: `Bearer ${token}`
var getJSONAuth = function getJSONAuth(url, token) {
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var headers = Object.assign({}, config.headers || {}, {
Authorization: 'Bearer ' + token
});
const options = Object.assign({}, config, {
var options = Object.assign({}, config, {
headers: headers

@@ -85,45 +149,86 @@ });

const postJSON = (() => {
var _ref3 = _asyncToGenerator(function* (url, data = {}, config = {}) {
try {
const headers = Object.assign({}, config.headers || {}, {
'content-type': 'application/json'
});
const options = Object.assign({}, config, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
});
const res = yield wrappedFetch(url, options);
var postJSON = function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(url) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var headers, options, res, errMsg, error;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.prev = 0;
headers = Object.assign({}, config.headers || {}, {
'content-type': 'application/json'
});
options = Object.assign({}, config, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
});
_context3.next = 5;
return wrappedFetch(url, options);
// status code error handling
if (res.status !== 200) {
let errMsg;
try {
errMsg = yield res.text();
} catch (err) {
errMsg = res.statusText;
case 5:
res = _context3.sent;
if (!(res.status !== 200)) {
_context3.next = 20;
break;
}
errMsg = void 0;
_context3.prev = 8;
_context3.next = 11;
return res.text();
case 11:
errMsg = _context3.sent;
_context3.next = 17;
break;
case 14:
_context3.prev = 14;
_context3.t0 = _context3['catch'](8);
errMsg = res.statusText;
case 17:
error = new Error(res.status + ' - ' + errMsg);
error.response = res;
throw error;
case 20:
_context3.next = 22;
return res.json();
case 22:
return _context3.abrupt('return', _context3.sent);
case 25:
_context3.prev = 25;
_context3.t1 = _context3['catch'](0);
throw _context3.t1;
case 28:
case 'end':
return _context3.stop();
}
const error = new Error(`${res.status} - ${errMsg}`);
error.response = res;
throw error;
}
}, _callee3, undefined, [[0, 25], [8, 14]]);
}));
return yield res.json();
} catch (err) {
throw err;
}
});
return function postJSON(_x3) {
return function postJSON(_x6) {
return _ref3.apply(this, arguments);
};
})();
}();
const postJSONAuth = (url, token, data = {}, config = {}) => {
const headers = Object.assign({}, config.headers || {}, {
Authorization: `Bearer ${token}`
var postJSONAuth = function postJSONAuth(url, token) {
var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var headers = Object.assign({}, config.headers || {}, {
Authorization: 'Bearer ' + token
});
const options = Object.assign({}, config, {
var options = Object.assign({}, config, {
headers: headers

@@ -134,45 +239,86 @@ });

const putJSON = (() => {
var _ref4 = _asyncToGenerator(function* (url, data = {}, config = {}) {
try {
const headers = Object.assign({}, config.headers || {}, {
'content-type': 'application/json'
});
const options = Object.assign({}, config, {
method: 'PUT',
headers: headers,
body: JSON.stringify(data)
});
const res = yield wrappedFetch(url, options);
var putJSON = function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(url) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var headers, options, res, errMsg, error;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.prev = 0;
headers = Object.assign({}, config.headers || {}, {
'content-type': 'application/json'
});
options = Object.assign({}, config, {
method: 'PUT',
headers: headers,
body: JSON.stringify(data)
});
_context4.next = 5;
return wrappedFetch(url, options);
// status code error handling
if (res.status !== 200) {
let errMsg;
try {
errMsg = yield res.text();
} catch (err) {
errMsg = res.statusText;
case 5:
res = _context4.sent;
if (!(res.status !== 200)) {
_context4.next = 20;
break;
}
errMsg = void 0;
_context4.prev = 8;
_context4.next = 11;
return res.text();
case 11:
errMsg = _context4.sent;
_context4.next = 17;
break;
case 14:
_context4.prev = 14;
_context4.t0 = _context4['catch'](8);
errMsg = res.statusText;
case 17:
error = new Error(res.status + ' - ' + errMsg);
error.response = res;
throw error;
case 20:
_context4.next = 22;
return res.json();
case 22:
return _context4.abrupt('return', _context4.sent);
case 25:
_context4.prev = 25;
_context4.t1 = _context4['catch'](0);
throw _context4.t1;
case 28:
case 'end':
return _context4.stop();
}
const error = new Error(`${res.status} - ${errMsg}`);
error.response = res;
throw error;
}
}, _callee4, undefined, [[0, 25], [8, 14]]);
}));
return yield res.json();
} catch (err) {
throw err;
}
});
return function putJSON(_x4) {
return function putJSON(_x11) {
return _ref4.apply(this, arguments);
};
})();
}();
const putJSONAuth = (url, token, data = {}, config = {}) => {
const headers = Object.assign({}, config.headers || {}, {
Authorization: `Bearer ${token}`
var putJSONAuth = function putJSONAuth(url, token) {
var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var headers = Object.assign({}, config.headers || {}, {
Authorization: 'Bearer ' + token
});
const options = Object.assign({}, config, {
var options = Object.assign({}, config, {
headers: headers

@@ -179,0 +325,0 @@ });

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

'use strict';
const truncate = (fullStr, strLen, separator) => {
var truncate = function truncate(fullStr, strLen, separator) {
if (fullStr.length <= strLen) return fullStr;

@@ -4,0 +5,0 @@

{
"name": "@marcopeg/utils",
"version": "1.4.1",
"version": "1.4.2",
"description": "Javascript utils for server and client projects",

@@ -12,2 +12,3 @@ "main": "index.js",

"presets": [
"es2015",
"es2017"

@@ -29,4 +30,5 @@ ]

"babel-core": "^6.26.3",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2017": "^6.24.1"
}
}
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