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

javascript-utils-library

v1.0.2

Published

A professional utility package providing common JavaScript operations for arrays, strings, objects, async operations, validation, and dates

Readme

JavaScript Utils

A professional utility package providing common JavaScript operations for arrays, strings, objects, async operations, validation, and dates.

Installation

npm install javascript-utils

Features

  • Array Utilities: Chunk, unique, flatten, and sort arrays
  • String Utilities: Case conversion, truncation, email validation
  • Object Utilities: Deep merge, pick, omit, and empty checks
  • Async Utilities: Delay, retry, and batch operations
  • Validation Utilities: URL validation, schema validation, empty checks
  • Date Utilities: Formatting, relative time, and date checks
  • TypeScript Support: Full TypeScript definitions included
  • Zero Dependencies: No external dependencies

Usage

Array Utilities

const { chunk, unique, flatten, sortBy } = require('javascript-utils');

// Chunk array into smaller arrays
const chunks = chunk([1, 2, 3, 4, 5, 6], 2);
// Returns: [[1, 2], [3, 4], [5, 6]]

// Remove duplicates
const uniqueItems = unique([1, 2, 2, 3, 3, 3]);
// Returns: [1, 2, 3]

// Flatten nested array
const flat = flatten([1, [2, [3, 4]], 5]);
// Returns: [1, 2, 3, 4, 5]

// Sort array by key
const sorted = sortBy(
  [{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }],
  'age'
);
// Returns sorted array by age

String Utilities

const { toCamelCase, toKebabCase, truncate, isValidEmail } = require('javascript-utils');

// Convert to camel case
toCamelCase('hello-world'); // Returns: 'helloWorld'

// Convert to kebab case
toKebabCase('helloWorld'); // Returns: 'hello-world'

// Truncate string
truncate('This is a long string', 10);
// Returns: 'This is a ...'

// Validate email
isValidEmail('[email protected]'); // Returns: true

Object Utilities

const { deepMerge, pick, omit, isEmpty } = require('javascript-utils');

// Deep merge objects
const merged = deepMerge(
  { a: { b: 1, c: 2 } },
  { a: { b: 3 } }
);
// Returns: { a: { b: 3, c: 2 } }

// Pick specific keys
const picked = pick({ a: 1, b: 2, c: 3 }, ['a', 'b']);
// Returns: { a: 1, b: 2 }

// Omit specific keys
const omitted = omit({ a: 1, b: 2, c: 3 }, ['c']);
// Returns: { a: 1, b: 2 }

// Check if empty
isEmpty({}); // Returns: true

Async Utilities

const { delay, retry, batch } = require('javascript-utils');

// Delay execution
await delay(1000); // Wait 1 second

// Retry async function
const result = await retry(
  async () => await fetchData(),
  3, // 3 retries
  1000 // 1 second delay
);

// Batch async operations
const results = await batch(
  [1, 2, 3, 4, 5],
  async (item) => await processItem(item),
  2 // Process 2 items at a time
);

Validation Utilities

const { isValidUrl, validateSchema, isEmptyValue } = require('javascript-utils');

// Validate URL
isValidUrl('https://example.com'); // Returns: true

// Validate object schema
const isValid = validateSchema(
  { name: 'John', age: 30 },
  { name: 'string', age: 'number' }
);
// Returns: true

// Check if empty
isEmptyValue(null); // Returns: true
isEmptyValue(''); // Returns: true
isEmptyValue([]); // Returns: true

Date Utilities

const { formatDate, fromNow, isToday } = require('javascript-utils');

// Format date
formatDate(new Date(), 'YYYY-MM-DD');
// Returns: '2024-01-15'

// Get relative time
fromNow(new Date(Date.now() - 3600000));
// Returns: '1 hour ago'

// Check if date is today
isToday(new Date()); // Returns: true

Using with Classes

You can also use the utility classes directly:

const { ArrayUtils, StringUtils, ObjectUtils } = require('javascript-utils');

// Use class methods
const chunks = ArrayUtils.chunk([1, 2, 3, 4], 2);
const camelCase = StringUtils.toCamelCase('hello-world');
const merged = ObjectUtils.deepMerge({ a: 1 }, { b: 2 });

TypeScript Support

Full TypeScript definitions are included:

import { chunk, unique, deepMerge } from 'javascript-utils';

const numbers: number[] = [1, 2, 3, 4, 5];
const chunks: number[][] = chunk(numbers, 2);

API Reference

Array Utils

  • chunk(array, size) - Chunk array into smaller arrays
  • unique(array, key?) - Remove duplicates from array
  • flatten(array, depth?) - Flatten nested array
  • sortBy(array, key, descending?) - Sort array by key

String Utils

  • toCamelCase(str) - Convert to camelCase
  • toKebabCase(str) - Convert to kebab-case
  • toPascalCase(str) - Convert to PascalCase
  • truncate(str, length, suffix?) - Truncate string
  • isValidEmail(str) - Validate email

Object Utils

  • deepMerge(...objects) - Deep merge objects
  • pick(obj, keys) - Pick keys from object
  • omit(obj, keys) - Omit keys from object
  • isEmpty(obj) - Check if object is empty

Async Utils

  • delay(ms) - Delay execution
  • retry(fn, retries?, delay?) - Retry async function
  • batch(items, fn, batchSize?) - Batch async operations

Validation Utils

  • isValidUrl(url) - Validate URL
  • validateSchema(obj, schema) - Validate object schema
  • isEmptyValue(value) - Check if value is empty

Date Utils

  • formatDate(date, format?) - Format date
  • fromNow(date) - Get relative time
  • isToday(date) - Check if date is today

Requirements

  • Node.js >= 14.0.0

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.