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:
| Option | Type | Default | Description |
|---|---|---|---|
strength | number | 2 | Number of factors to be covered (N-wise). |
subModels | SubModelType[] | undefined | Apply a different combination strength to a specific group of factors. |
weights | WeightsType | undefined | Index-keyed weights that bias value selection during row completion. |
presets | PresetRowType[] | undefined | Rows that must be included in the output. Equivalent to PICT's seeding feature. |
constraints | Condition[] | undefined | Declarative constraints evaluated under three-valued logic. See Constraint Logic. |
comparer | Comparer | undefined | Custom comparison functions for constraint evaluation. |
sorter | Function | sorters.hash | Determines the order of combinations. |
criterion | Function | criteria.greedy | Determines the algorithm for generating combinations. |
salt | string | number | "" | Value mixed into sorters.hash to control the ordering of pairs. |
tolerance | number | 0 | Tolerance 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.