README
helper-gib
Helper functions in TypeScript. Used in conjunction with developing Alexa Skills with ask-gib, but may be useful otherwise.
ask-gib for authoring Alexa Skills in TypeScript.
See alsoInstallation
Install with npm:
npm install --save helper-gib
Import ES6 style:
import * as help from 'helper-gib';
let h = new help.Helper(); // If you want to use the helper scoped to the file.
Usage
Logging
tl;d
let h = new help.Helper();
let lc = 'Foo.eee';
h.debug("Yo debug message here.", lc);
// [201825 10:15:5.692][debug][Foo.eee] Yo debug message here.
h.info("Helpful info here, default logPriority is 1", lc);
// [201825 10:15:5.697][info][Foo.eee] Helpful info here, default logPriority is 1
h.warn("Hmmm, you sure about that?", lc);
// [201825 10:15:5.697][warn][Foo.eee] Hmmm, you sure about that?
h.error("Danger Will Robinson!", lc);
// [201825 10:15:5.698][error][Foo.eee] Danger Will Robinson!
Basics
Logging is either done or not done based on h.logPriority
value. Sugared functions use default priority values.
So this:
h.debug("Yo debug message here.", lc);
is sugar for this:
h.log("Yo debug message here.", "debug", h.defaultDebugLogPriority, lc);
Errors are always logged, no matter what the logPriority is set at, or what logPriority is passed in. (Honestly, I can't remember why I kept around the logPriority with errors.)
Usage in an Alexa Skill class
If you want something slightly more powerful, this will give you a little more of an idea.
let h = new ask.Helper();
export class MyCoolSkillClass extends ask.FuncyAlexaSkill<SkillStore> {
constructor() {
h.logPriority = 0; // for debug
h.logPriority = 1; // for verbose
h.logPriority = 2; // for terse
// Can configure sugar log priority levels if you want
h.defaultInfoLogPriority = 2;
}
foo() {
// lc = log context, used extensively
let lc = _lc + 'foo';
try {
h.debug("debug message here.", lc);
h.log("Hmmm, debug msg, but show it on a higher priority", "debug", 1, lc);
h.info("Normal info here.", lc);
h.log("Always show this info regardless of priority", "info", 999999, lc);
h.warn("Warning...", lc);
h.log("Warning, but very low priority.", "warn", 0, lc);
} catch (someError) {
h.logError(`someError`, errExec, lc);
}
}
fooWithTracing() {
let lc = _lc + 'fooWithTracing';
let f = () => {
// put the actual function logic inside this lambda.
return 42;
}
// executing using h.gib will add tracing.
// There are more args to specify catch/finally blocks, rethrow
let fResult = h.gib(this, f, /*args*/ null, lc); // 42
return fResult;
}
}
let _lc = MyCoolSkillClass.name + '.';