Skip to content

Commit

Permalink
Use null instead of '' to denote no version
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Aug 25, 2024
1 parent 21700ca commit 6ccbfd4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next
- Added basic message when no arguments are given.
- Changed output of `getVersions` to return `null` instead of `''` when a version is not present.
- Changed output of `getVersions` to replace '`.x`' with the actual game version.
- Changed CLI output of `--list` to present the versions in prose instead of JSON.
- Changed help message.
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ function getPackFormats(version: string): Record<PackType, FormatResult> {
* @returns an object containing minimum and maximum applicable release and snapshot versions
*/
function getVersions(format: number, type: PackType = 'resource'): VersionsResult {
let output: VersionsResult = {
'releases': { 'min': '', 'max': '' },
'snapshots': { 'min': '', 'max': '' },
const output: VersionsResult = {
'releases': { 'min': null, 'max': null },
'snapshots': { 'min': null, 'max': null },
}
if (!format || format > LATEST[type] || (type === 'data' && format < 4)) return output

Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export type PackMap = Record<PackType, FormatResult>
export type FormatResult = number | null | undefined

export interface VersionsResult {
releases: { min: VersionName | '', max: VersionName | '' },
snapshots: { min: SnapshotName | '', max: SnapshotName | '' },
releases: { min: VersionName | null, max: VersionName | null },
snapshots: { min: SnapshotName | null, max: SnapshotName | null },
}
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ function testPackFormats() {

testPackFormats()

testVersions([3, 'data'], { releases: { min: '', max: '' }, snapshots: { min: '', max: '' } })
testVersions([10, 'resource'], { releases: { min: '', max: '' }, snapshots: { min: '', max: '' } })
testVersions([6, 'resource'], { releases: { min: '1.16.2', max: '1.16.5' }, snapshots: { min: '', max: '' } })
testVersions([3, 'data'], { releases: { min: null, max: null }, snapshots: { min: null, max: null } })
testVersions([10, 'resource'], { releases: { min: null, max: null }, snapshots: { min: null, max: null } })
testVersions([6, 'resource'], { releases: { min: '1.16.2', max: '1.16.5' }, snapshots: { min: null, max: null } })
testVersions([6, 'data'], { releases: { min: '1.16.2', max: '1.16.5' }, snapshots: { min: '20w45a', max: '20w45a' } })
testVersions([7, 'resource'], { releases: { min: '1.17', max: '1.17.1' }, snapshots: { min: '20w45a', max: '21w38a' } })
testVersions([10, 'data'], { releases: { min: '1.19', max: '1.19.3' }, snapshots: { min: '22w11a', max: '23w02a' } })
testVersions([11, 'resource'], { releases: { min: '', max: '' }, snapshots: { min: '22w42a', max: '22w44a' } })
testVersions([11, 'resource'], { releases: { min: null, max: null }, snapshots: { min: '22w42a', max: '22w44a' } })
testVersions([15, 'data'], { releases: { min: '1.20', max: '1.20.1' }, snapshots: { min: '23w18a', max: '23w30a' } })

console.log(`\nRan ${total} tests | ${passed} passed | ${failed} failed`)

0 comments on commit 6ccbfd4

Please sign in to comment.