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

js-partial-type-of

v1.0.0

Published

A partial to provide a better typeof capability by returning the practically correct type in string representation of the specific object.

Downloads

6

Readme

js-partial-type-of

Recent Version Travis CI - Build Status Coveralls - Code Coverage Status David - Dependencies David - DevDependencies Doclets Gitter - Repository Chat

Synopsis

A partial to provide a better typeof capability. This typeof partial returns the practically correct type in string representation of the specific object. Written in UMD.

Compatible with ECMAScript 6.

Install

npm install js-partial-type-of

Usage - Include/Initialization

  • AMD (e.g.: RequireJS)
define(['js-partial-type-of'], function(typeOf) {        
    // you can now use typeOf
});
  • CommonJS (e.g.: NodeJS)
var typeOf = require('js-partial-type-of');

// you can now use typeOf
  • Browser
// load the source from "node_modules/js-partial-type-of/dist/js-partial-type-of.js" - for development
// or from "node_modules/js-partial-type-of/dist/js-partial-type-of.min.js" - for production

var typeOf = js_partial_type_of; // it is available in the global namespace

// you can now use typeOf

Usage - After Initialization

  • General usage
// check the type of primitive types
typeOf(undefined) === 'undefined'
typeOf(null)      === 'null' // notice, that this will return **the practically correct type**
typeOf(true)      === 'boolean'
typeOf(false)     === 'boolean'
typeOf(-1)        === 'number'
typeOf(0)         === 'number'
typeOf(1)         === 'number'
typeOf(-Infinity) === 'number'
typeOf(Infinity)  === 'number'
typeOf(NaN)       === 'number'
typeOf('')        === 'string'
typeOf('string')  === 'string'
typeOf(Symbol())  === 'symbol'

// check the type of reference types
typeOf([])           === 'array' // notice, that this will return **the practically correct type**
typeOf({})           === 'object'
typeOf(function(){}) === 'function'
typeOf(new Date())   === 'date'
typeOf(new RegExp()) === 'regexp'
typeOf(/s+/g)        === 'regexp' // inline RegExp
typeOf(new Error())  === 'error' // also for any other errors, that extend the basic Error Object
  • Default behaviour
// default behaviour - similar to native typeof, but it returns **the practically correct types**
typeOf([])                === 'array' // notice, that this will return **the practically correct type**
typeOf({})                === 'object'
typeOf(function(){})      === 'function'
typeOf(new Date())        === 'date'
typeOf(new RegExp())      === 'regexp'
typeOf(new Int8Array(0))  === 'typedarray'
typeOf(new CustomClass()) === 'object'
  • Extended behaviours
// extended behaviour - return the specific type, rather useful for extended types
// when originalCase is not specified, by default, every type will be all lowercase.
typeOf([],                true) === 'array'
typeOf({},                true) === 'object'
typeOf(function(){},      true) === 'function'
typeOf(new Date(),        true) === 'date'
typeOf(new RegExp(),      true) === 'regexp'

// **note the differences below compared to previous example**
typeOf(new Int8Array(0),  true) === 'int8array'
typeOf(new CustomClass(), true) === 'customclass'

// extended behaviour - return the specific type in original case
// it is useful for logging and/or debugging purposes in general
typeOf([],                true, true) === 'Array'
typeOf({},                true, true) === 'Object'
typeOf(function(){},      true, true) === 'Function'
typeOf(new Date(),        true, true) === 'Date'
typeOf(new RegExp(),      true, true) === 'RegExp'

// **note the differences below compared to previous example**
typeOf(new Int8Array(0),  true, true) === 'Int8Array'
typeOf(new CustomClass(), true, true) === 'CustomClass'
// check the type for typed arrays
typeOf(new Int8Array(0))         === 'typedarray'
typeOf(new Uint8Array(0))        === 'typedarray'
typeOf(new Uint8ClampedArray(0)) === 'typedarray'
typeOf(new Int16Array(0))        === 'typedarray'
typeOf(new Uint16Array(0))       === 'typedarray'
typeOf(new Int32Array(0))        === 'typedarray'
typeOf(new Uint32Array(0))       === 'typedarray'
typeOf(new Float32Array(0))      === 'typedarray'
typeOf(new Float64Array(0))      === 'typedarray'

// check their types with specificType = true
typeOf(new Int8Array(0),         true) === 'int8array'
typeOf(new Uint8Array(0),        true) === 'uint8array'
typeOf(new Uint8ClampedArray(0), true) === 'uint8clampedarray'
typeOf(new Int16Array(0),        true) === 'int16array'
typeOf(new Uint16Array(0),       true) === 'uint16array'
typeOf(new Int32Array(0),        true) === 'int32array'
typeOf(new Uint32Array(0),       true) === 'uint32array'
typeOf(new Float32Array(0),      true) === 'float32array'
typeOf(new Float64Array(0),      true) === 'float64array'

// get their constructor's names in non-converted (original) case.
typeOf(new Int8Array(0),         true, true) === 'Int8Array'
typeOf(new Uint8Array(0),        true, true) === 'Uint8Array'
typeOf(new Uint8ClampedArray(0), true, true) === 'Uint8ClampedArray'
typeOf(new Int16Array(0),        true, true) === 'Int16Array'
typeOf(new Uint16Array(0),       true, true) === 'Uint16Array'
typeOf(new Int32Array(0),        true, true) === 'Int32Array'
typeOf(new Uint32Array(0),       true, true) === 'Uint32Array'
typeOf(new Float32Array(0),      true, true) === 'Float32Array'
typeOf(new Float64Array(0),      true, true) === 'Float64Array'

Documentation

Check the source here since it's well structured and documented. Also you can find the rendered jsDoc documentation on Doclets.io.

Also, check the unit tests in order to grasp the full-fledged capabilities.

Have fun! ;)

Issues

If you find any bugs and other issues, check the GSDC Guide - Issues section on how to submit issues in a standardized way on the project's issues page.

In case you have any suggestions regarding the project (features, additional capabilities, etc.), check the GSDC Guide - Suggestions section on how to submit suggestions in an easy, standardized way on the project's issues page.

Contribution

In order to contribute to this project, check the GSDC Guide for an easy, standardized way on how to contribute to projects.

Support

If you by any means find this project useful, consider supporting the organization.

There are multiple options to support the project and the developers. Any means of support is beneficial and helpful.

License

MIT @ Richard King