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

covertable

v2.2.6

Published

A flexible pairwise tool written in TypeScript

Downloads

1,783

Readme

npm version Workflow codecov

Installation

$ npm install covertable --save

Usage

Simple demo in Node.js:

var covertable = require('covertable');
var make = covertable.default;

var machine = ['iphone', 'pixel'];
var os = ['ios', 'android'];
var browser = ['FireFox', 'Chrome', 'Safari'];

make([machine, os, browser]);

Output:

[
  [ 'pixel', 'android', 'Chrome' ],
  [ 'pixel', 'ios', 'Safari' ],
  [ 'pixel', 'android', 'FireFox' ],
  [ 'iphone', 'android', 'Safari' ],
  [ 'iphone', 'ios', 'Chrome' ],
  [ 'iphone', 'ios', 'FireFox' ]
]

Of course, it also works in the browser well.

Advanced demo in TypeScript:

import { default as make, makeAsync, sorters, criteria } from "covertable";

const machine = ['iphone', 'pixel'];
const os = ['ios', 'android'];
const browser = ['FireFox', 'Chrome', 'Safari'];

make([machine, os, browser], { // optional
  length: 2, // default: 2
  criterion: criteria.simple, // default: criteria.greedy
  sorter: sorters.random, // default: sorters.hash
  preFilter: (row: any) => !(row[1] === 'android' && row[0] !== 'pixel'), // default: null
  postFilter: (row: any) => !(row[1] === 'ios' && row[2] !== 'Safari'), // default: null
});

Output:

[ // filtered
  [ 'iphone', 'ios', 'Safari' ],
  [ 'pixel', 'android', 'Chrome' ],
  [ 'pixel', 'ios', 'Safari' ]
]

You can use also makeAsync function (generator).

  • It receives the same arguments with make function.
  • It returns the row at the time it's made.

Object input and output

You can specify factors as object type:

import { default as make, sorters, criteria } from "covertable";

const machine = ['iphone', 'pixel'];
const os = ['ios', 'android'];
const browser = ['FireFox', 'Chrome', 'Safari'];

make({machine, os, browser}, { // optional
  length: 2,
  preFilter: (row: any) => !(row.os === 'android' && row.machine !== 'pixel'), // default: null
  postFilter: (row: any) => !(row.os === 'ios' && row.browser !== 'Safari'), // default: null
});

Then the output will change as follows:

[ // filtered
  { machine: 'iphone', browser: 'Safari', os: 'ios' },
  { machine: 'pixel', browser: 'Chrome', os: 'android' },
  { machine: 'pixel', browser: 'Safari', os: 'ios' },
]

Options

covertable.make function has options as object at 2nd argument.

All options are omittable.

length

Number of factors to be covered. (default: 2)

Obviously the more it increases, the more number of combinations increases.

sorter

Combinations depend on the order of spreading all over the rows.

You can choice a sorter from the following:

  • sorters.random: It makes different combinations everytime. (fastest)

  • sorters.hash: It makes combinations depending on hash of the pair and seed. (default)

    • It receives seed.
      • seed option decides the order of storing from unstored pairs.
      • When the combination of factors and seed are the same, covertable reproduces the same collective.

criterion

You can choice a criterion from the following:

  • criteria.simple: it extracts any pairs that can be stored into the processing row.
  • criteria.greedy: it attempts to make most efficient combinations. (default)

While criteria.simple processes quickly, criteria.greedy makes fewer combinations. Although the latter is superior to former in terms of fewer combinations generally, it is time-intensive process.

Not relevant options will be ignored.

preFilter

This is a function to filter beforehand.

It receives an argument row as object type.

When the function returns false, the row combination will not be registered.

  • If factors type is Array, you should specify an index at the subscript like row => row[1] < 6.
  • If factors type is Object, you should specify a key at the subscript like row => row.month < 6 or row => row['month'] < 6

postFilter

This means a function to filter later.

The usage is the same as preFilter, only the difference is the timing of the call. It will delete rows not matched this function at the last.

For this reason, the final test cases may not satisfy the factors coverage.

Requirement

ES2015 or later

Development

$ npm install

Testing

$ npm test -- --coverage

Publish

$ # npm adduser
$ npm run build
$ npm version patch
$ npm publish

More info