8000 Initial commit · arduino/cbor-js@72cad1d · GitHub
[go: up one dir, main page]

Skip to content

Commit 72cad1d

Browse files
committed
Initial commit
0 parents  commit 72cad1d

File tree

9 files changed

+1032
-0
lines changed

9 files changed

+1032
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage
2+
node_modules
3+
4+
sauce_connect.log

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
4+
before_script:
5+
- npm install -g grunt-cli
6+
script:
7+
- npm run-script ci
8+
env:
9+
global:
10+
- secure: "UM4h/x6asOBi5D9ieBW3v6TqTwVpFWFopaUH8WQ004xufrLM2BuqhWhldn3x8OdASia7uAzv40G4ApF+nbOdlsdjxqGH18NpsDsdd1aqziZvHbim7UiFwT93fngbPDInd0KI2q3U8ed0M9KtswvlHNAiIMVf8lEPW2B3At4shi8="
11+
- secure: "W3FSQ8IISzEjDov8pMaqO8pTJfQ5In/XMa/756ez80GWmdWs71NyxWKaSCm5aebU++P6ULk9+e1/V8Xz+UF+tZpPN+3Fl0y/aiNLQpi2f37WNEAPvGW7Y2+wUdZa74iTC7nmsVWqYFI47ylFyoKbdcrmSpQ3JFi18E1/QdEx77E="
12+
- secure: "Uax0duT20upUZWkmiuyhLmf12zJTcjwP1t8E5CLdx3eXBoFebs9fiKqoMV3ImUHLuYG4A34JGDMCWkrY8WYIi2ja8idzNjmDTcMz70U5B0v/ChFEKPUQVnpcM0FAkaHwZsoCrO1XJFnzJkHLLFoKEraUdHpl+ADMg1I+E9iakHM="

Gruntfile.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
module.exports = function(grunt) {
2+
var browsers = [{
3+
browserName: "chrome"
4+
}, {
5+
browserName: "firefox"
6+
}, {
7+
browserName: "opera"
8+
}, {
9+
browserName: "internet explorer",
10+
platform: "Windows 8.1",
11+
version: "11"
12+
}, {
13+
browserName: "internet explorer",
14+
platform: "Windows 7",
15+
version: "10"
16+
}, {
17+
browserName: "safari",
18+
platform: "OS X 10.9",
19+
version: "7"
20+
}, {
21+
browserName: "safari",
22+
platform: "OS X 10.8",
23+
version: "6"
24+
}, {
25+
browserName: "ipad",
26+
platform: "OS X 10.8",
27+
version: "6",
28+
"device-orientation": "portrait"
29+
}, {
30+
browserName: "iphone",
31+
platform: "OS X 10.8",
32+
version: "6",
33+
"device-orientation": "portrait"
34+
}, {
35+
browserName: "android",
36+
platform: "linux",
37+
version: "4.0",
38+
"device-orientation": "portrait"
39+
}, {
40+
browserName: "android",
41+
platform: "linux",
42+
version: "4.0",
43+
"device-type": "tablet",
44+
"device-orientation": "portrait"
45+
}];
46+
47+
var covDirectory = "coverage";
48+
var srcFiles = ["cbor.js"];
49+
var testFile = "test/index.html";
50+
var testPort = 9999;
51+
52+
grunt.initConfig({
53+
pkg: grunt.file.readJSON("package.json"),
54+
connect: {
55+
server: {
56+
options: {
57+
base: "",
58+
port: testPort
59+
}
60+
}
61+
},
62+
coveralls: {
63+
all: {
64+
src: covDirectory + "/lcov.info"
65+
}
66+
},
67+
jshint: {
68+
options: {
69+
"camelcase": true,
70+
"eqeqeq": true,
71+
"eqnull": true,
72+
"forin": true,
73+
"freeze": true,
74+
"immed": true,
75+
"latedef": true,
76+
"newcap": true,
77+
"noarg": true,
78+
"noempty": true,
79+
"nonew": true,
80+
"quotmark": "double",
81+
"strict": true,
82+
"trailing": true,
83+
"unused": true
84+
},
85+
all: srcFiles
86+
},
87+
qunit: {
88+
all: {
89+
options: {
90+
urls: [testFile],
91+
coverage: {
92+
src: srcFiles,
93+
instrumentedFiles: "temp/",
94+
lcovReport: covDirectory,
95+
branchesThresholdPct: 95,
96+
functionsThresholdPct: 100,
97+
linesThresholdPct: 95
98+
}
99+
}
100+
}
101+
},
102+
"saucelabs-qunit": {
103+
all: {
104+
options: {
105+
urls: ["http://localhost:" + testPort + "/" + testFile],
106+
build: process.env.TRAVIS_JOB_NUMBER || "unknown",
107+
browsers: browsers,
108+
concurrency: 3,
109+
tags: [process.env.TRAVIS_BRANCH || "unknown"]
110+
}
111+
}
112+
}
113+
});
114+
115+
grunt.loadNpmTasks("grunt-contrib-connect");
116+
grunt.loadNpmTasks("grunt-contrib-jshint");
117+
grunt.loadNpmTasks("grunt-contrib-qunit");
118+
grunt.loadNpmTasks("grunt-coveralls");
119+
grunt.loadNpmTasks("grunt-qunit-istanbul");
120+
grunt.loadNpmTasks("grunt-saucelabs");
121+
122+
grunt.registerTask("default", ["test"]);
123+
grunt.registerTask("test", ["qunit", "jshint"]);
124+
grunt.registerTask("ci", ["test", "coveralls", "connect", "saucelabs-qunit"]);
125+
};

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Patrick Gansterer <paroga@paroga.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
cbor-js
2+
=======
3+
4+
The Concise Binary Object Representation (CBOR) data format ([RFC 7049](http://tools.ietf.org/html/rfc7049)) implemented in pure JavaScript.
5+
6+
[![Build Status](https://api.travis-ci.org/paroga/cbor-js.png)](https://travis-ci.org/paroga/cbor-js)
7+
[![Coverage Status](https://coveralls.io/repos/paroga/cbor-js/badge.png?branch=master)](https://coveralls.io/r/paroga/cbor-js?branch=master)
8+
[![Dependency status](https://david-dm.org/paroga/cbor-js/status.png)](https://david-dm.org/paroga/cbor-js#info=dependencies&view=table)
9+
[![Dev Dependency Status](https://david-dm.org/paroga/cbor-js/dev-status.png)](https://david-dm.org/paroga/cbor-js#info=devDependencies&view=table)
10+
[![Selenium Test Status](https://saucelabs.com/buildstatus/paroga-cbor-js)](https://saucelabs.com/u/paroga-cbor-js)
11+
12+
[![Selenium Test Status](https://saucelabs.com/browser-matrix/paroga-cbor-js.svg)](https://saucelabs.com/u/paroga-cbor-js)
13+
14+
API
15+
---
16+
17+
The `cbor`-object provides the following two functions:
18+
19+
cbor.**decode**(*data*)
20+
> Take the ArrayBuffer object *data* and return it decoded as a JavaScript object.
21+
22+
cbor.**encode**(*data*)
23+
> Take the JavaScript object *data* and return it encoded as a ArrayBuffer object.
24+
25+
Usage
26+
-----
27+
28+
Include `cbor.js` in your or HTML page:
29+
```html
30+
<script src="path/to/cbor.js" type="text/javascript"></script>
31+
```
32+
33+
Then you can use it via the `cbor`-object in your code:
34+
```javascript
35+
var initial = { Hello: "World" };
36+
var encoded = cbor.encode(initial);
37+
var decoded = cbor.decode(encoded);
38+
```
39+
After running this example `initial` and `decoded` represent the same value.
40+
41+
### Combination with WebSocket
42+
43+
The API was designed to play well with the `WebSocket` object in the browser:
44+
```javascript
45+
var websocket = new WebSocket(url);
46+
websocket.binaryType = "arraybuffer";
47+
...
48+
websocket.onmessage = function(event) {
49+
var message = cbor.decode(event.data);
50+
};
51+
...
52+
websocket.send(cbor.encode(message));
53+
```

0 commit comments

Comments
 (0)
0