Comparing version 0.6.18 to 0.6.20
@@ -8,4 +8,4 @@ (function (exportName) { | ||
* zswang (http://weibo.com/zswang) | ||
* @version 0.6.18 | ||
* @date 2016-03-21 | ||
* @version 0.6.20 | ||
* @date 2016-04-06 | ||
*/ | ||
@@ -1128,6 +1128,9 @@ function createSchema() { | ||
*/ | ||
function stringBytes(value, options) { | ||
function stringBytes(value, options) { | ||
if (!options.browser && typeof Buffer !== 'undefined') { // NodeJS | ||
return new Buffer(value, options.encoding); | ||
} else { | ||
if (typeof TextEncoder === 'function') { | ||
return Array.from(new TextEncoder(options.encoding).encode(value)); | ||
} | ||
return encodeUTF8(value).split('').map(function (item) { | ||
@@ -1176,2 +1179,5 @@ return item.charCodeAt(); | ||
} | ||
if (typeof TextDecoder === 'function') { | ||
return new TextDecoder(options.encoding).decode(stringBuffer); | ||
} | ||
return decodeUTF8(String.fromCharCode.apply(String, stringBuffer)); | ||
@@ -1178,0 +1184,0 @@ }, |
@@ -8,4 +8,4 @@ (function (exportName) { | ||
* zswang (http://weibo.com/zswang) | ||
* @version 0.6.18 | ||
* @date 2016-03-21 | ||
* @version 0.6.20 | ||
* @date 2016-04-06 | ||
*/ | ||
@@ -1065,6 +1065,9 @@ function createSchema() { | ||
*/ | ||
function stringBytes(value, options) { | ||
function stringBytes(value, options) { | ||
if (!options.browser && typeof Buffer !== 'undefined') { // NodeJS | ||
return new Buffer(value, options.encoding); | ||
} else { | ||
if (typeof TextEncoder === 'function') { | ||
return Array.from(new TextEncoder(options.encoding).encode(value)); | ||
} | ||
return encodeUTF8(value).split('').map(function (item) { | ||
@@ -1113,2 +1116,5 @@ return item.charCodeAt(); | ||
} | ||
if (typeof TextDecoder === 'function') { | ||
return new TextDecoder(options.encoding).decode(stringBuffer); | ||
} | ||
return decodeUTF8(String.fromCharCode.apply(String, stringBuffer)); | ||
@@ -1115,0 +1121,0 @@ }, |
@@ -5,3 +5,3 @@ { | ||
"description": "Binary data packing and unpacking.", | ||
"version": "0.6.18", | ||
"version": "0.6.20", | ||
"homepage": "http://github.com/zswang/jpacks", | ||
@@ -8,0 +8,0 @@ "main": "jpacks.js", |
@@ -56,2 +56,6 @@ var protobufjs = require('protobufjs'); | ||
if (!value && /int64/.test(type.type.name)) { // 空值优化 | ||
value = 0; | ||
} | ||
if (type.type.name === 'bytes') { | ||
@@ -273,2 +277,14 @@ result[key] = bytesify(value, options); | ||
``` | ||
* @example protobufCreator():int64 from empty string | ||
```js | ||
var _ = jpacks; | ||
var _schema = _.protobuf('package Long; message Value { optional uint64 value = 1; }', 'Long.Value', null); | ||
var buffer = _.pack(_schema, { | ||
value: '' | ||
}); | ||
console.log(JSON.stringify(_.unpack(_schema, buffer))); | ||
// > {"value":"0"} | ||
``` | ||
'''</example>''' | ||
@@ -275,0 +291,0 @@ */ |
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
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
124071
4000