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

@kedata-software/toolkit-js

v0.1.2

Published

A collection of JavaScript utility functions. Safe to use in both Node.js and the browser.

Readme

@kedata-software/toolkit-js

A collection of useful TypeScript functions.

Installation

# npm
npm install @kedata/toolkit-js

# yarn
yarn add @kedata/toolkit-js

# pnpm
pnpm add @kedata/toolkit-js

Usage

import { functionName } from '@kedata/toolkit-js';

Functions

convertBytes

An object with methods to convert bytes to other units (KB, MB, GB).

Methods:

  • toKB(bytes: number): number
  • toMB(bytes: number): number
  • toGB(bytes: number): number

Example:

import { convertBytes } from '@kedata/toolkit-js';

convertBytes.toKB(1024); // 1
convertBytes.toMB(1048576); // 1
convertBytes.toGB(1073741824); // 1

createBasicToken

Creates a base64 encoded basic token from a username and password.

Parameters:

  • params: { username: string; password: string }

Example:

import { createBasicToken } from '@kedata/toolkit-js';

const token = createBasicToken({ username: 'test', password: 'password' });
// token will be 'dGVzdDpwYXNzd29yZA=='

dataAttrBoolean

Returns an empty string for a truthy value, otherwise undefined. Useful for data attributes that should only be present when a condition is true.

Parameters:

  • value?: unknown

Example:

import { dataAttrBoolean } from '@kedata/toolkit-js';

dataAttrBoolean(true); // ''
dataAttrBoolean(false); // undefined

decodeBasicToken

Decodes a base64 encoded basic token and returns the username and password.

Parameters:

  • token: string

Example:

import { decodeBasicToken } from '@kedata/toolkit-js';

const credentials = decodeBasicToken('dGVzdDpwYXNzd29yZA==');
// credentials will be { username: 'test', password: 'password' }

defaultArray

Returns the array if it's not null or undefined, otherwise returns an empty array.

Parameters:

  • value: T[] | undefined | null

Example:

import { defaultArray } from '@kedata/toolkit-js';

defaultArray([1, 2, 3]); // [1, 2, 3]
defaultArray(null); // []
defaultArray(undefined); // []

defaultObject

Returns the object if it's not null or undefined, otherwise returns an empty object.

Parameters:

  • value: T | undefined | null

Example:

import { defaultObject } from '@kedata/toolkit-js';

defaultObject({ a: 1 }); // { a: 1 }
defaultObject(null); // {}
defaultObject(undefined); // {}

delayAsync

Delays execution for a specified number of milliseconds.

Parameters:

  • ms: number

Example:

import { delayAsync } from '@kedata/toolkit-js';

await delayAsync(1000); // waits 1 second

getBytes

An object with methods to convert other units (KB, MB, GB) to bytes.

Methods:

  • fromKB(KB: number): number
  • fromMB(MB: number): number
  • fromGB(GB: number): number

Example:

import { getBytes } from '@kedata/toolkit-js';

getBytes.fromKB(1); // 1024
getBytes.fromMB(1); // 1048576
getBytes.fromGB(1); // 1073741824

isObjectEmpty

Checks if an object is empty.

Parameters:

  • obj?: Record<any, any> | null

Example:

import { isObjectEmpty } from '@kedata/toolkit-js';

isObjectEmpty({}); // true
isObjectEmpty({ a: 1 }); // false

nameInitials

Generates initials from a name.

Parameters:

  • name: string

Example:

import { nameInitials } from '@kedata/toolkit-js';

nameInitials('John Doe'); // 'JD'
nameInitials('John'); // 'J'

omitProps

Omits specified properties from an object.

Parameters:

  • obj: T
  • keys: K[]

Example:

import { omitProps } from '@kedata/toolkit-js';

const obj = { a: 1, b: 2, c: 3 };
omitProps(obj, ['b', 'c']); // { a: 1 }

parseEmail

Parses an email address and returns the username and host.

Parameters:

  • email: string

Example:

import { parseEmail } from '@kedata/toolkit-js';

parseEmail('[email protected]'); // { username: 'test', host: 'example.com' }

toSafeNumber

Converts a string to a number, returning 0 if the conversion results in NaN.

Parameters:

  • value: string

Example:

import { toSafeNumber } from '@kedata/toolkit-js';

toSafeNumber('123'); // 123
toSafeNumber('abc'); // 0

tryAsync

Wraps an async function in a try-catch block and returns a tuple with the result and error.

Parameters:

  • fn: () => Promise<D>

Example:

import { tryAsync } from '@kedata/toolkit-js';

const [data, error] = await tryAsync(() => Promise.resolve('success'));
// data will be 'success', error will be undefined

const [data2, error2] = await tryAsync(() => Promise.reject('failure'));
// data2 will be undefined, error2 will be 'failure'