binary-types
Advanced tools
Comparing version 1.1.2 to 2.0.0
15
index.js
'use strict'; | ||
try { //jshint evil:true | ||
void new Function('return function*(){yield 1}') | ||
module.exports = require('./index.es6') | ||
} | ||
catch (e) { | ||
module.exports = require('./index.es5') | ||
} | ||
var binary = exports | ||
, read = require('./read') | ||
, write = require('./write') | ||
binary.read = read | ||
binary.write = write | ||
binary.le = { read: read.le, write: write.le } | ||
binary.be = { read: read.be, write: write.be } |
{ | ||
"name": "binary-types", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "helpers for binary-parser", | ||
@@ -24,3 +24,3 @@ "main": "index.js", | ||
"scripts": { | ||
"prepublish": "regenerator -r index.es6.js > index.es5.js" | ||
"prepublish": "regenerator -r read.es6.js > read.es5.js" | ||
}, | ||
@@ -27,0 +27,0 @@ "devDependencies": { |
@@ -9,50 +9,62 @@ # binary-types | ||
## API | ||
## Types | ||
* u8 | ||
* u16le | ||
* u16be | ||
* u32le | ||
* u32be | ||
* f32le | ||
* f32be | ||
* f64le | ||
* f64be | ||
## Examples | ||
```js | ||
'use strict' | ||
module.exports = require('binary-parser')(parser) | ||
var read = require('binary-types') | ||
var binary = require('binary-types') | ||
, read = binary.read | ||
, write = binary.write | ||
function* parser() { | ||
exports.parse = require('binary-parser')(function* parser() { | ||
var value = yield* read.u8() | ||
return value | ||
}) | ||
exports.bufferify = function(str) { | ||
var buf = Buffer(str.length) | ||
if (buf.length > 0xFF) throw new Error('too long') | ||
return Buffer.concat(write.u8(buf.length), buf) | ||
} | ||
``` | ||
### u8 | ||
### u16le | ||
### u16be | ||
### u32le | ||
### u32be | ||
### f32le | ||
### f32be | ||
### f64le | ||
### f64be | ||
## API | ||
```js | ||
var binary = require('binary-types') | ||
, read = binary.read | ||
, write = binary.write | ||
``` | ||
what it says on the tin. | ||
### `yield* read[type]()` | ||
### le | ||
returns the decoded value. | ||
```js | ||
read.le = | ||
{ __proto__: read | ||
, u16: read.u16le | ||
, u32: read.u32le | ||
, f32: read.f32le | ||
, f64: read.f64le | ||
} | ||
``` | ||
### `write[type](value)` | ||
### be | ||
returns a buffer with the encoded value. | ||
```js | ||
read.be = | ||
{ __proto__: read | ||
, u16: read.u16be | ||
, u32: read.u32be | ||
, f32: read.f32be | ||
, f64: read.f64be | ||
} | ||
### endianness shortcuts | ||
to avoid repeating the endianness over and over: | ||
``` | ||
> read.be.u16 === read.u16be | ||
true | ||
> read.le.u16 === read.u16le | ||
true | ||
> binary.le.read === read.le | ||
true | ||
> binary.be.write === write.be | ||
true | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22505
9
640
70