typeof-article

0.1.1 • Public • Published

typeof-article NPM version NPM monthly downloads NPM total downloads Linux Build Status

Get the native JavaScript type of a value, preceded by the appropriate indefinite article (either a or an), for use in error messages.

Install

Install with npm:

$ npm install --save typeof-article

Usage

(A few of the types have some extra formatting where it makes sense. For example, instead of a regexp, it returns a regular expression, which IMHO is more readable to users. You can customize mappings if you want)

var type = require('typeof-article');
 
console.log(type({}));
//=> 'an object'
 
console.log(type([]));
//=> 'an array'
 
console.log(type(9));
//=> 'a number'
 
console.log(type(/abc/));
//=> 'a regular expression'
 
console.log(type(new WeakMap()));
//=> 'a WeakMap'

Get the object of types-to-articles mappings:

var types = require('typeof-article').types;

Also exposes a typeOf property, for getting the native type only:

var type = require('typeof-article');
type.types.weapmap = 'a WeakMap()';
 
console.log(type.typeOf(new WeakMap()));
//=> 'weakmap'

Customize

Customize any of the mappings:

var type = require('typeof-article');
type.types.weapmap = 'a WeakMap()';
 
console.log(type(new WeakMap()));
//=> 'a WeakMap()'

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. MIT


This file was generated by verb-generate-readme, v0.4.2, on January 30, 2017.

Package Sidebar

Install

npm i typeof-article

Weekly Downloads

275,461

Version

0.1.1

License

MIT

Last publish

Collaborators

  • jonschlinkert