babel-plugin-debug-tools
Advanced tools
Comparing version 1.0.17 to 1.0.18
{ | ||
"name": "babel-plugin-debug-tools", | ||
"version": "1.0.17", | ||
"version": "1.0.18", | ||
"description": "Helpers for debug Javascript Applications", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -8,5 +8,6 @@ # babel-debug-tools | ||
// app.js | ||
import { H5 } from './debug' | ||
function sum(a,b) { | ||
H5.LOG(a,b); | ||
→ console.log('a='+ a, 'b='+ b, ' at app.js:2:3'); | ||
→ console.log('a='+ a, 'b='+ b, ' at app.js:3:3'); | ||
return a+b; | ||
@@ -19,6 +20,7 @@ } | ||
// app.js | ||
import { H5 } from './debug' | ||
function sum(a,b) { | ||
H5.ASSERT(a>0,b>0) | ||
→ if (!(a>0)) throw new Error('assert a>0 at app.js:2:3'); | ||
→ if (!(b>0)) throw new Error('assert b>0 at app.js:2:3'); | ||
→ if (!(a>0)) throw new Error('assert a>0 at app.js:3:3'); | ||
→ if (!(b>0)) throw new Error('assert b>0 at app.js:3:3'); | ||
return a+b | ||
@@ -31,2 +33,3 @@ } | ||
// lib.js | ||
import { H5 } from './debug' | ||
function quadraticEquation(a,b,c) { | ||
@@ -42,2 +45,3 @@ const delta = b*b - 4*a*c; ← b² – 4ac | ||
// test.js | ||
import { H5 } from './debug' | ||
it(()=>{ | ||
@@ -86,4 +90,4 @@ H5.RESET() | ||
### debug module | ||
You will need a debug module, like that but customized for your needs. | ||
### debug.js module | ||
You will need a debug module, like that but customized to your needs. | ||
@@ -94,9 +98,9 @@ See sample project or DEBUG.ts | ||
let traceLog=[]; | ||
let traceLog = []; | ||
export const H5 = { | ||
LOG(loc, ...args) { | ||
console.log.apply(console, formatArgs(args, loc)); | ||
LOG() { | ||
console.log(formatArgs(arguments, 1)); | ||
}, | ||
ASSERT(loc, ...args) { | ||
ASSERT() { | ||
const loc = arguments[0] | ||
@@ -119,9 +123,12 @@ for (let i = 1; i < arguments.length; i++) { | ||
}, | ||
TRACE(...args) { | ||
traceLog.push(formatArgs(args)); | ||
}, | ||
HISTORY() { | ||
return traceLog.join('\n') | ||
}, | ||
} | ||
}, | ||
TRACE() { | ||
traceLog.push(formatArgs(arguments, 0)); | ||
}, | ||
CHECK(regExp) { | ||
return traceLog.some(l => regExp.test(l)) | ||
} | ||
}; | ||
@@ -132,17 +139,20 @@ function formatLoc(loc) { | ||
function formatArg(arg) { | ||
if (typeof arg === 'string') return arg | ||
return JSON.stringify(arg) | ||
} | ||
function formatArgs(args, loc) { | ||
function formatArgs(args, sLoc) { | ||
const flatArgs = [] | ||
args.forEach((arg) => { | ||
if (Array.isArray(args) && args.length == 2) { | ||
flatArgs.push(arg[0]+': '+formatArg(arg[1])) | ||
for (let i = 0; i < args.length - sLoc; i++) { | ||
const arg = args[i] | ||
if (Array.isArray(arg) && arg.length == 2) { | ||
flatArgs.push(formatArg(arg[0]) + ': ' + formatArg(arg[1])) | ||
} | ||
else flatArgs.push(formatArg(arg)) | ||
}) | ||
if (loc) | ||
flatArgs.push(formatLoc(loc)) | ||
return flatArgs | ||
} | ||
if (sLoc) | ||
flatArgs.push(formatArg(formatLoc(args[args.length - 1]))) | ||
return flatArgs.join(' ') | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48112
151