Socket
Socket
Sign inDemoInstall

@discoveryjs/json-ext

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@discoveryjs/json-ext - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

4

CHANGELOG.md

@@ -0,1 +1,5 @@

## 0.5.1 (2020-12-18)
- Fixed `parseChunked()` crash when input has trailing whitespaces
## 0.5.0 (2020-12-05)

@@ -2,0 +6,0 @@

20

dist/json-ext.js

@@ -8,3 +8,3 @@ (function (global, factory) {

var name = "@discoveryjs/json-ext";
var version = "0.5.0";
var version = "0.5.1";
var description = "A set of utilities that extend the use of JSON";

@@ -654,3 +654,3 @@ var keywords = [

push(chunk, last = false) {
push(chunk) {
if (typeof chunk !== 'string') {

@@ -671,3 +671,3 @@ // Suppose chunk is Buffer or Uint8Array

// This makes sense only if we expect more chunks and last char is not multi-bytes
if (!last && chunk[chunk.length - 1] > 127) {
if (chunk[chunk.length - 1] > 127) {
for (let seqLength = 0; seqLength < chunk.length; seqLength++) {

@@ -764,8 +764,8 @@ const byte = chunk[chunk.length - 1 - seqLength];

if (flushPoint > lastFlushPoint || (last && (chunkLength > 0 || this.pendingChunk !== null))) {
this.flush(chunk, lastFlushPoint, last ? chunkLength : flushPoint);
if (flushPoint > lastFlushPoint) {
this.flush(chunk, lastFlushPoint, flushPoint);
}
// Produce pendingChunk if any
if (!last && flushPoint < chunkLength) {
if (flushPoint < chunkLength) {
const newPending = chunk.slice(flushPoint, chunkLength);

@@ -780,4 +780,10 @@

finish() {
this.push('', true);
if (this.pendingChunk !== null) {
if (/[^ \t\r\n]/.test(this.pendingChunk)) {
this.flush('', 0, 0);
}
this.pendingChunk = null;
}
return this.value;

@@ -784,0 +790,0 @@ }

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).jsonExt=e()}(this,(function(){"use strict";function t(t){return"function"==typeof t.pipe&&"function"==typeof t._read&&"object"==typeof t._readableState&&null!==t._readableState}var e={escapableCharCodeSubstitution:{8:"\\b",9:"\\t",10:"\\n",12:"\\f",13:"\\r",34:'\\"',92:"\\\\"},isLeadingSurrogate:function(t){return t>=55296&&t<=56319},isTrailingSurrogate:function(t){return t>=56320&&t<=57343},type:{PRIMITIVE:1,PROMISE:4,ARRAY:3,OBJECT:2,STRING_STREAM:5,OBJECT_STREAM:6},isReadableStream:t,replaceValue:function(t,e,s,n){switch(s&&"function"==typeof s.toJSON&&(s=s.toJSON()),null!==n&&(s=n.call(t,String(e),s)),typeof s){case"function":case"symbol":s=void 0;break;case"object":if(null!==s){const t=s.constructor;t!==String&&t!==Number&&t!==Boolean||(s=s.valueOf())}}return s},getTypeNative:function(t){return null===t||"object"!=typeof t?1:Array.isArray(t)?3:2},getTypeAsync:function(e){return null===e||"object"!=typeof e?1:"function"==typeof e.then?4:t(e)?e._readableState.objectMode?6:5:Array.isArray(e)?3:2},normalizeReplacer:function(t){if("function"==typeof t)return t;if(Array.isArray(t)){const e=new Set(t.map((t=>"string"==typeof t||"number"==typeof t?String(t):null)).filter((t=>"string"==typeof t)));return e.add(""),(t,s)=>e.has(t)?s:void 0}return null},normalizeSpace:function(t){return"number"==typeof t?!(!Number.isFinite(t)||t<1)&&" ".repeat(Math.min(t,10)):"string"==typeof t&&t.slice(0,10)||!1}};const{normalizeReplacer:s,normalizeSpace:n,replaceValue:i,getTypeNative:a,getTypeAsync:r,isLeadingSurrogate:l,isTrailingSurrogate:h,escapableCharCodeSubstitution:u,type:{PRIMITIVE:o,OBJECT:c,ARRAY:f,PROMISE:p,STRING_STREAM:g,OBJECT_STREAM:d}}=e,S=Array.from({length:2048}).map(((t,e)=>u.hasOwnProperty(e)?2:e<32?6:e<128?1:2));function y(t){let e=0,s=!1;for(let n=0;n<t.length;n++){const i=t.charCodeAt(n);if(i<2048)e+=S[i];else{if(l(i)){e+=6,s=!0;continue}h(i)?e=s?e-2:e+6:e+=3}s=!1}return e+2}var b=TextDecoder;const{isReadableStream:k}=e,v=new b;function m(t){return null!==t&&"object"==typeof t}function O(t,e){return"SyntaxError"===t.name&&e.jsonParseOffset&&(t.message=t.message.replace(/at position (\d+)/,((t,s)=>"at position "+(Number(s)+e.jsonParseOffset)))),t}class D{constructor(){this.value=void 0,this.valueStack=null,this.stack=new Array(100),this.lastFlushDepth=0,this.flushDepth=0,this.stateString=!1,this.stateStringEscape=!1,this.pendingByteSeq=null,this.pendingChunk=null,this.pos=0,this.jsonParseOffset=0}flush(t,e,s){let n=t.slice(e,s);if(this.jsonParseOffset=this.pos,null!==this.pendingChunk&&(n=this.pendingChunk+n,this.pendingChunk=null),","===n[0]&&(n=n.slice(1),this.jsonParseOffset++),this.flushDepth===this.lastFlushDepth)this.flushDepth>0?(this.jsonParseOffset--,1===this.stack[this.flushDepth-1]?Object.assign(this.valueStack.value,JSON.parse("{"+n+"}")):this.valueStack.value.push(...JSON.parse("["+n+"]"))):(this.value=JSON.parse(n),this.valueStack={value:this.value,prev:null});else if(this.flushDepth>this.lastFlushDepth){for(let t=this.flushDepth-1;t>=this.lastFlushDepth;t--)n+=1===this.stack[t]?"}":"]";0===this.lastFlushDepth?(this.value=JSON.parse(n),this.valueStack={value:this.value,prev:null}):(this.jsonParseOffset--,1===this.stack[this.lastFlushDepth-1]?Object.assign(this.valueStack.value,JSON.parse("{"+n+"}")):this.valueStack.value.push(...JSON.parse("["+n+"]")));for(let t=this.lastFlushDepth||1;t<this.flushDepth;t++){let e=this.valueStack.value;if(1===this.stack[t-1]){let t;for(t in e);e=e[t]}else e=e[e.length-1];this.valueStack={value:e,prev:this.valueStack}}}else{for(let t=this.lastFlushDepth-1;t>=this.flushDepth;t--)this.jsonParseOffset--,n=(1===this.stack[t]?"{":"[")+n;1===this.stack[this.lastFlushDepth-1]?Object.assign(this.valueStack.value,JSON.parse(n)):this.valueStack.value.push(...JSON.parse(n));for(let t=this.lastFlushDepth-1;t>=this.flushDepth;t--)this.valueStack=this.valueStack.prev}this.pos+=s-e,this.lastFlushDepth=this.flushDepth}push(t,e=!1){if("string"!=typeof t){if(null!==this.pendingByteSeq){const e=t;(t=new Uint8Array(this.pendingByteSeq.length+e.length)).set(this.pendingByteSeq),t.set(e,this.pendingByteSeq.length),this.pendingByteSeq=null}if(!e&&t[t.length-1]>127)for(let e=0;e<t.length;e++){const s=t[t.length-1-e];if(s>>6==3){e++,(4!==e&&s>>3==30||3!==e&&s>>4==14||2!==e&&s>>5==6)&&(this.pendingByteSeq=t.slice(t.length-e),t=t.slice(0,-e));break}}t=v.decode(t)}const s=t.length;let n=0,i=0;t:for(let e=0;e<s;e++){if(this.stateString){for(;e<s;e++)if(this.stateStringEscape)this.stateStringEscape=!1;else switch(t.charCodeAt(e)){case 34:this.stateString=!1;continue t;case 92:this.stateStringEscape=!0}break}switch(t.charCodeAt(e)){case 34:this.stateString=!0,this.stateStringEscape=!1;break;case 44:i=e;break;case 123:i=e+1,this.stack[this.flushDepth++]=1;break;case 91:i=e+1,this.stack[this.flushDepth++]=2;break;case 93:case 125:i=e+1,this.flushDepth--,this.flushDepth<this.lastFlushDepth&&(this.flush(t,n,i),n=i)}}if((i>n||e&&(s>0||null!==this.pendingChunk))&&this.flush(t,n,e?s:i),!e&&i<s){const e=t.slice(i,s);this.pendingChunk=null!==this.pendingChunk?this.pendingChunk+e:e}}finish(){return this.push("",!0),this.value}}return{version:"0.5.0",stringifyInfo:function(t,e,l,h){e=s(e),l=function(t){return"string"==typeof(t=n(t))?t.length:0}(l),h=h||{};const u=new Map,S=new Set,b=new Set,k=new Set,v=new Set,m=h.async?r:a,O={"":t};let D=!1,w=0;return function t(s,n,a){if(D)return;a=i(s,n,a,e);let r=m(a);if(r!==o&&S.has(a))return k.add(a),w+=4,void(h.continueOnCircular||(D=!0));switch(r){case o:void 0!==a||Array.isArray(s)?w+=function(t){switch(typeof t){case"string":return y(t);case"number":return Number.isFinite(t)?String(t).length:4;case"boolean":return t?4:5;case"undefined":case"object":return 4;default:return 0}}(a):s===O&&(w+=9);break;case c:{if(u.has(a)){b.add(a),w+=u.get(a);break}const e=w;let s=0;w+=2,S.add(a);for(const e in a)if(hasOwnProperty.call(a,e)){const n=w;t(a,e,a[e]),n!==w&&(w+=y(e)+1,s++)}s>1&&(w+=s-1),S.delete(a),l>0&&s>0&&(w+=(1+(S.size+1)*l+1)*s,w+=1+S.size*l),u.set(a,w-e);break}case f:{if(u.has(a)){b.add(a),w+=u.get(a);break}const e=w;w+=2,S.add(a);for(let e=0;e<a.length;e++)t(a,e,a[e]);a.length>1&&(w+=a.length-1),S.delete(a),l>0&&a.length>0&&(w+=(1+(S.size+1)*l)*a.length,w+=1+S.size*l),u.set(a,w-e);break}case p:case g:v.add(a);break;case d:w+=2,v.add(a)}}(O,"",t),{minLength:isNaN(w)?1/0:w,circular:[...k],duplicate:[...b],async:[...v]}},stringifyStream:()=>{throw new Error("Method is not supported")},parseChunked:function(t){let e=new D;if(m(t)&&k(t))return new Promise(((s,n)=>{t.on("data",(t=>{try{e.push(t)}catch(t){n(O(t,e)),e=null}})).on("error",(t=>{e=null,n(t)})).on("end",(()=>{try{s(e.finish())}catch(t){n(O(t,e))}finally{e=null}}))}));if("function"==typeof t){const s=t();if(m(s)&&(Symbol.iterator in s||Symbol.asyncIterator in s))return new Promise((async(t,n)=>{try{for await(const t of s)e.push(t);t(e.finish())}catch(t){n(O(t,e))}finally{e=null}}))}throw new Error("Chunk emitter should be readable stream, generator, async generator or function returning an iterable object")}}}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).jsonExt=e()}(this,(function(){"use strict";function t(t){return"function"==typeof t.pipe&&"function"==typeof t._read&&"object"==typeof t._readableState&&null!==t._readableState}var e={escapableCharCodeSubstitution:{8:"\\b",9:"\\t",10:"\\n",12:"\\f",13:"\\r",34:'\\"',92:"\\\\"},isLeadingSurrogate:function(t){return t>=55296&&t<=56319},isTrailingSurrogate:function(t){return t>=56320&&t<=57343},type:{PRIMITIVE:1,PROMISE:4,ARRAY:3,OBJECT:2,STRING_STREAM:5,OBJECT_STREAM:6},isReadableStream:t,replaceValue:function(t,e,s,n){switch(s&&"function"==typeof s.toJSON&&(s=s.toJSON()),null!==n&&(s=n.call(t,String(e),s)),typeof s){case"function":case"symbol":s=void 0;break;case"object":if(null!==s){const t=s.constructor;t!==String&&t!==Number&&t!==Boolean||(s=s.valueOf())}}return s},getTypeNative:function(t){return null===t||"object"!=typeof t?1:Array.isArray(t)?3:2},getTypeAsync:function(e){return null===e||"object"!=typeof e?1:"function"==typeof e.then?4:t(e)?e._readableState.objectMode?6:5:Array.isArray(e)?3:2},normalizeReplacer:function(t){if("function"==typeof t)return t;if(Array.isArray(t)){const e=new Set(t.map((t=>"string"==typeof t||"number"==typeof t?String(t):null)).filter((t=>"string"==typeof t)));return e.add(""),(t,s)=>e.has(t)?s:void 0}return null},normalizeSpace:function(t){return"number"==typeof t?!(!Number.isFinite(t)||t<1)&&" ".repeat(Math.min(t,10)):"string"==typeof t&&t.slice(0,10)||!1}};const{normalizeReplacer:s,normalizeSpace:n,replaceValue:i,getTypeNative:a,getTypeAsync:r,isLeadingSurrogate:l,isTrailingSurrogate:h,escapableCharCodeSubstitution:u,type:{PRIMITIVE:o,OBJECT:c,ARRAY:f,PROMISE:p,STRING_STREAM:g,OBJECT_STREAM:d}}=e,S=Array.from({length:2048}).map(((t,e)=>u.hasOwnProperty(e)?2:e<32?6:e<128?1:2));function y(t){let e=0,s=!1;for(let n=0;n<t.length;n++){const i=t.charCodeAt(n);if(i<2048)e+=S[i];else{if(l(i)){e+=6,s=!0;continue}h(i)?e=s?e-2:e+6:e+=3}s=!1}return e+2}var b=TextDecoder;const{isReadableStream:k}=e,v=new b;function m(t){return null!==t&&"object"==typeof t}function O(t,e){return"SyntaxError"===t.name&&e.jsonParseOffset&&(t.message=t.message.replace(/at position (\d+)/,((t,s)=>"at position "+(Number(s)+e.jsonParseOffset)))),t}class D{constructor(){this.value=void 0,this.valueStack=null,this.stack=new Array(100),this.lastFlushDepth=0,this.flushDepth=0,this.stateString=!1,this.stateStringEscape=!1,this.pendingByteSeq=null,this.pendingChunk=null,this.pos=0,this.jsonParseOffset=0}flush(t,e,s){let n=t.slice(e,s);if(this.jsonParseOffset=this.pos,null!==this.pendingChunk&&(n=this.pendingChunk+n,this.pendingChunk=null),","===n[0]&&(n=n.slice(1),this.jsonParseOffset++),this.flushDepth===this.lastFlushDepth)this.flushDepth>0?(this.jsonParseOffset--,1===this.stack[this.flushDepth-1]?Object.assign(this.valueStack.value,JSON.parse("{"+n+"}")):this.valueStack.value.push(...JSON.parse("["+n+"]"))):(this.value=JSON.parse(n),this.valueStack={value:this.value,prev:null});else if(this.flushDepth>this.lastFlushDepth){for(let t=this.flushDepth-1;t>=this.lastFlushDepth;t--)n+=1===this.stack[t]?"}":"]";0===this.lastFlushDepth?(this.value=JSON.parse(n),this.valueStack={value:this.value,prev:null}):(this.jsonParseOffset--,1===this.stack[this.lastFlushDepth-1]?Object.assign(this.valueStack.value,JSON.parse("{"+n+"}")):this.valueStack.value.push(...JSON.parse("["+n+"]")));for(let t=this.lastFlushDepth||1;t<this.flushDepth;t++){let e=this.valueStack.value;if(1===this.stack[t-1]){let t;for(t in e);e=e[t]}else e=e[e.length-1];this.valueStack={value:e,prev:this.valueStack}}}else{for(let t=this.lastFlushDepth-1;t>=this.flushDepth;t--)this.jsonParseOffset--,n=(1===this.stack[t]?"{":"[")+n;1===this.stack[this.lastFlushDepth-1]?Object.assign(this.valueStack.value,JSON.parse(n)):this.valueStack.value.push(...JSON.parse(n));for(let t=this.lastFlushDepth-1;t>=this.flushDepth;t--)this.valueStack=this.valueStack.prev}this.pos+=s-e,this.lastFlushDepth=this.flushDepth}push(t){if("string"!=typeof t){if(null!==this.pendingByteSeq){const e=t;(t=new Uint8Array(this.pendingByteSeq.length+e.length)).set(this.pendingByteSeq),t.set(e,this.pendingByteSeq.length),this.pendingByteSeq=null}if(t[t.length-1]>127)for(let e=0;e<t.length;e++){const s=t[t.length-1-e];if(s>>6==3){e++,(4!==e&&s>>3==30||3!==e&&s>>4==14||2!==e&&s>>5==6)&&(this.pendingByteSeq=t.slice(t.length-e),t=t.slice(0,-e));break}}t=v.decode(t)}const e=t.length;let s=0,n=0;t:for(let i=0;i<e;i++){if(this.stateString){for(;i<e;i++)if(this.stateStringEscape)this.stateStringEscape=!1;else switch(t.charCodeAt(i)){case 34:this.stateString=!1;continue t;case 92:this.stateStringEscape=!0}break}switch(t.charCodeAt(i)){case 34:this.stateString=!0,this.stateStringEscape=!1;break;case 44:n=i;break;case 123:n=i+1,this.stack[this.flushDepth++]=1;break;case 91:n=i+1,this.stack[this.flushDepth++]=2;break;case 93:case 125:n=i+1,this.flushDepth--,this.flushDepth<this.lastFlushDepth&&(this.flush(t,s,n),s=n)}}if(n>s&&this.flush(t,s,n),n<e){const s=t.slice(n,e);this.pendingChunk=null!==this.pendingChunk?this.pendingChunk+s:s}}finish(){return null!==this.pendingChunk&&(/[^ \t\r\n]/.test(this.pendingChunk)&&this.flush("",0,0),this.pendingChunk=null),this.value}}return{version:"0.5.1",stringifyInfo:function(t,e,l,h){e=s(e),l=function(t){return"string"==typeof(t=n(t))?t.length:0}(l),h=h||{};const u=new Map,S=new Set,b=new Set,k=new Set,v=new Set,m=h.async?r:a,O={"":t};let D=!1,w=0;return function t(s,n,a){if(D)return;a=i(s,n,a,e);let r=m(a);if(r!==o&&S.has(a))return k.add(a),w+=4,void(h.continueOnCircular||(D=!0));switch(r){case o:void 0!==a||Array.isArray(s)?w+=function(t){switch(typeof t){case"string":return y(t);case"number":return Number.isFinite(t)?String(t).length:4;case"boolean":return t?4:5;case"undefined":case"object":return 4;default:return 0}}(a):s===O&&(w+=9);break;case c:{if(u.has(a)){b.add(a),w+=u.get(a);break}const e=w;let s=0;w+=2,S.add(a);for(const e in a)if(hasOwnProperty.call(a,e)){const n=w;t(a,e,a[e]),n!==w&&(w+=y(e)+1,s++)}s>1&&(w+=s-1),S.delete(a),l>0&&s>0&&(w+=(1+(S.size+1)*l+1)*s,w+=1+S.size*l),u.set(a,w-e);break}case f:{if(u.has(a)){b.add(a),w+=u.get(a);break}const e=w;w+=2,S.add(a);for(let e=0;e<a.length;e++)t(a,e,a[e]);a.length>1&&(w+=a.length-1),S.delete(a),l>0&&a.length>0&&(w+=(1+(S.size+1)*l)*a.length,w+=1+S.size*l),u.set(a,w-e);break}case p:case g:v.add(a);break;case d:w+=2,v.add(a)}}(O,"",t),{minLength:isNaN(w)?1/0:w,circular:[...k],duplicate:[...b],async:[...v]}},stringifyStream:()=>{throw new Error("Method is not supported")},parseChunked:function(t){let e=new D;if(m(t)&&k(t))return new Promise(((s,n)=>{t.on("data",(t=>{try{e.push(t)}catch(t){n(O(t,e)),e=null}})).on("error",(t=>{e=null,n(t)})).on("end",(()=>{try{s(e.finish())}catch(t){n(O(t,e))}finally{e=null}}))}));if("function"==typeof t){const s=t();if(m(s)&&(Symbol.iterator in s||Symbol.asyncIterator in s))return new Promise((async(t,n)=>{try{for await(const t of s)e.push(t);t(e.finish())}catch(t){n(O(t,e))}finally{e=null}}))}throw new Error("Chunk emitter should be readable stream, generator, async generator or function returning an iterable object")}}}));
{
"name": "@discoveryjs/json-ext",
"version": "0.5.0",
"version": "0.5.1",
"description": "A set of utilities that extend the use of JSON",

@@ -5,0 +5,0 @@ "keywords": [

@@ -195,3 +195,3 @@ const { isReadableStream } = require('./utils');

push(chunk, last = false) {
push(chunk) {
if (typeof chunk !== 'string') {

@@ -212,3 +212,3 @@ // Suppose chunk is Buffer or Uint8Array

// This makes sense only if we expect more chunks and last char is not multi-bytes
if (!last && chunk[chunk.length - 1] > 127) {
if (chunk[chunk.length - 1] > 127) {
for (let seqLength = 0; seqLength < chunk.length; seqLength++) {

@@ -305,8 +305,8 @@ const byte = chunk[chunk.length - 1 - seqLength];

if (flushPoint > lastFlushPoint || (last && (chunkLength > 0 || this.pendingChunk !== null))) {
this.flush(chunk, lastFlushPoint, last ? chunkLength : flushPoint);
if (flushPoint > lastFlushPoint) {
this.flush(chunk, lastFlushPoint, flushPoint);
}
// Produce pendingChunk if any
if (!last && flushPoint < chunkLength) {
if (flushPoint < chunkLength) {
const newPending = chunk.slice(flushPoint, chunkLength);

@@ -321,6 +321,12 @@

finish() {
this.push('', true);
if (this.pendingChunk !== null) {
if (/[^ \t\r\n]/.test(this.pendingChunk)) {
this.flush('', 0, 0);
}
this.pendingChunk = null;
}
return this.value;
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc