Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
- Add `type` arg to Node for specifying resource/data
- Added `--resource` & `--data` flags to CLI usage
- Removed hardcoded pack format end snapshot
  • Loading branch information
Nixinova committed Feb 12, 2021
1 parent 0799393 commit 2dd3b1c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 31 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.1.0
*2021-02-13*
- Added argument `type` to Node usage; valid values are `'data'` and `'resource'` for retrieving the respective pack format for certain versions.
- Added command-line flags `--data` (alias `-d`/`d`) and `--resource` (alias `-r`/`r`) to implement the above `type` usage.
- Removed speculative hardcoded end of the current pack format.

## 1.0.6
*2021-21-09*
- Fixed pack format ranges being exclusive.
Expand Down
18 changes: 15 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
const VERSION = '1.0.6'
const VERSION = '1.1.0'

const getPackFormat = require('./index.js')

Expand All @@ -8,8 +8,20 @@ const arg = n => process.argv[n + 1]
if (arg(1) && !arg(1).includes('h'))
if (arg(1).includes('v'))
console.log(`The current version of pack-format is ${VERSION}`)
else if (arg(1).includes('d'))
console.log(`Data pack format of ${arg(2)} is ${getPackFormat(arg(2), 'data')}`)
else if (arg(1).includes('r'))
console.log(`Resource pack format of ${arg(2)} is ${getPackFormat(arg(2), 'resource')}`)
else
console.log(`Pack format of ${arg(1)} is ${getPackFormat(arg(1))}`)
else
console.log('Type `pack-format <version>` to retrieve the pack format of any Minecraft version.')
else {
const log = (arg, desc) => {
console.log(`\n\tpack-format ${arg}`)
for (text of desc) console.log('\t ' + text)
}
console.log(`\npack-format arguments:\n`)
log('<version>', ['Retrieve the pack format of any Minecraft version.', ' Defaults to resource pack format when applicable.'])
log('(--data|-d) <version>', ['Retrieve the data pack format in particular when applicable.'])
log('(--resource|-r) <version>', ['Retrieve the resource pack format in particular when applicable.'])
}

28 changes: 14 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ class Snapshot {
getID() { return (this.getYear() - 10) * 52 + this.getWeek() }
}

function getPackFormat(version) {
function getPackFormat(version, type) {
if (!version) return
version = version.toString()

// Snapshot //

if (/^\d\dw\d\d\w$/.test(version)) {
const lastSnapshots = {
'13w23b': undefined,
'14w34d': 1,
'16w21b': 2,
'17w47b': 3,
'19w46b': 4,
'20w30a': 5,
'20w45a': 6, // datapack
'22w00a': 7, // current
const startSnapshots = {
'13w24a': 1,
'15w31a': 2,
'16w32a': 3,
'17w48a': 4,
'20w06a': 5,
'20w45a': { resource: 7, data: 6 },
'20w46a': 7,
}
const snapshot = new Snapshot(version)

for (let snap in lastSnapshots) {
if (snapshot.getID() <= (new Snapshot(snap)).getID()) {
return lastSnapshots[snap]
let ver;
for (let snap in startSnapshots) {
if (snapshot.getID() >= (new Snapshot(snap)).getID()) {
ver = startSnapshots[snap];
}
}
return
return ['number','undefined'].includes(typeof ver) ? ver : ver[type || 'resource'];
}

// Release //
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pack-format",
"version": "1.0.6",
"version": "1.1.0",
"description": "Returns the pack_format of any Minecraft version, including snapshots",
"scripts": {
"test": "node test"
Expand Down
41 changes: 28 additions & 13 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
const packFormat = require('./')

let total = 0, passed = 0, failed = 0
const test = (input, expected) => {
let ver = packFormat(input)
const test = ([input, type], expected) => {
let ver = packFormat(input, type)
let pass = ver == expected
if (pass) passed++
else failed++
total++
console.log(`${pass ? '+' : '-'} Pack format of ${input} is ${ver}`)
console.log(
(pass ? ' ' : '! ')
+ (type ? type[0].toUpperCase() + type.substr(1) + ' p' : 'P')
+ `ack format of ${input} is ${ver}`
+ (!pass ? ` (should be ${expected})` : '')
)
}

test('1.1', null)
test('1.6', 1)
test('1.9', 2)
test('1.16.1', 5)
test('1.16.3', 6)
test('1.16.2-pre1', 5)
test('1.30', null)
test('11w50a', null)
test('20w30a', 6)
test('99w99a', null)
test([null], null)
test(['invalid'], null)
test(['1'], null)
test(['1.1'], null)
test(['1.6'], 1)
test(['1.9'], 2)
test(['1.16.1'], 5)
test(['1.16.3'], 6)
test(['1.16.2-pre1'], 5)
test(['1.30'], null)
test(['11w50a'], null)
test(['13w23a'], null)
test(['13w24a'], 1)
test(['16w31a'], 2)
test(['16w32a'], 3)
test(['20w30a'], 5)
test(['20w45a'], 7)
test(['20w45a', 'resource'], 7)
test(['20w45a', 'data'], 6)
test(['20w46a', 'data'], 7)

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

0 comments on commit 2dd3b1c

Please sign in to comment.