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: 141da2e68cae707244069f71553adfbe5f500582
Choose a base ref
...
head repository: larvit/larvitutils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c50cb37d5ae6cbc3080eaaa53bc7e57dff4f2952
Choose a head ref
  • 8 commits
  • 16 files changed
  • 2 contributors

Commits on Feb 20, 2019

  1. Reconfigured renovate

    lillem4n committed Feb 20, 2019
    Copy the full SHA
    430037b View commit details

Commits on Feb 21, 2019

  1. Copy the full SHA
    97acd6c View commit details

Commits on Feb 25, 2019

  1. Copy the full SHA
    3d4e960 View commit details

Commits on Apr 7, 2019

  1. Copy the full SHA
    a001d45 View commit details

Commits on Apr 8, 2019

  1. Copy the full SHA
    80426e3 View commit details

Commits on Apr 12, 2019

  1. Copy the full SHA
    99aeaa4 View commit details

Commits on Apr 15, 2019

  1. Added async setTimeout

    lillem4n committed Apr 15, 2019
    Copy the full SHA
    d0ae981 View commit details
  2. Copy the full SHA
    c50cb37 View commit details
Showing with 533 additions and 1,543 deletions.
  1. +85 −33 .eslintrc
  2. +0 −2 .travis.yml
  3. +3 −14 LICENSE
  4. +47 −41 README.md
  5. +57 −49 index.js
  6. +185 −1,278 package-lock.json
  7. +2 −2 package.json
  8. +5 −1 renovate.json
  9. +2 −2 test/99lint.js
  10. +29 −29 test/formatUuid.js
  11. +10 −10 test/hrtimeToMs.js
  12. +22 −22 test/isInt.js
  13. +29 −29 test/log.js
  14. +18 −18 test/replaceAll.js
  15. +26 −0 test/setTimeout.js
  16. +13 −13 test/uuidToBuffer.js
118 changes: 85 additions & 33 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,35 +1,87 @@
{
"env": {
"es6": true,
"mocha": true,
"node": true
},
"rules": {
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"camelcase": [0],
"comma-spacing": [2, {"before": false, "after": true}],
"eol-last": [0],
"function-paren-newline": ["error", "multiline"],
"indent": ["error", "tab"],
"key-spacing": [0],
"keyword-spacing": ["error", {"before": true, "after": true}],
"no-mixed-requires": [0],
"no-multi-spaces": [0],
"no-process-exit": [0],
"no-shadow": [0],
"no-underscore-dangle": [0],
"no-unused-expressions": [2],
"no-unused-vars": [2],
"no-use-before-define": [0],
"one-var": [2],
"quote-props": ["error", "always", {"keywords": true, "unnecessary": true, "numbers": true}],
"quotes": [2, "single"],
"semi": [2, "always"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}],
"space-infix-ops": [2],
"space-unary-ops": [1, { "words": true, "nonwords": true }],
"strict": [2, "global"],
"vars-on-top": [2]
}
"root": true,
"parserOptions": {
"ecmaVersion": 2017
},
"env": {
"es6": true,
"mocha": true,
"node": true
},
"rules": {
"array-bracket-newline": ["error", "consistent"],
"array-bracket-spacing": ["error", "never"],
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", {"allowSingleLine": true}],
"capitalized-comments": ["error", "always", {"ignoreConsecutiveComments": true}],
"comma-dangle": ["error", "never"],
"comma-spacing": ["error", {"before": false, "after": true}],
"comma-style": ["error", "last"],
"computed-property-spacing": ["error", "never"],
"consistent-this": ["error", "that"],
"eol-last": ["error", "always"],
"eqeqeq": ["warn", "always"],
"func-call-spacing": ["error", "never"],
"func-style": ["error", "declaration", {"allowArrowFunctions": true}],
"function-paren-newline": ["error", "multiline"],
"indent": ["error", "tab"],
"key-spacing": [
"error",
{"beforeColon": false, "afterColon": true, "mode": "strict"}
],
"keyword-spacing": ["error", {"before": true, "after": true}],
"linebreak-style": ["error", "unix"],
"lines-around-comment": ["error", {"beforeBlockComment": true, "afterBlockComment": false}],
"lines-between-class-members": ["error", "always"],
"multiline-ternary": ["error", "never"],
"new-cap": ["error"],
"new-parens": ["error"],
"no-dupe-args": ["error"],
"no-dupe-keys": ["error"],
"no-invalid-regexp": ["error"],
"no-irregular-whitespace": ["error", {"skipStrings": true, "skipComments": true, "skipRegExps": true, "skipTemplates": true}],
"no-lonely-if": ["error"],
"no-mixed-operators": ["error"],
"no-mixed-requires": ["off"],
"no-mixed-spaces-and-tabs": ["error"],
"no-multi-spaces": ["error", { "ignoreEOLComments": false }],
"no-multiple-empty-lines": ["error", {"max": 2, "maxEOF": 1, "maxBOF": 0}],
"no-process-exit": ["off"],
"no-redeclare": ["error"],
"no-sequences": ["error"],
"no-shadow": ["off"],
"no-trailing-spaces": ["error", {"ignoreComments": true}],
"no-underscore-dangle": ["off"],
"no-unexpected-multiline": ["error"],
"no-unreachable": ["error"],
"no-unused-expressions": ["error"],
"no-unused-vars": ["error", {"caughtErrors": "all"}],
"no-use-before-define": ["error", {"functions": true, "classes": true, "variables": true}],
"no-var": ["error"],
"no-whitespace-before-property": ["error"],
"nonblock-statement-body-position": ["error", "beside"],
"one-var": ["error", "never"],
"padding-line-between-statements": [
"error",
{"blankLine": "always", "prev": "*", "next": "return"},
{"blankLine": "any", "prev": ["const", "let"], "next": "*"}
],
"quote-props": ["error", "as-needed"],
"quotes": ["error", "single"],
"semi-spacing": ["error", {"before": false, "after": true}],
"semi-style": ["error", "last"],
"semi": ["error", "always"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}],
"space-in-parens": ["error", "never"],
"space-infix-ops": ["error"],
"space-unary-ops": ["error", {"words": true, "nonwords": false}],
"spaced-comment": ["error", "always"],
"strict": ["error", "global"],
"template-tag-spacing": ["error", "never"],
"unicode-bom": ["error", "never"],
"valid-jsdoc": ["error", {"requireReturn": false}],
"valid-typeof": ["error"],
"vars-on-top": ["off"]
}
}
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: node_js

node_js:
- 6
- 8
- 10
- 11

17 changes: 3 additions & 14 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
ISC License (ISC)
Copyright (c) 2016, Larv IT AB
Copyright 2019 LARV IT AB

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

Small turtles may not eat this software.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
88 changes: 47 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -11,22 +11,30 @@ The library takes one parameter as option, "log". It is designed to take an inst
Example of loading the library with no configured logger (using the default):

```javascript
const utils = new (require('larvitutils'))();
const lUtils = new (require('larvitutils'))();
```

Example of loading the library with an instance of [winston](https://github.com/winstonjs/winston) as logger:

```javascript
const winston = require('winston'),
log = winston.createLogger({'transports':[new winston.transprots.Console()]}),
utils = new (require('larvitutils'))({'log': log});
const winston = require('winston');
const log = winston.createLogger({'transports':[new winston.transprots.Console()]});
const lUtils = new (require('larvitutils'))({log: log});
```

## Async setTimeout

```javascript
const lUtils = new (require('larvitutils'))();
await lUtils.setTimeout(1000);
console.log('1000ms later');
```

## Convert a buffer to an Uuid

```javascript
const utils = new (require('larvitutils'))(),
uuid = utils.formatUuid(new Buffer('f9684592b24542fa88c69f16b9236ac3', 'hex'));
const lUtils = new (require('larvitutils'))();
const uuid = lUtils.formatUuid(new Buffer('f9684592b24542fa88c69f16b9236ac3', 'hex'));

console.log(uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
```
@@ -36,8 +44,8 @@ Example usecase: fetch a binary column from a database and convert to a readable
## Format a hex string to uuid

```javascript
const utils = new (require('larvitutils'))(),
uuid = utils.formatUuid(' f9684592b24542fa88c69f16b9236ac3'); // Notice the starting space getting trimmed away
const lUtils = new (require('larvitutils'))();
const uuid = lUtils.formatUuid(' f9684592b24542fa88c69f16b9236ac3'); // Notice the starting space getting trimmed away

console.log(uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
```
@@ -49,65 +57,65 @@ Used to convert hrtime() calls to milliseconds, since hrtime() output is messy (
Usage:

```javascript
const utils = new (require('larvitutils'))(),
startTime = process.hrtime();
const lUtils = new (require('larvitutils'))();
const startTime = process.hrtime();

setTimeout(function() {
console.log('benchmark took %d ms', utils.hrtimeToMs(startTime, 4));
// benchmark took 34.0005 ms
console.log('benchmark took %d ms', lUtils.hrtimeToMs(startTime, 4));
// benchmark took 34.0005 ms
}, 34);
```

## Uuid string to buffer

```javascript
const utils = new (require('larvitutils'))(),
uuidStr = 'f9684592-b245-42fa-88c6-9f16b9236ac3';
const lUtils = new (require('larvitutils'))();
const uuidStr = 'f9684592-b245-42fa-88c6-9f16b9236ac3';

utils.uuidToBuffer(uuidStr); // Will return a buffer or false on failure
lUtils.uuidToBuffer(uuidStr); // Will return a buffer or false on failure
```

## Replace all for strings

```javascript
const utils = new (require('larvitutils'))(),
str = 'f9684592-b245-42fa-88c6-9f16b9236ac3';
const lUtils = new (require('larvitutils'))();
const str = 'f9684592-b245-42fa-88c6-9f16b9236ac3';

utils.replaceAll('-', '_', str); // f9684592_b245_42fa_88c6_9f16b9236ac3
lUtils.replaceAll('-', '_', str); // f9684592_b245_42fa_88c6_9f16b9236ac3
```

## Validate an uuid string

```javascript
const utils = new (require('larvitutils'))(),
validUuid = 'f9684592-b245-42fa-88c6-9f16b9236ac3',
invalidUuid1 = false,
invalidUuid2 = 'foobar',
invalidUuid3 = {'höhö': 'oveboll'};

utils.formatUuid(validUuid); // true
utils.formatUuid(invalidUuid1); // false
utils.formatUuid(invalidUuid2); // false
utils.formatUuid(invalidUuid3); // false
const lUtils = new (require('larvitutils'))();
const validUuid = 'f9684592-b245-42fa-88c6-9f16b9236ac3';
const invalidUuid1 = false;
const invalidUuid2 = 'foobar';
const invalidUuid3 = {höhö: 'oveboll'};

lUtils.formatUuid(validUuid); // true
lUtils.formatUuid(invalidUuid1); // false
lUtils.formatUuid(invalidUuid2); // false
lUtils.formatUuid(invalidUuid3); // false
```

## Check if input is an int
```javascript
const utils = new (require('larvitutils'))();
const lUtils = new (require('larvitutils'))();

utils.isInt(10); // true
utils.isInt(10.0); // true
utils.isInt(10.5); // false
utils.isInt('oveboll'); // false
lUtils.isInt(10); // true
lUtils.isInt(10.0); // true
lUtils.isInt(10.5); // false
lUtils.isInt('oveboll'); // false
```

## Simple logger

This is ment as a very simple replacement for winston

```javascript
const utils = new (require('larvitutils'))(),
log = new utils.Log();
const lUtils = new (require('larvitutils'))();
const log = new lUtils.Log();

log.info('Hello'); // prints to stdout "2018-08-08T20:02:34Z [inf] Hello
log.error('Hello'); // prints to stderr "2018-08-08T20:02:48Z [err] Hello
@@ -116,21 +124,19 @@ log.error('Hello'); // prints to stderr "2018-08-08T20:02:48Z [err] Hello
By default only info, warn and error are printed to screen. Set minimum level by string, like this:

```javascript
const utils = new (require('larvitutils'))(),
log = new utils.Log('debug');
const lUtils = new (require('larvitutils'))();
const log = new lUtils.Log('debug');

log.debug('Hello'); // prints to stdout "2018-08-08T20:02:34Z [deb] Debug
```

Or disable output entirely

```javascript
const utils = new (require('larvitutils'))(),
log = new utils.Log('none');
const lUtils = new (require('larvitutils'))();
const log = new lUtils.Log('none');

log.error('Hello'); // prints nothing
```



All logging methods: silly, debug, verbose, info, warn and error.
Loading