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

kit

v2.0.31

Published

A lightweight TypeScript utility library with Russian pluralization, object/array flattening, and utility types

Readme

npm version npm downloads GitHub stars License

kit

A lightweight TypeScript library providing some specific utilities and types.

Installation

npm install kit
# or
yarn add kit
# or
bun add kit

Usage

import { flatten } from 'kit';
// or
import flatten from 'kit/flatten';

Utilities

callAll

Utility that calls all provided functions with the same arguments, useful for combining multiple event handlers or callbacks.

import { callAll } from 'kit';

// Combine multiple event handlers
const handleClick = (event: MouseEvent) => console.log('Click!');
const handleAnalytics = (event: MouseEvent) => analytics.track('click', event);
const handleLogging = (event: MouseEvent) => logger.log('User clicked', event);

// Call all handlers with one call
const combinedHandler = callAll(handleClick, handleAnalytics, handleLogging);
button.addEventListener('click', combinedHandler);

// Or call them directly
callAll(handleClick, handleAnalytics, handleLogging)(event);

// Works with any number of functions
const singleHandler = callAll(handleClick); // Returns handleClick as-is
const noHandlers = callAll(); // Returns a no-op function

kindOf

Returns the specific type/kind of a value with enhanced type detection beyond typeof.

import { kindOf, Kind } from 'kit';

kindOf(null); // => Kind.Null
kindOf(undefined); // => Kind.Undefined
kindOf(NaN); // => Kind.Nan

kindOf('string'); // => Kind.String
kindOf(123); // => Kind.Number
kindOf(true); // => Kind.Boolean
kindOf(Symbol()); // => Kind.Symbol
kindOf([]); // => Kind.Array
kindOf(arguments); // => Kind.ArrayLike

kindOf(() => {}); // => Kind.Function

kindOf(new Set()); // => Kind.Set
kindOf(new Map()); // => Kind.Map
kindOf(new Date()); // => Kind.Date
kindOf(/regex/); // => Kind.RegExp
kindOf(Buffer.from('test')); // => Kind.Buffer

kindOf(class Test {}); // => Kind.Class
kindOf(Set); // => Kind.Class
kindOf(Map); // => Kind.Class
kindOf(Date); // => Kind.Class

pluralize

Russian pluralization utility that returns the correct word form based on count.

import { pluralize } from 'kit';

// Basic usage with three forms: nominative, genitive singular, genitive plural
pluralize(0, 'ящик', 'ящика', 'ящиков'); // => 'ящиков'
pluralize(1, 'ящик', 'ящика', 'ящиков'); // => 'ящик'
pluralize(2, 'ящик', 'ящика', 'ящиков'); // => 'ящика'
pluralize(5, 'ящик', 'ящика', 'ящиков'); // => 'ящиков'

// Can also use arrays
pluralize(1, ['ящик', 'ящика', 'ящиков']); // => 'ящик'
pluralize(2, ['ящик', 'ящика', 'ящиков']); // => 'ящика'

flatten

Flattens an object or an array.

import { flatten } from 'kit';

// Flatten an array
const flatNumbers = flatten([1, [2, [3, 4]]]); // => [1, 2, 3, 4]

// Flatten an object
const flatObject = flatten({
  a: 1,
  b: {
    c: {
      d: 2
    },
    d: [3, 4]
  }
}); // => { a: 1, 'b.c.d': 2, 'b.d': [3, 4]}

// Flatten an object with arrays unpacking
const flatObject = flatten({
  a: 1,
  b: {
    c: {
      d: 2
    },
    d: [3, 4]
  }
}); // => { a: 1, 'b.c.d': 2, 'b.d.0': 3, 'b.d.1': 4}

debugString

Converts any value into a readable string representation for debugging purposes. Guarantees to return a string representation of any value, first attempting to serialize it using JSON, and in case of failure, obtaining the most human-readable string description.

import { debugString } from 'kit';

// Primitives
debugString(123); // => '123'
debugString('hello'); // => 'hello'
debugString(null); // => 'null'
debugString(undefined); // => 'undefined'
debugString(true); // => 'true'
debugString(NaN); // => 'NaN'

// Functions
debugString(() => {}); // => '[function ()]'
debugString((a: number) => a); // => '[function (a)]'
debugString(function test(a: number) {}); // => '[function test(a)]'

// Arrays
debugString([1, 2, 3]); // => '[1, 2, 3]'

// Objects
debugString({ a: 1, b: 2, doc: document }); /** => {
  "a": 1,
  "b": 2,
  "doc": [object HTMLDocument]
} */

// Classes
debugString(class Person {}); // => '[class Person]'
debugString(Date); // => '[class Date]'

// Symbols
debugString(Symbol('test')); // => 'Symbol(test)'

// HTMl Elements
debugString(document.body); // => '<body class="dark-theme"><h1>...</body>'

argsNames

Extracts parameter names from a function as an array of strings.

import { argsNames } from 'kit';

// Extract parameter names from arrow functions
argsNames(() => {}); // => []
argsNames((a: number) => a); // => ['a']

// Extract parameter names from regular functions
argsNames(function (a: number, b: number) {
  return a + b;
}); // => ['a', 'b']

EventEmitter

A simple event emitter implementation for handling custom events.

import { EventEmitter } from 'kit';

const emitter = new EventEmitter();

// Subscribe to events
emitter.on('user:login', (user: User) => {
  console.log('User logged in:', user);
});

// Emit events
emitter.emit('user:login', { id: 1, name: 'John' });

// Emit once
emitter.once('user:login', { id: 1, name: 'John' });

// Remove listener
emitter.off('user:login', handler);

// Remove all listeners of event
emitter.removeAllListeners('user:login');
// or to empty event emitter
emitter.removeAllListeners();

isClass

Checks if a value is a class constructor function.

import { isClass } from 'kit';

// Class constructors
isClass(class Person {}); // => true
isClass(Date); // => true
isClass(Set); // => true
isClass(Map); // => true

// Regular functions
isClass(() => {}); // => false
isClass(function() {}); // => false
isClass(function parse() {}); // => false
isClass(function Person() {}); // => true

// Other values
isClass('string'); // => false
isClass(123); // => false
isClass({}); // => false
isClass([]); // => false

Types & Enums

Kind

Enum containing possible kind of value variants:

enum Kind {
  Null = 'null',
  String = 'string',
  Undefined = 'undefined',
  Array = 'array',
  ArrayLike = 'arraylike',
  Class = 'class',
  Function = 'function',
  Symbol = 'symbol',
  Number = 'number',
  Date = 'date',
  Boolean = 'boolean',
  RegExp = 'regexp',
  Buffer = 'buffer',
  NaN = 'nan',
  Set = 'set',
  Map = 'map',
  ArrayBuffer = 'arraybuffer',
  Error = 'error',
  Promise = 'promise',
  WeakMap = 'weakmap',
  WeakSet = 'weakset',
  Int8Array = 'int8array',
  Uint8Array = 'uint8array',
  Uint8ClampedArray = 'uint8clampedarray',
}

Primitive

Simple type for primitives.

import { Primitive } from 'kit';

type MyObject = {
  var1: Primitive;
};

License

MIT