@alexgyver/bson 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bson.js +3 -9
- package/bson.min.js +1 -0
- package/package.json +8 -1
- package/test.html +1 -1
- package/webpack.config.js +14 -0
package/bson.js
CHANGED
|
@@ -66,13 +66,7 @@ export default function decodeBson(b, codes = []) {
|
|
|
66
66
|
|
|
67
67
|
case BS_STRING: {
|
|
68
68
|
let len = unpack5(data, b[++i]);
|
|
69
|
-
|
|
70
|
-
txt = txt.replaceAll(/([^\\])\\([^\"\\nrt])/ig, "$1\\\\$2")
|
|
71
|
-
.replaceAll(/\t/ig, "\\t")
|
|
72
|
-
.replaceAll(/\n/ig, "\\n")
|
|
73
|
-
.replaceAll(/\r/ig, "\\r")
|
|
74
|
-
.replaceAll(/([^\\])(")/ig, '$1\\"');
|
|
75
|
-
s += '"' + txt + '"';
|
|
69
|
+
s += JSON.stringify(new TextDecoder().decode(b.slice(i + 1, i + 1 + len)));
|
|
76
70
|
i += len;
|
|
77
71
|
} break;
|
|
78
72
|
|
|
@@ -113,7 +107,7 @@ export default function decodeBson(b, codes = []) {
|
|
|
113
107
|
}
|
|
114
108
|
}
|
|
115
109
|
} catch (e) {
|
|
116
|
-
console.
|
|
110
|
+
console.error(e, s);
|
|
117
111
|
throw new Error("BSON decode error");
|
|
118
112
|
}
|
|
119
113
|
|
|
@@ -124,7 +118,7 @@ export default function decodeBson(b, codes = []) {
|
|
|
124
118
|
if (bins.length) makeBins(obj, bins);
|
|
125
119
|
return obj;
|
|
126
120
|
} catch (e) {
|
|
127
|
-
console.
|
|
121
|
+
console.error(e, s);
|
|
128
122
|
throw new Error("JSON parse error");
|
|
129
123
|
}
|
|
130
124
|
}
|
package/bson.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={d:(r,t)=>{for(var n in t)e.o(t,n)&&!e.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:t[n]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)},r={};function t(e,r=[]){if(!(e&&e instanceof Uint8Array))return null;if(!e.length)return{};const t="__BSON_BINARY";function n(e,r){return(e<<8|r)>>>0}let o=[],l=[],c=!0,s="";try{for(let i=0;i<e.length;i++){const a=224&e[i],f=31&e[i];switch(a){case 192:if(8&f){let e=16&f?"{":"[";s+=e,l.push(e)}else","==s[s.length-1]&&(s=s.slice(0,-1)),s+=(16&f?"}":"]")+",",l.pop();c=!0;continue;case 128:s+='"'+r[n(f,e[++i])]+'"';break;case 0:{let r=n(f,e[++i]);s+=JSON.stringify((new TextDecoder).decode(e.slice(i+1,i+1+r))),i+=r}break;case 64:{16&f&&(s+="-");let r=15&f,t=new Uint8Array(8);t.set(e.slice(i+1,i+1+r)),s+=new BigUint64Array(t.buffer)[0],i+=r}break;case 32:s+=1&f?"true":"false";break;case 96:{let r=new Float32Array(e.slice(i+1,i+1+4).buffer)[0];s+=isNaN(r)||!isFinite(r)?"null":r.toFixed(f),i+=4}break;case 160:{let r=n(f,e[++i]);i++,s+='"'+t+"#"+o.length+'"',o.push(e.slice(i,i+r)),i+=r-1}}"{"===l[l.length-1]?(s+=c?":":",",c=!c):s+=","}}catch(e){throw console.error(e,s),new Error("BSON decode error")}","==s[s.length-1]&&(s=s.slice(0,-1));try{let e=JSON.parse(s);return o.length&&function e(r,n){if("object"==typeof r)for(let o in r)"object"==typeof r[o]&&null!==r[o]?e(r[o],n):"string"==typeof r[o]&&r[o].startsWith(t)&&(r[o]=n[r[o].split("#")[1]])}(e,o),e}catch(e){throw console.error(e,s),new Error("JSON parse error")}}e.d(r,{A:()=>t});const n=r.A;export{n as default};
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexgyver/bson",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Decode BSON from BSON Arduino library",
|
|
5
5
|
"main": "./bson.js",
|
|
6
6
|
"module": "./bson.js",
|
|
7
7
|
"types": "./bson.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "webpack --config ./webpack.config.js"
|
|
10
|
+
},
|
|
8
11
|
"repository": {
|
|
9
12
|
"type": "git",
|
|
10
13
|
"url": "git+https://github.com/GyverLibs/bson.js.git"
|
|
11
14
|
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"webpack": "^5.98.0",
|
|
17
|
+
"webpack-cli": "^6.0.1"
|
|
18
|
+
},
|
|
12
19
|
"author": "AlexGyver <alex@alexgyver.ru>",
|
|
13
20
|
"license": "MIT"
|
|
14
21
|
}
|
package/test.html
CHANGED