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

async-af

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-af - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

117

logAF.js

@@ -0,21 +1,35 @@

const logAF = function logAF(...args) {
if (logAF.label) {
const lineNum = logAF.setFormat(args[0]);
args.unshift(lineNum);
}
Promise.all(args).then((toLog) => {
// eslint-disable-next-line
console ? console.log ? console.log(...toLog) : null : null;
});
};
logAF.label = true;
logAF.labelFormat = 'file';
/*
* labelFormat options:
*
* - fileName -
* @fileName.js:line:col: non-object
* @fileName.js:line:col:
* - file -
* @file.js:line:col: non-object
* @file.js:line:col:
* [Object]
*
* - filePath -
* @/Path/to/current/directory/fileName.js:line:col:
* - path -
* @/Path/to/current/directory/file.js:line:col:
* non-object
* @/Path/to/current/directory/fileName.js:line:col:
* @/Path/to/current/directory/file.js:line:col:
* [Object]
*
* - parent -
* @parentDirectory/fileName.js:line:col: non-object
* @parentDirectory/fileName.js:line:col:
* @parentDirectory/file.js:line:col: non-object
* @parentDirectory/file.js:line:col:
* [Object]
*
* - fatArrow -
* - arrow -
* ========================> non-object

@@ -25,47 +39,62 @@ * ========================> [Object]

const logAF = function logAF(...args) {
logAF.setFormat = function setFormat(firstArg) {
const error = new Error();
if (logAF.label && error.stack) {
let lineNum;
const newLineForObjs = typeof args[0] === 'object' ? '\n' : '';
const setFormat = {
fileName() {
const start = error.stack.lastIndexOf`/` + 1;
const end = error.stack.indexOf(')', start);
lineNum = `@${error.stack.slice(start, end)}:${newLineForObjs}`;
},
filePath() {
const target = error.stack.lastIndexOf`/`;
const cutoff = error.stack.slice(0, error.stack.indexOf(')', target));
lineNum = `@${cutoff.slice(cutoff.lastIndexOf`(` + 1)}:\n`;
},
parent() {
const target = error.stack.lastIndexOf`/`;
const end = error.stack.indexOf(')', target);
const start = error.stack.slice(0, target).lastIndexOf`/` + 1;
lineNum = `@${error.stack.slice(start, end)}:${newLineForObjs}`;
},
fatArrow() {
lineNum = '========================>';
},
};
setFormat[logAF.labelFormat]();
args.unshift(lineNum);
if (!error.stack) return '';
const newLineForObjs = typeof firstArg === 'object' ? '\n' : '';
const target = error.stack.lastIndexOf`/`;
const formats = {
file() {
const end = error.stack.indexOf(')', target + 1);
return `@${error.stack.slice(target + 1, end)}:${newLineForObjs}`;
},
path() {
const cutoff = error.stack.slice(0, error.stack.indexOf(')', target));
return `@${cutoff.slice(cutoff.lastIndexOf`(` + 1)}:\n`;
},
parent() {
const end = error.stack.indexOf(')', target);
const start = error.stack.slice(0, target).lastIndexOf`/` + 1;
return `@${error.stack.slice(start, end)}:${newLineForObjs}`;
},
arrow() {
return '========================>';
},
custom(format) { /* eslint-disable no-unused-vars, prefer-const, no-eval */
const location = formats.path().slice(1).split`:`;
let [path, line, col] = location;
path = path.split`/`;
const file = path.pop();
path = path.join`/`;
const parent = `${path.split`/`.pop()}/`;
path += '/';
const arrow = formats.arrow();
return eval(format.toString());
}, /* eslint-enable */
};
if (logAF.labelFormat === 'custom') {
const format = logAF.fullFormat;
return formats.custom(format.slice(format.indexOf`=` + 1));
}
Promise.all(args).then(toLog => console.log(...toLog));
return formats[logAF.labelFormat]();
};
logAF.label = true;
logAF.labelFormat = 'fileName';
logAF.options = function logAFOptions(options) {
if (options.label === false) logAF.label = false;
if (options.labelFormat) {
const validFormats = ['fileName', 'filePath', 'parent', 'fatArrow'];
const desiredFormat = options.labelFormat;
const validFormats = [
'file',
'path',
'parent',
'arrow',
'custom',
];
const desiredFormat = options.labelFormat.slice(0, 6);
if (!validFormats.includes(desiredFormat)) {
const msg = 'AsyncAF Warning: logAF labelFormat option must be set to \'fileName\' (default), \'filePath\', \'parent\', or \'fatArrow\'';
const msg = 'AsyncAF Warning: logAF labelFormat option must be set to \'file\' (default), \'path\', \'parent\', \'arrow\', or \'custom\'';
// eslint-disable-next-line
console ? console.warn ? console.warn(msg) : console.log ? console.log(msg) : null : null;
} else logAF.labelFormat = desiredFormat;
} else {
logAF.labelFormat = desiredFormat;
logAF.fullFormat = options.labelFormat;
}
}

@@ -72,0 +101,0 @@ };

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "1.5.0",
"version": "1.6.0",
"homepage": "https://github.com/AsyncAF/AsyncAF#readme",

@@ -9,0 +9,0 @@ "bugs": {

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