@json2csv/whatwg
Advanced tools
Comparing version 6.1.3 to 7.0.0
@@ -1,85 +0,57 @@ | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var AsyncParser_exports = {}; | ||
__export(AsyncParser_exports, { | ||
default: () => JSON2CSVNodeAsyncParser | ||
}); | ||
module.exports = __toCommonJS(AsyncParser_exports); | ||
var import_TransformStream = __toESM(require("./TransformStream.js")); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const TransformStream_js_1 = __importDefault(require("./TransformStream.js")); | ||
class JSON2CSVNodeAsyncParser { | ||
constructor(opts, asyncOpts, writableStrategy, readableStrategy) { | ||
this.opts = opts; | ||
this.asyncOpts = asyncOpts || {}; | ||
this.writableStrategy = writableStrategy; | ||
this.readableStrategy = readableStrategy; | ||
} | ||
/** | ||
* Main function that converts json to csv. | ||
* | ||
* @param {Stream|Array|Object} data Array of JSON objects to be converted to CSV | ||
* @returns {Stream} A stream producing the CSV formated data as a string | ||
*/ | ||
parse(data) { | ||
if (typeof data === "string" || ArrayBuffer.isView(data)) { | ||
data = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(data); | ||
controller.close(); | ||
constructor(opts = {}, asyncOpts = {}, writableStrategy, readableStrategy) { | ||
this.opts = opts; | ||
this.asyncOpts = asyncOpts; | ||
this.writableStrategy = writableStrategy; | ||
this.readableStrategy = readableStrategy; | ||
} | ||
/** | ||
* Main function that converts json to csv. | ||
* | ||
* @param {Stream|Array|Object} data Array of JSON objects to be converted to CSV | ||
* @returns {Stream} A stream producing the CSV formated data as a string | ||
*/ | ||
parse(data) { | ||
if (typeof data === 'string' || ArrayBuffer.isView(data)) { | ||
data = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(data); | ||
controller.close(); | ||
}, | ||
}); | ||
} | ||
}); | ||
} else if (Array.isArray(data)) { | ||
this.asyncOpts.objectMode = true; | ||
data = new ReadableStream({ | ||
start(controller) { | ||
data.filter((item) => item !== null).forEach((item) => controller.enqueue(item)); | ||
controller.close(); | ||
else if (Array.isArray(data)) { | ||
this.asyncOpts.objectMode = true; | ||
data = new ReadableStream({ | ||
start(controller) { | ||
data | ||
.filter((item) => item !== null) | ||
.forEach((item) => controller.enqueue(item)); | ||
controller.close(); | ||
}, | ||
}); | ||
} | ||
}); | ||
} else if (typeof data === "object" && !(data instanceof ReadableStream)) { | ||
this.asyncOpts.objectMode = true; | ||
data = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(data); | ||
controller.close(); | ||
else if (typeof data === 'object' && !(data instanceof ReadableStream)) { | ||
this.asyncOpts.objectMode = true; | ||
data = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(data); | ||
controller.close(); | ||
}, | ||
}); | ||
} | ||
}); | ||
if (!(data instanceof ReadableStream)) { | ||
throw new Error('Data should be a JSON object, JSON array, typed array, string or stream'); | ||
} | ||
const transform = new TransformStream_js_1.default(this.opts, this.asyncOpts, this.writableStrategy, this.readableStrategy); | ||
return data.pipeThrough(transform); | ||
} | ||
if (!(data instanceof ReadableStream)) { | ||
throw new Error( | ||
"Data should be a JSON object, JSON array, typed array, string or stream" | ||
); | ||
} | ||
const transform = new import_TransformStream.default( | ||
this.opts, | ||
this.asyncOpts, | ||
this.writableStrategy, | ||
this.readableStrategy | ||
); | ||
return data.pipeThrough(transform); | ||
} | ||
} | ||
exports.default = JSON2CSVNodeAsyncParser; | ||
//# sourceMappingURL=AsyncParser.js.map |
@@ -1,40 +0,11 @@ | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
AsyncParser: () => import_AsyncParser.default, | ||
TransformStream: () => import_TransformStream.default | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var import_AsyncParser = __toESM(require("./AsyncParser.js")); | ||
var import_TransformStream = __toESM(require("./TransformStream.js")); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
AsyncParser, | ||
TransformStream | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TransformStream = exports.AsyncParser = void 0; | ||
var AsyncParser_js_1 = require("./AsyncParser.js"); | ||
Object.defineProperty(exports, "AsyncParser", { enumerable: true, get: function () { return __importDefault(AsyncParser_js_1).default; } }); | ||
var TransformStream_js_1 = require("./TransformStream.js"); | ||
Object.defineProperty(exports, "TransformStream", { enumerable: true, get: function () { return __importDefault(TransformStream_js_1).default; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,75 +0,74 @@ | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var TransformStream_exports = {}; | ||
__export(TransformStream_exports, { | ||
default: () => JSON2CSVWHATWGTransformStream | ||
}); | ||
module.exports = __toCommonJS(TransformStream_exports); | ||
var import_plainjs = require("@json2csv/plainjs"); | ||
class Transformer extends import_plainjs.StreamParser { | ||
constructor(opts, asyncOpts) { | ||
super(opts, asyncOpts); | ||
} | ||
onData(data) { | ||
this.controller.enqueue(data); | ||
} | ||
onError(err) { | ||
this.controller.error(err); | ||
} | ||
onEnd() { | ||
this.controller.terminate(); | ||
} | ||
start(controller) { | ||
this.controller = controller; | ||
} | ||
transform(chunk) { | ||
this.tokenizer.write(chunk); | ||
} | ||
flush() { | ||
this.end(); | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const plainjs_1 = require("@json2csv/plainjs"); | ||
class JSON2CSVWHATWGTransformer extends plainjs_1.StreamParser { | ||
constructor(opts = {}, asyncOpts = {}) { | ||
super(opts, asyncOpts); | ||
} | ||
onData(data) { | ||
this.controller.enqueue(data); | ||
} | ||
onError(err) { | ||
this.controller.error(err); | ||
} | ||
onEnd() { | ||
this.controller.terminate(); | ||
} | ||
start(controller) { | ||
this.controller = controller; | ||
} | ||
transform(chunk) { | ||
this.tokenizer.write(chunk); | ||
} | ||
flush() { | ||
this.end(); | ||
} | ||
} | ||
class JSON2CSVWHATWGTransformStream extends TransformStream { | ||
constructor(opts, asyncOpts, writableStrategy, readableStrategy) { | ||
const transformer = new Transformer(opts, asyncOpts); | ||
super(transformer, writableStrategy, readableStrategy); | ||
if (typeof document === "object") { | ||
const delegate = document.createDocumentFragment(); | ||
["addEventListener", "dispatchEvent", "removeEventListener"].forEach( | ||
(f) => this[f] = (...args) => delegate[f](...args) | ||
); | ||
transformer.onHeader = (header) => this.dispatchEvent("header", header); | ||
transformer.onLine = (line) => this.dispatchEvent("line", line); | ||
const origOnData = transformer.onData.bind(transformer); | ||
transformer.onData = (data) => { | ||
origOnData(data); | ||
this.dispatchEvent("data", data); | ||
}; | ||
constructor(opts = {}, asyncOpts = {}, writableStrategy, readableStrategy) { | ||
const transformer = new JSON2CSVWHATWGTransformer(opts, asyncOpts); | ||
super(transformer, writableStrategy, readableStrategy); | ||
// Implement the EventTarget interface when running on a browser | ||
if (typeof document === 'object') { | ||
this.delegate = document.createDocumentFragment(); | ||
transformer.onHeader = (header) => this.dispatchEvent(new CustomEvent('header', { detail: header })); | ||
transformer.onLine = (line) => this.dispatchEvent(new CustomEvent('line', { detail: line })); | ||
const origOnData = transformer.onData.bind(transformer); | ||
transformer.onData = (data) => { | ||
origOnData(data); | ||
this.dispatchEvent(new CustomEvent('data', { detail: data })); | ||
}; | ||
} | ||
this.readable.promise = () => __awaiter(this, void 0, void 0, function* () { | ||
let csv = ''; | ||
const outputStream = new WritableStream({ | ||
write(chunk) { | ||
csv += chunk; | ||
}, | ||
}); | ||
yield this.readable.pipeTo(outputStream); | ||
return csv; | ||
}); | ||
} | ||
this.readable.promise = async () => { | ||
let csv = ""; | ||
const outputStream = new WritableStream({ | ||
write(chunk) { | ||
csv += chunk; | ||
} | ||
}); | ||
await this.readable.pipeTo(outputStream); | ||
return csv; | ||
}; | ||
} | ||
addEventListener(type, callback, options) { | ||
var _a; | ||
(_a = this.delegate) === null || _a === void 0 ? void 0 : _a.addEventListener(type, callback, options); | ||
} | ||
dispatchEvent(event) { | ||
return this.dispatchEvent(event); | ||
} | ||
removeEventListener(type, callback, options) { | ||
this.removeEventListener(type, callback, options); | ||
} | ||
} | ||
exports.default = JSON2CSVWHATWGTransformStream; | ||
//# sourceMappingURL=TransformStream.js.map |
{ | ||
"name": "@json2csv/whatwg", | ||
"version": "6.1.3", | ||
"version": "7.0.0", | ||
"description": "WHATWG Transform and Async interface to convert JSON into CSV.", | ||
@@ -29,23 +29,26 @@ "keywords": [ | ||
"./*": { | ||
"import": "./src/*", | ||
"import": "./dist/mjs/*", | ||
"require": "./dist/cjs/*" | ||
}, | ||
".": { | ||
"import": "./src/index.js", | ||
"import": "./dist/mjs/index.js", | ||
"require": "./dist/cjs/index.js" | ||
} | ||
}, | ||
"main": "src/index.js", | ||
"main": "dist/mjs/index.js", | ||
"scripts": { | ||
"lint": "eslint src test", | ||
"test": "npm run test:raw | tap-spec", | ||
"build:cjs": "tsc --module commonjs --verbatimModuleSyntax false --outDir ./dist/cjs && node ../../build-cjs.js", | ||
"build:mjs": "tsc --module esnext --outDir ./dist/mjs", | ||
"build": "npm run build:cjs && npm run build:mjs", | ||
"pretest": "npm run build", | ||
"test": "node test/CommonJS.cjs && npm run test:raw | tap-spec", | ||
"test-with-coverage": "c8 --reporter=text npm test", | ||
"test:raw": "node test", | ||
"test:raw": "ts-node --esm test/index.ts", | ||
"dependencies:update-internal": "npm uninstall @json2csv/plainjs && npm install @json2csv/plainjs", | ||
"build:cjs": "node ../../build-cjs.js whatwg", | ||
"prepublishOnly": "npm run build:cjs" | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"@json2csv/plainjs": "^6.1.3" | ||
"@json2csv/plainjs": "^7.0.0" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
119316
34
505
1
+ Added@json2csv/formatters@7.0.6(transitive)
+ Added@json2csv/plainjs@7.0.6(transitive)
+ Added@streamparser/json@0.0.20(transitive)
- Removed@json2csv/formatters@6.1.3(transitive)
- Removed@json2csv/plainjs@6.1.3(transitive)
- Removed@streamparser/json@0.0.12(transitive)
- Removedlodash.get@4.4.2(transitive)
Updated@json2csv/plainjs@^7.0.0