Skip to content

Commit 05d206b

Browse files
Update to 0.1.0.
1 parent 45eb67b commit 05d206b

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

json-bufferify.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* json-bufferify 0.0.9
3-
* Date: 2017-07-10
2+
* json-bufferify 0.1.0
3+
* Date: 2017-11-10
44
* © 2017 LangZhai(智能小菜菜)
55
* This is licensed under the GNU LGPL, version 3 or later.
66
* For details, see: http://www.gnu.org/licenses/lgpl.html

json-bufferify.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* json-bufferify 0.0.9
3-
* Date: 2017-07-10
2+
* json-bufferify 0.1.0
3+
* Date: 2017-11-10
44
* © 2017 LangZhai(智能小菜菜)
55
* This is licensed under the GNU LGPL, version 3 or later.
66
* For details, see: http://www.gnu.org/licenses/lgpl.html
@@ -202,8 +202,7 @@
202202
let view;
203203
if (template instanceof Object) {
204204
view = source instanceof DataView ? source : new DataView(source instanceof ArrayBuffer ? source : new Uint8Array(source).buffer);
205-
if (template instanceof Array) {
206-
template.length = view.getUint8(offset++);
205+
if (template instanceof Array && (template.length = view.getUint8(offset++))) {
207206
template.join().split(',').forEach((item, i) => template[i] = extend(true, {}, template[0]));
208207
}
209208
if (template instanceof Array && template[0] instanceof Object) {
@@ -248,11 +247,11 @@
248247
break;
249248
}
250249
} else {
251-
template[item] = String.fromCharCode.apply(null, new Array(view.getUint8(offset++)).join().split(',').map(() => {
250+
template[item] = template[item] = view.getUint8(offset++) ? String.fromCharCode.apply(null, new Array(template[item]).join().split(',').map(() => {
252251
let code = view.getUint16(offset);
253252
offset += 2;
254253
return code;
255-
}));
254+
})) : '';
256255
}
257256
});
258257
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-bufferify",
3-
"version": "0.0.9",
3+
"version": "0.1.0",
44
"main": "json-bufferify.js",
55
"types": "json-bufferify.d.ts",
66
"description": "This is a module to help you convert between JSON and ArrayBuffer, and you can run it in both Node.js and browser.",

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,12 @@ console.log(bufferify.decode(0, {
4040
id: '459823',
4141
name: 'Kevin'
4242
}]
43+
})));
44+
45+
console.log(bufferify.decode(0, ['number'], bufferify.encode(0, [])));
46+
47+
console.log(bufferify.decode(0, {
48+
str: 'string'
49+
}, bufferify.encode(0, {
50+
str: ''
4351
})));

0 commit comments

Comments
 (0)