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

Misc utils

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
increased by75.8%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Dependencies

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 or false on failure

Replace all for strings

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

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

Validate an uuid string

const	utils	= 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

Check if input is an int

const	utils	= require('larvitutils');

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

Instances

Just a very simple object intended to keep instances of objects across moduels.

file 1:

const	utils	= require('larvitutils');

let foo;

function Foo() {}

foo = new Foo();
foo.bar = 'baz';

utils.instances.foo = foo;

file 2:

const	utils	= require('larvitutils'),
	foo	= utils.instances.foo;

console.log(foo.bar); // 'baz'

Keywords

FAQs

Package last updated on 17 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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