Shared core for node-exports-info and node-imports-info: maps node version ranges to feature categories and looks up per-category flags.
Each of those packages is essentially data — a ranges map of node semver range → category, plus per-flag tables of which categories support which feature. This package provides the (otherwise duplicated) logic that operates on that data, as factory functions: pass in the data, get back the accessor.
Each entry point is a factory: call it with a package's data, and it returns the corresponding accessor function.
node-package-field-info/makeGetCategory:(ranges) => (nodeVersion?) => category. Returns the latest category matching the version (defaulting to the current node version); throws if none match.node-package-field-info/makeGetCategoriesForRange:(ranges) => (range) => category[]. Returns the categories whose range overlaps the given range.node-package-field-info/makeGetRange:(ranges) => (category) => range. Returns the range for a category; throws for an unknown category.node-package-field-info/makeGetRangePairs:(ranges) => () => [range, category][]. Returns the range/category pairs.node-package-field-info/makeIsCategory:(ranges) => (category) => boolean. Returns whether a value is a known category.node-package-field-info/makeGetCategoryFlags:(isCategory, flagTables) => (category) => flags. Returns an object of boolean flags (one per key inflagTables); throws for an unknown category.node-package-field-info/makeGetConditionsForCategory:(isCategory, conditionTables) => (category, moduleSystem?) => conditions. Returns the array of supported conditions (ornull) for a category, optionally narrowed to'require'/'import'; throws for an unknown category.conditionTablesis{ addonsCategories, moduleSyncCategories, nullCategories, defaultOnlyCategories }.node-package-field-info/makeGetCategoryInfo:(getConditionsForCategory, getCategoryFlags) => (category, moduleSystem?) => { conditions, flags }. Combines the two into one lookup.
The ranges object maps a node semver version range to a category, ordered most-recent first:
{
__proto__: null,
'>= 3': 'c',
'2.x': 'b',
'< 2': 'a',
}The flagTables object maps a flag name to the set of categories that support it:
{
foo: { __proto__: null, b: true, c: true },
bar: { __proto__: null, c: true },
}var makeGetCategory = require('node-package-field-info/makeGetCategory');
var ranges = { __proto__: null, '>= 3': 'c', '2.x': 'b', '< 2': 'a' };
var getCategory = makeGetCategory(ranges);
getCategory('2.5.0'); // 'b'node-exports-info: info about nodeexportsfield supportnode-imports-info: info about nodeimportsfield support
Simply clone the repo, npm install, and run npm test
