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

mavis

v2.0.0

Published

Thorough javascript type checker

Downloads

2

Readme

Mavis

Travisnpmnpm

Reliable, light-weight, highly-specific type checking for javascript. Like a thorough typeof.

I found myself writing this code over and over, so I figured I'd make a package out of it and send it to the internet.

Usage

Mavis works both in node and the browser. Simply include it as a <script> tag or

$ npm install mavis and require('mavis') from your app.

examples

// node
var type = require('mavis')
<!-- browser -->
<script src="mavis.js"></script>
// objects
type({}) // 'object'
type([]) // 'array'

function Example() {}
type(new Example) // 'object'

// functions
type(JSON.parse) // 'function'
type(function () {}) // 'function'
type(function* () {}) // 'generator'

// numbers
type(0) // 'number'
type(-100) // 'number'
type(Infinity) // 'infinity'
type(NaN) // 'NaN'

// strings
type('string') // 'string'
type(`template $(string)`) // 'string'

// errors
type(new Error) // 'error'
type(new TypeError) // 'error'
type(new SyntaxError) // 'error'
type(new EvalError) // 'error'
type(new RangeError) // 'error'
type(new ReferenceError) // 'error'

// html
type(new Image) // 'html'
type(new Audio) // 'html'
type(document) // 'html'

function element(type) {
	return document.createElement(type);
}
type(element('table')) // 'html'
type(element('div')) // 'html'
type(element('h1')) // 'html'
type(element('li')) // 'html'

// special
type(window) // 'global'
type(localStorage) // 'storage'
type(new Date) // 'date'
type(new Map) // 'map'
type(new Set) // 'set'
type(new Promise(func)) // 'promise'
type(arguments) // 'arguments'
type(/matcher/) // 'RegExp'
type(new Uint16Array) // 'uint16array'

type.is(actual, expected)

Mavis comes with type comparison. The result of a comparison is a boolean, unless you pass an array to match against, in which case the matching type is returned.

type.is('string', 'string') // true
type.is([1, 2, 3], 'html') // false
type.is(JSON, 'object') // true
type.is(5, ['object', 'number', 'array']) // 'number'

type.is(/exp/, 'RegExp') // true
type.is(/exp/, ['number', 'generator']) // false
type.is(/exp/, ['number', 'RegExp']) // 'RegExp'
type.is(/exp/, 'string') // false

advantages

Mavis is intentionally string-based. Some libraries check by constructor, although this forces you to ensure the type is defined before using it. By using strings, type-checking is completely backwards/forwards compatible. If a type you need to check against isn't supported in your browser, you can check for it without worrying. It's just a string!

final words

If you have any issues, problems, or questions, please submit an issue on GitHub.

Thanks for using Mavis!