mcdevs-wiki-extractor 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/relink.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/node
2
+ const pandoc = require('pandoc-filter')
3
+ const Link = pandoc.Link
4
+ const toOldNames = require('./common/toOldNames').transformPacketName
5
+
6
+ function relink (key, value, format, meta) {
7
+ if (key === 'Link' && value[2][0].indexOf('#') === 0) { return Link(value[0], value[1], ['#' + toOldNames(value[2][0].substr(1)), value[2][1]]) }
8
+ }
9
+
10
+ pandoc.stdio(relink)
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "mcdevs-wiki-extractor",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Extract structured data from the mcdevs wiki",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "mocha --reporter spec"
8
8
  },
9
9
  "dependencies": {
10
- "parse-wikitext": "^0.3.2",
11
- "async":"~0.9.0"
10
+ "async": "^2.6.1",
11
+ "pandoc-filter": "^1.0.0",
12
+ "pdc": "^0.2.3",
13
+ "ramda": "^0.30.1",
14
+ "parse-wikitext": "^1.0.0"
12
15
  },
13
16
  "devDependencies": {
14
- "mocha": "~2.2.5"
17
+ "mocha": "^11.0.1",
18
+ "standard": "^17.0.0"
15
19
  },
16
20
  "repository": {
17
21
  "type": "git",
@@ -1,236 +1,235 @@
1
+ /* eslint-env mocha */
2
+
1
3
  // items tests
2
4
 
3
- var assert = require("assert");
4
- var protocol_extractor = require("../").protocol_extractor;
5
-
6
- describe("protocol_extractor",function(){
7
- it("parse a simple packet correctly",function(){
8
- var testTable="{| class=\"wikitable\"\n" +
9
- " ! Packet ID\n" +
10
- " ! State\n" +
11
- " ! Bound To\n" +
12
- " ! Field Name\n" +
13
- " ! Field Type\n" +
14
- " ! Notes\n" +
15
- " |-\n" +
16
- " |rowspan=\"2\"| 0x0D\n" +
17
- " |rowspan=\"2\"| Play\n" +
18
- " |rowspan=\"2\"| Client\n" +
19
- " | Collected Entity ID\n" +
20
- " | VarInt\n" +
21
- " | \n" +
22
- " |- \n" +
23
- " | Collector Entity ID\n" +
24
- " | VarInt\n" +
25
- " | \n" +
26
- " |}";
27
-
28
- var expectedTable=[
5
+ const assert = require('assert')
6
+ const protocolExtractor = require('../').protocol_extractor
7
+
8
+ describe('protocol_extractor', function () {
9
+ it('parse a simple packet correctly', function () {
10
+ const testTable = '{| class="wikitable"\n' +
11
+ ' ! Packet ID\n' +
12
+ ' ! State\n' +
13
+ ' ! Bound To\n' +
14
+ ' ! Field Name\n' +
15
+ ' ! Field Type\n' +
16
+ ' ! Notes\n' +
17
+ ' |-\n' +
18
+ ' |rowspan="2"| 0x0D\n' +
19
+ ' |rowspan="2"| Play\n' +
20
+ ' |rowspan="2"| Client\n' +
21
+ ' | Collected Entity ID\n' +
22
+ ' | VarInt\n' +
23
+ ' | \n' +
24
+ ' |- \n' +
25
+ ' | Collector Entity ID\n' +
26
+ ' | VarInt\n' +
27
+ ' | \n' +
28
+ ' |}'
29
+
30
+ const expectedTable = [
29
31
  {
30
- "Packet ID":"0x0D",
31
- "State":"Play",
32
- "Bound To":"Client",
33
- "Field Name":"Collected Entity ID",
34
- "Field Type":"VarInt",
35
- "Notes":""
32
+ 'Packet ID': '0x0D',
33
+ State: 'Play',
34
+ 'Bound To': 'Client',
35
+ 'Field Name': 'Collected Entity ID',
36
+ 'Field Type': 'VarInt',
37
+ Notes: ''
36
38
  },
37
39
  {
38
- "Packet ID":"0x0D",
39
- "State":"Play",
40
- "Bound To":"Client",
41
- "Field Name":"Collector Entity ID",
42
- "Field Type":"VarInt",
43
- "Notes":""
40
+ 'Packet ID': '0x0D',
41
+ State: 'Play',
42
+ 'Bound To': 'Client',
43
+ 'Field Name': 'Collector Entity ID',
44
+ 'Field Type': 'VarInt',
45
+ Notes: ''
44
46
  }
45
- ];
47
+ ]
46
48
 
47
- var expectedPacket={
48
- "id": "0x0D",
49
- "fields": [
49
+ const expectedPacket = {
50
+ id: '0x0D',
51
+ fields: [
50
52
  {
51
- "name": "Collected Entity ID",
52
- "type": "VarInt"
53
+ name: 'Collected Entity ID',
54
+ type: 'VarInt'
53
55
  },
54
56
  {
55
- "name": "Collector Entity ID",
56
- "type": "VarInt"
57
+ name: 'Collector Entity ID',
58
+ type: 'VarInt'
57
59
  }
58
60
  ]
59
- };
60
-
61
-
62
- var actualTable=protocol_extractor.parseWikiTable(testTable.split("\n"));
63
- //console.log(actualTable);
64
-
65
- var actualPacket=protocol_extractor.tableToPacket(actualTable);
66
-
67
- //console.log(actualPacket);
68
-
69
-
70
-
71
- assert.deepEqual(actualTable,expectedTable);
72
-
73
- assert.deepEqual(actualPacket,expectedPacket);
74
- });
75
-
76
- it("parse a more complicated packet",function(){
77
- var testTable2= "{| class=\"wikitable\"\n"+
78
- " ! Packet ID\n"+
79
- " ! State\n"+
80
- " ! Bound To\n"+
81
- " ! Field Name\n"+
82
- " ! Field Type\n"+
83
- " ! Notes\n"+
84
- " |-\n"+
85
- " |rowspan=\"3\"| 0x06\n"+
86
- " |rowspan=\"3\"| Play\n"+
87
- " |rowspan=\"3\"| Client\n"+
88
- " | Health\n"+
89
- " | Float\n"+
90
- " | 0 or less = dead, 20 = full HP\n"+
91
- " |-\n"+
92
- " | Food\n"+
93
- " | VarInt\n"+
94
- " | 0–20\n"+
95
- " |- \n"+
96
- " | Food Saturation\n"+
97
- " | Float\n"+
98
- " | Seems to vary from 0.0 to 5.0 in integer increments\n"+
99
- " |}";
100
-
101
- //console.log(protocol_extractor.tableToPacket(protocol_extractor.parseWikiTable(testTable2.split("\n"))));
102
- });
103
-
104
- it("parse a packet with colspan",function(){
105
- var testTable3="{| class=\"wikitable\"\n"+
106
- " ! Packet ID\n"+
107
- " ! State\n"+
108
- " ! Bound To\n"+
109
- " !colspan=\"2\"| Field Name\n"+
110
- " !colspan=\"2\"| Field Type\n"+
111
- " ! Notes\n"+
112
- " |-\n"+
113
- " |rowspan=\"6\"| 0x22\n"+
114
- " |rowspan=\"6\"| Play\n"+
115
- " |rowspan=\"6\"| Client\n"+
116
- " |colspan=\"2\"| Chunk X\n"+
117
- " |colspan=\"2\"| Int\n"+
118
- " | Chunk X coordinate\n"+
119
- " |-\n"+
120
- " |colspan=\"2\"| Chunk Z\n"+
121
- " |colspan=\"2\"| Int\n"+
122
- " | Chunk Z coordinate\n"+
123
- " |-\n"+
124
- " |colspan=\"2\"| Record Count\n"+
125
- " |colspan=\"2\"| VarInt\n"+
126
- " | Number of elements in the following array, a.k.a. the number of blocks affected\n"+
127
- " |-\n"+
128
- " |rowspan=\"3\"| Record\n"+
129
- " | Horizontal Position\n"+
130
- " |rowspan=\"3\"| Array\n"+
131
- " | Unsigned Byte\n"+
132
- " | The 4 most significant bits (<code>0xF0</code>) encode the X coordinate, relative to the chunk. The 4 least significant bits (<code>0x0F</code>) encode the Z coordinate, relative to the chunk.\n"+
133
- " |-\n"+
134
- " | Y Coordinate\n"+
135
- " | Unsigned Byte\n"+
136
- " | \n"+
137
- " |-\n"+
138
- " | Block ID\n"+
139
- " | VarInt\n"+
140
- " | The new block ID for the block. <code><nowiki>id &lt;&lt; 4 | data</nowiki></code>\n"+
141
- " |}";
142
-
143
- // need special handling
144
- // not done yet : colspan in th
145
-
146
- //console.log(JSON.stringify(protocol_extractor.parseWikiTable(testTable3.split("\n")),null,2));
147
- });
148
-
149
- it("parse a packet with rowspan",function(){
150
-
151
-
152
- var testTable4= "{| class=\"wikitable\"\n"+
153
- " ! Packet ID\n"+
154
- " ! State\n"+
155
- " ! Bound To\n"+
156
- " ! Field Name\n"+
157
- " ! Field Type\n"+
158
- " ! Notes\n"+
159
- " |-\n"+
160
- " |rowspan=\"1\"| 0x00\n"+
161
- " | Status\n"+
162
- " | Server\n"+
163
- " |colspan=\"3\"| ''no fields''\n"+
164
- " |}\n";
165
-
166
- var expectedTable4=[
61
+ }
62
+
63
+ const actualTable = protocolExtractor.parseWikiTable(testTable.split('\n'))
64
+ // console.log(actualTable);
65
+
66
+ const actualPacket = protocolExtractor.tableToPacket(actualTable)
67
+
68
+ // console.log(actualPacket);
69
+
70
+ assert.deepEqual(actualTable, expectedTable)
71
+
72
+ assert.deepEqual(actualPacket, expectedPacket)
73
+ })
74
+
75
+ it('parse a more complicated packet', function () {
76
+ const testTable2 = '{| class="wikitable"\n' +
77
+ ' ! Packet ID\n' +
78
+ ' ! State\n' +
79
+ ' ! Bound To\n' +
80
+ ' ! Field Name\n' +
81
+ ' ! Field Type\n' +
82
+ ' ! Notes\n' +
83
+ ' |-\n' +
84
+ ' |rowspan="3"| 0x06\n' +
85
+ ' |rowspan="3"| Play\n' +
86
+ ' |rowspan="3"| Client\n' +
87
+ ' | Health\n' +
88
+ ' | Float\n' +
89
+ ' | 0 or less = dead, 20 = full HP\n' +
90
+ ' |-\n' +
91
+ ' | Food\n' +
92
+ ' | VarInt\n' +
93
+ ' | 0–20\n' +
94
+ ' |- \n' +
95
+ ' | Food Saturation\n' +
96
+ ' | Float\n' +
97
+ ' | Seems to vary from 0.0 to 5.0 in integer increments\n' +
98
+ ' |}'
99
+ console.log(testTable2)
100
+
101
+ // console.log(protocol_extractor.tableToPacket(protocol_extractor.parseWikiTable(testTable2.split("\n"))));
102
+ })
103
+
104
+ it('parse a packet with colspan', function () {
105
+ const testTable3 = '{| class="wikitable"\n' +
106
+ ' ! Packet ID\n' +
107
+ ' ! State\n' +
108
+ ' ! Bound To\n' +
109
+ ' !colspan="2"| Field Name\n' +
110
+ ' !colspan="2"| Field Type\n' +
111
+ ' ! Notes\n' +
112
+ ' |-\n' +
113
+ ' |rowspan="6"| 0x22\n' +
114
+ ' |rowspan="6"| Play\n' +
115
+ ' |rowspan="6"| Client\n' +
116
+ ' |colspan="2"| Chunk X\n' +
117
+ ' |colspan="2"| Int\n' +
118
+ ' | Chunk X coordinate\n' +
119
+ ' |-\n' +
120
+ ' |colspan="2"| Chunk Z\n' +
121
+ ' |colspan="2"| Int\n' +
122
+ ' | Chunk Z coordinate\n' +
123
+ ' |-\n' +
124
+ ' |colspan="2"| Record Count\n' +
125
+ ' |colspan="2"| VarInt\n' +
126
+ ' | Number of elements in the following array, a.k.a. the number of blocks affected\n' +
127
+ ' |-\n' +
128
+ ' |rowspan="3"| Record\n' +
129
+ ' | Horizontal Position\n' +
130
+ ' |rowspan="3"| Array\n' +
131
+ ' | Unsigned Byte\n' +
132
+ ' | The 4 most significant bits (<code>0xF0</code>) encode the X coordinate, relative to the chunk. The 4 least significant bits (<code>0x0F</code>) encode the Z coordinate, relative to the chunk.\n' +
133
+ ' |-\n' +
134
+ ' | Y Coordinate\n' +
135
+ ' | Unsigned Byte\n' +
136
+ ' | \n' +
137
+ ' |-\n' +
138
+ ' | Block ID\n' +
139
+ ' | VarInt\n' +
140
+ ' | The new block ID for the block. <code><nowiki>id &lt;&lt; 4 | data</nowiki></code>\n' +
141
+ ' |}'
142
+
143
+ console.log(testTable3)
144
+ // need special handling
145
+ // not done yet : colspan in th
146
+
147
+ // console.log(JSON.stringify(protocol_extractor.parseWikiTable(testTable3.split("\n")),null,2));
148
+ })
149
+
150
+ it('parse a packet with rowspan', function () {
151
+ const testTable4 = '{| class="wikitable"\n' +
152
+ ' ! Packet ID\n' +
153
+ ' ! State\n' +
154
+ ' ! Bound To\n' +
155
+ ' ! Field Name\n' +
156
+ ' ! Field Type\n' +
157
+ ' ! Notes\n' +
158
+ ' |-\n' +
159
+ ' |rowspan="1"| 0x00\n' +
160
+ ' | Status\n' +
161
+ ' | Server\n' +
162
+ " |colspan=\"3\"| ''no fields''\n" +
163
+ ' |}\n'
164
+
165
+ const expectedTable4 = [
167
166
  {
168
- "Packet ID":"0x00",
169
- "State":"Status",
170
- "Bound To":"Server",
171
- "Field Name":"''no fields''",
172
- "Field Type":"''no fields''",
173
- "Notes":"''no fields''"
167
+ 'Packet ID': '0x00',
168
+ State: 'Status',
169
+ 'Bound To': 'Server',
170
+ 'Field Name': "''no fields''",
171
+ 'Field Type': "''no fields''",
172
+ Notes: "''no fields''"
174
173
  }
175
- ];
176
-
177
- // need to handle colspan
178
-
179
- var lines4=testTable4.split("\n");
180
- //console.log(JSON.stringify(protocol_extractor.tableToRows(lines4),null,2));
181
-
182
- var actualTable4=protocol_extractor.parseWikiTable(lines4);
183
-
184
- //console.log(JSON.stringify(expectedTable4,null,2));
185
- //console.log(JSON.stringify(actualTable4,null,2));
186
-
187
- assert.deepEqual(actualTable4,expectedTable4);
188
- //console.log(actualTable4);
189
- //console.log(protocol_extractor.tableToPacket(actualTable4));
190
-
191
- //console.log(protocol_extractor.tableToPacket(actualTable4));
192
- });
193
-
194
- it("parse a packet with more rowspan",function(){
195
-
196
- var testTable5="{| class=\"wikitable\"\n"+
197
- " |-\n"+
198
- " ! Packet ID\n"+
199
- " ! State\n"+
200
- " ! Bound To\n"+
201
- " ! Field Name\n"+
202
- " ! Field Type\n"+
203
- " ! Notes\n"+
204
- " |-\n"+
205
- " |rowspan=\"6\"| 0x08\n"+
206
- " |rowspan=\"6\"| Play\n"+
207
- " |rowspan=\"6\"| Server\n"+
208
- " | Location\n"+
209
- " | Position\n"+
210
- " | Block position\n"+
211
- " |-\n"+
212
- " | Face\n"+
213
- " | Byte\n"+
214
- " | The face on which the block is placed (see above)\n"+
215
- " |-\n"+
216
- " | Held Item\n"+
217
- " | [[Slot Data|Slot]]\n"+
218
- " | \n"+
219
- " |-\n"+
220
- " | Cursor Position X\n"+
221
- " | Byte\n"+
222
- " | The position of the crosshair on the block\n"+
223
- " |-\n"+
224
- " | Cursor Position Y \n"+
225
- " | Byte\n"+
226
- " | \n"+
227
- " |-\n"+
228
- " | Cursor Position Z\n"+
229
- " | Byte\n"+
230
- " | \n"+
231
- " |}";
232
-
233
- //console.log(JSON.stringify(protocol_extractor.tableToRows(testTable5.split("\n")),null,2));
234
- //console.log(protocol_extractor.parseWikiTable(testTable5.split("\n")));
174
+ ]
175
+
176
+ // need to handle colspan
177
+
178
+ const lines4 = testTable4.split('\n')
179
+ // console.log(JSON.stringify(protocol_extractor.tableToRows(lines4),null,2));
180
+
181
+ const actualTable4 = protocolExtractor.parseWikiTable(lines4)
182
+
183
+ // console.log(JSON.stringify(expectedTable4,null,2));
184
+ // console.log(JSON.stringify(actualTable4,null,2));
185
+
186
+ assert.deepEqual(actualTable4, expectedTable4)
187
+ // console.log(actualTable4);
188
+ // console.log(protocol_extractor.tableToPacket(actualTable4));
189
+
190
+ // console.log(protocol_extractor.tableToPacket(actualTable4));
191
+ })
192
+
193
+ it('parse a packet with more rowspan', function () {
194
+ const testTable5 = '{| class="wikitable"\n' +
195
+ ' |-\n' +
196
+ ' ! Packet ID\n' +
197
+ ' ! State\n' +
198
+ ' ! Bound To\n' +
199
+ ' ! Field Name\n' +
200
+ ' ! Field Type\n' +
201
+ ' ! Notes\n' +
202
+ ' |-\n' +
203
+ ' |rowspan="6"| 0x08\n' +
204
+ ' |rowspan="6"| Play\n' +
205
+ ' |rowspan="6"| Server\n' +
206
+ ' | Location\n' +
207
+ ' | Position\n' +
208
+ ' | Block position\n' +
209
+ ' |-\n' +
210
+ ' | Face\n' +
211
+ ' | Byte\n' +
212
+ ' | The face on which the block is placed (see above)\n' +
213
+ ' |-\n' +
214
+ ' | Held Item\n' +
215
+ ' | [[Slot Data|Slot]]\n' +
216
+ ' | \n' +
217
+ ' |-\n' +
218
+ ' | Cursor Position X\n' +
219
+ ' | Byte\n' +
220
+ ' | The position of the crosshair on the block\n' +
221
+ ' |-\n' +
222
+ ' | Cursor Position Y \n' +
223
+ ' | Byte\n' +
224
+ ' | \n' +
225
+ ' |-\n' +
226
+ ' | Cursor Position Z\n' +
227
+ ' | Byte\n' +
228
+ ' | \n' +
229
+ ' |}'
230
+ console.log(testTable5)
231
+
232
+ // console.log(JSON.stringify(protocol_extractor.tableToRows(testTable5.split("\n")),null,2));
233
+ // console.log(protocol_extractor.parseWikiTable(testTable5.split("\n")));
235
234
  })
236
- });
235
+ })
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- node_modules
package/circle.yml DELETED
@@ -1,3 +0,0 @@
1
- machine:
2
- node:
3
- version: 0.10.28