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

@vsokolov/utils

v0.31.4

Published

Various TypeScript/JavaScripts utils functions for node and browser

Readme

@vsokolov/utils

NPM version License: MIT npm downloads semantic-release

A comprehensive collection of TypeScript/JavaScript utility functions for both Node.js and browser environments. This library provides a wide range of helper functions for common programming tasks, including array manipulation, date handling, string operations, and more.

Features

  • Array Utilities: Flatten, sort, filter, and manipulate arrays with ease
  • Date/Time Handling: Comprehensive date parsing, formatting, and manipulation
  • String Operations: Common string manipulation and validation functions
  • Type Checking: Type-safe type checking utilities
  • Object Manipulation: Deep cloning, merging, and property manipulation
  • Browser & Node.js Support: Works in both environments
  • Fully Typed: Written in TypeScript with full type definitions
  • Tree-shakeable: Only include what you use in your bundle

Installation

Using npm:

npm install @vsokolov/utils

Using yarn:

yarn add @vsokolov/utils

Using pnpm:

pnpm add @vsokolov/utils

Usage

Importing

You can import the entire library:

import * as utils from '@vsokolov/utils';

Or import individual functions for better tree-shaking:

import { flattenArray, formatDate, isString } from '@vsokolov/utils';

Examples

Array Utilities

import { flattenArray, sortBy, unique } from '@vsokolov/utils';

// Flatten nested arrays
const nested = [1, [2, [3, [4]], 5]];
const flat = flattenArray(nested); // [1, 2, 3, 4, 5]

// Get unique values
const duplicates = [1, 2, 2, 3, 3, 3];
const uniqueValues = unique(duplicates); // [1, 2, 3]

// Sort array of objects
const users = [
    { name: 'John', age: 30 },
    { name: 'Jane', age: 25 },
    { name: 'Doe', age: 35 }
];
const sortedUsers = sortBy(users, 1, 'age'); // Sort by age in ascending order

Date Utilities

import { formatDate, getMonthList, timeAgo } from '@vsokolov/utils';

// Format date
const today = new Date();
const formatted = formatDate(today); // '2023-06-30'

// Time ago
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
const timeSince = timeAgo(yesterday); // '1 day ago'

// Get month names
const months = getMonthList(); // ['January', 'February', ...]

String Utilities

import { isEmail, slugify, truncate } from '@vsokolov/utils';

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

// Create URL-friendly slug
slugify('Hello World!'); // 'hello-world'

// Validate email
const isValid = isEmail('[email protected]'); // true

API Reference

Array

  • flattenArray<T>(array: T[]): T[] - Flatten nested arrays
  • unique<T>(array: T[]): T[] - Get unique values from array
  • sortBy(arr: Record<string, any>[], order: 1 | -1, key: string) - Sort array of objects by key
  • removeItem<T>(array: T[], values: T[]): T[] - Remove items from array
  • randomItem<T>(array: T[], count: number): T[] - Get random items from array
  • intersection<T>(arr1: T[], arr2: T[]): T[] - Get intersection of two arrays
  • countBy(array: Array<number | string>): Record<string, number> - Count occurrences of each value

Date

  • formatDate(date?: Date): string - Format date as YYYY-MM-DD
  • timeAgo(date: Date): string - Get time ago string (e.g., "2 hours ago")
  • getMonthList(): string[] - Get list of month names
  • timeStamptToDate(timestamp: string | number): string - Convert timestamp to date string
  • dateTimeToCron(date: Date): string - Convert Date to cron syntax
  • cronToDateTime(cronSyntax: string): Date - Convert cron syntax to Date

String

  • truncate(str: string, maxLength: number, suffix = '...'): string - Truncate string with ellipsis
  • slugify(str: string): string - Convert string to URL-friendly slug
  • camelToKebab(str: string): string - Convert camelCase to kebab-case
  • kebabToCamel(str: string): string - Convert kebab-case to camelCase

Object

  • deepClone<T>(obj: T): T - Deep clone an object
  • mergeDeep(target: object, ...sources: object[]): object - Deep merge objects
  • pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> - Pick properties from object
  • omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> - Omit properties from object

Type Checking

  • isString(value: any): value is string
  • isNumber(value: any): value is number
  • isObject(value: any): value is object
  • isArray(value: any): value is any[]
  • isFunction(value: any): value is Function
  • isPromise(value: any): value is Promise<any>
  • isEmail(value: string): boolean
  • isUrl(value: string): boolean

Browser Support

This library supports all modern browsers and Node.js 14+. For older browsers, you may need to include polyfills for:

  • Array.prototype.flat (or use the provided flattenArray function)
  • Object.entries
  • Object.values
  • Promise
  • URL and URLSearchParams

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you find this library useful, please consider giving it a ⭐️ on GitHub.

Changelog

See CHANGELOG.md for a list of changes in each version.