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

mout-lang-type

v0.6.0

Published

An extension to the `mout/lang` utilities

Downloads

731

Readme

mout-lang-type

Travis CI Latest GitHub Tag Latest GitHub Release Total Downloads via GitHub Node.js Module Version Downloads via npm per Month Bower Component Version

An extension to the mout/lang utilities for more reliable type testing

mout-lang-type is an extension to MOUT’s lang utilities. It provides two major modules: A typeOf and an isType function to be used for more reliable type checks where the included kindOf and isKind functions would fail. The difference is that those included functions always use the string description tags of objects (historically known as the [[Class]] internal slot tags) expressed in UpperCamelCase for testing, whereas these additional functions use only the limited set of built-in object tags expressed in lowerCamelCase and yield precedence to the results of the native typeof operator whenever possible:

kindOf( navigator ); // 'Navigator'
typeOf( navigator ); // 'object'

typeof []; // 'object'
typeOf( [] ); // 'array'

This extension also provides two additional modules: An instanceOf function that improves the native instanceof operator by supporting comparisons with primitive values and fixing a memory leak in legacy Internet Explorer versions; and an isComplex function that tests whether values are of complex (non-primitive) data types or not:

1 instanceof Number; // false
instanceOf( 1, Number ); // true

// No memory leaks in IE < 9 on COM objects:
instanceOf( window, Object ); // false

isComplex( 1 ); // false
isComplex( new Number ); // true

Lastly, this extension provides a bunch of replacement modules: An isPrimitive function that adds support for ES2015 symbols and finally the isFunction, isObject and isRegExp functions that internally use isType instead of isKind for their specific type checks:

isFunction( alert ); // true, even in IE7
isObject( window ); // true, same here
isPrimitive( Symbol() ); // true
isRegExp( /^regExp$/i ); // true

Getting started

Installation

Install this extension as a dependency to your project using Bower:

$ bower install --save mout-lang-type

Alternatively, it is also available using npm:

$ npm install --save mout-lang-type

Usage

You can load and use this extension as a module using the AMD or CommonJS API:

// Load the overall module:
var
  moutLangType = require('mout-lang-type');

// Use the overall module:
moutLangType.lang.instanceOf( [], Array ); // true
moutLangType.lang.typeOf( null ) === 'null'; // true


// Load all lang utilities:
var
  lang = require('mout-lang-type/lang');

// Use the lang utilities:
lang.isPrimitive( false ); // true
lang.isType( new String('foo'), 'string'); // true


// Load the individual utilities:
var
  isComplex = require('mout-lang-type/lang/isComplex'),
  isFunction = require('mout-lang-type/lang/isFunction');

// Use the individual utilities:
isComplex( new String('bar') ); // true
isFunction( Array ); // true

Keep in mind that the module’s name mout-lang-type in AMD is actually just the module’s root directory and can differ from the example above depending on your deployed scripts directory structure.

Policy

This is communist software. It is crafted with heart and soul to the best of the author’s knowledge and belief: Not for profit but to satisfy the concrete needs. Do whatever you want with it (as long as you keep the author’s copyright notice in all copies or substantial portions of it included) for free. Imagine how the world could be if others would produce and distribute their products for the same benefits and ask yourself why they’re actually not.

License

This software is licensed under MIT License.

Copyright © 2015 Christian Grete