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 🙏

© 2024 – Pkg Stats / Ryan Hefner

typifier

v0.1.2

Published

The javascript library to get or check the type of a given variable.

Downloads

2,443

Readme

typifier

npm package GitHub release (latest by date) downloads License: MIT

The javascript library to get or check the type of a given variable.

Table of contents

Usage

Usage example

// node js
const Typifier = require('typifier');
// browser
<script type="text/javascript" src="js/lib/typifier.bundle.js"></script>


// code samples
Typifier.isArray([1,2,3])                       // => true
Typifier.isArray("[1,2,3]")                     // => false

Typifier.isObject({ a: b })                     // => true
Typifier.isObject([1,2,3])                      // => false

Typifier.isString("superString")                // => true
Typifier.isString(123)                          // => false
Typifier.isString(new String("string class"))   // => false

Typifier.isStringClass(new String('abc'))       // => true
Typifier.isStringClass("primitive String")      // => false

Typifier.isNumber(123)                          // => true
Typifier.isNumber(123.45)                       // => true
Typifier.isNumber("123")                        // => false
Typifier.isNumber(new Number(123))              // => false

Typifier.isNumberClass(new Number(123))         // => true
Typifier.isNumberClass(123)                     // => false

Typifier.isNumberString("123")                  // => true
Typifier.isNumberString("123.55")               // => true
Typifier.isNumberString("0x123")                // => true
Typifier.isNumberString(123)                    // => false

Typifier.isDate(new Date())                     // => true
Typifier.isDate(123)                            // => false
Typifier.isDate("2021-01-01T00:00:00Z")         // => false (class check only)

Typifier.isRegExp(/abc/g)                       // => true
Typifier.isRegExp("/abc/g")                     // => false

Typifier.isNaN(NaN)                             // => true
Typifier.isNaN(123)                             // => false

Typifier.isInfinity(Infinity)                   // => true
Typifier.isInfinity(NaN)                        // => false

Typifier.isUndefined(undefined)                 // => true
Typifier.isUndefined(0)                         // => false

Typifier.isNull(null)                           // => true
Typifier.isNull(false)                          // => false

Typifier.isBoolean(true)                        // => true
Typifier.isBoolean(false)                       // => true
Typifier.isBoolean("")                          // => false
Typifier.isBoolean(new Boolean(true))           // => false

Typifier.isBooleanClass(new Boolean(true))      // => true
Typifier.isBooleanClass(new Boolean(false))     // => true
Typifier.isBooleanClass(true)                   // => false

Typifier.isFunction((a) => {})                  // => true
Typifier.isFunction("cool")                     // => false

Typifier.isClass(Typifier)                      // => true
Typifier.isClass("stringy")                     // => false

Typifier.is("Typifier", Typifier)               // => true
Typifier.is("MyClass", MyClass)                 // => true
Typifier.is("String", "some string")            // => true
Typifier.is("Array", [1,2,3])                   // => true
Typifier.is("String", 123)                      // => false

Typifier.isSet("some string")                   // => true
Typifier.isSet("")                              // => true
Typifier.isSet(0)                               // => true
Typifier.isSet(false)                           // => true
Typifier.isSet(undefined)                       // => false
Typifier.isSet(null)                            // => false

Typifier.getType("some string")                 // => "string"
Typifier.getType(new String("some string"))     // => "String"
Typifier.getType(123)                           // => "number"
Typifier.getType(new Number(123))               // => "Number"
Typifier.getType(Typifier)                      // => "class"
Typifier.getType({ a: 1})                       // => "Object"
Typifier.getType([1,2,3])                       // => "Array"
Typifier.getType(null)                          // => "null"
Typifier.getType(undefined)                     // => "undefined"
Typifier.getType(Infinity)                      // => "Infinity"
Typifier.getType(NaN)                           // => "NaN"
Typifier.getType(() => {})                      // => "function"
Typifier.getType(true)                          // => "boolean"
Typifier.getType(new Boolean(true))             // => "Boolean"
Typifier.getType(/regex/g)                      // => "RegExp"

Installation

NodeJS

You can either use npm or yarn to install typifier.

yarn

In your project root directory execute the following command:

yarn add typifier

npm

In your project root directory execute the following command:

npm install typifier

Browser

Download the latest release on Github or the from the folder dist and put it in an appropriate folder of your project, e.g. js/lib and reference it by a script tag in your project:


<script type="text/javascript" src="js/lib/typifier.bundle.js"></script>

Optionally you may add the source file to your build pipeline, if you are using webpack, brunch or any other packager.

Bundle releases

As typifier depends on LuckyCase, there is also a bundle release called typifier.bundle.js where the latter is included. If you already use LuckyCase separately, use the default version typifier.js without included dependencies. If you don't know what you should use, use the bundled release!

Minified releases

If you prefer minified builds, use the *.min.js version. Be aware that they do not contain any javascript documentation that may be very useful when working with a powerful IDE.

Documentation

See JS doc here.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/magynhard/typifier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.