Skip to content

inspect-js/node-package-field-info

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

node-package-field-info Version Badge

github actions coverage License Downloads

npm badge

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.

Entry points

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 in flagTables); throws for an unknown category.
  • node-package-field-info/makeGetConditionsForCategory: (isCategory, conditionTables) => (category, moduleSystem?) => conditions. Returns the array of supported conditions (or null) for a category, optionally narrowed to 'require'/'import'; throws for an unknown category. conditionTables is { 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 },
}

Example

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'

Related packages

Tests

Simply clone the repo, npm install, and run npm test

About

Shared core for node-exports-info and node-imports-info: maps node version ranges to feature categories and looks up per-category flags

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors