Skip to content

Commit 460f6e6

Browse files
committed
Add README stuff
1 parent d5da4d5 commit 460f6e6

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.*.sw[opn]
2+
node_modules

Diff for: README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
bytes.js
2+
========
3+
4+
Utf8 bytes array from/to string.
5+
6+
Install
7+
-------
8+
9+
npm install bytes.js
10+
11+
Example
12+
-------
13+
14+
```js
15+
var bytes = require('bytes.js');
16+
17+
bytes.fromString('abc') // [97, 98, 99]
18+
bytes.toString([97, 98, 99]) // 'abc'
19+
bytes.fromString('你好') // [228, 189, 160, 229, 165, 189]
20+
bytes.toString([228, 189, 160, 229, 165, 189]) // '你好'
21+
```
22+
23+
License
24+
--------
25+
26+
MIT. Copyright (c) Chao Wang <[email protected]>

Diff for: package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "bytes.js",
3+
"version": "0.0.1",
4+
"repository": {
5+
"type": "git",
6+
"url": "git://github.com/hit9/bytes.js"
7+
},
8+
"description": "Utf8 bytes array from/to string.",
9+
"author": "hit9 <[email protected]>",
10+
"keywords": ["utf8", "bytes"],
11+
"main": "./bytes.js",
12+
"scripts": {"test": "node test.js"},
13+
"devDependencies": {"mut": "0.0.3"},
14+
"license": "MIT"
15+
}

Diff for: test.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// tests for `bytes.js`.
2+
var bytes = require('./bytes');
3+
var mut = require('mut');
4+
var assert = require('assert');
5+
6+
var runTest = function(fn, cases) {
7+
for (var i = 0; i < cases.length; i++) {
8+
var item = cases[i];
9+
var got = fn.apply(null, item.args);
10+
assert.deepEqual(got, item.except);
11+
}
12+
};
13+
14+
mut('bytes.js', function(test) {
15+
var fromStringCases = [
16+
{args: ['~'], except: [0x7e]},
17+
{args: ['1234'], except: [0x31, 0x32, 0x33, 0x34]},
18+
{args: ['abc'], except: [0x61, 0x62, 0x63]},
19+
{args: ['\u0129'], except: [0xc4, 0xa9]},
20+
{args: ['\u07ff'], except: [0xdf, 0xbf]},
21+
{args: ['你好'], except: [0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd]},
22+
];
23+
test('fromString', function(done) {
24+
runTest(bytes.fromString, fromStringCases);
25+
done();
26+
});
27+
28+
var toStringCases = [
29+
{args: [[0x7e]], except: '~'},
30+
{args: [[0x31, 0x32, 0x33, 0x34]], except: '1234'},
31+
{args: [[0x61, 0x62, 0x63]], except: 'abc'},
32+
{args: [[0xc4, 0xa9]], except: '\u0129'},
33+
{args: [[0xdf, 0xbf]], except: '\u07ff'},
34+
{args: [[0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd]], except: '你好'}
35+
]
36+
test('toString', function(done) {
37+
runTest(bytes.toString, toStringCases);
38+
done();
39+
});
40+
});

0 commit comments

Comments
 (0)