Giter Site home page Giter Site logo

typifier's Introduction

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.

typifier's People

Contributors

magynhard avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.