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 🙏

© 2025 – Pkg Stats / Ryan Hefner

dxkit-js

v1.1.12

Published

Modern TypeScript utility library with tree-shaking support - Array, String, Number, Network, Sleep, and JWT utilities for JavaScript and TypeScript projects

Readme

Advanced JavaScript Kit

Modern TypeScript utility library with tree-shaking support - Comprehensive collection of array, string, number, network, sleep, and JWT utilities for JavaScript and TypeScript projects.

npm version TypeScript MIT License Tree Shakable

A collection of advanced JavaScript/TypeScript utility functions for modern development.

🌐 Environment Compatibility

This library is designed to work across multiple JavaScript environments with platform-specific exports:

  • dxkit-js - Universal utilities that work in Node.js, Browser, and Web Workers
  • 🟡 dxkit-js/node - Node.js-only utilities + all universal utilities
  • 🟢 dxkit-js/browser - Browser-optimized utilities + all universal utilities
  • 📦 Individual imports - dxkit-js/module/function for maximum tree-shaking

Breaking Change (v1.1.0): Node.js-only modules (network, jwt) are no longer exported from the main package. Use dxkit-js/node instead.

Features

  • 🚀 TypeScript Support - Full TypeScript support with type definitions
  • 📦 Tree Shakable - Import only what you need
  • 🧪 Well Tested - Comprehensive test coverage
  • 📖 Well Documented - JSDoc comments for all functions
  • 🔧 Modern Build - Built with tsup for optimal bundling
  • 💡 Excellent IDE Support - Full auto-completion and IntelliSense support
  • 🌐 Cross-Platform - Works in Node.js, browsers, and web workers

Installation

npm install dxkit-js

Alternative package managers:

# Yarn
yarn add dxkit-js

# pnpm
pnpm add dxkit-js

# Bun
bun add dxkit-js

Usage

Universal Modules (Work Everywhere)

For maximum compatibility, import universal modules that work in Node.js, Browser, and Web Workers:

import { chunk, capitalize, clamp, sleep, convertToSeconds } from 'dxkit-js';

// Array utilities
const chunkedArray = chunk([1, 2, 3, 4, 5], 2);
// Result: [[1, 2], [3, 4], [5]]

// String utilities
const capitalizedString = capitalize('hello world');
// Result: "Hello world"

// Number utilities
const clampedNumber = clamp(15, 0, 10);
// Result: 10

// Sleep utilities
await sleep({ seconds: 2, milliseconds: 500 }); // Sleep for 2.5 seconds

// Time utilities
const seconds = convertToSeconds({ minutes: 5, seconds: 30 });
// Result: 330 (seconds)

Node.js-Only Modules

For Node.js-specific functionality (network operations, JWT handling):

import { isPortInUse, findAvailablePort, jwtSign, jwtVerify } from 'dxkit-js/node';

// Network utilities (Node.js only)
const portInUse = await isPortInUse(3000);
const availablePort = await findAvailablePort({ startPort: 8000 });

// JWT utilities (Node.js only)
const token = jwtSign({ userId: '123' }, 'your-secret-key');
const payload = jwtVerify(token, 'your-secret-key');

// Note: Universal utilities are also available from /node for convenience
import { chunk, capitalize } from 'dxkit-js/node';

Browser-Only Modules

For browser-specific optimizations (currently same as universal, but future-proof):

import { chunk, capitalize, clamp, sleep, convertToSeconds } from 'dxkit-js/browser';

// Currently includes all universal utilities
// Future browser-specific features will be added here

Environment-Specific Usage

import { 
  isNodeEnvironment, 
  EnvironmentError 
} from 'dxkit-js';

// Check environment before using Node.js-only features
if (isNodeEnvironment()) {
  // Use Node.js-specific imports
  const { isPortInUse } = await import('dxkit-js/node');
  const { jwtSign } = await import('dxkit-js/node');
  
  const portInUse = await isPortInUse(3000);
  const token = jwtSign({ userId: '123' }, 'secret');
} else {
  console.log('Using browser-compatible features only');
  // Use browser/universal imports
  const { chunk, capitalize } = await import('dxkit-js/browser');
}

Error Handling

import { jwtVerify, EnvironmentError } from 'dxkit-js/node';

try {
  const payload = jwtVerify(token, secret);
} catch (error) {
  if (error instanceof EnvironmentError) {
    console.log(`Feature not available: ${error.message}`);
    console.log(`Required: ${error.requiredEnvironment}, Current: ${error.currentEnvironment}`);
  }
}

Tree-shaking Support

You can also import individual functions for optimal tree-shaking:

// Universal utilities - individual imports
import { chunk } from 'dxkit-js/array/chunk';
import { capitalize } from 'dxkit-js/string/capitalize';
import { clamp } from 'dxkit-js/number/clamp';
import { sleep } from 'dxkit-js/sleep/sleep';
import { convertToSeconds } from 'dxkit-js/time/time';

// Node.js-only utilities - individual imports  
import { isPortInUse, findAvailablePort } from 'dxkit-js/network/port';
import { jwtSign, jwtVerify } from 'dxkit-js/jwt/jwt';

// Platform-specific bundles (recommended)
import { chunk, capitalize, clamp } from 'dxkit-js';        // Universal only
import { isPortInUse, jwtSign, chunk } from 'dxkit-js/node';     // Node.js + Universal
import { chunk, capitalize, sleep } from 'dxkit-js/browser';   // Browser + Universal

📋 Available Modules

✅ Universal Modules (Node.js + Browser + Web Workers)

| Module | Functions | Description | |--------|-----------|-------------| | array/chunk | chunk | Split arrays into chunks of specified size | | string/capitalize | capitalize, capitalizeWords | String capitalization utilities | | number/clamp | clamp, inRange | Number range utilities | | sleep/sleep | sleep | Promise-based sleep with multiple time units | | time/time | convertToSeconds | Time conversion utilities | | utils/environment | isNodeEnvironment, isBrowserEnvironment, getEnvironment | Environment detection |

🟡 Node.js Only Modules

| Module | Functions | Description | |--------|-----------|-------------| | network/port | isPortInUse, isPortAvailable, findAvailablePort | Port checking and management | | jwt/jwt | jwtSign, jwtVerify | JSON Web Token operations |

Note: Node.js-only modules will throw EnvironmentError when used in non-Node.js environments.

TypeScript Configuration

For optimal compatibility with this package, ensure your tsconfig.json uses modern module resolution:

{
  "compilerOptions": {
    "moduleResolution": "bundler", // or "node16"/"nodenext"
    "module": "ESNext", // or "Node16"
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true
  }
}

Troubleshooting Import Issues

If you encounter module resolution errors like:

Cannot find module 'dxkit-js/string/capitalize' or its corresponding type declarations

Try these solutions:

  1. Update your TypeScript configuration to use modern module resolution (see above)
  2. Ensure you're using a recent Node.js version (16+ recommended)
  3. Copy the example configuration from example-tsconfig-for-consumers.json in this package
  4. As a workaround, you can import directly from the dist folder:
    import { capitalize } from "dxkit-js/dist/string/capitalize.js";

IDE Support

This package provides excellent IDE support with:

  • Auto-completion for all functions and their parameters
  • Type checking with full TypeScript support
  • JSDoc documentation shown in hover tooltips
  • Auto-import suggestions when typing function names

API Reference

📚 Package Documentation

For comprehensive documentation with examples, advanced usage patterns, and best practices, see the individual package documentation:

Quick Reference

Array Utilities

  • chunk<T>(array: T[], size: number): T[][] - Splits an array into chunks of a specified size

String Utilities

  • capitalize(str: string): string - Capitalizes the first letter of a string
  • capitalizeWords(str: string): string - Capitalizes the first letter of each word

Number Utilities

  • clamp(number: number, lower: number, upper: number): number - Clamps a number within bounds
  • inRange(number: number, lower: number, upper: number): boolean - Checks if number is in range

Sleep Utilities

  • sleep(params: TSleepParams): Promise<void> - Advanced sleep with flexible options
  • sleepMs(ms: number): Promise<void> - Sleep for milliseconds
  • sleepSeconds(seconds: number): Promise<void> - Sleep for seconds
  • sleepMinutes(minutes: number): Promise<void> - Sleep for minutes
  • sleepUntil(unixTimestamp: number): Promise<void> - Sleep until timestamp

Network Utilities

  • isPortInUse(port: number, options?): Promise<boolean> - Check if port is in use
  • isPortAvailable(port: number, options?): Promise<boolean> - Check if port is available
  • findAvailablePort(options?): Promise<number> - Find an available port
  • checkMultiplePorts(ports: number[], options?): Promise<Map<number, boolean>> - Check multiple ports
  • waitForPort(port: number, state: string, options?): Promise<void> - Wait for port state

JWT Utilities

  • jwtSign<T>(payload: T, secret: string, options?): Promise<string> - Sign JWT token
  • jwtVerify<T>(token: string, secret: string, options?): Promise<T | null> - Verify JWT token
  • jwtDecode<T>(token: string, options?): T | null - Decode JWT without verification
  • jwtIsExpired(token: string): boolean | null - Check if token is expired
  • jwtTimeUntilExpiry(token: string): number | null - Get time until expiration

Development

# Install dependencies
npm install

# Build the project
npm run build

# Watch mode for development
npm run dev

# Type checking
npm run type-check

# Run tests
npm run test

License

MIT