Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

larvitutils

Package Overview
Dependencies
Maintainers
1
Versions
185
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

larvitutils - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

test/setTimeout.js

106

index.js
'use strict';
const topLogPrefix = 'larvitutils: index.js: ';
const topLogPrefix = 'larvitutils: index.js: ';
function Utils(options) {
const that = this;
const that = this;
if ( ! that) {
if (!that) {
throw new Error('This library must be instanciated.');
}
that.options = options || {};
that.options = options || {};
if ( ! that.options.log) {
that.options.log = new that.Log();
if (!that.options.log) {
that.options.log = new that.Log();
}
that.log = that.options.log;
that.log = that.options.log;
}

@@ -24,14 +24,14 @@

*
* @param arr prevTime - the output from process.hrtime() to diff to
* @param int precision - defaults to 2
* @return string - time diff in milliseconds rounded to given precision
* @param {array} prevTime - the output from process.hrtime() to diff to
* @param {integer} precision - defaults to 2
* @return {string} - time diff in milliseconds rounded to given precision
*/
Utils.prototype.hrtimeToMs = function hrtimeToMs(prevTime, precision) {
const diff = process.hrtime(prevTime);
const diff = process.hrtime(prevTime);
if (precision === undefined) {
precision = 2;
precision = 2;
}
return (diff[0] * 1000 + (diff[1] / 1000000)).toFixed(precision);
return ((diff[0] * 1000) + (diff[1] / 1000000)).toFixed(precision);
};

@@ -45,6 +45,7 @@

* Formats an uuid string
*
* For example adds missing "-", trimming spaces etc
*
* @param str uuidStr - Can also take a buffer
* @return str uuid string or false on failure
* @param {string} uuidStr - Can also take a buffer
* @return {string} uuid string or false on failure
*/

@@ -55,3 +56,3 @@ Utils.prototype.formatUuid = function formatUuid(uuidStr) {

if (Buffer.isBuffer(uuidStr)) {
uuidStr = uuidStr.toString('hex');
uuidStr = uuidStr.toString('hex');
}

@@ -65,3 +66,3 @@

// Remove all but hex characters
uuidStr = uuidStr.replace(/[^A-Fa-f0-9]/g, '').toLowerCase();
uuidStr = uuidStr.replace(/[^A-Fa-f0-9]/g, '').toLowerCase();

@@ -74,3 +75,3 @@ // All uuid strings have exactly 32 hex characters!

// Add dashes in the right places
uuidStr = uuidStr.substring(0, 8) + '-' + uuidStr.substring(8, 12) + '-' + uuidStr.substring(12, 16) + '-' + uuidStr.substring(16, 20) + '-' + uuidStr.substring(20);
uuidStr = uuidStr.substring(0, 8) + '-' + uuidStr.substring(8, 12) + '-' + uuidStr.substring(12, 16) + '-' + uuidStr.substring(16, 20) + '-' + uuidStr.substring(20);

@@ -83,27 +84,33 @@ return uuidStr;

*
* @param str search
* @param str replace
* @param str str
*
* @return str
* @param {string} search - What to search for
* @param {string} replace - What to replace it with
* @param {string} str - The string to perform this to
* @return {string} - The result
*/
Utils.prototype.replaceAll = function replaceAll(search, replace, str) {
const that = this;
const that = this;
return str.replace(new RegExp(that.escapeRegExp(search), 'g'), replace);
};
Utils.prototype.setTimeout = async function lUtilsSetTimeout(ms) {
return new Promise(resolve => {
setTimeout(() => resolve(), ms);
});
};
/**
* Make a buffer from an uuid string
*
* @param str uuidStr - Can be with or without dashes, padded spaces etc will be trimmed
* @return buffer or false on fail
* @param {string} uuidStr - Can be with or without dashes, padded spaces etc will be trimmed
* @return {buffer} or false on fail
*/
Utils.prototype.uuidToBuffer = function uuidToBuffer(uuidStr) {
const logPrefix = topLogPrefix + 'uuidToBuffer() - ',
that = this;
const logPrefix = topLogPrefix + 'uuidToBuffer() - ';
if (typeof uuidStr !== 'string') {
const stack = new Error().stack;
that.log.warn(logPrefix + 'uuidStr is not a string, but a ' + (typeof uuidStr));
that.log.verbose(logPrefix + stack);
const stack = new Error().stack;
this.log.warn(logPrefix + 'uuidStr is not a string, but a ' + (typeof uuidStr));
this.log.verbose(logPrefix + stack);
return false;

@@ -117,9 +124,10 @@ }

if (uuidStr.length !== 32) {
const stack = new Error().stack;
that.log.warn(logPrefix + 'uuidStr should be exactly 32 characters after regex, but is: ' + uuidStr.length);
that.log.verbose(logPrefix + stack);
const stack = new Error().stack;
this.log.warn(logPrefix + 'uuidStr should be exactly 32 characters after regex, but is: ' + uuidStr.length);
this.log.verbose(logPrefix + stack);
return false;
}
return new Buffer.from(uuidStr, 'hex');
return new Buffer.from(uuidStr, 'hex'); // eslint-disable-line new-cap
};

@@ -130,7 +138,7 @@

*
* @param mixed Value to check
* @return Boolean
* @param {mixed} value - The value to check
* @return {boolean} true or false
*/
Utils.prototype.isInt = function isInt(value) {
const x = parseFloat(value);
const x = parseFloat(value);

@@ -145,12 +153,12 @@ if (isNaN(value)) {

Utils.prototype.Log = function Log(options) {
const that = this;
const that = this;
that.options = options || {};
that.options = options || {};
if (typeof that.options === 'string') {
that.options = {'level': that.options};
that.options = {level: that.options};
}
if ( ! that.options.level) {
that.options.level = 'info';
if (!that.options.level) {
that.options.level = 'info';
}

@@ -172,3 +180,3 @@ };

Utils.prototype.Log.prototype.debug = function debug(msg) {
if (['silly', 'debug'].indexOf(this.options.level) !== - 1) {
if (['silly', 'debug'].indexOf(this.options.level) !== -1) {
this.stdout('\x1b[1;35mdeb\x1b[0m', msg);

@@ -179,3 +187,3 @@ }

Utils.prototype.Log.prototype.verbose = function verbose(msg) {
if (['silly', 'debug', 'verbose'].indexOf(this.options.level) !== - 1) {
if (['silly', 'debug', 'verbose'].indexOf(this.options.level) !== -1) {
this.stdout('\x1b[1;34mver\x1b[0m', msg);

@@ -186,3 +194,3 @@ }

Utils.prototype.Log.prototype.info = function info(msg) {
if (['silly', 'debug', 'verbose', 'info'].indexOf(this.options.level) !== - 1) {
if (['silly', 'debug', 'verbose', 'info'].indexOf(this.options.level) !== -1) {
this.stdout('\x1b[1;32minf\x1b[0m', msg);

@@ -193,3 +201,3 @@ }

Utils.prototype.Log.prototype.warn = function warn(msg) {
if (['silly', 'debug', 'verbose', 'info', 'warn'].indexOf(this.options.level) !== - 1) {
if (['silly', 'debug', 'verbose', 'info', 'warn'].indexOf(this.options.level) !== -1) {
this.stderr('\x1b[1;33mwar\x1b[0m', msg);

@@ -200,3 +208,3 @@ }

Utils.prototype.Log.prototype.error = function error(msg) {
if (['silly', 'debug', 'verbose', 'info', 'error'].indexOf(this.options.level) !== - 1) {
if (['silly', 'debug', 'verbose', 'info', 'error'].indexOf(this.options.level) !== -1) {
this.stderr('\x1b[1;31merr\x1b[0m', msg);

@@ -206,2 +214,2 @@ }

exports = module.exports = Utils;
exports = module.exports = Utils;
{
"name": "larvitutils",
"version": "2.1.1",
"version": "2.2.0",
"description": "Misc utils",
"main": "index.js",
"devDependencies": {
"mocha": "6.0.0",
"mocha": "6.1.3",
"mocha-eslint": "5.0.0"

@@ -9,0 +9,0 @@ },

@@ -14,3 +14,3 @@ [![Build Status](https://travis-ci.org/larvit/larvitutils.svg)](https://travis-ci.org/larvit/larvitutils) [![Dependencies](https://david-dm.org/larvit/larvitutils.svg)](https://david-dm.org/larvit/larvitutils.svg)

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

@@ -21,12 +21,20 @@

```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'));

@@ -41,4 +49,4 @@ console.log(uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3

```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

@@ -55,8 +63,8 @@ console.log(uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3

```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);

@@ -68,6 +76,6 @@ ```

```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
```

@@ -78,6 +86,6 @@

```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
```

@@ -88,12 +96,12 @@

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

@@ -103,8 +111,8 @@

```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
```

@@ -117,4 +125,4 @@

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

@@ -128,4 +136,4 @@ log.info('Hello'); // prints to stdout "2018-08-08T20:02:34Z [inf] Hello

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

@@ -138,4 +146,4 @@ log.debug('Hello'); // prints to stdout "2018-08-08T20:02:34Z [deb] Debug

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

@@ -145,4 +153,2 @@ log.error('Hello'); // prints nothing

All logging methods: silly, debug, verbose, info, warn and error.
{
"extends": [
"config:base"
]
],
"automerge": true,
"major": {
"automerge": false
}
}

@@ -7,7 +7,7 @@ 'use strict';

// Increase the timeout of the test if linting takes to long
'timeout': 5000, // Defaults to the global mocha `timeout` option
timeout: 5000, // Defaults to the global mocha `timeout` option
// Increase the time until a test is marked as slow
'slow': 1000, // Defaults to the global mocha `slow` option
slow: 1000 // Defaults to the global mocha `slow` option
}
);
'use strict';
const assert = require('assert'),
utils = new (require(__dirname + '/../index.js'))();
const assert = require('assert');
const utils = new (require(__dirname + '/../index.js'))();
describe('formatUuid', function () {
it('Should convert a binary buffer to Uuid string', function (done) {
const uuid = utils.formatUuid(Buffer.from('f9684592b24542fa88c69f16b9236ac3', 'hex'));
describe('formatUuid', () => {
it('Should convert a binary buffer to Uuid string', done => {
const uuid = utils.formatUuid(Buffer.from('f9684592b24542fa88c69f16b9236ac3', 'hex'));
assert.strictEqual(uuid, 'f9684592-b245-42fa-88c6-9f16b9236ac3');
assert.strictEqual(uuid, 'f9684592-b245-42fa-88c6-9f16b9236ac3');

@@ -15,26 +15,26 @@ done();

it('Should trim a hex string and return its uuid value', function (done) {
const uuidStr = ' 0e7e26b7-f1804d65-9512-80b776a7509e ',
formatted = utils.formatUuid(uuidStr);
it('Should trim a hex string and return its uuid value', done => {
const uuidStr = ' 0e7e26b7-f1804d65-9512-80b776a7509e ';
const formatted = utils.formatUuid(uuidStr);
assert.strictEqual(formatted, '0e7e26b7-f180-4d65-9512-80b776a7509e');
assert.strictEqual(formatted, '0e7e26b7-f180-4d65-9512-80b776a7509e');
done();
});
it('Should add dashes to a hex string', function (done) {
const uuidStr = '62be934b24c24944981c40d4163e3bc9',
formatted = utils.formatUuid(uuidStr);
it('Should add dashes to a hex string', done => {
const uuidStr = '62be934b24c24944981c40d4163e3bc9';
const formatted = utils.formatUuid(uuidStr);
assert.strictEqual(formatted, '62be934b-24c2-4944-981c-40d4163e3bc9');
assert.strictEqual(formatted, '62be934b-24c2-4944-981c-40d4163e3bc9');
done();
});
it('Should fail to format a malformed string', function (done) {
const blaj = utils.formatUuid('blaj'),
toShortHex = utils.formatUuid('62be934b24c2494981c40d4163e3bc9'),
toLongHex = utils.formatUuid('62be934b24c24944981c40d4163e3bc93');
it('Should fail to format a malformed string', done => {
const blaj = utils.formatUuid('blaj');
const toShortHex = utils.formatUuid('62be934b24c2494981c40d4163e3bc9');
const toLongHex = utils.formatUuid('62be934b24c24944981c40d4163e3bc93');
assert.strictEqual(blaj, false);
assert.strictEqual(toShortHex, false);
assert.strictEqual(toLongHex, false);
assert.strictEqual(blaj, false);
assert.strictEqual(toShortHex, false);
assert.strictEqual(toLongHex, false);

@@ -44,6 +44,6 @@ done();

it('Should format a upper case string to lower case', function (done) {
const formatted = utils.formatUuid('80D7B01D-E5D8-43A4-B5F1-E2703506860A');
it('Should format a upper case string to lower case', done => {
const formatted = utils.formatUuid('80D7B01D-E5D8-43A4-B5F1-E2703506860A');
assert.strictEqual(formatted, '80d7b01d-e5d8-43a4-b5f1-e2703506860a');
assert.strictEqual(formatted, '80d7b01d-e5d8-43a4-b5f1-e2703506860a');

@@ -53,8 +53,8 @@ done();

it('Should fail on anything but a string', function (done) {
const test1 = utils.formatUuid([3, 4]),
test2 = utils.formatUuid({'höhö': 'fippel'});
it('Should fail on anything but a string', done => {
const test1 = utils.formatUuid([3, 4]);
const test2 = utils.formatUuid({höhö: 'fippel'});
assert.strictEqual(test1, false);
assert.strictEqual(test2, false);
assert.strictEqual(test1, false);
assert.strictEqual(test2, false);

@@ -61,0 +61,0 @@ done();

'use strict';
const assert = require('assert'),
utils = new (require(__dirname + '/../index.js'))();
const assert = require('assert');
const utils = new (require(__dirname + '/../index.js'))();
describe('hrtimeToMs', function () {
it('Test default amount of decimals', function (done) {
const res = utils.hrtimeToMs(process.hrtime());
assert.strictEqual(typeof res, 'string', 'res should be a string, but returned as ' + typeof res + ' and its value is ' + res);
assert.strictEqual(res.split('.')[1].length, 2, 'The string length after the . should be 2, but is ' + res.split('.')[1].length);
it('Test default amount of decimals', done => {
const res = utils.hrtimeToMs(process.hrtime());
assert.strictEqual(typeof res, 'string', 'res should be a string, but returned as ' + typeof res + ' and its value is ' + res);
assert.strictEqual(res.split('.')[1].length, 2, 'The string length after the . should be 2, but is ' + res.split('.')[1].length);
done();
});
it('Test custom amount of decimals', function (done) {
const res = utils.hrtimeToMs(process.hrtime(), 4);
assert.strictEqual(typeof res, 'string', 'res should be a string, but returned as ' + typeof res + ' and its value is ' + res);
assert.strictEqual(res.split('.')[1].length, 4, 'The string length after the . should be 4, but is ' + res.split('.')[1].length);
it('Test custom amount of decimals', done => {
const res = utils.hrtimeToMs(process.hrtime(), 4);
assert.strictEqual(typeof res, 'string', 'res should be a string, but returned as ' + typeof res + ' and its value is ' + res);
assert.strictEqual(res.split('.')[1].length, 4, 'The string length after the . should be 4, but is ' + res.split('.')[1].length);
done();
});
});
'use strict';
const assert = require('assert'),
utils = new (require(__dirname + '/../index.js'))();
const assert = require('assert');
const utils = new (require(__dirname + '/../index.js'))();
describe('isInt', function () {
it('Should return false if input is a string', function (done) {
const input = 'string',
checkedInt = utils.isInt(input);
it('Should return false if input is a string', done => {
const input = 'string';
const checkedInt = utils.isInt(input);
assert.strictEqual(checkedInt, false, 'Should return false if input is a string, but returned true.');
assert.strictEqual(checkedInt, false, 'Should return false if input is a string, but returned true.');

@@ -16,7 +16,7 @@ done();

it('Should return false if input is a function', function (done) {
const input = function () {},
checkedInt = utils.isInt(input);
it('Should return false if input is a function', done => {
function input() {};
const checkedInt = utils.isInt(input);
assert.strictEqual(checkedInt, false, 'Should return false if input is a function, but returned true.');
assert.strictEqual(checkedInt, false, 'Should return false if input is a function, but returned true.');

@@ -26,7 +26,7 @@ done();

it('Should return false if input is a float', function (done) {
const input = 1.5,
checkedInt = utils.isInt(input);
it('Should return false if input is a float', done => {
const input = 1.5;
const checkedInt = utils.isInt(input);
assert.strictEqual(checkedInt, false, 'Should return false if input is a float, but returned true.');
assert.strictEqual(checkedInt, false, 'Should return false if input is a float, but returned true.');

@@ -36,7 +36,7 @@ done();

it('Should return true if input is a float with a zero decimal', function (done) {
const input = 1.0,
checkedInt = utils.isInt(input);
it('Should return true if input is a float with a zero decimal', done => {
const input = 1.0;
const checkedInt = utils.isInt(input);
assert.strictEqual(checkedInt, true, 'Should return true if input is a float with zero decimal, but returned false.');
assert.strictEqual(checkedInt, true, 'Should return true if input is a float with zero decimal, but returned false.');

@@ -46,7 +46,7 @@ done();

it('Should return true if input is a int', function (done) {
const input = 1,
checkedInt = utils.isInt(input);
it('Should return true if input is a int', done => {
const input = 1;
const checkedInt = utils.isInt(input);
assert.strictEqual(checkedInt, true, 'Should return true if input is a int, but returned false.');
assert.strictEqual(checkedInt, true, 'Should return true if input is a int, but returned false.');

@@ -53,0 +53,0 @@ done();

'use strict';
const assert = require('assert'),
utils = new (require(__dirname + '/../index.js'))();
const assert = require('assert');
const utils = new (require(__dirname + '/../index.js'))();
describe('log', function () {
it('should log to info', function (done) {
const oldStdout = process.stdout.write,
log = new utils.Log();
it('should log to info', done => {
const oldStdout = process.stdout.write;
const log = new utils.Log();

@@ -14,3 +14,3 @@ let outputMsg;

process.stdout.write = function (msg) {
outputMsg = msg;
outputMsg = msg;
};

@@ -20,5 +20,5 @@

process.stdout.write = oldStdout;
process.stdout.write = oldStdout;
assert.strictEqual(outputMsg.substring(19), 'Z [\u001b[1;32minf\u001b[0m] flurp\n');
assert.strictEqual(outputMsg.substring(19), 'Z [\u001b[1;32minf\u001b[0m] flurp\n');

@@ -28,5 +28,5 @@ done();

it('should log to error', function (done) {
const oldStderr = process.stderr.write,
log = new utils.Log();
it('should log to error', done => {
const oldStderr = process.stderr.write;
const log = new utils.Log();

@@ -36,3 +36,3 @@ let outputMsg;

process.stderr.write = function (msg) {
outputMsg = msg;
outputMsg = msg;
};

@@ -42,5 +42,5 @@

process.stderr.write = oldStderr;
process.stderr.write = oldStderr;
assert.strictEqual(outputMsg.substring(19), 'Z [\u001b[1;31merr\u001b[0m] burp\n');
assert.strictEqual(outputMsg.substring(19), 'Z [\u001b[1;31merr\u001b[0m] burp\n');

@@ -50,10 +50,10 @@ done();

it('should not print debug by default', function (done) {
const oldStdout = process.stdout.write,
log = new utils.Log();
it('should not print debug by default', done => {
const oldStdout = process.stdout.write;
const log = new utils.Log();
let outputMsg = 'yay';
let outputMsg = 'yay';
process.stdout.write = function (msg) {
outputMsg = msg;
outputMsg = msg;
};

@@ -63,5 +63,5 @@

process.stdout.write = oldStdout;
process.stdout.write = oldStdout;
assert.strictEqual(outputMsg, 'yay');
assert.strictEqual(outputMsg, 'yay');

@@ -71,10 +71,10 @@ done();

it('should print debug when given "silly" as level', function (done) {
const oldStdout = process.stdout.write,
log = new utils.Log('silly');
it('should print debug when given "silly" as level', done => {
const oldStdout = process.stdout.write;
const log = new utils.Log('silly');
let outputMsg = 'woof';
let outputMsg = 'woof';
process.stdout.write = function (msg) {
outputMsg = msg;
outputMsg = msg;
};

@@ -84,8 +84,8 @@

process.stdout.write = oldStdout;
process.stdout.write = oldStdout;
assert.strictEqual(outputMsg.substring(19), 'Z [\u001b[1;35mdeb\u001b[0m] wapp\n');
assert.strictEqual(outputMsg.substring(19), 'Z [\u001b[1;35mdeb\u001b[0m] wapp\n');
done();
});
});
});
'use strict';
const assert = require('assert'),
utils = new (require(__dirname + '/../index.js'))();
const assert = require('assert');
const utils = new (require(__dirname + '/../index.js'))();
describe('replaceAll', function () {
it('Should replace all occurences of - to _ in an UUID', function (done) {
const uuidStr = 'f9684592-b245-42fa-88c6-9f16b9236ac3',
newStr = utils.replaceAll('-', '_', uuidStr);
it('Should replace all occurences of - to _ in an UUID', done => {
const uuidStr = 'f9684592-b245-42fa-88c6-9f16b9236ac3';
const newStr = utils.replaceAll('-', '_', uuidStr);
assert.strictEqual(newStr, 'f9684592_b245_42fa_88c6_9f16b9236ac3');
assert.strictEqual(newStr, 'f9684592_b245_42fa_88c6_9f16b9236ac3');

@@ -16,7 +16,7 @@ done();

it('Should leave a string unaltered if it have no occurences of the string to be replaced', function (done) {
const uuidStr = 'f9684592b24542fa88c69f16b9236ac3',
newStr = utils.replaceAll('-', '_', uuidStr);
it('Should leave a string unaltered if it have no occurences of the string to be replaced', done => {
const uuidStr = 'f9684592b24542fa88c69f16b9236ac3';
const newStr = utils.replaceAll('-', '_', uuidStr);
assert.strictEqual(newStr, 'f9684592b24542fa88c69f16b9236ac3');
assert.strictEqual(newStr, 'f9684592b24542fa88c69f16b9236ac3');

@@ -26,7 +26,7 @@ done();

it('Should be able to replace to nothing', function (done) {
const uuidStr = 'f9684592-b245-42fa-88c6-9f16b9236ac3',
newStr = utils.replaceAll('-', '', uuidStr);
it('Should be able to replace to nothing', done => {
const uuidStr = 'f9684592-b245-42fa-88c6-9f16b9236ac3';
const newStr = utils.replaceAll('-', '', uuidStr);
assert.strictEqual(newStr, 'f9684592b24542fa88c69f16b9236ac3');
assert.strictEqual(newStr, 'f9684592b24542fa88c69f16b9236ac3');

@@ -36,7 +36,7 @@ done();

it('Should not break if we pass RegExp unsafe char', function (done) {
const uuidStr = 'f9684592-b245-42fa.88c6.9f16b9236ac3',
newStr = utils.replaceAll('.', 'poo', uuidStr);
it('Should not break if we pass RegExp unsafe char', done => {
const uuidStr = 'f9684592-b245-42fa.88c6.9f16b9236ac3';
const newStr = utils.replaceAll('.', 'poo', uuidStr);
assert.strictEqual(newStr, 'f9684592-b245-42fapoo88c6poo9f16b9236ac3');
assert.strictEqual(newStr, 'f9684592-b245-42fapoo88c6poo9f16b9236ac3');

@@ -43,0 +43,0 @@ done();

'use strict';
const assert = require('assert'),
Utils = require(__dirname + '/../index.js'),
utils = new Utils({'log': new (new Utils()).Log('none')});
const assert = require('assert');
const Utils = require(__dirname + '/../index.js');
const utils = new Utils({log: new (new Utils()).Log('none')});
describe('uuidToBuffer', function () {
it('Should convert an Uuid string to a buffer', function (done) {
const uuidStr = 'f9684592-b245-42fa-88c6-9f16b9236ac3',
uuidBuf = utils.uuidToBuffer(uuidStr);
it('Should convert an Uuid string to a buffer', done => {
const uuidStr = 'f9684592-b245-42fa-88c6-9f16b9236ac3';
const uuidBuf = utils.uuidToBuffer(uuidStr);

@@ -17,5 +17,5 @@ assert(uuidBuf.toString('hex') === 'f9684592b24542fa88c69f16b9236ac3', 'Uuid string is wrong, expected "f9684592b24542fa88c69f16b9236ac3" but got "' + uuidBuf.toString('hex') + '"');

it('Should fail to convert an invalid Uuid string to buffer', function (done) {
const uuidStr = 'f96845-42fa-88c6-9f16b9236ac3',
uuidBuf = utils.uuidToBuffer(uuidStr);
it('Should fail to convert an invalid Uuid string to buffer', done => {
const uuidStr = 'f96845-42fa-88c6-9f16b9236ac3';
const uuidBuf = utils.uuidToBuffer(uuidStr);

@@ -27,6 +27,6 @@ assert(uuidBuf === false, 'uuidBuf should be false, but is "' + uuidBuf + '"');

it('Should fail to convert a non-string', function (done) {
assert.strictEqual(utils.uuidToBuffer({'foo': 'bar'}), false);
assert.strictEqual(utils.uuidToBuffer(undefined), false);
assert.strictEqual(utils.uuidToBuffer(null), false);
it('Should fail to convert a non-string', done => {
assert.strictEqual(utils.uuidToBuffer({foo: 'bar'}), false);
assert.strictEqual(utils.uuidToBuffer(undefined), false);
assert.strictEqual(utils.uuidToBuffer(null), false);

@@ -33,0 +33,0 @@ done();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc