@discoveryjs/json-ext
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -0,1 +1,6 @@ | ||
## 0.3.1 (2020-10-26) | ||
- Changed build setup to allow building by any bundler that supports `browser` property in `package.json` | ||
- Exposed version | ||
## 0.3.0 (2020-09-28) | ||
@@ -2,0 +7,0 @@ |
@@ -7,2 +7,73 @@ (function (global, factory) { | ||
var name = "@discoveryjs/json-ext"; | ||
var version = "0.3.1"; | ||
var description = "A set of utilities that extend the use of JSON"; | ||
var keywords = [ | ||
"json", | ||
"utils", | ||
"stream", | ||
"async", | ||
"promise", | ||
"stringify", | ||
"info" | ||
]; | ||
var author = "Roman Dvornov <rdvornov@gmail.com> (https://github.com/lahmatiy)"; | ||
var license = "MIT"; | ||
var repository = "discoveryjs/json-ext"; | ||
var main = "./src/index"; | ||
var browser = { | ||
"./src/stringify-stream.js": "./browser-method-is-not-supported.js" | ||
}; | ||
var scripts = { | ||
test: "mocha --reporter progress", | ||
lint: "eslint src test", | ||
"lint-and-test": "npm run lint && npm test", | ||
build: "rollup --config", | ||
"test:all": "npm run test:src && npm run test:dist", | ||
"test:src": "npm test", | ||
"test:dist": "MODE=dist npm test && MODE=dist-min npm test", | ||
"build-and-test": "npm run build && npm run test:dist", | ||
coverage: "nyc npm test", | ||
travis: "nyc npm run lint-and-test && npm run coveralls", | ||
coveralls: "nyc report --reporter=text-lcov | coveralls", | ||
prepublishOnly: "npm run build" | ||
}; | ||
var dependencies = { | ||
}; | ||
var devDependencies = { | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
chalk: "^4.1.0", | ||
coveralls: "^3.1.0", | ||
eslint: "^7.6.0", | ||
mocha: "^8.1.1", | ||
nyc: "^15.1.0", | ||
rollup: "^2.28.2", | ||
"rollup-plugin-terser": "^7.0.2" | ||
}; | ||
var engines = { | ||
node: ">=12.0.0" | ||
}; | ||
var files = [ | ||
"dist", | ||
"src" | ||
]; | ||
var require$$0 = { | ||
name: name, | ||
version: version, | ||
description: description, | ||
keywords: keywords, | ||
author: author, | ||
license: license, | ||
repository: repository, | ||
main: main, | ||
browser: browser, | ||
scripts: scripts, | ||
dependencies: dependencies, | ||
devDependencies: devDependencies, | ||
engines: engines, | ||
files: files | ||
}; | ||
const PrimitiveType = 1; | ||
@@ -382,7 +453,10 @@ const ObjectType = 2; | ||
var stringifyStream = "Method is not supported"; | ||
var browserMethodIsNotSupported = () => { | ||
throw new Error('Method is not supported'); | ||
}; | ||
var src = { | ||
version: require$$0.version, | ||
stringifyInfo: stringifyInfo, | ||
stringifyStream: stringifyStream | ||
stringifyStream: browserMethodIsNotSupported | ||
}; | ||
@@ -389,0 +463,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).jsonExt=t()}(this,(function(){"use strict";function e(e){return"function"==typeof e.pipe&&"function"==typeof e._read&&"object"==typeof e._readableState&&null!==e._readableState}var t={escapableCharCodeSubstitution:{8:"\\b",9:"\\t",10:"\\n",12:"\\f",13:"\\r",34:'\\"',92:"\\\\"},isLeadingSurrogate:function(e){return e>=55296&&e<=56319},isTrailingSurrogate:function(e){return e>=56320&&e<=57343},type:{PRIMITIVE:1,PROMISE:4,ARRAY:3,OBJECT:2,STRING_STREAM:5,OBJECT_STREAM:6},isReadableStream:e,replaceValue:function(e,t,n,r){switch(n&&"function"==typeof n.toJSON&&(n=n.toJSON()),null!==r&&(n=r.call(e,String(t),n)),typeof n){case"function":case"symbol":n=void 0;break;case"object":if(null!==n){const e=n.constructor;e!==String&&e!==Number&&e!==Boolean||(n=n.valueOf())}}return n},getTypeNative:function(e){return null===e||"object"!=typeof e?1:Array.isArray(e)?3:2},getTypeAsync:function(t){return null===t||"object"!=typeof t?1:"function"==typeof t.then?4:e(t)?t._readableState.objectMode?6:5:Array.isArray(t)?3:2},normalizeReplacer:function(e){if("function"==typeof e)return e;if(Array.isArray(e)){const t=new Set(e.map((e=>"string"==typeof e||"number"==typeof e?String(e):null)).filter((e=>"string"==typeof e)));return t.add(""),(e,n)=>t.has(e)?n:void 0}return null},normalizeSpace:function(e){return"number"==typeof e?!(!Number.isFinite(e)||e<1)&&" ".repeat(Math.min(e,10)):"string"==typeof e&&e.slice(0,10)||!1}};const{normalizeReplacer:n,normalizeSpace:r,replaceValue:i,getTypeNative:a,getTypeAsync:o,isLeadingSurrogate:s,isTrailingSurrogate:c,escapableCharCodeSubstitution:u,type:{PRIMITIVE:l,OBJECT:f,ARRAY:d,PROMISE:p,STRING_STREAM:y,OBJECT_STREAM:g}}=t,b=Array.from({length:2048}).map(((e,t)=>u.hasOwnProperty(t)?2:t<32?6:t<128?1:2));function h(e){let t=0,n=!1;for(let r=0;r<e.length;r++){const i=e.charCodeAt(r);if(i<2048)t+=b[i];else{if(s(i)){t+=6,n=!0;continue}c(i)?t=n?t-2:t+6:t+=3}n=!1}return t+2}return{stringifyInfo:function(e,t,s,c){t=n(t),s=function(e){return"string"==typeof(e=r(e))?e.length:0}(s),c=c||{};const u=new Map,b=new Set,S=new Set,m=new Set,T=new Set,A=c.async?o:a,R={"":e};let w=!1,E=0;return function e(n,r){if(w)return;r=i(this,n,r,t);let a=A(r);if(a!==l&&b.has(r))return m.add(r),E+=4,void(c.continueOnCircular||(w=!0));switch(a){case l:void 0!==r||Array.isArray(this)?E+=function(e){switch(typeof e){case"string":return h(e);case"number":return Number.isFinite(e)?String(e).length:4;case"boolean":return e?4:5;case"undefined":case"object":return 4;default:throw new TypeError("Do not know how to serialize a "+typeof e)}}(r):this===R&&(E+=9);break;case f:{if(u.has(r)){S.add(r),E+=u.get(r);break}const t=E;let n=0;E+=2,b.add(r);for(const t in r)if(hasOwnProperty.call(r,t)){const i=E;e.call(r,t,r[t]),i!==E&&(E+=h(t)+1,n++)}n>1&&(E+=n-1),b.delete(r),s>0&&n>0&&(E+=(1+(b.size+1)*s+1)*n,E+=1+b.size*s),u.set(r,E-t);break}case d:{if(u.has(r)){S.add(r),E+=u.get(r);break}const t=E;E+=2,b.add(r);for(let t=0;t<r.length;t++)e.call(r,String(t),r[t]);r.length>1&&(E+=r.length-1),b.delete(r),s>0&&r.length>0&&(E+=(1+(b.size+1)*s)*r.length,E+=1+b.size*s),u.set(r,E-t);break}case p:case y:T.add(r);break;case g:E+=2,T.add(r)}}.call(R,"",e),{minLength:isNaN(E)?1/0:E,circular:[...m],duplicate:[...S],async:[...T]}},stringifyStream:"Method is not supported"}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).jsonExt=t()}(this,(function(){"use strict";function e(e){return"function"==typeof e.pipe&&"function"==typeof e._read&&"object"==typeof e._readableState&&null!==e._readableState}var t={escapableCharCodeSubstitution:{8:"\\b",9:"\\t",10:"\\n",12:"\\f",13:"\\r",34:'\\"',92:"\\\\"},isLeadingSurrogate:function(e){return e>=55296&&e<=56319},isTrailingSurrogate:function(e){return e>=56320&&e<=57343},type:{PRIMITIVE:1,PROMISE:4,ARRAY:3,OBJECT:2,STRING_STREAM:5,OBJECT_STREAM:6},isReadableStream:e,replaceValue:function(e,t,n,r){switch(n&&"function"==typeof n.toJSON&&(n=n.toJSON()),null!==r&&(n=r.call(e,String(t),n)),typeof n){case"function":case"symbol":n=void 0;break;case"object":if(null!==n){const e=n.constructor;e!==String&&e!==Number&&e!==Boolean||(n=n.valueOf())}}return n},getTypeNative:function(e){return null===e||"object"!=typeof e?1:Array.isArray(e)?3:2},getTypeAsync:function(t){return null===t||"object"!=typeof t?1:"function"==typeof t.then?4:e(t)?t._readableState.objectMode?6:5:Array.isArray(t)?3:2},normalizeReplacer:function(e){if("function"==typeof e)return e;if(Array.isArray(e)){const t=new Set(e.map((e=>"string"==typeof e||"number"==typeof e?String(e):null)).filter((e=>"string"==typeof e)));return t.add(""),(e,n)=>t.has(e)?n:void 0}return null},normalizeSpace:function(e){return"number"==typeof e?!(!Number.isFinite(e)||e<1)&&" ".repeat(Math.min(e,10)):"string"==typeof e&&e.slice(0,10)||!1}};const{normalizeReplacer:n,normalizeSpace:r,replaceValue:i,getTypeNative:o,getTypeAsync:a,isLeadingSurrogate:s,isTrailingSurrogate:c,escapableCharCodeSubstitution:u,type:{PRIMITIVE:l,OBJECT:f,ARRAY:d,PROMISE:p,STRING_STREAM:y,OBJECT_STREAM:g}}=t,h=Array.from({length:2048}).map(((e,t)=>u.hasOwnProperty(t)?2:t<32?6:t<128?1:2));function b(e){let t=0,n=!1;for(let r=0;r<e.length;r++){const i=e.charCodeAt(r);if(i<2048)t+=h[i];else{if(s(i)){t+=6,n=!0;continue}c(i)?t=n?t-2:t+6:t+=3}n=!1}return t+2}return{version:"0.3.1",stringifyInfo:function(e,t,s,c){t=n(t),s=function(e){return"string"==typeof(e=r(e))?e.length:0}(s),c=c||{};const u=new Map,h=new Set,S=new Set,m=new Set,T=new Set,A=c.async?a:o,w={"":e};let R=!1,E=0;return function e(n,r){if(R)return;r=i(this,n,r,t);let o=A(r);if(o!==l&&h.has(r))return m.add(r),E+=4,void(c.continueOnCircular||(R=!0));switch(o){case l:void 0!==r||Array.isArray(this)?E+=function(e){switch(typeof e){case"string":return b(e);case"number":return Number.isFinite(e)?String(e).length:4;case"boolean":return e?4:5;case"undefined":case"object":return 4;default:throw new TypeError("Do not know how to serialize a "+typeof e)}}(r):this===w&&(E+=9);break;case f:{if(u.has(r)){S.add(r),E+=u.get(r);break}const t=E;let n=0;E+=2,h.add(r);for(const t in r)if(hasOwnProperty.call(r,t)){const i=E;e.call(r,t,r[t]),i!==E&&(E+=b(t)+1,n++)}n>1&&(E+=n-1),h.delete(r),s>0&&n>0&&(E+=(1+(h.size+1)*s+1)*n,E+=1+h.size*s),u.set(r,E-t);break}case d:{if(u.has(r)){S.add(r),E+=u.get(r);break}const t=E;E+=2,h.add(r);for(let t=0;t<r.length;t++)e.call(r,String(t),r[t]);r.length>1&&(E+=r.length-1),h.delete(r),s>0&&r.length>0&&(E+=(1+(h.size+1)*s)*r.length,E+=1+h.size*s),u.set(r,E-t);break}case p:case y:T.add(r);break;case g:E+=2,T.add(r)}}.call(w,"",e),{minLength:isNaN(E)?1/0:E,circular:[...m],duplicate:[...S],async:[...T]}},stringifyStream:()=>{throw new Error("Method is not supported")}}})); |
{ | ||
"name": "@discoveryjs/json-ext", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "A set of utilities that extend the use of JSON", | ||
@@ -18,2 +18,5 @@ "keywords": [ | ||
"main": "./src/index", | ||
"browser": { | ||
"./src/stringify-stream.js": "./browser-method-is-not-supported.js" | ||
}, | ||
"scripts": { | ||
@@ -36,2 +39,3 @@ "test": "mocha --reporter progress", | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
@@ -38,0 +42,0 @@ "chalk": "^4.1.0", |
@@ -7,8 +7,8 @@ # json-ext | ||
A set of utilities that extend the use of JSON. | ||
A set of utilities that extend the use of JSON. Designed to be fast and memory efficient | ||
Features: | ||
- [x] Value info: `stringifyInfo()` | ||
- [x] Stringify stream: `stringifyStream()` | ||
- [x] `stringifyInfo()` – Get estimated size and other facts of JSON.stringify() without converting a value to string | ||
- [x] `stringifyStream()` – Stringify stream (Node.js) | ||
- [ ] **TBD** Parse stream | ||
@@ -26,6 +26,4 @@ - [ ] **TBD** Support for circular references | ||
<!-- TOC depthfrom:3 --> | ||
- [stringifyStreamvalue[, replacer[, space]]](#stringifystreamvalue-replacer-space) | ||
- [stringifyInfovalue[, replacer[, space[, options]]]](#stringifyinfovalue-replacer-space-options) | ||
- [stringifyStream(value[, replacer[, space]])](#stringifystreamvalue-replacer-space) | ||
- [stringifyInfo(value[, replacer[, space[, options]]])](#stringifyinfovalue-replacer-space-options) | ||
- [Options](#options) | ||
@@ -35,4 +33,2 @@ - [async](#async) | ||
<!-- /TOC --> | ||
### stringifyStream(value[, replacer[, space]]) | ||
@@ -42,9 +38,9 @@ | ||
Extensions: | ||
- Output `null` to the output when `JSON.stringify()` returns `undefined` (since streams may not to emit undefined) | ||
- A promise is resolving and the result value is stringifying as a regular value | ||
- A Stream in non-object mode is piping to output as is | ||
- A Stream in object mode is piping to output as an array of objects | ||
[Compare with other solutions](https://github.com/discoveryjs/json-ext/tree/master/benchmarks#stream-stringifying) (benchmark) | ||
[Comparison with other solutions](https://github.com/discoveryjs/json-ext/tree/master/benchmarks#stream-stringifying) (benchmark) | ||
Departs from JSON.stringify(): | ||
- Outputs `null` when `JSON.stringify()` returns `undefined` (since streams may not emit `undefined`) | ||
- A promise is resolving and the resulting value is stringifying as a regular one | ||
- A stream in non-object mode is piping to output as is | ||
- A stream in object mode is piping to output as an array of objects | ||
@@ -82,4 +78,8 @@ ### stringifyInfo(value[, replacer[, space[, options]]]) | ||
### version | ||
The version of library, e.g. `"0.3.1"`. | ||
## License | ||
MIT |
module.exports = { | ||
version: require('../package.json').version, | ||
stringifyInfo: require('./stringify-info'), | ||
stringifyStream: require('./stringify-stream') | ||
}; |
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
43001
1015
10