-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tierney Cyren <hello@bnb.im>
- Loading branch information
Showing
8 changed files
with
228 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: "Test Suite: @nodevu/translate" | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'translate/**' | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
tests: | ||
if: github.repository == 'cutenode/nodevu' | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [current, lts/*, lts/-1] | ||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
- name: Setup Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install latest npm | ||
run: npm i -g npm | ||
- name: Run npm install (project) | ||
run: npm install | ||
- name: Run npm install (package) | ||
run: npm install -w translate | ||
- name: Run npm test | ||
run: npm test -w translate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
"parsefiles", | ||
"earliest", | ||
"ranges", | ||
"aliases" | ||
"aliases", | ||
"translate" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# @nodevu/translate | ||
|
||
A translation layer to use the terms previously defined by the Node.js Package Maintenance WG's [Package Support document](https://github.com/nodejs/package-maintenance/blob/main/docs/PACKAGE-SUPPORT.md) to terms that can easily be used by [@nodevu/ranges](https://npm.im/@nodevu/ranges). | ||
|
||
|
||
## Usage | ||
|
||
```js | ||
const ranges = require('@nodevu/ranges') | ||
const translate = require('@nodevu/translate') | ||
|
||
async function getTranslatedData () { | ||
// translation for the 'current' Package Support term | ||
const current = await ranges(await translate('current')) | ||
|
||
// translation for the 'lts_latest' Package Support term | ||
const lts_latest = await ranges(await translate('lts_latest')) | ||
|
||
// translation for the 'lts' Package Support term | ||
const lts = await ranges(await translate('lts')) | ||
|
||
// translation for the 'supported' Package Support term | ||
const supported = await ranges(await translate('supported')) | ||
|
||
// translation for the 'all' Package Support term | ||
const all = await ranges(await translate('all')) | ||
|
||
// return the data in a single object | ||
return { | ||
current, | ||
lts_latest, | ||
lts, | ||
supported, | ||
all | ||
} | ||
} | ||
|
||
getTranslatedData().then(console.log) | ||
``` | ||
|
||
## API | ||
|
||
- `translate(alias)` | ||
- `alias` (string): A Node.js Package Support Alias. | ||
|
||
Possible values for `alias`: | ||
- `current`: returns `['current']` | ||
- `lts_latest`: returns `['lts/latest']` | ||
- `lts`: returns `['lts/active', 'lts/maintenance']` | ||
- `supported`: returns `['current', 'lts/active', 'lts/maintenance']` | ||
- `all`: returns `['current', 'lts/active', 'lts/maintenance', 'eol']` | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const ranges = require('../../ranges') // would normally be "const ranges = require('@nodevu/ranges')" in your code | ||
const translate = require('../index') // would normally be "const translate = require('@nodevu/translate')" in your code | ||
|
||
async function getTranslatedData () { | ||
// translation for the 'current' Package Support term | ||
const translatedCurrent = await ranges('current') | ||
|
||
// translation for the 'lts_latest' Package Support term | ||
const translatedLtsLatest = await ranges(await translate('lts_latest')) | ||
|
||
// translation for the 'lts' Package Support term | ||
const translatedLts = await ranges(await translate('lts')) | ||
|
||
// translation for the 'supported' Package Support term | ||
const translatedSupported = await ranges(await translate('supported')) | ||
|
||
// translation for the 'all' Package Support term | ||
const translatedAll = await ranges(await translate('all')) | ||
|
||
// return the data in a single object | ||
return { | ||
"current": translatedCurrent, | ||
"lts_latest": translatedLtsLatest, | ||
"lts": translatedLts, | ||
"supported": translatedSupported, | ||
"all": translatedAll | ||
} | ||
} | ||
|
||
getTranslatedData().then(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// ordered from most recent coverage to oldest coverage | ||
const translations = { | ||
current: ['current'], | ||
lts_latest: ['lts/latest'], | ||
lts: ['lts/active', 'lts/maintenance'], | ||
supported: ['current', 'lts/active', 'lts/maintenance'], | ||
all: ['current', 'lts/active', 'lts/maintenance', 'eol'] | ||
} | ||
|
||
async function translate (legacyName) { | ||
if (!translations[legacyName]) { | ||
throw new Error(`Unknown value: ${legacyName}`) | ||
} else { | ||
return translations[legacyName] | ||
} | ||
} | ||
|
||
module.exports = translate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@nodevu/translate", | ||
"version": "0.0.1", | ||
"description": "a translation layer between the nodevu naming mechanism and the Node.js supported mechanism. Neceessary for legacy interop.", | ||
"keywords": [ | ||
"nodevu", | ||
"node", | ||
"nodejs", | ||
"versions", | ||
"supported" | ||
], | ||
"homepage": "https://github.com/cutenode/nodevu#readme", | ||
"bugs": { | ||
"url": "https://github.com/cutenode/nodevu/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/cutenode/nodevu.git" | ||
}, | ||
"license": "MIT", | ||
"author": "Tierney Cyren", | ||
"main": "index.js", | ||
"scripts": { | ||
"coverage": "nyc node--test", | ||
"lint": "standard --env mocha", | ||
"lint:fix": "standard --fix --env mocha", | ||
"lint:packagejson": "npx sort-package-json", | ||
"test": "node--test", | ||
"updates": "npx npm-check-updates" | ||
}, | ||
"devDependencies": { | ||
"@nodevu/ranges": "^0.0.1", | ||
"nyc": "^15.1.0", | ||
"standard": "^17.0.0", | ||
"test": "^3.2.1" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const assert = require('node:assert') | ||
const translate = require('../index') | ||
const { describe, it } = require('test') | ||
|
||
describe('test that translating current works as expected', async () => { | ||
it('should return "current" when passed "current"', async () => { | ||
const result = await translate('current') | ||
assert.deepStrictEqual(result, ['current']) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const assert = require('node:assert') | ||
const translate = require('../index') | ||
const ranges = require('@nodevu/ranges') | ||
const { describe, it } = require('test') | ||
|
||
describe('test that each alias works with @nodevu/ranges', async () => { | ||
it('should return the same result when both the translated and untranslated "current" are passed to @nodevu/ranges', async () => { | ||
const untranslated = await ranges('current') | ||
const translated = await ranges(await translate('current')) | ||
|
||
assert.deepStrictEqual(untranslated, translated) | ||
}) | ||
|
||
it('should return the same result when "lts/latest" and the translated "lts_latest" are passed to @nodevu/ranges', async () => { | ||
const untranslated = await ranges('lts/latest') | ||
const translated = await ranges(await translate('lts_latest')) | ||
|
||
assert.deepStrictEqual(untranslated, translated) | ||
}) | ||
|
||
it('should return the same result when "lts/active" and "lts/maintenance" and the translated "lts" are passed to @nodevu/ranges', async () => { | ||
const untranslated = await ranges(['lts/active', 'lts/maintenance']) | ||
const translated = await ranges(await translate('lts')) | ||
|
||
assert.deepStrictEqual(untranslated, translated) | ||
}) | ||
|
||
it('should return the same result when "current", "lts/active", and "lts/maintenance" and the translated "supported" are passed to @nodevu/ranges', async () => { | ||
const untranslated = await ranges(['current', 'lts/active', 'lts/maintenance']) | ||
const translated = await ranges(await translate('supported')) | ||
|
||
assert.deepStrictEqual(untranslated, translated) | ||
}) | ||
|
||
it('should return the same result when "current", "lts/active", "lts/maintenance", and "eol" and the translated "all" are passed to @nodevu/ranges', async () => { | ||
const untranslated = await ranges(['current', 'lts/active', 'lts/maintenance', 'eol']) | ||
const translated = await ranges(await translate('all')) | ||
|
||
assert.deepStrictEqual(untranslated, translated) | ||
}) | ||
}) |