
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@oxog/kindof
Advanced tools
Zero-dependency advanced type detection library with TypeScript support, plugin system, and 100% test coverage
Zero-dependency advanced type detection library with TypeScript support, plugin system, and 100% test success rate.
npm install @oxog/kindof
yarn add @oxog/kindof
pnpm add @oxog/kindof
import { kindOf } from '@oxog/kindof';
// Basic type detection
kindOf(42); // 'number'
kindOf('hello'); // 'string'
kindOf([1, 2, 3]); // 'array'
kindOf(new Date()); // 'date'
kindOf(new Map()); // 'map'
kindOf(async () => {}); // 'asyncfunction'
kindOf(new Int32Array()); // 'int32array'
// TypeScript support with type inference
const value: unknown = 'hello';
if (kindOf(value) === 'string') {
// TypeScript knows value is string here
console.log(value.toUpperCase());
}
Detects all JavaScript types including:
Primitives: undefined, null, boolean, number, string, symbol, bigint
Objects: object, array, function, date, regexp, error
Collections: map, set, weakmap, weakset
Modern Types: promise, generatorfunction, asyncfunction, asyncgeneratorfunction, proxy, dataview, arraybuffer, sharedarraybuffer
Typed Arrays: int8array, uint8array, uint8clampedarray, int16array, uint16array, int32array, uint32array, float32array, float64array, bigint64array, biguint64array
Special Types: arguments, buffer, stream, eventemitter, element, node, window, global
import { isString, isNumber, isArray, isPromise } from '@oxog/kindof';
// Type guards with TypeScript inference
if (isString(value)) {
// TypeScript knows value is string
}
if (isArray(value)) {
// TypeScript knows value is array
value.forEach(item => console.log(item));
}
// Generic type checking
import { isType } from '@oxog/kindof';
if (isType(value, 'date')) {
// TypeScript knows value is Date
console.log(value.getFullYear());
}
import { getDetailedType } from '@oxog/kindof';
const details = getDetailedType([1, 2, 3]);
// {
// type: 'array',
// constructor: 'Array',
// prototype: 'Array',
// isPrimitive: false,
// isBuiltIn: true,
// isNullish: false,
// isIterable: true,
// isAsync: false,
// customType: null,
// metadata: { length: 3 }
// }
import { coerceType, toString, toNumber, toBoolean } from '@oxog/kindof';
coerceType('42', 'number'); // 42
coerceType(42, 'string'); // '42'
coerceType(1, 'boolean'); // true
toString(42); // '42'
toNumber('42'); // 42
toBoolean(1); // true
import { validateSchema } from '@oxog/kindof';
const schema = {
name: 'string',
age: 'number',
tags: ['string']
};
const result = validateSchema({
name: 'John',
age: 30,
tags: ['admin', 'user']
}, schema);
if (result.valid) {
console.log('Valid!');
} else {
console.log('Errors:', result.errors);
}
import { fastKindOf } from '@oxog/kindof';
// Ultra-fast detection for common types
fastKindOf('hello'); // 'string'
fastKindOf(42); // 'number'
fastKindOf([]); // 'array'
fastKindOf({}); // 'object'
import { kindOfMany } from '@oxog/kindof';
const types = kindOfMany(['hello', 42, [], {}]);
// ['string', 'number', 'array', 'object']
import { enableCache, disableCache, clearCache } from '@oxog/kindof';
enableCache(); // Enable caching for better performance
disableCache(); // Disable caching
clearCache(); // Clear the cache
kindOf(value: unknown): stringMain type detection function. Returns a string representing the type of the value.
fastKindOf(value: unknown): stringFast type detection optimized for common primitive types and basic objects.
kindOfMany(values: unknown[]): string[]Batch type detection for multiple values.
getDetailedType(value: unknown): DetailedTypeReturns comprehensive type information including metadata.
All type guards follow the pattern is{Type}(value: unknown): value is {Type}.
Examples: isString, isNumber, isArray, isPromise, isMap, etc.
validateSchema(value: unknown, schema: SchemaType, options?: ValidationOptions): ValidationResultValidates a value against a schema definition.
createValidator(schema: SchemaType, options?: ValidationOptions): (value: unknown) => ValidationResultCreates a reusable validator function.
coerceType<T>(value: unknown, targetType: T): TypeMap[T] | nullAttempts to convert a value to the target type.
toString(value: unknown): stringConverts any value to a string representation.
toNumber(value: unknown): number | nullConverts a value to a number or returns null if impossible.
toBoolean(value: unknown): booleanConverts a value to a boolean using JavaScript truthiness rules.
// Before (kind-of)
const kindOf = require('kind-of');
kindOf(42); // 'number'
// After (@oxog/kindof)
import { kindOf } from '@oxog/kindof';
kindOf(42); // 'number'
// Additional features
import { isNumber, validateSchema } from '@oxog/kindof';
@oxog/kindof vs alternatives:
Primitive types: 3.2x faster than kind-of
Objects: 2.8x faster than kind-of
Arrays: 4.1x faster than kind-of
Modern types: 5.2x faster than kind-of
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)MIT © Ersin Koç
See CHANGELOG.md for details.
FAQs
Zero-dependency advanced type detection library with TypeScript support, plugin system, and 100% test coverage
The npm package @oxog/kindof receives a total of 0 weekly downloads. As such, @oxog/kindof popularity was classified as not popular.
We found that @oxog/kindof 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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.