Skip to content

Commit

Permalink
feat: isLts boolean flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Oct 19, 2023
1 parent 4640a8f commit 9bfee60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface VersionInfo {
maintenance?: Date;
end?: Date;
releaseDate: Date;
isLts: boolean;
}

declare function nv(alias?: string|string[], opts?: Options): Promise<VersionInfo[]>;
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ async function getLatestVersionsByCodename (now, cache, mirror) {
lts: s && s.lts && new Date(s.lts),
maintenance: s && s.maintenance && new Date(s.maintenance),
end: s && s.end && new Date(s.end),
releaseDate: new Date(ver.date)
releaseDate: new Date(ver.date),
isLts: false
}

// All versions get added to all
Expand All @@ -124,6 +125,7 @@ async function getLatestVersionsByCodename (now, cache, mirror) {
// Latest lts
if (now > v.lts) {
lts[versionName] = v
v.isLts = true

if (now < v.maintenance) {
ltsActive[versionName] = v
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ suite('nv', () => {
assert.strictEqual(versions[0].lts.toISOString(), '2018-10-30T00:00:00.000Z')
assert.strictEqual(versions[0].maintenance.toISOString(), '2020-05-19T00:00:00.000Z')
assert.strictEqual(versions[0].end.toISOString(), '2021-04-30T00:00:00.000Z')
assert.strictEqual(versions[0].isLts, true)
})

test('lts', async () => {
Expand All @@ -29,9 +30,11 @@ suite('nv', () => {
assert.strictEqual(versions[0].major, 8)
assert.strictEqual(versions[0].codename, 'carbon')
assert.strictEqual(versions[0].versionName, 'v8')
assert.strictEqual(versions[0].isLts, true)
assert.strictEqual(versions[1].major, 10)
assert.strictEqual(versions[1].codename, 'dubnium')
assert.strictEqual(versions[1].versionName, 'v10')
assert.strictEqual(versions[1].isLts, true)
})

test('active', async () => {
Expand Down Expand Up @@ -139,4 +142,10 @@ suite('nv', () => {
assert.strictEqual(versions.length, 1)
assert.strictEqual(versions[0].major, 18)
})

test('isLts: false', async () => {
const versions = await nv('0.8.0', { now })
assert.strictEqual(versions[0].major, 0)
assert.strictEqual(versions[0].isLts, false)
})
})

0 comments on commit 9bfee60

Please sign in to comment.