
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
A lightweight TypeScript utility library with Russian pluralization, object/array flattening, and utility types
A lightweight TypeScript library providing some specific utilities and types.
npm install kit
# or
yarn add kit
# or
bun add kit
import { flatten } from 'kit';
// or
import flatten from 'kit/flatten';
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
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
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, ['ящик', 'ящика', 'ящиков']); // => 'ящика'
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}
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>'
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']
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();
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
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',
}
Simple type for primitives.
import { Primitive } from 'kit';
type MyObject = {
var1: Primitive;
};
MIT
FAQs
A lightweight TypeScript utility library with Russian pluralization, object/array flattening, and utility types
The npm package kit receives a total of 176 weekly downloads. As such, kit popularity was classified as not popular.
We found that kit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.