npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

like-util

v0.2.8

Published

Reusable utility code

Downloads

6

Readme

like-util

Reusable utility code.

// crypto
const { createHash, createHmac, passwordHash } = require('like-util')
const { randomBytes, randomHex, randomFloat, randomInt } = require('like-util')

// network
const { ip2int, int2ip } = require('like-util')

// errors
const { ErrorHandler } = require('like-util')

// date
const { dateToSeconds, dateToLocale } = require('like-util')

// others
const { sleep, isObjectEqual } = require('like-util')

// shared object
const { shared } = require('like-util')
const shared = require('like-util/shared')

Install

npm i like-util

Examples

crypto

// hashing
createHash('sha1', 'secret text') // => '43de199bc1b7196be767cce745baece4dc95fbf2'
createHmac('sha1', 'secret key', 'secret text') // => '85c15fbb5b1c3afbd645f99977a260c4984086f8'

// password hash
const hashed = await passwordHash('hwy123') // 108 len EcM4...3Fr4+I=
const result = await passwordHash('hwy123', hashed) // EcM4...3Fr4+I= (same output)
const match = hashed === result // true

// All are cryptographically secure:
await randomBytes(4) // => <Buffer 52 62 03 01>
await randomHex(4) // => 'f3a66fa0' (bytes to hex are double in size)
await randomFloat() // => 0.29868882046557754
await randomInt(0, 3) // => 0, 1 or 2
await randomNumber(0, 3) // => 0, 1, 2 or 3

Notice that randomInt(min, max): min is inclusive and max is exclusive
randomFloat() is like Math.random(): 0 (inclusive) and 1 (exclusive)

network

ip2int('142.250.188.14') // => 2398796814
int2ip(2398796814) // => '142.250.188.14'

ip2int('113.5.67.242') // => 1896170482
int2ip(1896170482) // => '113.5.67.242'

ip2int('0.0.0.0') // => 0
ip2int('0.0.0.255') // => 255
ip2int('0.0.255.255') // => 65535

Date

dateToSeconds() // => 1647838051

dateToLocale() // => '21/03/2022, 01:47:21'
dateToLocale({ year: false, second: false }) // => '21/03, 01:47'
dateToLocale({ time: 1647838051337, millis: true }) // => '21/03/2022, 01:47:31.337'

Others

await sleep(1000)

isObjectEqual({ a: 1, b: 2 }, { a: 1, b: 2 }) // => true
isObjectEqual({ a: 1, b: 2 }, { b: 2, a: 1 }) // => true (still true)
isObjectEqual({ a: { b: { c: 1 } } }, { a: { b: { c: 1 } } }) // => true
isObjectEqual({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 }) // => false

const obj = { a: 1, b: function () {} }
isObjectEqual(obj, JSON.parse(JSON.stringify(obj))) // => false

Shared object

It's just a quick access for an object.
At the start-up of your app, you can initialize it and then use it:

// app.js
const shared = require('like-util/shared')
shared.web3 = new Web3()

// route.js
const { web3 } = require('like-util/shared')
// ...

ErrorHandler, optionally with yup

It can help you handling errors in your HTTP server:

const express = require('express')
require('express-async-errors')
const { ErrorHandler } = require('like-util')
const yup = require('yup')

const app = express()

// I really like yup, it's very easy to create schemas for requests
const schema = yup.object().shape({
  email: yup.string().default('').min(5).max(128),
  password: yup.string().default('').min(4),
  repassword: yup.string().default('').oneOf([yup.ref('password')])
})

app.post('/signup', async function (req, res) {
  // We don't need to try-catch,
  // in case there is an error at validation, it will send status 400
  const body = await schema.validate(req.body)

  if (body.password !== body.repassword) {
    throw ErrorHandler(400, 'The passwords are not equals')
  }

  // Let's say this operation throws an error which is a critical error,
  // it will send status 500 with a generic message to avoid leaking internal errors
  await db.insert('users', { ... })

  res.send('ok')
})

app.use(ErrorHandler.middleware) // handle errors

app.listen(3000, () => console.log('listening'))

Tests

There are no tests yet

License

Code released under the MIT License.