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

facies

v3.0.3

Published

A featureful function parameters signature module

Downloads

135

Readme

Facies

facies is a featureful parameters signature module for nodejs.

NPM Summary NPM Downloads

Build Status Coverage Status

Features

  • Duck type matching
  • Default values

See the changelog and the API reference

Requirements

facies works with NodeJS 6.x and above. Install it the usual way:

npm install facies

How To

facies is designed for use with array-like values, e.g. the arguments keyword:

const facies = require("facies");

const target = function () {
	const parameters = facies.match([
		Number,
		[String, "a"],
	], arguments);

	// parameters is an array:
	// - [0] is a Number
	// - [1] is a string with default value "a"
};

It works by matching the given values against a list of interface definitions. Interface definitions are constructed either from a type constructor for exact matching or from a literal object describing the expected interface. So both String and {length: Function} will match strings.

Interface definitions can be given in an array where the last value will be the default value used if none of the other values match the corresponding value. Multiple interface definitions can also be bundled together using the variadic Interface construct, which responds to the instanceof operator:

[]         instanceof facies.Interface({forEach: Function}); // true
new Map()  instanceof facies.Interface({forEach: Function}); // true
/^$/       instanceof facies.Interface(RegExp, Date);        // true
new Date() instanceof facies.Interface(RegExp, Date);        // true

If actual values do not match the expected interface definition, facies.match will also throw a TypeError. If more values are given than the result of matching (including default values), facies.match will also throw a TypeError.

The facies.match function is currified using Ramda, so that it can be partially applied to the interface expectation if needed.