Skip to main content

Advanced Usage

Although covertable works with a minimum number of arguments, several options are available. This section shows how to use them in detail.

Type Inference with Object Factors

When factors are specified as an object, results will also be in object form. You can use SuggestRowType to get full type inference:

import { make, SuggestRowType } from "covertable";

const machine = ["iPhone", "Pixel", "XPERIA", "ZenFone", "Galaxy"];
const os = ["iOS", "Android"];
const browser = ["FireFox", "Chrome", "Safari"];

const factors = { machine, os, browser };

const rows = make(factors, {
strength: 2,
constraints: [
// iPhone ↔ iOS
{ operator: 'or', conditions: [
{ operator: 'ne', field: 'machine', value: 'iPhone' },
{ operator: 'eq', field: 'os', value: 'iOS' },
]},
{ operator: 'or', conditions: [
{ operator: 'eq', field: 'machine', value: 'iPhone' },
{ operator: 'ne', field: 'os', value: 'iOS' },
]},
],
});

Options Reference

The make function accepts an options object as its second argument:

OptionTypeDefaultDescription
strengthnumber2Number of factors to be covered (N-wise).
subModelsSubModelType[]undefinedApply a different combination strength to a specific group of factors.
weightsWeightsTypeundefinedIndex-keyed weights that bias value selection during row completion.
presetsPresetRowType[]undefinedRows that must be included in the output. Equivalent to PICT's seeding feature.
constraintsCondition[]undefinedDeclarative constraints evaluated under three-valued logic. See Constraint Logic.
comparerComparerundefinedCustom comparison functions for constraint evaluation.
sorterFunctionsorters.hashDetermines the order of combinations.
criterionFunctioncriteria.greedyDetermines the algorithm for generating combinations.
saltstring | number""Value mixed into sorters.hash to control the ordering of pairs.
tolerancenumber0Tolerance used by criteria.greedy to trade optimality for speed.

See Options Detail for full documentation of each option, or PictModel for the PICT-compatible model parser.