@nodevu/ranges
Advanced tools
+108
-44
| const nodevu = require('@nodevu/core') | ||
| const aliases = require('@nodevu/aliases') | ||
@@ -6,3 +7,3 @@ // building out the model of what we want to see. not totally necessary, | ||
| // also nice to just be able to see it visually represented :) | ||
| const ranges = { | ||
| const defaultRangesObject = { | ||
| all: { | ||
@@ -56,61 +57,101 @@ versions: [], | ||
| async function generateRanges () { | ||
| // describing this early so it doesn't need to be commented everywhere: | ||
| // filter can accept an array or a string. Each object's building phase | ||
| // will check to make sure that the filter is valid - either as a string | ||
| // or as an array. If it's not, do nothing and move on. That specific | ||
| // string/filter logic is contained in if/else statements that get a bit | ||
| // verbose but JavaScript doesn't really have a less verbose way to do it. | ||
| // If you figure one out, or there's one in the future, please feel free | ||
| // to submit a PR to update this code. | ||
| async function generateRanges (filter) { | ||
| if (typeof filter === 'string') { | ||
| // check to make sure that the filter is valid. if it's not, yeet. | ||
| if (!aliases.includes(filter)) { | ||
| throw new Error(`Unknown value passed as a filter. The passed value: '${filter}'.`) | ||
| } | ||
| } else if (Array.isArray(filter) === true) { | ||
| // check to make sure that the filter is valid. if it's not, yeet. | ||
| if (!filter.every(alias => aliases.includes(alias))) { | ||
| throw new Error(`At least one of the values passed as a filter is unknown. The passed value(s): '${filter.join('\', \'')}'`) | ||
| } | ||
| } else if (filter) { | ||
| throw new Error(`Unknown value passed as a filter. The passed value: '${filter}', with a type of '${typeof filter}'. Make sure you are passing a string (or an Array of strings) with valid value(s).`) | ||
| } else { | ||
| filter = 'all' | ||
| } | ||
| // set up the data from @nodevu/core | ||
| const data = await nodevu() | ||
| // deep clone the default object so we don't modify it. | ||
| // | ||
| // modifying the default object has some super wonky side effects | ||
| // on subsequent calls to this function that we don't want. | ||
| const ranges = JSON.parse(JSON.stringify(defaultRangesObject)) | ||
| for (const line in data) { | ||
| for (const key in data[line].releases) { | ||
| ranges.all.versions.push(key) // put every release into the all array | ||
| // define `all` data | ||
| if (filter === 'all' || filter.includes('all')) { | ||
| ranges.all.versions.push(key) // put every release into the all array | ||
| if (data[line].releases[key].lts.isLts === true && ranges.all.newestLts === undefined) { | ||
| ranges.all.newestLts = `${key}` // if there's no entries yet and this iteration is an LTS release, push it into the array | ||
| } | ||
| if (data[line].releases[key].lts.isLts === true && ranges.all.newestLts === undefined) { | ||
| ranges.all.newestLts = `${key}` // if there's no entries yet and this iteration is an LTS release, push it into the array | ||
| } | ||
| if (data[line].releases[key].security.isSecurity === true && ranges.all.newestSecurity === undefined) { | ||
| ranges.all.newestSecurity = `${key}` // if there's no entries yet and this iteration is an LTS release, push it into the array | ||
| if (data[line].releases[key].security.isSecurity === true && ranges.all.newestSecurity === undefined) { | ||
| ranges.all.newestSecurity = `${key}` // if there's no entries yet and this iteration is an LTS release, push it into the array | ||
| } | ||
| } | ||
| // define current data | ||
| if (data[line].support?.phases.current === 'start') { | ||
| ranges.current.versions.push(key) // add current iteration to the versions array if the phase is `start` which means it'll be current. | ||
| // define 'current' data | ||
| if (filter === 'current' || filter === 'all' || filter.includes('current') || filter.includes('all')) { | ||
| if (data[line].support?.phases.current === 'start') { | ||
| ranges.current.versions.push(key) // add current iteration to the versions array if the phase is `start` which means it'll be current. | ||
| if (ranges.current.oldestSecurity === undefined && ranges.current.newestSecurity === undefined) { | ||
| ranges.current.oldestSecurity = `${data[line].security.oldest}` | ||
| ranges.current.newestSecurity = `${data[line].security.newest}` | ||
| if (ranges.current.oldestSecurity === undefined && ranges.current.newestSecurity === undefined) { | ||
| ranges.current.oldestSecurity = `${data[line].security.oldest}` | ||
| ranges.current.newestSecurity = `${data[line].security.newest}` | ||
| } | ||
| } | ||
| } | ||
| // define lts/latest data | ||
| if (data[line].support?.phases.current === 'lts') { | ||
| // TODO: do we want to include all versions in the release line, even prior to it being minted LTS? | ||
| if (data[line].releases[key].lts.isLts) { | ||
| // define 'lts/latest' data | ||
| if (filter === 'lts/latest' || filter === 'lts/active' || filter === 'all' || filter.includes('lts/latest') || filter.includes('lts/active') || filter.includes('all')) { | ||
| if (data[line].support?.phases.current === 'lts' && data[line].releases[key].lts.isLts) { | ||
| // TODO: do we want to include all versions in the release line, even prior to it being minted LTS? | ||
| ranges['lts/latest'].versions.push(key) | ||
| } | ||
| if (ranges['lts/latest'].oldestSecurity === undefined) { // only checking if this one is undefined, since everything else _should_ be undefined if this one is. saves some processing power. | ||
| ranges['lts/latest'].oldestSecurity = `${data[line].security.oldest}` | ||
| ranges['lts/latest'].newestSecurity = `${data[line].security.newest}` | ||
| ranges['lts/latest'].oldestLts = `${data[line].support.lts.oldest}` | ||
| ranges['lts/latest'].newestLts = `${data[line].support.lts.newest}` | ||
| if (ranges['lts/latest'].oldestSecurity === undefined) { // only checking if this one is undefined, since everything else _should_ be undefined if this one is. saves some processing power. | ||
| ranges['lts/latest'].oldestSecurity = `${data[line].security.oldest}` | ||
| ranges['lts/latest'].newestSecurity = `${data[line].security.newest}` | ||
| ranges['lts/latest'].oldestLts = `${data[line].support.lts.oldest}` | ||
| ranges['lts/latest'].newestLts = `${data[line].support.lts.newest}` | ||
| } | ||
| } | ||
| } | ||
| // define lts/maintenance data | ||
| if (data[line].support?.phases.current === 'maintenance') { | ||
| if (data[line].releases[key].lts.isLts) { | ||
| // define 'lts/maintenance' data | ||
| if (filter === 'lts/maintenance' || filter === 'lts/active' || filter === 'all' || filter.includes('lts/maintenance') || filter.includes('lts/active') || filter.includes('all')) { | ||
| if (data[line].support?.phases.current === 'maintenance' && data[line].releases[key].lts.isLts) { | ||
| ranges['lts/maintenance'].versions.push(key) | ||
| } | ||
| if (ranges['lts/maintenance'].newestSecurity === undefined && ranges['lts/maintenance'].newestLts === undefined) { | ||
| ranges['lts/maintenance'].newestSecurity = `${data[line].security.newest}` | ||
| ranges['lts/maintenance'].newestLts = `${data[line].support.lts.newest}` | ||
| } | ||
| if (ranges['lts/maintenance'].newestSecurity === undefined && ranges['lts/maintenance'].newestLts === undefined) { | ||
| ranges['lts/maintenance'].newestSecurity = `${data[line].security.newest}` | ||
| ranges['lts/maintenance'].newestLts = `${data[line].support.lts.newest}` | ||
| } | ||
| if (ranges['lts/maintenance'].oldestSecurity !== `${data[line].security.oldest}` || ranges['lts/maintenance'].oldestLts !== `${data[line].support.lts.oldest}`) { | ||
| ranges['lts/maintenance'].oldestSecurity = `${data[line].security.oldest}` | ||
| ranges['lts/maintenance'].oldestLts = `${data[line].support.lts.oldest}` | ||
| if (ranges['lts/maintenance'].oldestSecurity !== `${data[line].security.oldest}` || ranges['lts/maintenance'].oldestLts !== `${data[line].support.lts.oldest}`) { | ||
| ranges['lts/maintenance'].oldestSecurity = `${data[line].security.oldest}` | ||
| ranges['lts/maintenance'].oldestLts = `${data[line].support.lts.oldest}` | ||
| } | ||
| } | ||
| } | ||
| if (data[line].support?.phases.current === 'end') { | ||
| ranges.eol.versions.push(key) | ||
| // define 'eol' data | ||
| if (filter === 'eol' || filter === 'all' || filter.includes('eol') || filter.includes('all')) { | ||
| if (data[line].support?.phases.current === 'end') { | ||
| ranges.eol.versions.push(key) | ||
| } | ||
| } | ||
@@ -120,8 +161,13 @@ } | ||
| // define lts/active data (doesn't need to be in the loops, since it's basically just a union of lts/latest and lts/maintenance) | ||
| ranges['lts/active'].versions = ranges['lts/latest'].versions.concat(ranges['lts/maintenance'].versions) | ||
| ranges['lts/active'].oldestLts = ranges['lts/maintenance'].oldestLts // the maintenance LTS is the older LTS | ||
| ranges['lts/active'].newestLts = ranges['lts/latest'].newestLts // the latest LTS is the newer LTS | ||
| ranges['lts/active'].oldestSecurity = ranges['lts/maintenance'].oldestSecurity // the maintenance security is the older security | ||
| ranges['lts/active'].newestSecurity = ranges['lts/latest'].newestSecurity // the latest security is the newer security | ||
| // define lts/active data | ||
| // | ||
| // doesn't need to be in the loops, since it's basically just a union | ||
| // of lts/latest and lts/maintenance | ||
| if (filter === 'lts/active' || filter === 'all' || filter.includes('lts/active') || filter.includes('all')) { | ||
| ranges['lts/active'].versions = ranges['lts/latest'].versions.concat(ranges['lts/maintenance'].versions) | ||
| ranges['lts/active'].oldestLts = ranges['lts/maintenance'].oldestLts // the maintenance LTS is the older LTS | ||
| ranges['lts/active'].newestLts = ranges['lts/latest'].newestLts // the latest LTS is the newer LTS | ||
| ranges['lts/active'].oldestSecurity = ranges['lts/maintenance'].oldestSecurity // the maintenance security is the older security | ||
| ranges['lts/active'].newestSecurity = ranges['lts/latest'].newestSecurity // the latest security is the newer security | ||
| } | ||
@@ -134,2 +180,20 @@ // some quick maths for dynamically defining newest and oldest, regardless of what ranges we have. | ||
| // delete what we don't need | ||
| for (const property in ranges) { | ||
| if (ranges[property].versions.length === 0) { | ||
| delete ranges[property] | ||
| } | ||
| } | ||
| // make sure we remove any unrequested remnants from lts/active construction | ||
| if (Array.isArray(filter) && filter.includes('lts/active')) { | ||
| if (!filter.includes('lts/latest')) { | ||
| delete ranges['lts/latest'] | ||
| } | ||
| if (!filter.includes('lts/maintenance')) { | ||
| delete ranges['lts/maintenance'] | ||
| } | ||
| } | ||
| return ranges | ||
@@ -136,0 +200,0 @@ } |
+6
-4
| { | ||
| "name": "@nodevu/ranges", | ||
| "version": "0.0.3", | ||
| "version": "0.1.0", | ||
| "description": "support node's unofficial alias namespace", | ||
@@ -15,3 +15,4 @@ "main": "index.js", | ||
| "coverage": "nyc node--test", | ||
| "updates": "npx npm-check-updates" | ||
| "updates:check": "npx npm-check-updates", | ||
| "updates:update": "npx npm-check-updates -u" | ||
| }, | ||
@@ -29,3 +30,4 @@ "repository": { | ||
| "dependencies": { | ||
| "@nodevu/core": "^0.0.4" | ||
| "@nodevu/core": "^0.0.4", | ||
| "@nodevu/aliases": "^0.0.2" | ||
| }, | ||
@@ -35,4 +37,4 @@ "devDependencies": { | ||
| "standard": "^17.0.0", | ||
| "test": "^3.2.1" | ||
| "test": "^3.3.0" | ||
| } | ||
| } |
12718
33.48%175
49.57%2
100%+ Added
+ Added