Skip to content

Commit 6727d64

Browse files
committed
use standardjs
1 parent 763d017 commit 6727d64

File tree

9 files changed

+1407
-1405
lines changed

9 files changed

+1407
-1405
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
22
node_modules/
3+
package-lock.json

compound.js

+36-39
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,53 @@
1-
module.exports= {
2-
'compound':[readCompound,writeCompound,sizeOfCompound]
3-
};
1+
module.exports = {
2+
'compound': [readCompound, writeCompound, sizeOfCompound]
3+
}
44

5-
function readCompound(buffer,offset,typeArgs,rootNode)
6-
{
7-
var results = {
5+
function readCompound (buffer, offset, typeArgs, rootNode) {
6+
const results = {
87
value: {},
98
size: 0
10-
};
9+
}
1110
while (true) {
12-
var typ=this.read(buffer,offset,"i8",rootNode);
11+
const typ = this.read(buffer, offset, 'i8', rootNode)
1312
if (typ.value === 0) {
14-
offset+=typ.size;
15-
results.size+=typ.size;
16-
break;
13+
offset += typ.size
14+
results.size += typ.size
15+
break
1716
}
1817

19-
var readResults=this.read(buffer,offset,"nbt",rootNode);
20-
offset+=readResults.size;
21-
results.size+=readResults.size;
18+
const readResults = this.read(buffer, offset, 'nbt', rootNode)
19+
offset += readResults.size
20+
results.size += readResults.size
2221
results.value[readResults.value.name] = {
2322
type: readResults.value.type,
2423
value: readResults.value.value
25-
};
24+
}
2625
}
27-
return results;
26+
return results
2827
}
2928

30-
function writeCompound(value,buffer,offset,typeArgs,rootNode)
31-
{
32-
var self=this;
29+
function writeCompound (value, buffer, offset, typeArgs, rootNode) {
30+
const self = this
3331
Object.keys(value).map(function (key) {
34-
offset=self.write({
35-
name:key,
36-
type:value[key].type,
37-
value:value[key].value
38-
},buffer,offset,"nbt",rootNode);
39-
});
40-
offset=this.write(0,buffer,offset,"i8",rootNode);
32+
offset = self.write({
33+
name: key,
34+
type: value[key].type,
35+
value: value[key].value
36+
}, buffer, offset, 'nbt', rootNode)
37+
})
38+
offset = this.write(0, buffer, offset, 'i8', rootNode)
4139

42-
return offset;
40+
return offset
4341
}
4442

45-
function sizeOfCompound(value,typeArgs,rootNode)
46-
{
47-
var self=this;
48-
var size=Object.keys(value).reduce(function (size,key) {
49-
return size+self.sizeOf({
50-
name:key,
51-
type:value[key].type,
52-
value:value[key].value
53-
},"nbt",rootNode);
54-
},0);
55-
return 1+size;
56-
}
43+
function sizeOfCompound (value, typeArgs, rootNode) {
44+
const self = this
45+
const size = Object.keys(value).reduce(function (size, key) {
46+
return size + self.sizeOf({
47+
name: key,
48+
type: value[key].type,
49+
value: value[key].value
50+
}, 'nbt', rootNode)
51+
}, 0)
52+
return 1 + size
53+
}

nbt.js

+52-57
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,76 @@
1-
var zlib = require('zlib');
2-
var ProtoDef=require("protodef").ProtoDef;
3-
var compound=require("./compound").compound;
1+
const zlib = require('zlib')
2+
const ProtoDef = require('protodef').ProtoDef
3+
const compound = require('./compound').compound
44

5+
const nbtJson = JSON.stringify(require('./nbt.json'))
6+
const leNbtJson = nbtJson.replace(/(i[0-9]+)/g, 'l$1')
57

6-
var nbtJson=JSON.stringify(require('./nbt.json'));
7-
var leNbtJson=nbtJson.replace(/(i[0-9]+)/g,"l$1");
8-
9-
function createProto(le) {
10-
var proto = new ProtoDef();
11-
proto.addType("compound",compound);
12-
proto.addTypes(JSON.parse(le ? leNbtJson : nbtJson));
13-
return proto;
8+
function createProto (le) {
9+
const proto = new ProtoDef()
10+
proto.addType('compound', compound)
11+
proto.addTypes(JSON.parse(le ? leNbtJson : nbtJson))
12+
return proto
1413
}
1514

16-
var proto=createProto(false);
17-
var protoLE=createProto(true);
15+
const proto = createProto(false)
16+
const protoLE = createProto(true)
1817

19-
function writeUncompressed(value,le) {
20-
return (le ? protoLE : proto).createPacketBuffer("nbt",value);
18+
function writeUncompressed (value, le) {
19+
return (le ? protoLE : proto).createPacketBuffer('nbt', value)
2120
}
2221

23-
function parseUncompressed(data,le) {
24-
return (le ? protoLE : proto).parsePacketBuffer("nbt",data).data;
22+
function parseUncompressed (data, le) {
23+
return (le ? protoLE : proto).parsePacketBuffer('nbt', data).data
2524
}
2625

26+
const hasGzipHeader = function (data) {
27+
let result = true
28+
if (data[0] !== 0x1f) result = false
29+
if (data[1] !== 0x8b) result = false
30+
return result
31+
}
2732

28-
var hasGzipHeader = function(data){
29-
var result=true;
30-
if(data[0]!=0x1f) result=false;
31-
if(data[1]!=0x8b) result=false;
32-
return result;
33-
};
34-
35-
function parse(data, le, callback) {
36-
var isLe=false;
37-
if (typeof le === "function") {
38-
callback=le;
39-
}
40-
else {
41-
isLe=le;
33+
function parse (data, le, callback) {
34+
let isLe = false
35+
if (typeof le === 'function') {
36+
callback = le
37+
} else {
38+
isLe = le
4239
}
4340
if (hasGzipHeader(data)) {
44-
zlib.gunzip(data, function(error, uncompressed) {
41+
zlib.gunzip(data, function (error, uncompressed) {
4542
if (error) {
46-
callback(error, data);
43+
callback(error, data)
4744
} else {
48-
callback(null, parseUncompressed(uncompressed,isLe));
45+
callback(null, parseUncompressed(uncompressed, isLe))
4946
}
50-
});
47+
})
5148
} else {
52-
callback(null, parseUncompressed(data,isLe));
49+
callback(null, parseUncompressed(data, isLe))
5350
}
5451
}
5552

56-
function simplify(data)
57-
{
58-
function transform(value,type)
59-
{
60-
if(type=="compound") {
61-
return Object.keys(value).reduce(function(acc,key){
62-
acc[key]=simplify(value[key]);
63-
return acc;
64-
},{});
53+
function simplify (data) {
54+
function transform (value, type) {
55+
if (type === 'compound') {
56+
return Object.keys(value).reduce(function (acc, key) {
57+
acc[key] = simplify(value[key])
58+
return acc
59+
}, {})
6560
}
66-
if(type=="list") {
67-
return value.value.map(function(v){return transform(v,value.type)});
61+
if (type === 'list') {
62+
return value.value.map(function (v) { return transform(v, value.type) })
6863
}
69-
return value;
64+
return value
7065
}
71-
return transform(data.value,data.type);
66+
return transform(data.value, data.type)
7267
}
7368

74-
module.exports={
75-
writeUncompressed:writeUncompressed,
76-
parseUncompressed:parseUncompressed,
77-
simplify:simplify,
78-
parse:parse,
79-
proto:proto,
80-
protoLE:protoLE
81-
};
69+
module.exports = {
70+
writeUncompressed: writeUncompressed,
71+
parseUncompressed: parseUncompressed,
72+
simplify: simplify,
73+
parse: parse,
74+
proto: proto,
75+
protoLE: protoLE
76+
}

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
},
2222
"devDependencies": {
2323
"chai": "^2.1.0",
24-
"mocha": "^2.1.0"
24+
"mocha": "^2.1.0",
25+
"standard": "^11.0.1"
2526
},
2627
"scripts": {
27-
"test": "mocha --reporter spec"
28+
"test": "mocha --reporter spec",
29+
"pretest": "npm run lint",
30+
"lint": "standard"
2831
},
2932
"dependencies": {
3033
"protodef": "^1.2.1"

0 commit comments

Comments
 (0)