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

@emiketic/lib-utils

v1.0.1

Published

Shared utility functions: validation, color, image, JWT, phone, navigation, and more

Readme

@emiketic/lib-utils

Shared utility functions for NodeJS and NextJS. Covers validation, text, math, navigation, JWT, phone, color, image analysis, and more.

Install

npm install @emiketic/lib-utils
# or
pnpm add @emiketic/lib-utils

Entry Points

| Import path | Environment | Extra peer deps required | |---|---|---| | @emiketic/lib-utils | Isomorphic (Node + browser) | — | | @emiketic/lib-utils/server | Node.js only | — | | @emiketic/lib-utils/client | Browser + React only | chroma-js, @mantine/core, react, next |


@emiketic/lib-utils — Isomorphic utilities

Validation

import { isEmail, isValidObjectId, isValidUUID, isValidURL, isFile } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | isEmail | (value?: string) => boolean | Returns true if the string is a valid e-mail address. | | isValidObjectId | (id: string) => boolean | Returns true if the string is a valid MongoDB ObjectId (24 hex chars) or UUID v1–v5. | | isValidUUID | (id: string) => boolean | Returns true if the string is a valid UUID v1–v5. | | isValidURL | (url: string) => boolean | Returns true for valid http/https URLs, localhost, IP addresses, and domains. | | isFile | (file: unknown) => boolean | Returns true if the value is a File-like object (browser) or a Node.js Readable stream. |

Primitives

import { truncate } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | truncate | (text: string, maxLength?: number) => string | Truncates a string to maxLength chars (default 25), appending if needed. |

SSR

import { isServer, isClient } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | isServer | () => boolean | Returns true when running in a Node.js / server context. | | isClient | () => boolean | Returns true when running in the browser. |

Maths

import { formatNumberToOneDecimal } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | formatNumberToOneDecimal | (value?: number \| null) => number | Rounds a number to 1 decimal place. Returns 0 for null/undefined. |

Navigation

import { getParentFolder } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | getParentFolder | (path: string) => string | Returns the parent segment of a path string. "/a/b/c""/a/b". |

Testing

import { isStorybook } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | isStorybook | () => boolean | Returns true when the page is rendered inside Storybook (detects port 6006 or "storybook" in the URL). |

Phone

import { isValidPhone } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | isValidPhone | (phoneNumberString: string) => boolean | Returns true if the string is a valid international phone number (via libphonenumber-js). |

JWT

import { getEncodedToken, decodeToken } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | getEncodedToken | (data, secret, expiresInHours?) => Promise<unknown> | Signs a payload as a JWT using RS256. secret is a PEM private key or HMAC secret. Default expiry: 1 hour. | | decodeToken | (token, secret) => Promise<unknown> | Verifies and decodes a JWT. secret is the corresponding public key or HMAC secret. |

Location

import { getAddressFromComponents } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | getAddressFromComponents | (components: GeocoderAddressComponent[]) => AddressObject | Parses a Google Maps Geocoder address_components array into a flat object with home, postal_code, street, region, city, and country fields. |

File

import { getBase64FromUrl } from '@emiketic/lib-utils';

| Function | Signature | Description | |---|---|---| | getBase64FromUrl | (url: string, extension?: string) => Promise<string> | Fetches a remote URL and returns a base64-encoded data URI (e.g. data:image/jpeg;base64,...). |


@emiketic/lib-utils/server — Server-only utilities

Requires Node.js. Do not import in browser/client bundles.

import { getFileFromPath } from '@emiketic/lib-utils/server';

| Function | Signature | Description | |---|---|---| | getFileFromPath | (filePath: string, type?: string) => Promise<File> | Reads a file from disk and returns a File-like object compatible with browser FormData APIs. Useful for server-side form submissions. |


@emiketic/lib-utils/client — Client/browser utilities

Requires browser DOM APIs. For Next.js apps, wrap in a Client Component ("use client").

Peer dependencies: chroma-js, @mantine/core >=7, react >=18, next >=14

Color

import { getPrimaryShadeColor, getBackgroundTextColor, getBackgroundColor } from '@emiketic/lib-utils/client';

| Function | Signature | Description | |---|---|---| | getPrimaryShadeColor | (color: string) => string | Returns a full-saturation, mid-lightness (55%) version of the color — suitable as a primary theme shade. | | getBackgroundTextColor | (color?, darkenAmount?, lightenAmount?) => string | Returns a dark or light text color that contrasts well against the given background color. | | getBackgroundColor | (color?, darkenAmount?, lightenAmount?) => string | Returns a complementary background color based on luminance contrast. |

Image

import { getDominantColorFromImageUrl } from '@emiketic/lib-utils/client';

| Function | Signature | Description | |---|---|---| | getDominantColorFromImageUrl | (imageUrl, fallbackDominant?, fallbackBackground?) => Promise<{ dominant: string, background: string }> | Extracts the dominant foreground color and background color from an image via canvas pixel analysis with edge detection. Browser-only. |

Navigation (Next.js)

import useQueryParamBuilder from '@emiketic/lib-utils/client';

| Hook | Returns | Description | |---|---|---| | useQueryParamBuilder | { createQueryString, deleteParamFromQueryString } | React hook for building/modifying URL query strings. createQueryString(name, value) sets a param; deleteParamFromQueryString(name) removes one. Requires Next.js (next/navigation). |


License

MIT