Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: larvit/larvitutils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c50cb37d5ae6cbc3080eaaa53bc7e57dff4f2952
Choose a base ref
...
head repository: larvit/larvitutils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 933e0198b5123c29089c94301c7ba023aa082ae4
Choose a head ref
  • 4 commits
  • 13 files changed
  • 2 contributors

Commits on Apr 18, 2019

  1. Copy the full SHA
    2b38101 View commit details

Commits on Jul 10, 2019

  1. Copy the full SHA
    9638ab3 View commit details
  2. Copy the full SHA
    e01a438 View commit details
  3. Copy the full SHA
    933e019 View commit details
Showing with 1,685 additions and 580 deletions.
  1. +1 −1 .travis.yml
  2. +2 −0 README.md
  3. +19 −16 index.js
  4. +1,454 −350 package-lock.json
  5. +7 −4 package.json
  6. +2 −9 test/99lint.js
  7. +38 −40 test/formatUuid.js
  8. +12 −14 test/hrtimeToMs.js
  9. +30 −32 test/isInt.js
  10. +62 −50 test/log.js
  11. +24 −26 test/replaceAll.js
  12. +16 −18 test/setTimeout.js
  13. +18 −20 test/uuidToBuffer.js
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ language: node_js

node_js:
- 10
- 11
- 12

notifications:
email:
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -139,4 +139,6 @@ const log = new lUtils.Log('none');
log.error('Hello'); // prints nothing
```

The default log level can be changed by setting environment variable NODE_LOG_LVL

All logging methods: silly, debug, verbose, info, warn and error.
35 changes: 19 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -3,19 +3,17 @@
const topLogPrefix = 'larvitutils: index.js: ';

function Utils(options) {
const that = this;

if (!that) {
if (!this) {
throw new Error('This library must be instanciated.');
}

that.options = options || {};
this.options = options || {};

if (!that.options.log) {
that.options.log = new that.Log();
if (!this.options.log) {
this.options.log = new this.Log();
}

that.log = that.options.log;
this.log = this.options.log;
}

/**
@@ -82,8 +80,7 @@ Utils.prototype.formatUuid = function formatUuid(uuidStr) {
* @return {string} - The result
*/
Utils.prototype.replaceAll = function replaceAll(search, replace, str) {
const that = this;
return str.replace(new RegExp(that.escapeRegExp(search), 'g'), replace);
return str.replace(new RegExp(this.escapeRegExp(search), 'g'), replace);
};


@@ -141,17 +138,23 @@ Utils.prototype.isInt = function isInt(value) {
return (x | 0) === x;
};

/**
* Simple logging instance
*
* @param {object | string} options[=process.env.NODE_LOG_LVL] - Optional options object or minimum log level
* @param {string} options.level[=process.env.NODE_LOG_LVL] - log level
*/
Utils.prototype.Log = function Log(options) {
const that = this;

that.options = options || {};
this.options = options || {};

if (typeof that.options === 'string') {
that.options = {level: that.options};
if (typeof this.options === 'string') {
this.options = { level: this.options };
}

if (!that.options.level) {
that.options.level = 'info';
if (!this.options.level && process.env.NODE_LOG_LVL) {
this.options.level = process.env.NODE_LOG_LVL;
} else if (!this.options.level) {
this.options.level = 'info';
}
};

Loading