Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (54 loc) · 1.63 KB
/
Copy pathindex.js
File metadata and controls
58 lines (54 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @file Translates the terms of the Node.js package support document to the
* aliases `@nodevu/ranges` takes.
*
* @example
* ```js
* const translate = require('@nodevu/translate');
* ```
*/
/**
* The aliases each package support term covers, ordered from the most recent
* coverage to the oldest.
*
* @example
* ```js
* translations.lts; // ['lts/active', 'lts/maintenance']
* ```
*/
const translations = /** @type {const} */ ({
current: ['current'],
lts_latest: ['lts/latest'],
lts: ['lts/active', 'lts/maintenance'],
supported: ['current', 'lts/active', 'lts/maintenance'],
all: ['current', 'lts/active', 'lts/maintenance', 'eol'],
});
/**
* Translates a term of the Node.js package support document to the aliases
* `@nodevu/ranges` takes.
*
* @template {keyof typeof translations} Term
* @param {Term} legacyName The term, such as `'supported'`.
* @returns {Promise<Array<(typeof translations)[Term][number]>>} The aliases
* the term covers, newest first.
* @public
* @example
* ```js
* const ranges = require('@nodevu/ranges');
* const translate = require('@nodevu/translate');
*
* await translate('supported'); // ['current', 'lts/active', 'lts/maintenance']
*
* const supported = await ranges(await translate('supported'));
* ```
*/
async function translate(legacyName) {
// an own-property check, so names like `toString` don't resolve to
// Object.prototype's members
if (!Object.hasOwn(translations, legacyName)) {
throw new Error(`Unknown value: ${legacyName}`);
}
// a copy, so a caller changing the result can't change later results
return [...translations[legacyName]];
}
module.exports = translate;