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

typof

v1.0.8

Published

Infer types.

Downloads

949

Readme

Contents

About

Infer types.

Features

  • Infers multiple types
  • Infers integer and float types
  • Infers the type from a string
  • There are simple type converters

Installation

You can install it as follows.

# NPM
npm add typof

# PNPM
pnpm add typof

# Yarn
yarn add typof

# Bun
bun add typof

# Deno
deno add typof

Documentation

Tree

Briefly as follows.

Typof
│
├── typof(value)
├── string(value)
├── number(value)
├── integer(value)
├── boolean(value)
├── date(value)
├── object(value)
├── array(value)
├── _null(value)
├── _undefined(value)
│
└── type Types

Import

Briefly as follows.

import { typof } from 'typof';

Methods

typof(value)

Infer types.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | --------------------- | | value | Unknown | | Value to infer types. |

returns Types[]

Example:

// Tests are as follows. (Is this an integer?)
if (typof(0).includes('integer')) console.log('This is an integer.');

// Index zero always ensures reliable type checking. As the index increases, species depth also increases.
if (typof('0.5')[0] === 'string') console.log('This is a string.');

typof('test'); // [ "string" ]

typof('0'); // [ "string", "number", "integer" ]
typof(0); // [ "number", "integer" ]

typof('0.5'); // [ "string", "number", "float" ]
typof(0.5); // [ "number", "float" ]

typof('true'); // [ "string", "boolean" ]
typof(true); // [ "boolean" ]

typof('2025-01-01'); // [ "string", "date" ]
typof(new Date('2025-01-01')); // [ "object", "date" ]

typof('{"key":"value"}'); // [ "string", "object" ]
typof({ key: 'value' }); // [ "object" ]

typof('["test"]'); // [ "string", "array" ]
typof(['test']); // [ "array" ]

typof('null'); // [ "string", "null" ]
typof(null); // [ "null" ]

typof('undefined'); // [ "string", "undefined" ]
typof(undefined); // [ "undefined" ]

string(value)

Convert to string.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | ----------------- | | value | Unknown | | Value to convert. |

returns String

Example:

string(0.5); // "0.5"
string(true); // "true"
string(new Date('2025-01-01')); // "2025-01-01T00:00:00.000Z"
string({ key: 'value' }); // '{"key":"value"}'
string(['test']); // '["test"]'
string(null); // "null"
string(undefined); // "undefined"

number(value)

Convert to number.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | ----------------- | | value | Unknown | | Value to convert. |

returns Number

Example:

number('0.5'); // 0.5
number(0.5); // 0.5
number('test'); // NaN

integer(value)

Convert to integer.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | ----------------- | | value | Unknown | | Value to convert. |

returns Number

Example:

integer('0.5'); // 0
integer(0.5); // 0
integer('test'); // NaN

boolean(value)

Convert to boolean.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | ----------------- | | value | Unknown | | Value to convert. |

returns Boolean | Value

Example:

boolean('true'); // true
boolean(true); // true
boolean('test'); // "test"

date(value)

Convert to date.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | ----------------- | | value | Unknown | | Value to convert. |

returns Date | Value

Example:

date('2025-01-01'); // 2025-01-01T00:00:00.000Z
date(new Date('2025-01-01')); // 2025-01-01T00:00:00.000Z
date('test'); // "test"

object(value)

Convert to object.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | ----------------- | | value | Unknown | | Value to convert. |

returns Object | Value

Example:

object('{"key":"value"}'); // { key: "value" }
object('["test"]'); // '["test"]'

array(value)

Convert to array.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | ----------------- | | value | Unknown | | Value to convert. |

returns Unknown[] | Value

Example:

array('["test"]'); // [ "test" ]
array('{"key":"value"}'); // '{"key":"value"}'

_null(value)

Convert to null.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | ----------------- | | value | Unknown | | Value to convert. |

returns Null | Value

Example:

_null('null'); // null
_null(null); // null
_null('test'); // "test"

_undefined(value)

Convert to undefined.

| Parameter | Type | Default | Description | | --------- | ------- | ------- | ----------------- | | value | Unknown | | Value to convert. |

returns Undefined | Value

Example:

_undefined('undefined'); // undefined
_undefined(undefined); // undefined
_undefined('test'); // "test"

Types

| Type | | ------- | | Types |

Links

License

MIT License

Copyright (c) 2025 Keift

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.