Skip to content

Commit e5e565f

Browse files
authored
Merge pull request keichi#54 from keichi/fix-readme-format
Several cosmetic improvements to README
2 parents c6b22b7 + b6a946e commit e5e565f

File tree

1 file changed

+79
-79
lines changed

1 file changed

+79
-79
lines changed

README.md

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ With no prefix, it parses as a signed number, with `u` prefixed as an unsigned n
9191

9292
```javascript
9393
var parser = new Parser()
94-
// Signed 32-bit integer (little endian)
94+
// Signed 32-bit integer (little endian)
9595
.int32le('a')
9696
// Unsigned 8-bit integer
9797
.uint8('b')
@@ -126,7 +126,7 @@ with an alphabet. `options` is an object; following options are available:
126126
Use number for statically sized arrays, string to reference another variable and
127127
function to do some calculation.
128128
- `zeroTerminated` - (Optional, defaults to `false`) If true, then this parser reads until it reaches zero.
129-
- `greedy - (Optional, defaults to `false`) If true, then this parser reads until it reaches the end of the buffer. Will consume zero-bytes.
129+
- `greedy` - (Optional, defaults to `false`) If true, then this parser reads until it reaches the end of the buffer. Will consume zero-bytes.
130130
- `stripNull` - (Optional, must be used with `length`) If true, then strip null characters from end of the string
131131

132132
### buffer(name [,options])
@@ -149,63 +149,63 @@ Parse bytes as an array. `options` is an object; following options are available
149149
- `type` - (Required) Type of the array element. Can be a string or an user defined Parser object.
150150
If it's a string, you have to choose from [u]int{8, 16, 32}{le, be}.
151151
- `length` - (either `length`, `lengthInBytes`, or `readUntil` is required) Length of the array. Can be a number, string or a function.
152-
Use number for statically sized arrays.
152+
Use number for statically sized arrays.
153153
- `lengthInBytes` - (either `length`, `lengthInBytes`, or `readUntil` is required) Length of the array expressed in bytes. Can be a number, string or a function.
154-
Use number for statically sized arrays.
154+
Use number for statically sized arrays.
155155
- `readUntil` - (either `length`, `lengthInBytes`, or `readUntil` is required) If `'eof'`, then this parser
156-
reads until the end of `Buffer` object. If function it reads until the function returns true.
156+
reads until the end of `Buffer` object. If function it reads until the function returns true.
157157

158158
```javascript
159159
var parser = new Parser()
160-
// Statically sized array
161-
.array('data', {
162-
type: 'int32',
163-
length: 8
164-
})
165-
166-
// Dynamically sized array (reference another variable)
167-
.uint8('dataLength')
168-
.array('data2', {
169-
type: 'int32',
170-
length: 'dataLength'
171-
})
172-
173-
// Dynamically sized array (with some calculation)
174-
.array('data3', {
175-
type: 'int32',
176-
length: function() { return this.dataLength - 1; } // other fields are available through this
177-
});
178-
179-
// Statically sized array
180-
.array('data4', {
181-
type: 'int32',
182-
lengthInBytes: 16
183-
})
184-
185-
// Dynamically sized array (reference another variable)
186-
.uint8('dataLengthInBytes')
187-
.array('data5', {
188-
type: 'int32',
189-
lengthInBytes: 'dataLengthInBytes'
190-
})
191-
192-
// Dynamically sized array (with some calculation)
193-
.array('data6', {
194-
type: 'int32',
195-
lengthInBytes: function() { return this.dataLengthInBytes - 4; } // other fields are available through this
196-
})
197-
198-
// Dynamically sized array (with stop-check on parsed item)
199-
.array('data7', {
200-
type: 'int32',
201-
readUntil: function(item, buffer) { return item === 42 } // stop when specific item is parsed. buffer can be used to perform a read-ahead.
202-
});
203-
204-
// Use user defined parser object
205-
.array('data8', {
206-
type: userDefinedParser,
207-
length: 'dataLength'
208-
});
160+
// Statically sized array
161+
.array('data', {
162+
type: 'int32',
163+
length: 8
164+
})
165+
166+
// Dynamically sized array (references another variable)
167+
.uint8('dataLength')
168+
.array('data2', {
169+
type: 'int32',
170+
length: 'dataLength'
171+
})
172+
173+
// Dynamically sized array (with some calculation)
174+
.array('data3', {
175+
type: 'int32',
176+
length: function() { return this.dataLength - 1; } // other fields are available through this
177+
});
178+
179+
// Statically sized array
180+
.array('data4', {
181+
type: 'int32',
182+
lengthInBytes: 16
183+
})
184+
185+
// Dynamically sized array (references another variable)
186+
.uint8('dataLengthInBytes')
187+
.array('data5', {
188+
type: 'int32',
189+
lengthInBytes: 'dataLengthInBytes'
190+
})
191+
192+
// Dynamically sized array (with some calculation)
193+
.array('data6', {
194+
type: 'int32',
195+
lengthInBytes: function() { return this.dataLengthInBytes - 4; } // other fields are available through this
196+
})
197+
198+
// Dynamically sized array (with stop-check on parsed item)
199+
.array('data7', {
200+
type: 'int32',
201+
readUntil: function(item, buffer) { return item === 42 } // stop when specific item is parsed. buffer can be used to perform a read-ahead.
202+
});
203+
204+
// Use user defined parser object
205+
.array('data8', {
206+
type: userDefinedParser,
207+
length: 'dataLength'
208+
});
209209
```
210210

211211
### choice(name [,options])
@@ -214,9 +214,9 @@ Combining `choice` with `array` is useful for parsing a typical
214214
[Type-Length-Value](http://en.wikipedia.org/wiki/Type-length-value) styled format.
215215

216216
- `tag` - (Required) The value used to determine which parser to use from the `choices`
217-
Can be a string pointing to another field or a function.
217+
Can be a string pointing to another field or a function.
218218
- `choices` - (Required) An object which key is an integer and value is the parser which is executed
219-
when `tag` equals the key value.
219+
when `tag` equals the key value.
220220
- `defaultChoice` - (Optional) In case of the tag value doesn't match any of `choices` use this parser.
221221

222222
```javascript
@@ -225,15 +225,15 @@ var parser2 = ...;
225225
var parser3 = ...;
226226

227227
var parser = new Parser()
228-
.uint8('tagValue')
229-
.choice('data', {
230-
tag: 'tagValue',
231-
choices: {
232-
1: parser1, // When tagValue == 1, execute parser1
233-
4: parser2, // When tagValue == 4, execute parser2
234-
5: parser3 // When tagValue == 5, execute parser3
235-
}
236-
});
228+
.uint8('tagValue')
229+
.choice('data', {
230+
tag: 'tagValue',
231+
choices: {
232+
1: parser1, // When tagValue == 1, execute parser1
233+
4: parser2, // When tagValue == 4, execute parser2
234+
5: parser3 // When tagValue == 5, execute parser3
235+
}
236+
});
237237
```
238238

239239
### nest(name [,options])
@@ -252,12 +252,12 @@ The default endianess of `Parser` is set to big-endian.
252252
```javascript
253253
var parser = new Parser()
254254
.endianess('le')
255-
// You can specify endianess explicitly
256-
.uint16be('a')
255+
// You can specify endianess explicitly
256+
.uint16be('a')
257257
.uint32le('a')
258-
// Or you can omit endianess (in this case, little-endian is used)
259-
.uint16('b')
260-
.int32('c')
258+
// Or you can omit endianess (in this case, little-endian is used)
259+
.uint16('b')
260+
.int32('c')
261261
```
262262

263263
### namely(alias)
@@ -356,14 +356,14 @@ Usually used for debugging.
356356
These are common options that can be specified in all parsers.
357357

358358
- `formatter` - Function that transforms the parsed value into a more desired form.
359-
```javascript
360-
var parser = new Parser()
361-
.array('ipv4', {
362-
type: uint8,
363-
length: '4',
364-
formatter: function(arr) { return arr.join('.'); }
365-
});
366-
```
359+
```javascript
360+
var parser = new Parser()
361+
.array('ipv4', {
362+
type: uint8,
363+
length: '4',
364+
formatter: function(arr) { return arr.join('.'); }
365+
});
366+
```
367367

368368
- `assert` - Do assertion on the parsed result (useful for checking magic numbers and so on).
369369
If `assert` is a `string` or `number`, the actual parsed result will be compared with it
@@ -374,7 +374,7 @@ On the other hand, if `assert` is a function, that function is executed with one
374374
```javascript
375375
// simple maginc number validation
376376
var ClassFile =
377-
Parser.start()
377+
Parser.start()
378378
.endianess('big')
379379
.uint32('magic', {assert: 0xcafebabe})
380380

0 commit comments

Comments
 (0)