Skip to content

Commit

Permalink
1.1.2
Browse files Browse the repository at this point in the history
- Change input coercing
- Fix major releases returning incorrect values
  • Loading branch information
Nixinova committed Feb 28, 2021
1 parent 25c4e21 commit 0c4017d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.1.2
*2021-02-28*
- Changed coercing of version input to be more lenient.
- Fixed major releases returning the pack format of their last minor release.

## 1.1.1
*2021-02-13*
- Fixed command-line usage not parsing pre-release and release candidate versions.
Expand All @@ -11,7 +16,7 @@
- Removed speculative hardcoded end of the current pack format.

## 1.0.6
*2021-21-09*
*2021-02-09*
- Fixed pack format ranges being exclusive.

## 1.0.5
Expand Down
10 changes: 5 additions & 5 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ if (arg(1) && !arg(1).includes('h'))
console.log(`Pack format of ${arg(1)} is ${getPackFormat(arg(1))}`)
else {
const indent = n => ' '.repeat(n * 4)
const log = (arg, desc) => {
const log = (arg, ...desc) => {
console.log(`\n${indent(2)}pack-format ${arg}`)
for (text of desc) console.log(indent(3) + text)
for (i in desc) console.log(indent(+i + 3) + desc[i])
}
console.log(`\n${indent(1)}pack-format arguments:`)
log('<version>', ['Retrieve the pack format of any Minecraft version.', indent(1) + '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.'])
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.')
}

20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

class Snapshot {
constructor(version) { this.version = version }
getYear() { return parseInt(this.version.replace(/^(\d\d).+$/, '$1')) }
getWeek() { return parseInt(this.version.replace(/^\d\dw(\d\d)\w$/, '$1')) }
getID() { return (this.getYear() - 10) * 52 + this.getWeek() }
get year() { return parseInt(this.version.replace(/^(\d\d).+$/, '$1')) }
get week() { return parseInt(this.version.replace(/^\d\dw(\d\d)\w$/, '$1')) }
get id() { return (this.year - 10) * 52 + this.week }
}

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

// Snapshot //

Expand All @@ -25,18 +25,18 @@ function getPackFormat(version, type) {
}
const snapshot = new Snapshot(version)

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

// Release //

version = version.toLowerCase().replace(' pre-release ', '-pre').replace(' release candidate ', '-rc')
version = version.replace(/-? *pre[- ]?(release)? */i, '-pre').replace(/ *release candidate */i, '-rc')

if (version.includes('-')) {
if (version.includes('1.16.2-pre')) return 5
Expand All @@ -49,7 +49,7 @@ function getPackFormat(version, type) {
2: ['1.9.x', '1.10.x'],
3: ['1.11.x', '1.12.x'],
4: ['1.13.x', '1.14.x'],
5: ['1.15.x', '1.16', '1.16.1'],
5: ['1.15.x', '1.16.0', '1.16.1'],
6: ['1.16.x'],
7: ['1.17.x'],
}
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.1.1",
"version": "1.1.2",
"description": "Returns the pack_format of any Minecraft version, including snapshots",
"scripts": {
"test": "node test"
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# pack-format

pack-format is a Node.js tool for retrieving the `pack_format` of any Minecraft version, including snapshots.
pack-format is a tool for retrieving the `pack_format` of any Minecraft version, including snapshots.

## About

Expand All @@ -15,7 +15,7 @@ It was added in Minecraft version 1.6, and as such using this tool on any versio

pack-format is available on [npm](https://www.npmjs.com/package/pack-format).

To install pack-format, open your command prompt and type `npm install pack-format` to use for a Node.js project, or `npm install -g pack-format` to use from the command line.
To install pack-format, open the command line and type `npm install pack-format` to use for a Node.js project, or `npm install -g pack-format` to use from the command line.

## Usage

Expand All @@ -39,6 +39,6 @@ Pack format of 1.14.4 is 4
> pack-format --resource 1.16.2-pre1
Resource pack format of 1.16.2-pre1 is 5

> pack-format --data 20w30a
> pack-format --data 20w45a
Data pack format of 20w45a is 6
```
4 changes: 3 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ 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.16.2 pre1'], 5)
test(['1.16.2 pre-release 1'], 5)
test(['1.30'], null)
test(['1.16.3'], 6)
test(['11w50a'], null)
test(['13w23a'], null)
test(['13w24a'], 1)
Expand Down

0 comments on commit 0c4017d

Please sign in to comment.