Skip to content

Commit

Permalink
Minor overall improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani committed Sep 5, 2018
1 parent 92f386c commit f275c40
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions signale.js
Expand Up @@ -11,14 +11,6 @@ let isPreviousLogInteractive = false;
const defaults = pkg.options.default;
const namespace = pkg.name;

const arrayify = x => {
return Array.isArray(x) ? x : [x];
};
const now = () => Date.now();
const timeSpan = then => {
return (now() - then);
};

class Signale {
constructor(options = {}) {
this._interactive = options.interactive || false;
Expand All @@ -36,6 +28,10 @@ class Signale {
});
}

get _now() {
return Date.now();
}

get scopeName() {
return this._scopeName;
}
Expand Down Expand Up @@ -86,6 +82,14 @@ class Signale {
this._config = Object.assign(this.packageConfiguration, configObj);
}

_arrayify(x) {
return Array.isArray(x) ? x : [x];
}

_timeSpan(then) {
return (this._now - then);
}

_getLongestLabel() {
const {_types} = this;
const labels = Object.keys(_types).map(x => _types[x].label);
Expand All @@ -103,7 +107,7 @@ class Signale {
}

_formatStream(stream) {
return arrayify(stream);
return this._arrayify(stream);
}

_formatDate() {
Expand All @@ -127,7 +131,7 @@ class Signale {
}

_formatMessage(str, type) {
str = arrayify(str);
str = this._arrayify(str);

if (this._config.coloredInterpolation) {
const _ = Object.assign({}, util.inspect.styles);
Expand All @@ -146,22 +150,28 @@ class Signale {

_meta() {
const meta = [];

if (this._config.displayDate) {
meta.push(this._formatDate());
}

if (this._config.displayTimestamp) {
meta.push(this._formatTimestamp());
}

if (this._config.displayFilename) {
meta.push(this._formatFilename());
}

if (this._scopeName.length !== 0 && this._config.displayScope) {
meta.push(this._formatScopeName());
}

if (meta.length !== 0) {
meta.push(`${figures.pointerSmall}`);
return meta.map(item => chalk.grey(item));
}

return meta;
}

Expand Down Expand Up @@ -268,6 +278,7 @@ class Signale {
if (String.prototype.padEnd) {
return str.padEnd(targetLength);
}

targetLength -= str.length;
return str + ' '.repeat(targetLength);
}
Expand Down Expand Up @@ -300,7 +311,7 @@ class Signale {
label = `timer_${this._timers.size}`;
}

this._timers.set(label, Date.now());
this._timers.set(label, this._now);
const message = this._meta();

const report = [
Expand All @@ -322,7 +333,7 @@ class Signale {
});
}
if (this._timers.has(label)) {
const span = timeSpan(this._timers.get(label));
const span = this._timeSpan(this._timers.get(label));
this._timers.delete(label);

const message = this._meta();
Expand Down

0 comments on commit f275c40

Please sign in to comment.