Function
Static Public Summary | ||
public |
assert deep equality each value in Object|Array |
|
public |
arrayLength(name: string, length: number | string) assert array to be a given length |
|
public |
bindObject(obj: object, ctx: object): object bind each function in an object to a given context |
|
public |
asserts a variable matches a given bitmask |
|
public |
map a value by checking whether it has some bits set |
|
public |
assert value via callback |
|
public |
replace a variable in the stack by a mapped version of itself |
|
public |
assert equality objects |
|
public |
assert strict equal single value |
|
public |
asserts a variable exists in the first place |
|
public |
retrieve the first object from an array of objects, matching a specified attribute against a specified value like findAll, but returning only the first element |
|
public |
retrieve a filtered array of objects from an array of objects, matching a specified attribute against a specified value |
|
public |
retrieve a value from an accessable type (like array[0] or object['foo']) |
|
public |
assert value to be within the bounds of an array |
|
public |
assert array|object to contain item |
|
public |
replace Corrode#vars completely with a value from Corrode#vars especially useful when pushing a variable further up in the stack |
|
public |
tapBindObject(obj: object, ctx: object): object bind each function in an object with a tap to a given context |
Static Public
public allEqual(name: string, testValue: mixed) source
import {allEqual} from 'corrode/src/assert/index.js'
assert deep equality each value in Object|Array
Params:
Name | Type | Attribute | Description |
name | string | key of the object|array to test |
|
testValue | mixed | comparision, undefined for auto-detect |
Throw:
* |
TypeError assertion-error |
public arrayLength(name: string, length: number | string) source
import {arrayLength} from 'corrode/src/assert/index.js'
assert array to be a given length
Throw:
* |
TypeError assertion-error |
public bindObject(obj: object, ctx: object): object source
import {bindObject} from 'corrode/src/utils/index.js'
bind each function in an object to a given context
public bitmask(name: string, mask: number, assertMatch: boolean) source
import {bitmask} from 'corrode/src/assert/index.js'
asserts a variable matches a given bitmask
Throw:
* |
TypeError assertion-error |
public bitmask(name: string, maskObject: Object | number): * source
import {bitmask} from 'corrode/src/map/index.js'
map a value by checking whether it has some bits set
Params:
Name | Type | Attribute | Description |
name | string | identifier of the variable, to write to Corrode#vars |
|
maskObject | Object | number | Object or number by which to check the bits of the variable to map |
Return:
* |
Example:
parser.uint8('bits').map.bitmask('bits', 0x80)
// [0b10111110] => { bits: true }
parser.uint8('bits').map.bitmask('bits', {
isCompressed: 0x80,
isReadOnly: 0x40
})
// [0b10111110] => { bits: { isCompressed: true, isReadOnly: false } }
public callback(name: string, fn: function, testname: string) source
import {callback} from 'corrode/src/assert/index.js'
assert value via callback
Throw:
* |
TypeError assertion-error |
public callback(name: string, fn: function(val: *)) source
import {callback} from 'corrode/src/map/index.js'
replace a variable in the stack by a mapped version of itself
Example:
parser.uint8('value').map.callback('value', val => (val - 1) * 2)
// [21] => { value: 10 }
public deepEqual(name: string, value: object) source
import {deepEqual} from 'corrode/src/assert/index.js'
assert equality objects
Throw:
* |
TypeError assertion-error |
Test:
public equal(name: string, value: mixed) source
import {equal} from 'corrode/src/assert/index.js'
assert strict equal single value
Params:
Name | Type | Attribute | Description |
name | string | key of the value to test |
|
value | mixed | comparision |
Throw:
* |
TypeError assertion-error |
Test:
public exists(name: string) source
import {exists} from 'corrode/src/assert/index.js'
asserts a variable exists in the first place
Params:
Name | Type | Attribute | Description |
name | string | key of the value to test |
Throw:
* |
TypeError assertion-error |
Test:
public find(name: string, array: Array<Object>, attr: string, src: string) source
import {find} from 'corrode/src/map/index.js'
retrieve the first object from an array of objects, matching a specified attribute against a specified value like findAll, but returning only the first element
Params:
Name | Type | Attribute | Description |
name | string | identifier of the variable, to write to Corrode#vars |
|
array | Array<Object> | array, containing the objects to filter |
|
attr | string | identifier of the attribute from an object of |
|
src | string |
|
Corrode#vars-identifier to read from |
Throw:
when no object can be found |
Example:
parser.uint8('matchAgainst').map.find('matchAgainst', [
{ id: 1, name: 'foo' },
{ id: 7, name: 'bar' },
{ id: 4, name: 'qux' }
], 'id')
// [4] => { matchAgainst: { id: 4, name: 'qux' } }
// [2] => Error cannot find object!
Test:
public findAll(name: string, array: Array<Object>, attr: string, src: string) source
import {findAll} from 'corrode/src/map/index.js'
retrieve a filtered array of objects from an array of objects, matching a specified attribute against a specified value
Params:
Name | Type | Attribute | Description |
name | string | identifier of the variable, to write to Corrode#vars |
|
array | Array<Object> | array, containing the objects to filter |
|
attr | string | identifier of the attribute from an object of |
|
src | string |
|
Corrode#vars-identifier to read from |
Throw:
when no object can be found |
Example:
parser.uint8('matchAgainst').map.findAll('matchAgainst', [
{ children: 1, name: 'foo' },
{ children: 2, name: 'bar' },
{ children: 2, name: 'qux' }
], 'children')
// [2] => { matchAgainst: [
// { children: 2, name: 'bar' },
// { children: 2, name: 'qux' }
// ]}
// [1] => { matchAgainst: [
// { children: 1, name: 'foo' }
// ]}
Test:
public get(name: string, accessable: array | object | string, src: string) source
import {get} from 'corrode/src/map/index.js'
retrieve a value from an accessable type (like array[0] or object['foo'])
Params:
Name | Type | Attribute | Description |
name | string | identifier of the variable to map |
|
accessable | array | object | string | accessable variable |
|
src | string |
|
identifier of the variable in Corrode#vars by which to access |
Example:
parser.uint8('accessor').map.get('accessor', ['A', 'B', 'C', 'D'])
// [2] => { accessor: 'C' }
parser.terminatedString('accessor').map.get('accessor', { foo: 'A', bar: 'B', qux: 'C' })
// ['q', 'u', 'x', 0x00] => { accessor: 'C' }
public inBounds(name: string, value: array) source
import {inBounds} from 'corrode/src/assert/index.js'
assert value to be within the bounds of an array
Params:
Name | Type | Attribute | Description |
name | string | key of the number to test |
|
value | array | comparision |
Throw:
* |
TypeError assertion-error |
Test:
public includes(name: string, arr: array | object) source
import {includes} from 'corrode/src/assert/index.js'
assert array|object to contain item
Throw:
* |
TypeError assertion-error |
public push(name: string) source
import {push} from 'corrode/src/map/index.js'
replace Corrode#vars completely with a value from Corrode#vars especially useful when pushing a variable further up in the stack
Params:
Name | Type | Attribute | Description |
name | string |
|
identifier of the variable being used as replacement |
Example:
parser.loop('array', function(){
this
.uint8('value')
.map.double()
.map.push('value');
});
// [1, 2, 3, 4] => { array: [2, 4, 6, 8] }
Corrode.addExtension('doStuff', function(){
this
.uint32('address')
.tap(function(){
this.vars.address = `0x${this.vars.address.toString(16)}`;
})
.map.push('address');
});
parser.ext.doStuff('hexAddress');
// [245] => { hexAddress: '0xf5' }
public tapBindObject(obj: object, ctx: object): object source
import {tapBindObject} from 'corrode/src/utils/index.js'
bind each function in an object with a tap to a given context