bison-types
Advanced tools
Comparing version
{ | ||
"name": "bison-types", | ||
"version": "2.0.0", | ||
"version": "2.0.2", | ||
"description": "Convert between json and binary", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -69,4 +69,6 @@ # bison-types | ||
## Provided simple types | ||
## Provided types | ||
The following types can be declared as a string, for example: `{timestamp: 'uint16'}`. | ||
* `uint8` - unsigned 8 bit integer | ||
@@ -84,8 +86,28 @@ * `uint16` - unsigned 16 bit integer | ||
The is also an `enumeration` type, which can be used to represent enums from arrays of objects: | ||
```coffee | ||
# will store the index in the array | ||
levelIndex = bison.enumeration 'uint8', ['admin', 'reader', 'writer'] | ||
# will store the value in the object | ||
levelCode = bison.enumeration 'uint16', | ||
'admin': 0xb8a3 | ||
'reader': 0xb90a | ||
'writer': 0xf23c | ||
bison.preCompile | ||
'levelIndex': levelIndex | ||
'levelCode': levelCode | ||
'user': [ | ||
{id: 'uint8'} | ||
{levelX: levelIndex} | ||
{levelY: levelCode} | ||
] | ||
``` | ||
## Creating your own custom types | ||
*NOTE:* All examples are written in coffeescript | ||
There are 2 different ways that you can define a custom type | ||
There are 2 different ways that you can define a custom type | ||
### By mapping it to another type | ||
@@ -111,5 +133,6 @@ | ||
### By explicitly creating a _read function | ||
We expose the underlying [clever-buffer](https://github.com/TabDigital/clever-buffer) as @buffer. | ||
You can call any of it's methods | ||
You can call any of its methods | ||
@@ -116,0 +139,0 @@ ```coffee |
require("coffee-script"); | ||
exports.Reader = require("./reader"); | ||
exports.Writer = require("./writer"); | ||
exports.preCompile = require("./preCompile"); | ||
exports.Reader = require("./reader"); | ||
exports.Writer = require("./writer"); | ||
exports.preCompile = require("./preCompile"); | ||
exports.enumeration = require("./enum"); |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
147521
1.95%21
10.53%5
66.67%396
6.17%