Package Exports
- larvitutils
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (larvitutils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
larvitutils
Misc utilities
Convert a buffer to an Uuid
const utils = require('larvitutils'),
uuid = utils.formatUuid(new Buffer('f9684592b24542fa88c69f16b9236ac3', 'hex'));
console.log(uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
Example usecase: fetch a binary column from a database and convert to a readable Uuid string
Format a hex string to uuid
const utils = require('larvitutils'),
uuid = utils.formatUuid(' f9684592b24542fa88c69f16b9236ac3'); // Notice the starting space getting trimmed away
console.log(uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
hrtimeToMs()
Used to convert hrtime() calls to milliseconds, since hrtime() output is messy (seconrds + nanoseconrds)
Usage:
const utils = require('larvitutils'),
startTime = process.hrtime();
setTimeout(function() {
console.log('benchmark took %d ms', utils.hrtimeToMs(startTime, 4));
// benchmark took 34.0005 ms
}, 34);
Uuid string to buffer
const utils = require('larvitutils'),
uuidStr = 'f9684592-b245-42fa-88c6-9f16b9236ac3';
utils.uuidToBuffer(uuidStr); // Will return a buffer
Replace all for strings
const utils = require('larvitutils'),
str = 'f9684592-b245-42fa-88c6-9f16b9236ac3';
utils.replaceAll('-', '_', str); // f9684592_b245_42fa_88c6_9f16b9236ac3