initial commit.
This commit is contained in:
10
node_modules/json2csv/.eslintrc
generated
vendored
Normal file
10
node_modules/json2csv/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 8
|
||||
},
|
||||
"extends": "eslint:recommended"
|
||||
}
|
||||
3
node_modules/json2csv/.gitattributes
generated
vendored
Normal file
3
node_modules/json2csv/.gitattributes
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
* text=auto
|
||||
test/fixtures/csv/eol.csv text eol=crlf
|
||||
test/fixtures/csv/escapeEOL.csv text eol=crlf
|
||||
614
node_modules/json2csv/CHANGELOG.md
generated
vendored
Normal file
614
node_modules/json2csv/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,614 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
### [5.0.7](https://github.com/zemirco/json2csv/compare/v5.0.6...v5.0.7) (2022-02-23)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* unwind transform issue with nested arrays ([#549](https://github.com/zemirco/json2csv/issues/549)) ([485ea77](https://github.com/zemirco/json2csv/commit/485ea77886f1e09d768ed1cce0af6faeb06707cf))
|
||||
|
||||
### [5.0.6](https://github.com/zemirco/json2csv/compare/v5.0.5...v5.0.6) (2021-02-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Escape quotes excel ([#512](https://github.com/zemirco/json2csv/issues/512)) ([ab3bf8a](https://github.com/zemirco/json2csv/commit/ab3bf8ad3ce64cff7d6149e1b70f92b71bebf6c7))
|
||||
|
||||
### [5.0.5](https://github.com/zemirco/json2csv/compare/v5.0.4...v5.0.5) (2020-11-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* don't mutate original object in unset ([#499](https://github.com/zemirco/json2csv/issues/499)) ([6e4ea5e](https://github.com/zemirco/json2csv/commit/6e4ea5ebdc263006ca6ff45879fbb7e0bd65bef2))
|
||||
|
||||
### [5.0.4](https://github.com/zemirco/json2csv/compare/v5.0.3...v5.0.4) (2020-11-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fix issue with unwind and empty arrays creating an extra column ([#496](https://github.com/zemirco/json2csv/issues/496)) ([0b331fc](https://github.com/zemirco/json2csv/commit/0b331fc3ad345f8062abe60f64cb3b43dad30fb0))
|
||||
|
||||
### [5.0.3](https://github.com/zemirco/json2csv/compare/v5.0.2...v5.0.3) (2020-09-24)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* audit dependencies fix ([d6d0fc7](https://github.com/zemirco/json2csv/commit/d6d0fc78128e01e021414aaf52a65cbcd09a1225))
|
||||
* update commander dep ([322e568](https://github.com/zemirco/json2csv/commit/322e568793ec4a64f43ec2ac82c9886177bcc4ed))
|
||||
|
||||
### [5.0.2](https://github.com/zemirco/json2csv/compare/v5.0.1...v5.0.2) (2020-09-24)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **cli:** fix relative paths issue in CLI when not streaming ([#488](https://github.com/zemirco/json2csv/issues/488)) ([06079e8](https://github.com/zemirco/json2csv/commit/06079e840128030eacfecde66da11295eb162234))
|
||||
|
||||
### [5.0.1](https://github.com/zemirco/json2csv/compare/v5.0.0...v5.0.1) (2020-04-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* wrong call to processValue ([#454](https://github.com/zemirco/json2csv/issues/454)) ([66abd45](https://github.com/zemirco/json2csv/commit/66abd45))
|
||||
|
||||
## [5.0.0](https://github.com/zemirco/json2csv/compare/v4.5.2...v5.0.0) (2020-03-15)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* Node 8 and 9 no longer supported, use Node 10 or greater. It might still work, but it has reached End-Of-Life.
|
||||
* module no longer takes `unwind`, `unwindBlank`, `flatten` or the `flattenSeparator` options, instead see the new `transforms` option. CLI options are unchanged from the callers side, but use the built in transforms under the hood.
|
||||
|
||||
* Add support for transforms
|
||||
|
||||
* Add documentation about transforms
|
||||
* remove extra commonjs build, use starting point in package.json `main` field.
|
||||
* Renamed `doubleQuote` to `escapedQuote`
|
||||
* remove `stringify` option
|
||||
* `--fields-config` option has been removed, use the new `--config` option for all configuration, not just fields.
|
||||
* Drop node 6 and 7, and add node 11 and 12
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Always error asynchronously from parseAsync method ([#412](https://github.com/zemirco/json2csv/issues/412)) ([16cc044](https://github.com/zemirco/json2csv/commit/16cc044))
|
||||
* audit deps ([15992cf](https://github.com/zemirco/json2csv/commit/15992cf))
|
||||
* drop Node 8 and 9 ([7295465](https://github.com/zemirco/json2csv/commit/7295465))
|
||||
* Make some CLI options mandatory ([#433](https://github.com/zemirco/json2csv/issues/433)) ([bd51527](https://github.com/zemirco/json2csv/commit/bd51527))
|
||||
* Remove CommonJS build ([#422](https://github.com/zemirco/json2csv/issues/422)) ([5ce0089](https://github.com/zemirco/json2csv/commit/5ce0089))
|
||||
* Remove stringify option ([#419](https://github.com/zemirco/json2csv/issues/419)) ([39f303d](https://github.com/zemirco/json2csv/commit/39f303d))
|
||||
* Rename doubleQuote to escapedQuote ([#418](https://github.com/zemirco/json2csv/issues/418)) ([f99408c](https://github.com/zemirco/json2csv/commit/f99408c))
|
||||
* update CI node versions ([#413](https://github.com/zemirco/json2csv/issues/413)) ([6fd6c09](https://github.com/zemirco/json2csv/commit/6fd6c09))
|
||||
* update commander cli dep ([74aa40a](https://github.com/zemirco/json2csv/commit/74aa40a))
|
||||
* update commander dep ([272675b](https://github.com/zemirco/json2csv/commit/272675b))
|
||||
* **deps:** audit dependencies ([bf9877a](https://github.com/zemirco/json2csv/commit/bf9877a))
|
||||
* **deps:** update commander ([3f099f2](https://github.com/zemirco/json2csv/commit/3f099f2))
|
||||
* **security:** fix audit vulnerabilities ([b57715b](https://github.com/zemirco/json2csv/commit/b57715b))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add support for flattening arrays and change transforms arguments to an object. ([#432](https://github.com/zemirco/json2csv/issues/432)) ([916e448](https://github.com/zemirco/json2csv/commit/916e448))
|
||||
* Add support for transforms ([#431](https://github.com/zemirco/json2csv/issues/431)) ([f1d04d0](https://github.com/zemirco/json2csv/commit/f1d04d0))
|
||||
* Improve async promise to optionally not return ([#421](https://github.com/zemirco/json2csv/issues/421)) ([3e296f6](https://github.com/zemirco/json2csv/commit/3e296f6))
|
||||
* Improves the unwind transform so it unwinds all unwindable fields if … ([#434](https://github.com/zemirco/json2csv/issues/434)) ([ec1f301](https://github.com/zemirco/json2csv/commit/ec1f301))
|
||||
* replace fields config by a global config ([#338](https://github.com/zemirco/json2csv/issues/338)) ([d6c1c5f](https://github.com/zemirco/json2csv/commit/d6c1c5f))
|
||||
|
||||
## [4.5.2](https://github.com/zemirco/json2csv/compare/v4.5.1...v4.5.2) (2019-07-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Improve the inference of the header name when using function as value ([#395](https://github.com/zemirco/json2csv/issues/395)) ([590d19a](https://github.com/zemirco/json2csv/commit/590d19a))
|
||||
|
||||
|
||||
|
||||
<a name="4.4.0"></a>
|
||||
## [4.4.0](https://github.com/zemirco/json2csv/compare/v4.3.5...v4.4.0) (2019-03-25)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Performance improvements and new async api ([#360](https://github.com/zemirco/json2csv/issues/360)) ([d59dea1](https://github.com/zemirco/json2csv/commit/d59dea1))
|
||||
|
||||
|
||||
<a name="4.3.5"></a>
|
||||
## [4.3.5](https://github.com/zemirco/json2csv/compare/v4.3.4...v4.3.5) (2019-02-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* audit deps ([3182707](https://github.com/zemirco/json2csv/commit/3182707))
|
||||
* unwind of nested fields ([#357](https://github.com/zemirco/json2csv/issues/357)) ([2d69281](https://github.com/zemirco/json2csv/commit/2d69281))
|
||||
|
||||
|
||||
|
||||
<a name="4.3.4"></a>
|
||||
## [4.3.4](https://github.com/zemirco/json2csv/compare/v4.3.3...v4.3.4) (2019-02-11)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* issue with fields.value function not receiving correct fields ([#353](https://github.com/zemirco/json2csv/issues/353)) ([851c02f](https://github.com/zemirco/json2csv/commit/851c02f))
|
||||
|
||||
|
||||
|
||||
<a name="4.3.3"></a>
|
||||
## [4.3.3](https://github.com/zemirco/json2csv/compare/v4.3.2...v4.3.3) (2019-01-11)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* audit dep fix ([1ef4bcd](https://github.com/zemirco/json2csv/commit/1ef4bcd))
|
||||
* Remove invalid reference to flat ([#347](https://github.com/zemirco/json2csv/issues/347)) ([130ef7d](https://github.com/zemirco/json2csv/commit/130ef7d))
|
||||
* Remove preferGlobal from package.json ([#346](https://github.com/zemirco/json2csv/issues/346)) ([2b6ad3a](https://github.com/zemirco/json2csv/commit/2b6ad3a))
|
||||
|
||||
|
||||
|
||||
<a name="4.3.2"></a>
|
||||
## [4.3.2](https://github.com/zemirco/json2csv/compare/v4.3.1...v4.3.2) (2018-12-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Remove lodash.clonedeep dependency ([#339](https://github.com/zemirco/json2csv/issues/339)) ([d28955a](https://github.com/zemirco/json2csv/commit/d28955a)), closes [#333](https://github.com/zemirco/json2csv/issues/333)
|
||||
|
||||
|
||||
|
||||
<a name="4.3.1"></a>
|
||||
## [4.3.1](https://github.com/zemirco/json2csv/compare/v4.3.0...v4.3.1) (2018-11-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Return correct exit code on error ([#337](https://github.com/zemirco/json2csv/issues/337)) ([a793de5](https://github.com/zemirco/json2csv/commit/a793de5))
|
||||
|
||||
|
||||
|
||||
<a name="4.3.0"></a>
|
||||
# [4.3.0](https://github.com/zemirco/json2csv/compare/v4.2.1...v4.3.0) (2018-11-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Optimize performance around the usage of fields ([#328](https://github.com/zemirco/json2csv/issues/328)) ([d9e4463](https://github.com/zemirco/json2csv/commit/d9e4463))
|
||||
* Remove wrong submodule ([#326](https://github.com/zemirco/json2csv/issues/326)) ([6486bb0](https://github.com/zemirco/json2csv/commit/6486bb0))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add support for objectMode in the stream API ([#325](https://github.com/zemirco/json2csv/issues/325)) ([8f0ae55](https://github.com/zemirco/json2csv/commit/8f0ae55))
|
||||
|
||||
|
||||
|
||||
<a name="4.2.1"></a>
|
||||
## [4.2.1](https://github.com/zemirco/json2csv/compare/v4.2.0...v4.2.1) (2018-08-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* bug that modifies opts after parsing an object/stream ([#318](https://github.com/zemirco/json2csv/issues/318)) ([f0a4830](https://github.com/zemirco/json2csv/commit/f0a4830))
|
||||
* Clean up the flattening separator feature ([#315](https://github.com/zemirco/json2csv/issues/315)) ([ee3d181](https://github.com/zemirco/json2csv/commit/ee3d181))
|
||||
|
||||
|
||||
|
||||
<a name="4.2.0"></a>
|
||||
# [4.2.0](https://github.com/zemirco/json2csv/compare/v4.1.6...v4.2.0) (2018-07-31)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Added flattenSeparator option ([#314](https://github.com/zemirco/json2csv/issues/314)) ([5c5de9f](https://github.com/zemirco/json2csv/commit/5c5de9f))
|
||||
|
||||
|
||||
|
||||
<a name="4.1.6"></a>
|
||||
## [4.1.6](https://github.com/zemirco/json2csv/compare/v4.1.5...v4.1.6) (2018-07-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Update dependencies and remove cli-table2 dependency ([#312](https://github.com/zemirco/json2csv/issues/312)) ([5981ba3](https://github.com/zemirco/json2csv/commit/5981ba3))
|
||||
|
||||
|
||||
|
||||
<a name="4.1.5"></a>
|
||||
## [4.1.5](https://github.com/zemirco/json2csv/compare/v4.1.4...v4.1.5) (2018-06-26)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Process stdin as a stream ([#308](https://github.com/zemirco/json2csv/issues/308)) ([2b186b6](https://github.com/zemirco/json2csv/commit/2b186b6))
|
||||
|
||||
|
||||
|
||||
<a name="4.1.4"></a>
|
||||
## [4.1.4](https://github.com/zemirco/json2csv/compare/v4.1.3...v4.1.4) (2018-06-23)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* don't escape tabs ([#305](https://github.com/zemirco/json2csv/issues/305)) ([a36c8e3](https://github.com/zemirco/json2csv/commit/a36c8e3))
|
||||
|
||||
|
||||
|
||||
<a name="4.1.3"></a>
|
||||
## [4.1.3](https://github.com/zemirco/json2csv/compare/v4.1.2...v4.1.3) (2018-05-23)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Escape custom quotes correctly ([#301](https://github.com/zemirco/json2csv/issues/301)) ([7d57208](https://github.com/zemirco/json2csv/commit/7d57208))
|
||||
|
||||
|
||||
|
||||
<a name="4.1.2"></a>
|
||||
## [4.1.2](https://github.com/zemirco/json2csv/compare/v4.1.1...v4.1.2) (2018-04-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **tests:** Skip bogus pretty print tests only in old node versions ([#290](https://github.com/zemirco/json2csv/issues/290)) ([0f3b885](https://github.com/zemirco/json2csv/commit/0f3b885))
|
||||
|
||||
|
||||
|
||||
<a name="4.1.1"></a>
|
||||
## [4.1.1](https://github.com/zemirco/json2csv/compare/v4.1.0...v4.1.1) (2018-04-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* readme CLI's info ([#289](https://github.com/zemirco/json2csv/issues/289)) ([9fe65b3](https://github.com/zemirco/json2csv/commit/9fe65b3))
|
||||
* Add tests and docs to unwind-blank feature ([#287](https://github.com/zemirco/json2csv/issues/287)) ([e3d4a05](https://github.com/zemirco/json2csv/commit/e3d4a05))
|
||||
* **perf:** Improve unwind performance and maintainability ([#288](https://github.com/zemirco/json2csv/issues/288)) ([80e496d](https://github.com/zemirco/json2csv/commit/80e496d))
|
||||
|
||||
|
||||
|
||||
<a name="4.1.0"></a>
|
||||
## [4.1.0](https://github.com/zemirco/json2csv/compare/v4.0.4...v4.1.0) (2018-04-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Avoid redundant deep cloning when unwinding. ([#286](https://github.com/zemirco/json2csv/issues/286)) ([95a6ca9](https://github.com/zemirco/json2csv/commit/95a6ca9))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add ability to unwind by blanking out instead of repeating data ([#285](https://github.com/zemirco/json2csv/issues/285)) ([61d9808](https://github.com/zemirco/json2csv/commit/61d9808))
|
||||
|
||||
|
||||
|
||||
<a name="4.0.4"></a>
|
||||
## [4.0.4](https://github.com/zemirco/json2csv/compare/v4.0.3...v4.0.4) (2018-04-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* comment out failing tests ([#283](https://github.com/zemirco/json2csv/issues/283)) ([5b25eaa](https://github.com/zemirco/json2csv/commit/5b25eaa))
|
||||
* Support empty array with opts.fields ([#281](https://github.com/zemirco/json2csv/issues/281)) ([eccca89](https://github.com/zemirco/json2csv/commit/eccca89))
|
||||
* **tests:** emit correct lines from transform ([#282](https://github.com/zemirco/json2csv/issues/282)) ([2322ddf](https://github.com/zemirco/json2csv/commit/2322ddf))
|
||||
|
||||
|
||||
|
||||
<a name="4.0.3"></a>
|
||||
## [4.0.3](https://github.com/zemirco/json2csv/compare/v4.0.2...v4.0.3) (2018-04-09)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* error when a field is null and flatten is used ([#274](https://github.com/zemirco/json2csv/issues/274)) ([1349a94](https://github.com/zemirco/json2csv/commit/1349a94))
|
||||
* throw error for empty dataset only if fields not specified ([0d8534e](https://github.com/zemirco/json2csv/commit/0d8534e))
|
||||
|
||||
|
||||
|
||||
<a name="4.0.2"></a>
|
||||
## [4.0.2](https://github.com/zemirco/json2csv/compare/v4.0.1...v4.0.2) (2018-03-09)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **parser:** RangeError ([#271](https://github.com/zemirco/json2csv/issues/271)) ([c8d5a87](https://github.com/zemirco/json2csv/commit/c8d5a87))
|
||||
|
||||
|
||||
|
||||
<a name="4.0.1"></a>
|
||||
## [4.0.1](https://github.com/zemirco/json2csv/compare/v4.0.0...v4.0.1) (2018-03-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* double quote escaping before new line ([#268](https://github.com/zemirco/json2csv/issues/268)) ([fa991cf](https://github.com/zemirco/json2csv/commit/fa991cf))
|
||||
|
||||
|
||||
|
||||
<a name="4.0.0"></a>
|
||||
# [4.0.0](https://github.com/zemirco/json2csv/compare/v4.0.0-alpha.2...v4.0.0) (2018-02-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Replace webpack with rollup packaging ([#266](https://github.com/zemirco/json2csv/issues/266)) ([a9f8020](https://github.com/zemirco/json2csv/commit/a9f8020))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Pass transform options through ([#262](https://github.com/zemirco/json2csv/issues/262)) ([650913f](https://github.com/zemirco/json2csv/commit/650913f))
|
||||
|
||||
|
||||
|
||||
<a name="4.0.0-alpha.2"></a>
|
||||
# [4.0.0-alpha.2](https://github.com/zemirco/json2csv/compare/v4.0.0-alpha.1...v4.0.0-alpha.2) (2018-02-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* flatten issue with toJSON ([#259](https://github.com/zemirco/json2csv/issues/259)) ([7006d2b](https://github.com/zemirco/json2csv/commit/7006d2b))
|
||||
|
||||
|
||||
|
||||
<a name="4.0.0-alpha.1"></a>
|
||||
# [4.0.0-alpha.1](https://github.com/zemirco/json2csv/compare/v4.0.0-alpha.0...v4.0.0-alpha.1) (2018-02-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Remove TypeScript definition ([#256](https://github.com/zemirco/json2csv/issues/256)) ([4f09694](https://github.com/zemirco/json2csv/commit/4f09694))
|
||||
|
||||
|
||||
|
||||
<a name="4.0.0-alpha.0"></a>
|
||||
# [4.0.0-alpha.0](https://github.com/zemirco/json2csv/compare/v3.11.5...v4.0.0-alpha.0) (2018-02-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Add CLI tests ([#247](https://github.com/zemirco/json2csv/issues/247)) ([bb8126f](https://github.com/zemirco/json2csv/commit/bb8126f))
|
||||
* Add excel string to cli and standardize ([#231](https://github.com/zemirco/json2csv/issues/231)) ([421baad](https://github.com/zemirco/json2csv/commit/421baad))
|
||||
* Allow passing ldjson input files ([#220](https://github.com/zemirco/json2csv/issues/220)) ([9c861ed](https://github.com/zemirco/json2csv/commit/9c861ed))
|
||||
* Avoid throwing an error on elements that can't be stringified (like functions) ([#223](https://github.com/zemirco/json2csv/issues/223)) ([679c687](https://github.com/zemirco/json2csv/commit/679c687))
|
||||
* backslash logic ([#222](https://github.com/zemirco/json2csv/issues/222)) ([29e9445](https://github.com/zemirco/json2csv/commit/29e9445))
|
||||
* broken stdin input ([#241](https://github.com/zemirco/json2csv/issues/241)) ([6cb407c](https://github.com/zemirco/json2csv/commit/6cb407c))
|
||||
* Combine EOL and newLine parameters ([#219](https://github.com/zemirco/json2csv/issues/219)) ([4668a8b](https://github.com/zemirco/json2csv/commit/4668a8b))
|
||||
* header flag ([#221](https://github.com/zemirco/json2csv/issues/221)) ([7f7338f](https://github.com/zemirco/json2csv/commit/7f7338f))
|
||||
* outdated jsdoc ([#243](https://github.com/zemirco/json2csv/issues/243)) ([efe9888](https://github.com/zemirco/json2csv/commit/efe9888))
|
||||
* pretty print issues ([#242](https://github.com/zemirco/json2csv/issues/242)) ([3bd9655](https://github.com/zemirco/json2csv/commit/3bd9655))
|
||||
* Process header cells as any other cell ([#244](https://github.com/zemirco/json2csv/issues/244)) ([1fcde13](https://github.com/zemirco/json2csv/commit/1fcde13))
|
||||
* Remove callback support ([2096ade](https://github.com/zemirco/json2csv/commit/2096ade))
|
||||
* Remove fieldNames ([#232](https://github.com/zemirco/json2csv/issues/232)) ([6cc74b2](https://github.com/zemirco/json2csv/commit/6cc74b2))
|
||||
* Remove path-is-absolute dependency ([#225](https://github.com/zemirco/json2csv/issues/225)) ([f71a3df](https://github.com/zemirco/json2csv/commit/f71a3df))
|
||||
* Rename hasCSVColumnTitle to noHeader ([#216](https://github.com/zemirco/json2csv/issues/216)) ([f053c8b](https://github.com/zemirco/json2csv/commit/f053c8b))
|
||||
* Rename ld-json to ndjson ([#240](https://github.com/zemirco/json2csv/issues/240)) ([24a7893](https://github.com/zemirco/json2csv/commit/24a7893))
|
||||
* Rename unwindPath to unwind ([#230](https://github.com/zemirco/json2csv/issues/230)) ([7143bc7](https://github.com/zemirco/json2csv/commit/7143bc7))
|
||||
* Streamify pretty print ([#248](https://github.com/zemirco/json2csv/issues/248)) ([fb7ad53](https://github.com/zemirco/json2csv/commit/fb7ad53))
|
||||
|
||||
|
||||
### Chores
|
||||
|
||||
* Refactor the entire library to ES6 ([#233](https://github.com/zemirco/json2csv/issues/233)) ([dce4d33](https://github.com/zemirco/json2csv/commit/dce4d33))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add doubleQuote to cli, rename other options to line up with the cli ([5e402dc](https://github.com/zemirco/json2csv/commit/5e402dc))
|
||||
* Add fields config option to CLI ([#245](https://github.com/zemirco/json2csv/issues/245)) ([74ef666](https://github.com/zemirco/json2csv/commit/74ef666))
|
||||
* Add streaming API ([#235](https://github.com/zemirco/json2csv/issues/235)) ([01ca93e](https://github.com/zemirco/json2csv/commit/01ca93e))
|
||||
* Split tests in multiple files ([#246](https://github.com/zemirco/json2csv/issues/246)) ([839de77](https://github.com/zemirco/json2csv/commit/839de77))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* Replaces field-list with field-config
|
||||
* Remove `preserveNewLinesInValues` option, preserve by default
|
||||
|
||||
* Refactor the entire library to ES6
|
||||
|
||||
* Fix PR issues
|
||||
|
||||
* Add strict mode for node 4.X
|
||||
* Remove fieldNames
|
||||
|
||||
* Increase coverage back to 100%
|
||||
* callback is no longer available, just return the csv from the json2csv.
|
||||
|
||||
- updated tests
|
||||
- updated readme
|
||||
* * Rename unwindPath to unwind
|
||||
|
||||
* Fix field-list in CLI
|
||||
* newLine removed, eol kept.
|
||||
* Rename del to delimiter to match the cli flag
|
||||
* Rename quotes to quote to match the cli flag
|
||||
|
||||
* Remove unused double quotes comment
|
||||
|
||||
* Fix noHeader in CLI
|
||||
|
||||
* Revert "Remove unused double quotes comment"
|
||||
|
||||
This reverts commit 250d3e6ddf3062cbdc1e0174493a37fa21197d8e.
|
||||
|
||||
* Add doubleQuote to CLI
|
||||
* Rename hasCSVColumnTitle to noHeader to keep in line with the CLI
|
||||
|
||||
|
||||
|
||||
<a name="3.11.5"></a>
|
||||
## [3.11.5](https://github.com/zemirco/json2csv/compare/v3.11.4...v3.11.5) (2017-10-23)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* backslash value not escaped properly ([#202](https://github.com/zemirco/json2csv/issues/202)) ([#204](https://github.com/zemirco/json2csv/issues/204)) ([2cf50f1](https://github.com/zemirco/json2csv/commit/2cf50f1))
|
||||
|
||||
|
||||
|
||||
<a name="3.11.4"></a>
|
||||
## [3.11.4](https://github.com/zemirco/json2csv/compare/v3.11.3...v3.11.4) (2017-10-09)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **security:** Update debug to 3.1.0 for security reasons ([9c7cfaa](https://github.com/zemirco/json2csv/commit/9c7cfaa))
|
||||
|
||||
|
||||
|
||||
<a name="3.11.3"></a>
|
||||
## [3.11.3](https://github.com/zemirco/json2csv/compare/v3.11.2...v3.11.3) (2017-10-09)
|
||||
|
||||
|
||||
|
||||
<a name="3.11.2"></a>
|
||||
## [3.11.2](https://github.com/zemirco/json2csv/compare/v3.11.1...v3.11.2) (2017-09-13)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Remove extra space character in mode withBOM: true [#190](https://github.com/zemirco/json2csv/issues/190) ([#194](https://github.com/zemirco/json2csv/issues/194)) ([e8b6f6b](https://github.com/zemirco/json2csv/commit/e8b6f6b))
|
||||
|
||||
|
||||
|
||||
<a name="3.11.1"></a>
|
||||
## [3.11.1](https://github.com/zemirco/json2csv/compare/v3.11.0...v3.11.1) (2017-08-11)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **cli:** pass BOM cli option to function ([#193](https://github.com/zemirco/json2csv/issues/193)) ([70cfdfe](https://github.com/zemirco/json2csv/commit/70cfdfe))
|
||||
|
||||
|
||||
|
||||
<a name="3.11.0"></a>
|
||||
# [3.11.0](https://github.com/zemirco/json2csv/compare/v3.10.0...v3.11.0) (2017-08-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Handle dates without double-escaping ([#189](https://github.com/zemirco/json2csv/issues/189)) ([ff514ba](https://github.com/zemirco/json2csv/commit/ff514ba))
|
||||
* unwind parameter in command line mode ([#191](https://github.com/zemirco/json2csv/issues/191)) ([e706c25](https://github.com/zemirco/json2csv/commit/e706c25))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Added flag to signal if resulting function value should be stringified or not ([#192](https://github.com/zemirco/json2csv/issues/192)) ([aaa6b05](https://github.com/zemirco/json2csv/commit/aaa6b05))
|
||||
|
||||
|
||||
|
||||
<a name="3.10.0"></a>
|
||||
# [3.10.0](https://github.com/zemirco/json2csv/compare/v3.9.1...v3.10.0) (2017-07-24)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add BOM character option ([#187](https://github.com/zemirco/json2csv/issues/187)) ([0c799ca](https://github.com/zemirco/json2csv/commit/0c799ca))
|
||||
|
||||
|
||||
|
||||
<a name="3.9.1"></a>
|
||||
## [3.9.1](https://github.com/zemirco/json2csv/compare/v3.9.0...v3.9.1) (2017-07-14)
|
||||
|
||||
|
||||
|
||||
<a name="3.9.0"></a>
|
||||
# [3.9.0](https://github.com/zemirco/json2csv/compare/v3.8.0...v3.9.0) (2017-07-11)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Parameter unwindPath for multiple fields ([#174](https://github.com/zemirco/json2csv/issues/174)) ([#183](https://github.com/zemirco/json2csv/issues/183)) ([fbcaa10](https://github.com/zemirco/json2csv/commit/fbcaa10))
|
||||
|
||||
|
||||
|
||||
<a name="3.8.0"></a>
|
||||
# [3.8.0](https://github.com/zemirco/json2csv/compare/v3.7.3...v3.8.0) (2017-07-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **docs:** Add a coma in the ReadMe example ([#181](https://github.com/zemirco/json2csv/issues/181)) ([abeb820](https://github.com/zemirco/json2csv/commit/abeb820))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Preserve new lines in cells with option `preserveNewLinesInValues` ([#91](https://github.com/zemirco/json2csv/issues/91)) ([#171](https://github.com/zemirco/json2csv/issues/171)) ([187b701](https://github.com/zemirco/json2csv/commit/187b701))
|
||||
|
||||
|
||||
|
||||
<a name="3.7.3"></a>
|
||||
## [3.7.3](https://github.com/zemirco/json2csv/compare/v3.7.1...v3.7.3) (2016-12-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **jsdoc:** JSDoc Editting ([#155](https://github.com/zemirco/json2csv/issues/155)) ([76075d6](https://github.com/zemirco/json2csv/commit/76075d6))
|
||||
* **ts:** Fix type definition ([#154](https://github.com/zemirco/json2csv/issues/154)) ([fae53a1](https://github.com/zemirco/json2csv/commit/fae53a1))
|
||||
|
||||
|
||||
|
||||
## 3.6.3 / 2016-08-17
|
||||
|
||||
* Fix crashing on EPIPE error [#134](https://github.com/zemirco/json2csv/pull/134)
|
||||
* Add UMD build for browser usage [#136](https://github.com/zemirco/json2csv/pull/136)
|
||||
* Add docs during prepublish
|
||||
|
||||
## 3.6.2 / 2016-07-22
|
||||
|
||||
* Remove debugger, see [#132](https://github.com/zemirco/json2csv/pull/132)
|
||||
* Fix changelog typo
|
||||
|
||||
## 3.6.1 / 2016-07-12
|
||||
|
||||
* Fix auto-fields returning all available fields, even if not available on the first object, see #104
|
||||
|
||||
## 3.6.0 / 2016-07-07
|
||||
|
||||
* Make callback optional
|
||||
* Make callback use `process.nextTick`, so it's not sync
|
||||
|
||||
Thanks @STRML!
|
||||
|
||||
## 3.5.1 / 2016-06-29
|
||||
|
||||
* Revert [#114](https://github.com/zemirco/json2csv/pull/114), due to more issues
|
||||
* Update npmignore
|
||||
* Add a changelog
|
||||
* Updatee readme
|
||||
|
||||
## 3.5.0 / 2016-06-21
|
||||
|
||||
* `includeEmptyRows` options added, see [#122](https://github.com/zemirco/json2csv/pull/122) (Thanks @glutentag)
|
||||
* `-a` or `--include-empty-rows` added for the CLI.
|
||||
|
||||
## 2.2.1 / 2013-11-10
|
||||
|
||||
* mainly for development e.g. adding code format, update readme..
|
||||
|
||||
## 2.2.0 / 2013-11-08
|
||||
|
||||
* not create CSV column title by passing hasCSVColumnTitle: false, into params.
|
||||
* if field is not exist in object then the field value in CSV will be empty.
|
||||
* fix data in object format - {...}
|
||||
|
||||
## 2.1.0 / 2013-06-11
|
||||
|
||||
* quote titles in the first row
|
||||
|
||||
## 2.0.0 / 2013-03-04
|
||||
|
||||
* err in callback function
|
||||
|
||||
## 1.3.1 / 2013-02-20
|
||||
|
||||
* fix stdin encoding
|
||||
|
||||
## 1.3.0 / 2013-02-20
|
||||
|
||||
* support reading from stdin [#9](https://github.com/zeMirco/json2csv/pull/9)
|
||||
|
||||
## 1.2.0 / 2013-02-20
|
||||
|
||||
* support custom field names [#8](https://github.com/zeMirco/json2csv/pull/8)
|
||||
|
||||
## 1.1.0 / 2013-01-19
|
||||
|
||||
* add optional custom delimiter
|
||||
14
node_modules/json2csv/LICENSE.md
generated
vendored
Normal file
14
node_modules/json2csv/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
Copyright (C) 2012 [Mirco Zeiss](mailto: mirco.zeiss@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
||||
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
970
node_modules/json2csv/README.md
generated
vendored
Normal file
970
node_modules/json2csv/README.md
generated
vendored
Normal file
@@ -0,0 +1,970 @@
|
||||
# json2csv
|
||||
|
||||
Converts json into csv with column titles and proper line endings.
|
||||
Can be used as a module and from the command line.
|
||||
|
||||
[![npm version][npm-badge]][npm-badge-url]
|
||||
[![Build Status][travis-badge]][travis-badge-url]
|
||||
[![Coverage Status][coveralls-badge]][coveralls-badge-url]
|
||||
|
||||
See the [CHANGELOG] for details about the latest release.
|
||||
|
||||
## Features
|
||||
|
||||
- Fast and lightweight
|
||||
- Scalable to infinitely large datasets (using stream processing)
|
||||
- Support for standard JSON as well as NDJSON
|
||||
- Advanced data selection (automatic field discovery, underscore-like selectors, custom data getters, default values for missing fields, transforms, etc.)
|
||||
- Highly customizable (supportting custom quotation marks, delimiters, eol values, etc.)
|
||||
- Automatic escaping (preserving new lines, quotes, etc. in them)
|
||||
- Optional headers
|
||||
- Unicode encoding support
|
||||
- Pretty printing in table format to stdout
|
||||
|
||||
## How to install
|
||||
|
||||
You can install json2csv as a dependency using NPM.
|
||||
Requires **Node v10** or higher.
|
||||
|
||||
```sh
|
||||
# Global so it can be called from anywhere
|
||||
$ npm install -g json2csv
|
||||
# or as a dependency of a project
|
||||
$ npm install json2csv --save
|
||||
```
|
||||
|
||||
Also, if you are loading json2csv directly to the browser you can pull it directly from the CDN.
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/json2csv"></script>
|
||||
```
|
||||
|
||||
By default, the above script will get the latest release of json2csv. You can also specify a specific version:
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/json2csv@4.2.1"></script>
|
||||
```
|
||||
|
||||
## Command Line Interface
|
||||
|
||||
`json2csv` can be called from the command line if installed globally (using the `-g` flag).
|
||||
|
||||
```bash
|
||||
Usage: json2csv [options]
|
||||
|
||||
Options:
|
||||
-V, --version output the version number
|
||||
-i, --input <input> Path and name of the incoming json file. Defaults to stdin.
|
||||
-o, --output <output> Path and name of the resulting csv file. Defaults to stdout.
|
||||
-c, --config <path> Specify a file with a valid JSON configuration.
|
||||
-n, --ndjson Treat the input as NewLine-Delimited JSON.
|
||||
-s, --no-streaming Process the whole JSON array in memory instead of doing it line by line.
|
||||
-f, --fields <fields> List of fields to process. Defaults to field auto-detection.
|
||||
-v, --default-value <defaultValue> Default value to use for missing fields.
|
||||
-q, --quote <quote> Character(s) to use as quote mark. Defaults to '"'.
|
||||
-Q, --escaped-quote <escapedQuote> Character(s) to use as a escaped quote. Defaults to a double `quote`, '""'.
|
||||
-d, --delimiter <delimiter> Character(s) to use as delimiter. Defaults to ','. (default: ",")
|
||||
-e, --eol <eol> Character(s) to use as End-of-Line for separating rows. Defaults to '\n'. (default: "\n")
|
||||
-E, --excel-strings Wraps string data to force Excel to interpret it as string even if it contains a number.
|
||||
-H, --no-header Disable the column name header.
|
||||
-a, --include-empty-rows Includes empty rows in the resulting CSV output.
|
||||
-b, --with-bom Includes BOM character at the beginning of the CSV.
|
||||
-p, --pretty Print output as a pretty table. Use only when printing to console.
|
||||
--unwind [paths] Creates multiple rows from a single JSON document similar to MongoDB unwind.
|
||||
--unwind-blank When unwinding, blank out instead of repeating data. Defaults to false. (default: false)
|
||||
--flatten-objects Flatten nested objects. Defaults to false. (default: false)
|
||||
--flatten-arrays Flatten nested arrays. Defaults to false. (default: false)
|
||||
--flatten-separator <separator> Flattened keys separator. Defaults to '.'. (default: ".")
|
||||
-h, --help output usage information
|
||||
```
|
||||
|
||||
If no input `-i` is specified the result is expected from to the console standard input.
|
||||
If no output `-o` is specified the result is printed to the console standard output.
|
||||
If no fields `-f` or config `-c` are passed the fields of the first element are used since json2csv CLI process the items one at a time. You can use the `--no-streaming` flag to load the entire JSON in memory and get all the headers. However, keep in mind that this is slower and requires much more memory.
|
||||
Use `-p` to show the result as a table in the console.
|
||||
|
||||
Any option passed through the config file `-c` will be overriden if a specific flag is passed as well. For example, the fields option of the config will be overriden if the fields flag `-f` is used.
|
||||
|
||||
### CLI examples
|
||||
|
||||
All examples use this example [input file](https://github.com/zemirco/json2csv/blob/master/test/fixtures/json/default.json).
|
||||
|
||||
#### Input file and specify fields
|
||||
|
||||
```sh
|
||||
$ json2csv -i input.json -f carModel,price,color
|
||||
carModel,price,color
|
||||
"Audi",10000,"blue"
|
||||
"BMW",15000,"red"
|
||||
"Mercedes",20000,"yellow"
|
||||
"Porsche",30000,"green"
|
||||
```
|
||||
|
||||
#### Input file, specify fields and use pretty logging
|
||||
|
||||
```sh
|
||||
$ json2csv -i input.json -f carModel,price,color -p
|
||||
```
|
||||
|
||||

|
||||
|
||||
#### Generating CSV containing only specific fields
|
||||
|
||||
```sh
|
||||
$ json2csv -i input.json -f carModel,price,color -o out.csv
|
||||
$ cat out.csv
|
||||
carModel,price,color
|
||||
"Audi",10000,"blue"
|
||||
"BMW",15000,"red"
|
||||
"Mercedes",20000,"yellow"
|
||||
"Porsche",30000,"green"
|
||||
```
|
||||
|
||||
Same result will be obtained passing the fields config as a file.
|
||||
|
||||
```sh
|
||||
$ json2csv -i input.json -c fieldsConfig.json -o out.csv
|
||||
```
|
||||
|
||||
where the file `fieldsConfig.json` contains
|
||||
|
||||
```json
|
||||
[
|
||||
"carModel",
|
||||
"price",
|
||||
"color"
|
||||
]
|
||||
```
|
||||
|
||||
#### Read input from stdin
|
||||
|
||||
```sh
|
||||
$ json2csv -f price
|
||||
[{"price":1000},{"price":2000}]
|
||||
```
|
||||
|
||||
Hit <kbd>Enter</kbd> and afterwards <kbd>CTRL</kbd> + <kbd>D</kbd> to end reading from stdin. The terminal should show
|
||||
|
||||
```
|
||||
price
|
||||
1000
|
||||
2000
|
||||
```
|
||||
|
||||
#### Appending to existing CSV
|
||||
|
||||
Sometimes you want to add some additional rows with the same columns.
|
||||
This is how you can do that.
|
||||
|
||||
```sh
|
||||
# Initial creation of csv with headings
|
||||
$ json2csv -i test.json -f name,version > test.csv
|
||||
# Append additional rows
|
||||
$ json2csv -i test.json -f name,version --no-header >> test.csv
|
||||
```
|
||||
|
||||
## Javascript module
|
||||
|
||||
`json2csv` can also be use programatically from you javascript codebase.
|
||||
|
||||
### Available Options
|
||||
|
||||
The programatic APIs take a configuration object very equivalent to the CLI options.
|
||||
|
||||
- `fields` - Array of Objects/Strings. Defaults to toplevel JSON attributes. See example below.
|
||||
- `ndjson` - Only effective on the streaming API. Indicates that data coming through the stream is NDJSON.
|
||||
- `transforms` - Array of transforms to be applied to each data item. A transform is simply a function that receives a data item and returns the transformed item.
|
||||
- `defaultValue` - String, default value to use when missing data. Defaults to `<empty>` if not specified. (Overridden by `fields[].default`)
|
||||
- `quote` - String, quote around cell values and column names. Defaults to `"` if not specified.
|
||||
- `escapedQuote` - String, the value to replace escaped quotes in strings. Defaults to 2x`quotes` (for example `""`) if not specified.
|
||||
- `delimiter` - String, delimiter of columns. Defaults to `,` if not specified.
|
||||
- `eol` - String, overrides the default OS line ending (i.e. `\n` on Unix and `\r\n` on Windows).
|
||||
- `excelStrings` - Boolean, converts string data into normalized Excel style data.
|
||||
- `header` - Boolean, determines whether or not CSV file will contain a title column. Defaults to `true` if not specified.
|
||||
- `includeEmptyRows` - Boolean, includes empty rows. Defaults to `false`.
|
||||
- `withBOM` - Boolean, with BOM character. Defaults to `false`.
|
||||
|
||||
### json2csv parser (Synchronous API)
|
||||
|
||||
`json2csv` can also be used programatically as a synchronous converter using its `parse` method.
|
||||
```js
|
||||
const { Parser } = require('json2csv');
|
||||
|
||||
const fields = ['field1', 'field2', 'field3'];
|
||||
const opts = { fields };
|
||||
|
||||
try {
|
||||
const parser = new Parser(opts);
|
||||
const csv = parser.parse(myData);
|
||||
console.log(csv);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
```
|
||||
|
||||
you can also use the convenience method `parse`
|
||||
|
||||
```js
|
||||
const { parse } = require('json2csv');
|
||||
|
||||
const fields = ['field1', 'field2', 'field3'];
|
||||
const opts = { fields };
|
||||
|
||||
try {
|
||||
const csv = parse(myData, opts);
|
||||
console.log(csv);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
```
|
||||
|
||||
Both of the methods above load the entire JSON in memory and do the whole processing in-memory while blocking Javascript event loop. For that reason is rarely a good reason to use it until your data is very small or your application doesn't do anything else.
|
||||
|
||||
### json2csv async parser (Streaming API)
|
||||
|
||||
The synchronous API has the downside of loading the entire JSON array in memory and blocking javascript's event loop while processing the data. This means that your server won't be able to process more request or your UI will become irresponsive while data is being processed. For those reasons, is rarely a good reason to use it unless your data is very small or your application doesn't do anything else.
|
||||
|
||||
The async parser process the data as a non-blocking stream. This approach ensures a consistent memory footprint and avoid blocking javascript's event loop. Thus, it's better suited for large datasets or system with high concurrency.
|
||||
|
||||
One very important difference between the asynchronous and the synchronous APIs is that using the asynchronous API json objects are processed one by one. In practice, this means that only the fields in the first object of the array are automatically detected and other fields are just ignored. To avoid this, it's advisable to ensure that all the objects contain exactly the same fields or provide the list of fields using the `fields` option.
|
||||
|
||||
The async API uses takes a second options arguments that's directly passed to the underlying streams and accept the same options as the standard [Node.js streams](https://nodejs.org/api/stream.html#stream_new_stream_duplex_options).
|
||||
|
||||
Instances of `AsyncParser` expose three objects:
|
||||
* *input:* Which allows to push more data
|
||||
* *processor:* A readable string representing the whole data processing. You can listen to all the standard events of Node.js streams.
|
||||
* *transform:* The json2csv transform. See bellow for more details.
|
||||
|
||||
```js
|
||||
const { AsyncParser } = require('json2csv');
|
||||
|
||||
const fields = ['field1', 'field2', 'field3'];
|
||||
const opts = { fields };
|
||||
const transformOpts = { highWaterMark: 8192 };
|
||||
|
||||
const asyncParser = new AsyncParser(opts, transformOpts);
|
||||
|
||||
let csv = '';
|
||||
asyncParser.processor
|
||||
.on('data', chunk => (csv += chunk.toString()))
|
||||
.on('end', () => console.log(csv))
|
||||
.on('error', err => console.error(err));
|
||||
|
||||
// You can also listen for events on the conversion and see how the header or the lines are coming out.
|
||||
asyncParser.transform
|
||||
.on('header', header => console.log(header))
|
||||
.on('line', line => console.log(line))
|
||||
.on('error', err => console.log(err));
|
||||
|
||||
asyncParser.input.push(data); // This data might come from an HTTP request, etc.
|
||||
asyncParser.input.push(null); // Sending `null` to a stream signal that no more data is expected and ends it.
|
||||
```
|
||||
|
||||
`AsyncParser` also exposes some convenience methods:
|
||||
* `fromInput` allows you to set the input stream.
|
||||
* `throughTransform` allows you to add transforms to the stream.
|
||||
* `toOutput` allows you to set the output stream.
|
||||
* `promise` returns a promise that resolves when the stream ends or errors. Takes a boolean parameter to indicate if the resulting CSV should be kept in-memory and be resolved by the promise.
|
||||
|
||||
```js
|
||||
const { createReadStream, createWriteStream } = require('fs');
|
||||
const { AsyncParser } = require('json2csv');
|
||||
|
||||
const fields = ['field1', 'field2', 'field3'];
|
||||
const opts = { fields };
|
||||
const transformOpts = { highWaterMark: 8192 };
|
||||
|
||||
// Using the promise API
|
||||
const input = createReadStream(inputPath, { encoding: 'utf8' });
|
||||
const asyncParser = new JSON2CSVAsyncParser(opts, transformOpts);
|
||||
const parsingProcessor = asyncParser.fromInput(input);
|
||||
|
||||
parsingProcessor.promise()
|
||||
.then(csv => console.log(csv))
|
||||
.catch(err => console.error(err));
|
||||
|
||||
// Using the promise API just to know when the process finnish
|
||||
// but not actually load the CSV in memory
|
||||
const input = createReadStream(inputPath, { encoding: 'utf8' });
|
||||
const output = createWriteStream(outputPath, { encoding: 'utf8' });
|
||||
const asyncParser = new JSON2CSVAsyncParser(opts, transformOpts);
|
||||
const parsingProcessor = asyncParser.fromInput(input).toOutput(output);
|
||||
|
||||
parsingProcessor.promise(false).catch(err => console.error(err));
|
||||
```
|
||||
|
||||
you can also use the convenience method `parseAsync` which accept both JSON arrays/objects and readable streams and returns a promise.
|
||||
|
||||
```js
|
||||
const { parseAsync } = require('json2csv');
|
||||
|
||||
const fields = ['field1', 'field2', 'field3'];
|
||||
const opts = { fields };
|
||||
|
||||
parseAsync(myData, opts)
|
||||
.then(csv => console.log(csv))
|
||||
.catch(err => console.error(err));
|
||||
```
|
||||
|
||||
### json2csv transform (Streaming API)
|
||||
|
||||
json2csv also exposes the raw stream transform so you can pipe your json content into it. This is the same Transform that `AsyncParser` uses under the hood.
|
||||
|
||||
```js
|
||||
const { createReadStream, createWriteStream } = require('fs');
|
||||
const { Transform } = require('json2csv');
|
||||
|
||||
const fields = ['field1', 'field2', 'field3'];
|
||||
const opts = { fields };
|
||||
const transformOpts = { highWaterMark: 16384, encoding: 'utf-8' };
|
||||
|
||||
const input = createReadStream(inputPath, { encoding: 'utf8' });
|
||||
const output = createWriteStream(outputPath, { encoding: 'utf8' });
|
||||
const json2csv = new Transform(opts, transformOpts);
|
||||
|
||||
const processor = input.pipe(json2csv).pipe(output);
|
||||
|
||||
// You can also listen for events on the conversion and see how the header or the lines are coming out.
|
||||
json2csv
|
||||
.on('header', header => console.log(header))
|
||||
.on('line', line => console.log(line))
|
||||
.on('error', err => console.log(err));
|
||||
```
|
||||
|
||||
The stream API can also work on object mode. This is useful when you have an input stream in object mode or if you are getting JSON objects one by one and want to convert them to CSV as they come.
|
||||
|
||||
```js
|
||||
const { Transform } = require("json2csv");
|
||||
const { Readable } = require('stream');
|
||||
|
||||
const input = new Readable({ objectMode: true });
|
||||
input._read = () => {};
|
||||
// myObjectEmitter is just a fake example representing anything that emit objects.
|
||||
myObjectEmitter.on('object', obj => input.push(obj));
|
||||
// Pushing a null close the stream
|
||||
myObjectEmitter.end(() => input.push(null));
|
||||
|
||||
const output = process.stdout;
|
||||
|
||||
const opts = {};
|
||||
const transformOpts = { objectMode: true };
|
||||
|
||||
const json2csv = new Transform(opts, transformOpts);
|
||||
const processor = input.pipe(json2csv).pipe(output);
|
||||
```
|
||||
|
||||
### Data transforms
|
||||
|
||||
json2csv supports data transforms. A transform is simply a function that receives a data item and returns the transformed item.
|
||||
|
||||
|
||||
#### Custom transforms
|
||||
|
||||
```js
|
||||
function (item) {
|
||||
// apply tranformations or create new object
|
||||
return transformedItem;
|
||||
}
|
||||
```
|
||||
or using ES6
|
||||
```js
|
||||
(item) => {
|
||||
// apply tranformations or create new object
|
||||
return transformedItem;
|
||||
}
|
||||
```
|
||||
|
||||
For example, let's add a line counter to our CSV, capitalize the car field and change the price to be in Ks (1000s).
|
||||
```js
|
||||
let counter = 1;
|
||||
(item) => ({ counter: counter++, ...item, car: item.car.toUpperCase(), price: item.price / 1000 });
|
||||
```
|
||||
|
||||
#### Built-in transforms
|
||||
|
||||
There is a number of built-in transform provider by the library.
|
||||
|
||||
```js
|
||||
const { transforms: { unwind, flatten } } = require('json2csv');
|
||||
```
|
||||
|
||||
##### Unwind
|
||||
|
||||
The unwind transform deconstructs an array field from the input item to output a row for each element. Is's similar to MongoDB's $unwind aggregation.
|
||||
|
||||
The transform needs to be instantiated and takes an options object as arguments containing:
|
||||
- `paths` - Array of String, list the paths to the fields to be unwound. It's mandatory and should not be empty.
|
||||
- `blankOut` - Boolean, unwind using blank values instead of repeating data. Defaults to `false`.
|
||||
|
||||
```js
|
||||
// Default
|
||||
unwind({ paths: ['fieldToUnwind'] });
|
||||
|
||||
// Blanking out repeated data
|
||||
unwind({ paths: ['fieldToUnwind'], blankOut: true });
|
||||
```
|
||||
|
||||
##### Flatten
|
||||
Flatten nested javascript objects into a single level object.
|
||||
|
||||
The transform needs to be instantiated and takes an options object as arguments containing:
|
||||
- `objects` - Boolean, whether to flatten JSON objects or not. Defaults to `true`.
|
||||
- `arrays`- Boolean, whether to flatten Arrays or not. Defaults to `false`.
|
||||
- `separator` - String, separator to use between nested JSON keys when flattening a field. Defaults to `.`.
|
||||
|
||||
```js
|
||||
// Default
|
||||
flatten();
|
||||
|
||||
// Custom separator '__'
|
||||
flatten({ separator: '_' });
|
||||
|
||||
// Flatten only arrays
|
||||
flatten({ objects: false, arrays: true });
|
||||
```
|
||||
|
||||
### Javascript module examples
|
||||
|
||||
#### Example `fields` option
|
||||
```js
|
||||
{
|
||||
fields: [
|
||||
// Supports pathname -> pathvalue
|
||||
'simplepath', // equivalent to {value:'simplepath'}
|
||||
'path.to.value' // also equivalent to {value:'path.to.value'}
|
||||
|
||||
// Supports label -> simple path
|
||||
{
|
||||
label: 'some label', // Optional, column will be labeled 'path.to.something' if not defined)
|
||||
value: 'path.to.something', // data.path.to.something
|
||||
default: 'NULL' // default if value is not found (Optional, overrides `defaultValue` for column)
|
||||
},
|
||||
|
||||
// Supports label -> derived value
|
||||
{
|
||||
label: 'some label', // Optional, column will be labeled with the function name or empty if the function is anonymous
|
||||
value: (row, field) => row[field.label].toLowerCase() ||field.default,
|
||||
default: 'NULL' // default if value function returns null or undefined
|
||||
},
|
||||
|
||||
// Supports label -> derived value
|
||||
{
|
||||
value: (row) => row.arrayField.join(',')
|
||||
},
|
||||
|
||||
// Supports label -> derived value
|
||||
{
|
||||
value: (row) => `"${row.arrayField.join(',')}"`
|
||||
},
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Example 1
|
||||
|
||||
```js
|
||||
const { Parser } = require('json2csv');
|
||||
|
||||
const myCars = [
|
||||
{
|
||||
"car": "Audi",
|
||||
"price": 40000,
|
||||
"color": "blue"
|
||||
}, {
|
||||
"car": "BMW",
|
||||
"price": 35000,
|
||||
"color": "black"
|
||||
}, {
|
||||
"car": "Porsche",
|
||||
"price": 60000,
|
||||
"color": "green"
|
||||
}
|
||||
];
|
||||
|
||||
const json2csvParser = new Parser();
|
||||
const csv = json2csvParser.parse(myCars);
|
||||
|
||||
console.log(csv);
|
||||
```
|
||||
|
||||
will output to console
|
||||
|
||||
```
|
||||
"car", "price", "color"
|
||||
"Audi", 40000, "blue"
|
||||
"BMW", 35000, "black"
|
||||
"Porsche", 60000, "green"
|
||||
```
|
||||
|
||||
#### Example 2
|
||||
|
||||
You can choose which fields to include in the CSV.
|
||||
|
||||
```js
|
||||
const { Parser } = require('json2csv');
|
||||
const fields = ['car', 'color'];
|
||||
|
||||
const json2csvParser = new Parser({ fields });
|
||||
const csv = json2csvParser.parse(myCars);
|
||||
|
||||
console.log(csv);
|
||||
```
|
||||
|
||||
will output to console
|
||||
|
||||
```
|
||||
"car", "color"
|
||||
"Audi", "blue"
|
||||
"BMW", "black"
|
||||
"Porsche", "green"
|
||||
```
|
||||
|
||||
#### Example 3
|
||||
|
||||
You can choose custom column names for the exported file.
|
||||
|
||||
```js
|
||||
const { Parser } = require('json2csv');
|
||||
|
||||
const fields = [{
|
||||
label: 'Car Name',
|
||||
value: 'car'
|
||||
},{
|
||||
label: 'Price USD',
|
||||
value: 'price'
|
||||
}];
|
||||
|
||||
const json2csvParser = new Parser({ fields });
|
||||
const csv = json2csvParser.parse(myCars);
|
||||
|
||||
console.log(csv);
|
||||
```
|
||||
|
||||
will output to console
|
||||
|
||||
```
|
||||
"Car Name", "Price USD"
|
||||
"Audi", 40000
|
||||
"BMW", 35000
|
||||
"Porsche", 60000
|
||||
```
|
||||
|
||||
#### Example 4
|
||||
|
||||
You can also specify nested properties using dot notation.
|
||||
|
||||
```js
|
||||
const { Parser } = require('json2csv');
|
||||
|
||||
const myCars = [
|
||||
{
|
||||
"car": { "make": "Audi", "model": "A3" },
|
||||
"price": 40000,
|
||||
"color": "blue"
|
||||
}, {
|
||||
"car": { "make": "BMW", "model": "F20" },
|
||||
"price": 35000,
|
||||
"color": "black"
|
||||
}, {
|
||||
"car": { "make": "Porsche", "model": "9PA AF1" },
|
||||
"price": 60000,
|
||||
"color": "green"
|
||||
}
|
||||
];
|
||||
|
||||
const fields = ['car.make', 'car.model', 'price', 'color'];
|
||||
|
||||
const json2csvParser = new Parser({ fields });
|
||||
const csv = json2csvParser.parse(myCars);
|
||||
|
||||
console.log(csv);
|
||||
```
|
||||
|
||||
will output to console
|
||||
|
||||
```
|
||||
"car.make", "car.model", "price", "color"
|
||||
"Audi", "A3", 40000, "blue"
|
||||
"BMW", "F20", 35000, "black"
|
||||
"Porsche", "9PA AF1", 60000, "green"
|
||||
```
|
||||
|
||||
#### Example 5
|
||||
|
||||
Use a custom delimiter to create tsv files using the delimiter option:
|
||||
|
||||
```js
|
||||
const { Parser } = require('json2csv');
|
||||
|
||||
const json2csvParser = new Parser({ delimiter: '\t' });
|
||||
const tsv = json2csvParser.parse(myCars);
|
||||
|
||||
console.log(tsv);
|
||||
```
|
||||
|
||||
will output to console
|
||||
|
||||
```
|
||||
"car" "price" "color"
|
||||
"Audi" 10000 "blue"
|
||||
"BMW" 15000 "red"
|
||||
"Mercedes" 20000 "yellow"
|
||||
"Porsche" 30000 "green"
|
||||
```
|
||||
|
||||
If no delimiter is specified, the default `,` is used.
|
||||
|
||||
#### Example 6
|
||||
|
||||
You can choose custom quotation marks.
|
||||
|
||||
```js
|
||||
const { Parser } = require('json2csv');
|
||||
|
||||
const json2csvParser = new Parser({ quote: '' });
|
||||
const csv = json2csvParser.parse(myCars);
|
||||
|
||||
console.log(csv);
|
||||
```
|
||||
|
||||
will output to console
|
||||
|
||||
```
|
||||
car, price, color
|
||||
Audi, 40000, blue
|
||||
BMW", 35000, black
|
||||
Porsche", 60000, green
|
||||
```
|
||||
|
||||
#### Example 7
|
||||
|
||||
You can unwind arrays similar to MongoDB's $unwind operation using the `unwind` transform.
|
||||
|
||||
```js
|
||||
const { Parser, transforms: { unwind } } = require('json2csv');
|
||||
|
||||
const myCars = [
|
||||
{
|
||||
"carModel": "Audi",
|
||||
"price": 0,
|
||||
"colors": ["blue","green","yellow"]
|
||||
}, {
|
||||
"carModel": "BMW",
|
||||
"price": 15000,
|
||||
"colors": ["red","blue"]
|
||||
}, {
|
||||
"carModel": "Mercedes",
|
||||
"price": 20000,
|
||||
"colors": "yellow"
|
||||
}, {
|
||||
"carModel": "Porsche",
|
||||
"price": 30000,
|
||||
"colors": ["green","teal","aqua"]
|
||||
}
|
||||
];
|
||||
|
||||
const fields = ['carModel', 'price', 'colors'];
|
||||
const transforms = [unwind({ paths: ['colors'] })];
|
||||
|
||||
const json2csvParser = new Parser({ fields, transforms });
|
||||
const csv = json2csvParser.parse(myCars);
|
||||
|
||||
console.log(csv);
|
||||
```
|
||||
|
||||
will output to console
|
||||
|
||||
```
|
||||
"carModel","price","colors"
|
||||
"Audi",0,"blue"
|
||||
"Audi",0,"green"
|
||||
"Audi",0,"yellow"
|
||||
"BMW",15000,"red"
|
||||
"BMW",15000,"blue"
|
||||
"Mercedes",20000,"yellow"
|
||||
"Porsche",30000,"green"
|
||||
"Porsche",30000,"teal"
|
||||
"Porsche",30000,"aqua"
|
||||
```
|
||||
|
||||
#### Example 8
|
||||
|
||||
You can also unwind arrays multiple times or with nested objects.
|
||||
|
||||
```js
|
||||
const { Parser, transforms: { unwind } } = require('json2csv');
|
||||
|
||||
const myCars = [
|
||||
{
|
||||
"carModel": "BMW",
|
||||
"price": 15000,
|
||||
"items": [
|
||||
{
|
||||
"name": "airbag",
|
||||
"color": "white"
|
||||
}, {
|
||||
"name": "dashboard",
|
||||
"color": "black"
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"carModel": "Porsche",
|
||||
"price": 30000,
|
||||
"items": [
|
||||
{
|
||||
"name": "airbag",
|
||||
"items": [
|
||||
{
|
||||
"position": "left",
|
||||
"color": "white"
|
||||
}, {
|
||||
"position": "right",
|
||||
"color": "gray"
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"name": "dashboard",
|
||||
"items": [
|
||||
{
|
||||
"position": "left",
|
||||
"color": "gray"
|
||||
}, {
|
||||
"position": "right",
|
||||
"color": "black"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const fields = ['carModel', 'price', 'items.name', 'items.color', 'items.items.position', 'items.items.color'];
|
||||
const transforms = [unwind({ paths: ['items', 'items.items'] })];
|
||||
const json2csvParser = new Parser({ fields, transforms });
|
||||
const csv = json2csvParser.parse(myCars);
|
||||
|
||||
console.log(csv);
|
||||
```
|
||||
|
||||
will output to console
|
||||
|
||||
```
|
||||
"carModel","price","items.name","items.color","items.items.position","items.items.color"
|
||||
"BMW",15000,"airbag","white",,
|
||||
"BMW",15000,"dashboard","black",,
|
||||
"Porsche",30000,"airbag",,"left","white"
|
||||
"Porsche",30000,"airbag",,"right","gray"
|
||||
"Porsche",30000,"dashboard",,"left","gray"
|
||||
"Porsche",30000,"dashboard",,"right","black"
|
||||
```
|
||||
|
||||
#### Example 9
|
||||
|
||||
You can also unwind arrays blanking the repeated fields.
|
||||
|
||||
```js
|
||||
const { Parser, transforms: { unwind } } = require('json2csv');
|
||||
|
||||
const myCars = [
|
||||
{
|
||||
"carModel": "BMW",
|
||||
"price": 15000,
|
||||
"items": [
|
||||
{
|
||||
"name": "airbag",
|
||||
"color": "white"
|
||||
}, {
|
||||
"name": "dashboard",
|
||||
"color": "black"
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"carModel": "Porsche",
|
||||
"price": 30000,
|
||||
"items": [
|
||||
{
|
||||
"name": "airbag",
|
||||
"items": [
|
||||
{
|
||||
"position": "left",
|
||||
"color": "white"
|
||||
}, {
|
||||
"position": "right",
|
||||
"color": "gray"
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"name": "dashboard",
|
||||
"items": [
|
||||
{
|
||||
"position": "left",
|
||||
"color": "gray"
|
||||
}, {
|
||||
"position": "right",
|
||||
"color": "black"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const fields = ['carModel', 'price', 'items.name', 'items.color', 'items.items.position', 'items.items.color'];
|
||||
const transforms = [unwind({ paths: ['items', 'items.items'], blankOut: true })];
|
||||
|
||||
const json2csvParser = new Parser({ fields, transforms });
|
||||
const csv = json2csvParser.parse(myCars);
|
||||
|
||||
console.log(csv);
|
||||
```
|
||||
|
||||
will output to console
|
||||
|
||||
```
|
||||
"carModel","price","items.name","items.color","items.items.position","items.items.color"
|
||||
"BMW",15000,"airbag","white",,
|
||||
,,"dashboard","black",,
|
||||
"Porsche",30000,"airbag",,"left","white"
|
||||
,,,,"right","gray"
|
||||
,,"dashboard",,"left","gray"
|
||||
,,,,"right","black"
|
||||
```
|
||||
|
||||
### Migrations
|
||||
|
||||
#### Migrating from 3.X to 4.X
|
||||
|
||||
What in 3.X used to be
|
||||
```js
|
||||
const json2csv = require('json2csv');
|
||||
const csv = json2csv({ data: myData, fields: myFields, unwindPath: paths, ... });
|
||||
```
|
||||
|
||||
should be replaced by
|
||||
```js
|
||||
const { Parser } = require('json2csv');
|
||||
const json2csvParser = new Parser({ fields: myFields, unwind: paths, ... });
|
||||
const csv = json2csvParser.parse(myData);
|
||||
```
|
||||
|
||||
or the convenience method
|
||||
```js
|
||||
const json2csv = require('json2csv');
|
||||
const csv = json2csv.parse(myData, { fields: myFields, unwind: paths, ... });
|
||||
```
|
||||
|
||||
Please note that many of the configuration parameters have been slightly renamed. Please check one by one that all your parameters are correct.
|
||||
You can se the documentation for json2csv 3.11.5 [here](https://github.com/zemirco/json2csv/blob/v3.11.5/README.md).
|
||||
|
||||
#### Migrating from 4.X to 5.X
|
||||
|
||||
In the CLI, the config file option, `-c`, used to be a list of fields and now it's expected to be a full configuration object.
|
||||
|
||||
The `stringify` option hass been removed.
|
||||
|
||||
`doubleQuote` has been renamed to `escapedQuote`.
|
||||
|
||||
The `unwind` and `flatten` -related options has been moved to their own transforms.
|
||||
|
||||
What used to be
|
||||
```js
|
||||
const { Parser } = require('json2csv');
|
||||
const json2csvParser = new Parser({ unwind: paths, unwindBlank: true, flatten: true, flattenSeparator: '__' });
|
||||
const csv = json2csvParser.parse(myData);
|
||||
```
|
||||
|
||||
should be replaced by
|
||||
```js
|
||||
const { Parser, transforms: { unwind, flatten } } = require('json2csv');
|
||||
const json2csvParser = new Parser({ transforms: [unwind({ paths, blankOut: true }), flatten('__')] });
|
||||
const csv = json2csvParser.parse(myData);
|
||||
```
|
||||
|
||||
You can se the documentation for json2csv v4.X.X [here](https://github.com/zemirco/json2csv/blob/v4/README.md).
|
||||
|
||||
## Known Gotchas
|
||||
|
||||
### Excel support
|
||||
|
||||
#### Avoiding excel autoformatting
|
||||
|
||||
Excel tries to automatically detect the format of every field (number, date, string, etc.) regardless of whether the field is quoted or not.
|
||||
|
||||
This might produce few undesired effects with, for example, serial numbers:
|
||||
- Large numbers are displayed using scientific notation
|
||||
- Leading zeros are stripped.
|
||||
|
||||
Enabling the `excelString` option produces an Excel-specific CSV file that forces Excel to interpret string fields as strings. Please note that the CSV will look incorrect if viewing it somewhere else than Excel.
|
||||
|
||||
#### Avoiding CSV injection
|
||||
|
||||
As part of Excel automatically format detection, fields regarded as formulas (starting with `=`, `+`, `-` or `@`) are interpreted regardless of whether the field is quoted or not, creating a security risk (see [CSV Injection](https://www.owasp.org/index.php/CSV_Injection).
|
||||
|
||||
This issue has nothing to do with the CSV format, since CSV knows nothing about formulas, but with how Excel parses CSV files.
|
||||
|
||||
Enabling the `excelString` option produces an Excel-specific CSV file that forces Excel to interpret string fields as strings. Please note that the CSV will look incorrect if viewing it somewhere else than Excel.
|
||||
|
||||
#### Preserving new lines
|
||||
|
||||
Excel only recognizes `\r\n` as valid new line inside a cell.
|
||||
|
||||
#### Unicode Support
|
||||
|
||||
Excel can display Unicode correctly (just setting the `withBOM` option to true). However, Excel can't save unicode so, if you perform any changes to the CSV and save it from Excel, the Unicode characters will not be displayed correctly.
|
||||
|
||||
|
||||
### PowerShell escaping
|
||||
|
||||
PowerShell do some estrange double quote escaping escaping which results on each line of the CSV missing the first and last quote if outputting the result directly to stdout. Instead of that, it's advisable that you write the result directly to a file.
|
||||
|
||||
## Building
|
||||
|
||||
json2csv is packaged using `rollup`. You can generate the packages running:
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
which generates 3 files under the `dist folder`:
|
||||
|
||||
* `json2csv.umd.js` UMD module transpiled to ES5
|
||||
* `json2csv.esm.js` ES5 module (import/export)
|
||||
* `json2csv.cjs.js` CommonJS module
|
||||
|
||||
When you use packaging tools like webpack and such, they know which version to use depending on your configuration.
|
||||
|
||||
## Testing
|
||||
|
||||
Run the folowing command to check the code style.
|
||||
|
||||
```sh
|
||||
$ npm run lint
|
||||
```
|
||||
|
||||
Run the following command to run the tests and return coverage
|
||||
|
||||
```sh
|
||||
$ npm run test-with-coverage
|
||||
```
|
||||
|
||||
## Contributors
|
||||
|
||||
After you clone the repository you just need to install the required packages for development by runnning following command under json2csv dir.
|
||||
|
||||
```sh
|
||||
$ npm install
|
||||
```
|
||||
|
||||
Before making any pull request please ensure sure that your code is formatted, test are passing and test coverage haven't decreased. (See [Testing](#testing))
|
||||
|
||||
## License
|
||||
|
||||
See [LICENSE.md].
|
||||
|
||||
[npm-badge]: https://badge.fury.io/js/json2csv.svg
|
||||
[npm-badge-url]: http://badge.fury.io/js/json2csv
|
||||
[travis-badge]: https://travis-ci.org/zemirco/json2csv.svg
|
||||
[travis-badge-url]: https://travis-ci.org/zemirco/json2csv
|
||||
[coveralls-badge]: https://coveralls.io/repos/zemirco/json2csv/badge.svg?branch=master
|
||||
[coveralls-badge-url]: https://coveralls.io/r/zemirco/json2csv?branch=master
|
||||
[CHANGELOG]: https://github.com/zemirco/json2csv/blob/master/CHANGELOG.md
|
||||
[LICENSE.md]: https://github.com/zemirco/json2csv/blob/master/LICENSE.md
|
||||
183
node_modules/json2csv/bin/json2csv.js
generated
vendored
Executable file
183
node_modules/json2csv/bin/json2csv.js
generated
vendored
Executable file
@@ -0,0 +1,183 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
const { promisify } = require('util');
|
||||
const { createReadStream, createWriteStream, readFile: readFileOrig, writeFile: writeFileOrig } = require('fs');
|
||||
const os = require('os');
|
||||
const { isAbsolute, join } = require('path');
|
||||
const program = require('commander');
|
||||
const pkg = require('../package');
|
||||
const json2csv = require('../lib/json2csv');
|
||||
const parseNdJson = require('./utils/parseNdjson');
|
||||
const TablePrinter = require('./utils/TablePrinter');
|
||||
|
||||
const readFile = promisify(readFileOrig);
|
||||
const writeFile = promisify(writeFileOrig);
|
||||
|
||||
const { unwind, flatten } = json2csv.transforms;
|
||||
const JSON2CSVParser = json2csv.Parser;
|
||||
const Json2csvTransform = json2csv.Transform;
|
||||
|
||||
program
|
||||
.version(pkg.version)
|
||||
.option('-i, --input <input>', 'Path and name of the incoming json file. Defaults to stdin.')
|
||||
.option('-o, --output <output>', 'Path and name of the resulting csv file. Defaults to stdout.')
|
||||
.option('-c, --config <path>', 'Specify a file with a valid JSON configuration.')
|
||||
.option('-n, --ndjson', 'Treat the input as NewLine-Delimited JSON.')
|
||||
.option('-s, --no-streaming', 'Process the whole JSON array in memory instead of doing it line by line.')
|
||||
.option('-f, --fields <fields>', 'List of fields to process. Defaults to field auto-detection.')
|
||||
.option('-v, --default-value <defaultValue>', 'Default value to use for missing fields.')
|
||||
.option('-q, --quote <quote>', 'Character(s) to use as quote mark. Defaults to \'"\'.')
|
||||
.option('-Q, --escaped-quote <escapedQuote>', 'Character(s) to use as a escaped quote. Defaults to a double `quote`, \'""\'.')
|
||||
.option('-d, --delimiter <delimiter>', 'Character(s) to use as delimiter. Defaults to \',\'.', ',')
|
||||
.option('-e, --eol <eol>', 'Character(s) to use as End-of-Line for separating rows. Defaults to \'\\n\'.', os.EOL)
|
||||
.option('-E, --excel-strings','Wraps string data to force Excel to interpret it as string even if it contains a number.')
|
||||
.option('-H, --no-header', 'Disable the column name header.')
|
||||
.option('-a, --include-empty-rows', 'Includes empty rows in the resulting CSV output.')
|
||||
.option('-b, --with-bom', 'Includes BOM character at the beginning of the CSV.')
|
||||
.option('-p, --pretty', 'Print output as a pretty table. Use only when printing to console.')
|
||||
// Built-in transforms
|
||||
.option('--unwind [paths]', 'Creates multiple rows from a single JSON document similar to MongoDB unwind.')
|
||||
.option('--unwind-blank', 'When unwinding, blank out instead of repeating data. Defaults to false.', false)
|
||||
.option('--flatten-objects', 'Flatten nested objects. Defaults to false.', false)
|
||||
.option('--flatten-arrays', 'Flatten nested arrays. Defaults to false.', false)
|
||||
.option('--flatten-separator <separator>', 'Flattened keys separator. Defaults to \'.\'.', '.')
|
||||
.parse(process.argv);
|
||||
|
||||
function makePathAbsolute(filePath) {
|
||||
return (filePath && !isAbsolute(filePath))
|
||||
? join(process.cwd(), filePath)
|
||||
: filePath;
|
||||
}
|
||||
|
||||
program.input = makePathAbsolute(program.input);
|
||||
program.output = makePathAbsolute(program.output);
|
||||
program.config = makePathAbsolute(program.config);
|
||||
|
||||
// don't fail if piped to e.g. head
|
||||
/* istanbul ignore next */
|
||||
process.stdout.on('error', (error) => {
|
||||
if (error.code === 'EPIPE') process.exit(1);
|
||||
});
|
||||
|
||||
function getInputStream(inputPath) {
|
||||
if (inputPath) return createReadStream(inputPath, { encoding: 'utf8' });
|
||||
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
return process.stdin;
|
||||
}
|
||||
|
||||
function getOutputStream(outputPath, config) {
|
||||
if (outputPath) return createWriteStream(outputPath, { encoding: 'utf8' });
|
||||
if (config.pretty) return new TablePrinter(config).writeStream();
|
||||
return process.stdout;
|
||||
}
|
||||
|
||||
async function getInput(inputPath, ndjson) {
|
||||
if (!inputPath) return getInputFromStdin();
|
||||
if (ndjson) return parseNdJson(await readFile(inputPath, 'utf8'));
|
||||
return require(inputPath);
|
||||
}
|
||||
|
||||
async function getInputFromStdin() {
|
||||
return new Promise((resolve, reject) => {
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
|
||||
let inputData = '';
|
||||
process.stdin.on('data', chunk => (inputData += chunk));
|
||||
/* istanbul ignore next */
|
||||
process.stdin.on('error', err => reject(new Error('Could not read from stdin', err)));
|
||||
process.stdin.on('end', () => {
|
||||
try {
|
||||
resolve(program.ndjson ? parseNdJson(inputData) : JSON.parse(inputData));
|
||||
} catch (err) {
|
||||
reject(new Error('Invalid data received from stdin', err));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function processOutput(outputPath, csv, config) {
|
||||
if (!outputPath) {
|
||||
// eslint-disable-next-line no-console
|
||||
config.pretty ? (new TablePrinter(config)).printCSV(csv) : console.log(csv);
|
||||
return;
|
||||
}
|
||||
|
||||
await writeFile(outputPath, csv);
|
||||
}
|
||||
|
||||
async function processInMemory(config, opts) {
|
||||
const input = await getInput(program.input, config.ndjson);
|
||||
const output = new JSON2CSVParser(opts).parse(input);
|
||||
await processOutput(program.output, output, config);
|
||||
}
|
||||
|
||||
async function processStream(config, opts) {
|
||||
const input = getInputStream(program.input);
|
||||
const transform = new Json2csvTransform(opts);
|
||||
const output = getOutputStream(program.output, config);
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
input.pipe(transform).pipe(output);
|
||||
input.on('error', reject);
|
||||
transform.on('error', reject);
|
||||
output.on('error', reject)
|
||||
.on('finish', resolve);
|
||||
});
|
||||
}
|
||||
|
||||
(async (program) => {
|
||||
try {
|
||||
const config = Object.assign({}, program.config ? require(program.config) : {}, program);
|
||||
|
||||
const transforms = [];
|
||||
if (config.unwind) {
|
||||
transforms.push(unwind({
|
||||
paths: config.unwind === true ? undefined : config.unwind.split(','),
|
||||
blankOut: config.unwindBlank
|
||||
}));
|
||||
}
|
||||
|
||||
if (config.flattenObjects || config.flattenArrays) {
|
||||
transforms.push(flatten({
|
||||
objects: config.flattenObjects,
|
||||
arrays: config.flattenArrays,
|
||||
separator: config.flattenSeparator
|
||||
}));
|
||||
}
|
||||
|
||||
const opts = {
|
||||
transforms,
|
||||
fields: config.fields
|
||||
? (Array.isArray(config.fields) ? config.fields : config.fields.split(','))
|
||||
: config.fields,
|
||||
defaultValue: config.defaultValue,
|
||||
quote: config.quote,
|
||||
escapedQuote: config.escapedQuote,
|
||||
delimiter: config.delimiter,
|
||||
eol: config.eol,
|
||||
excelStrings: config.excelStrings,
|
||||
header: config.header,
|
||||
includeEmptyRows: config.includeEmptyRows,
|
||||
withBOM: config.withBom
|
||||
};
|
||||
|
||||
await (config.streaming ? processStream : processInMemory)(config, opts);
|
||||
} catch(err) {
|
||||
let processedError = err;
|
||||
if (program.input && err.message.includes(program.input)) {
|
||||
processedError = new Error(`Invalid input file. (${err.message})`);
|
||||
} else if (program.output && err.message.includes(program.output)) {
|
||||
processedError = new Error(`Invalid output file. (${err.message})`);
|
||||
} else if (program.config && err.message.includes(program.config)) {
|
||||
processedError = new Error(`Invalid config file. (${err.message})`);
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(processedError);
|
||||
process.exit(1);
|
||||
}
|
||||
})(program);
|
||||
117
node_modules/json2csv/bin/utils/TablePrinter.js
generated
vendored
Normal file
117
node_modules/json2csv/bin/utils/TablePrinter.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
'use strict';
|
||||
|
||||
const { Writable } = require('stream');
|
||||
|
||||
const MIN_CELL_WIDTH = 15;
|
||||
|
||||
class TablePrinter {
|
||||
constructor(opts) {
|
||||
this.opts = opts;
|
||||
this._hasWritten = false;
|
||||
}
|
||||
|
||||
push(csv) {
|
||||
const lines = csv.split(this.opts.eol);
|
||||
|
||||
if (!lines.length) return;
|
||||
|
||||
if (!this._hasWritten) this.setColumnWidths(lines[0]);
|
||||
|
||||
const top = this._hasWritten ? this.middleLine : this.topLine;
|
||||
this.print(top, lines);
|
||||
this._hasWritten = true;
|
||||
}
|
||||
|
||||
end(csv) {
|
||||
let lines = csv.split(this.opts.eol);
|
||||
if (!this._hasWritten) this.setColumnWidths(lines[0]);
|
||||
const top = this._hasWritten ? this.middleLine : this.topLine;
|
||||
this.print(top, lines, this.bottomLine);
|
||||
}
|
||||
|
||||
printCSV(csv) {
|
||||
this.end(csv);
|
||||
}
|
||||
|
||||
setColumnWidths(line) {
|
||||
this.colWidths = line
|
||||
.split(this.opts.delimiter)
|
||||
.map(elem => Math.max(elem.length * 2, MIN_CELL_WIDTH));
|
||||
|
||||
this.topLine = `┌${this.colWidths.map(i => '─'.repeat(i)).join('┬')}┐`;
|
||||
this.middleLine = `├${this.colWidths.map(i => '─'.repeat(i)).join('┼')}┤`;
|
||||
this.bottomLine = `└${this.colWidths.map(i => '─'.repeat(i)).join('┴')}┘`;
|
||||
}
|
||||
|
||||
print(top, lines, bottom) {
|
||||
const table = `${top}\n`
|
||||
+ lines
|
||||
.map(row => this.formatRow(row))
|
||||
.join(`\n${this.middleLine}\n`)
|
||||
+ (bottom ? `\n${bottom}` : '');
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(table);
|
||||
}
|
||||
|
||||
formatRow(row) {
|
||||
const wrappedRow = row
|
||||
.split(this.opts.delimiter)
|
||||
.map((cell, i) => cell.match(new RegExp(`(.{1,${this.colWidths[i] - 2}})`, 'g')) || []);
|
||||
|
||||
const height = wrappedRow.reduce((acc, cell) => Math.max(acc, cell.length), 0);
|
||||
|
||||
const processedCells = wrappedRow
|
||||
.map((cell, i) => this.formatCell(cell, height, this.colWidths[i]));
|
||||
|
||||
return Array(height).fill('')
|
||||
.map((_, i) => `│${processedCells.map(cell => cell[i]).join('│')}│`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
formatCell(content, heigth, width) {
|
||||
const paddedContent = this.padCellHorizontally(content, width);
|
||||
return this.padCellVertically(paddedContent, heigth, width);
|
||||
}
|
||||
|
||||
padCellVertically(content, heigth, width) {
|
||||
const vertPad = heigth - content.length;
|
||||
const vertPadTop = Math.ceil(vertPad / 2);
|
||||
const vertPadBottom = vertPad - vertPadTop;
|
||||
const emptyLine = ' '.repeat(width);
|
||||
|
||||
return [
|
||||
...Array(vertPadTop).fill(emptyLine),
|
||||
...content,
|
||||
...Array(vertPadBottom).fill(emptyLine)
|
||||
];
|
||||
}
|
||||
|
||||
padCellHorizontally(content, width) {
|
||||
return content.map((line) => {
|
||||
const horPad = width - line.length - 2;
|
||||
return ` ${line}${' '.repeat(horPad)} `;
|
||||
});
|
||||
}
|
||||
|
||||
writeStream() {
|
||||
let csv = '';
|
||||
const table = this;
|
||||
return new Writable({
|
||||
write(chunk, encoding, callback) {
|
||||
csv += chunk.toString();
|
||||
const index = csv.lastIndexOf(table.opts.eol);
|
||||
let lines = csv.substring(0, index);
|
||||
csv = csv.substring(index + 1);
|
||||
|
||||
if (lines) table.push(lines);
|
||||
callback();
|
||||
},
|
||||
final() {
|
||||
table.end(csv);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TablePrinter;
|
||||
11
node_modules/json2csv/bin/utils/parseNdjson.js
generated
vendored
Normal file
11
node_modules/json2csv/bin/utils/parseNdjson.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
function parseNdJson(input) {
|
||||
return input
|
||||
.split('\n')
|
||||
.map(line => line.trim())
|
||||
.filter(line => line !== '')
|
||||
.map(line=> JSON.parse(line));
|
||||
}
|
||||
|
||||
module.exports = parseNdJson;
|
||||
2361
node_modules/json2csv/dist/json2csv.esm.js
generated
vendored
Normal file
2361
node_modules/json2csv/dist/json2csv.esm.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
7448
node_modules/json2csv/dist/json2csv.umd.js
generated
vendored
Normal file
7448
node_modules/json2csv/dist/json2csv.umd.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
60
node_modules/json2csv/lib/JSON2CSVAsyncParser.js
generated
vendored
Normal file
60
node_modules/json2csv/lib/JSON2CSVAsyncParser.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
const { Transform } = require('stream');
|
||||
const JSON2CSVTransform = require('./JSON2CSVTransform');
|
||||
const { fastJoin } = require('./utils');
|
||||
|
||||
class JSON2CSVAsyncParser {
|
||||
constructor(opts, transformOpts) {
|
||||
this.input = new Transform(transformOpts);
|
||||
this.input._read = () => {};
|
||||
|
||||
this.transform = new JSON2CSVTransform(opts, transformOpts);
|
||||
this.processor = this.input.pipe(this.transform);
|
||||
}
|
||||
|
||||
fromInput(input) {
|
||||
if (this._input) {
|
||||
throw new Error('Async parser already has an input.');
|
||||
}
|
||||
this._input = input;
|
||||
this.input = this._input.pipe(this.processor);
|
||||
return this;
|
||||
}
|
||||
|
||||
throughTransform(transform) {
|
||||
if (this._output) {
|
||||
throw new Error('Can\'t add transforms once an output has been added.');
|
||||
}
|
||||
this.processor = this.processor.pipe(transform);
|
||||
return this;
|
||||
}
|
||||
|
||||
toOutput(output) {
|
||||
if (this._output) {
|
||||
throw new Error('Async parser already has an output.');
|
||||
}
|
||||
this._output = output;
|
||||
this.processor = this.processor.pipe(output);
|
||||
return this;
|
||||
}
|
||||
|
||||
promise(returnCSV = true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!returnCSV) {
|
||||
this.processor
|
||||
.on('finish', () => resolve())
|
||||
.on('error', err => reject(err));
|
||||
return;
|
||||
}
|
||||
|
||||
let csvBuffer = [];
|
||||
this.processor
|
||||
.on('data', chunk => csvBuffer.push(chunk.toString()))
|
||||
.on('finish', () => resolve(fastJoin(csvBuffer, '')))
|
||||
.on('error', err => reject(err));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JSON2CSVAsyncParser
|
||||
188
node_modules/json2csv/lib/JSON2CSVBase.js
generated
vendored
Normal file
188
node_modules/json2csv/lib/JSON2CSVBase.js
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
'use strict';
|
||||
|
||||
const os = require('os');
|
||||
const lodashGet = require('lodash.get');
|
||||
const { getProp, fastJoin, flattenReducer } = require('./utils');
|
||||
|
||||
class JSON2CSVBase {
|
||||
constructor(opts) {
|
||||
this.opts = this.preprocessOpts(opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check passing opts and set defaults.
|
||||
*
|
||||
* @param {Json2CsvOptions} opts Options object containing fields,
|
||||
* delimiter, default value, quote mark, header, etc.
|
||||
*/
|
||||
preprocessOpts(opts) {
|
||||
const processedOpts = Object.assign({}, opts);
|
||||
processedOpts.transforms = !Array.isArray(processedOpts.transforms)
|
||||
? (processedOpts.transforms ? [processedOpts.transforms] : [])
|
||||
: processedOpts.transforms
|
||||
processedOpts.delimiter = processedOpts.delimiter || ',';
|
||||
processedOpts.eol = processedOpts.eol || os.EOL;
|
||||
processedOpts.quote = typeof processedOpts.quote === 'string'
|
||||
? processedOpts.quote
|
||||
: '"';
|
||||
processedOpts.escapedQuote = typeof processedOpts.escapedQuote === 'string'
|
||||
? processedOpts.escapedQuote
|
||||
: `${processedOpts.quote}${processedOpts.quote}`;
|
||||
processedOpts.header = processedOpts.header !== false;
|
||||
processedOpts.includeEmptyRows = processedOpts.includeEmptyRows || false;
|
||||
processedOpts.withBOM = processedOpts.withBOM || false;
|
||||
|
||||
return processedOpts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and normalize the fields configuration.
|
||||
*
|
||||
* @param {(string|object)[]} fields Fields configuration provided by the user
|
||||
* or inferred from the data
|
||||
* @returns {object[]} preprocessed FieldsInfo array
|
||||
*/
|
||||
preprocessFieldsInfo(fields) {
|
||||
return fields.map((fieldInfo) => {
|
||||
if (typeof fieldInfo === 'string') {
|
||||
return {
|
||||
label: fieldInfo,
|
||||
value: (fieldInfo.includes('.') || fieldInfo.includes('['))
|
||||
? row => lodashGet(row, fieldInfo, this.opts.defaultValue)
|
||||
: row => getProp(row, fieldInfo, this.opts.defaultValue),
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof fieldInfo === 'object') {
|
||||
const defaultValue = 'default' in fieldInfo
|
||||
? fieldInfo.default
|
||||
: this.opts.defaultValue;
|
||||
|
||||
if (typeof fieldInfo.value === 'string') {
|
||||
return {
|
||||
label: fieldInfo.label || fieldInfo.value,
|
||||
value: (fieldInfo.value.includes('.') || fieldInfo.value.includes('['))
|
||||
? row => lodashGet(row, fieldInfo.value, defaultValue)
|
||||
: row => getProp(row, fieldInfo.value, defaultValue),
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof fieldInfo.value === 'function') {
|
||||
const label = fieldInfo.label || fieldInfo.value.name || '';
|
||||
const field = { label, default: defaultValue };
|
||||
return {
|
||||
label,
|
||||
value(row) {
|
||||
const value = fieldInfo.value(row, field);
|
||||
return (value === null || value === undefined)
|
||||
? defaultValue
|
||||
: value;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Invalid field info option. ' + JSON.stringify(fieldInfo));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the title row with all the provided fields as column headings
|
||||
*
|
||||
* @returns {String} titles as a string
|
||||
*/
|
||||
getHeader() {
|
||||
return fastJoin(
|
||||
this.opts.fields.map(fieldInfo => this.processValue(fieldInfo.label)),
|
||||
this.opts.delimiter
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess each object according to the given transforms (unwind, flatten, etc.).
|
||||
* @param {Object} row JSON object to be converted in a CSV row
|
||||
*/
|
||||
preprocessRow(row) {
|
||||
return this.opts.transforms.reduce((rows, transform) =>
|
||||
rows.map(row => transform(row)).reduce(flattenReducer, []),
|
||||
[row]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the content of a specific CSV row
|
||||
*
|
||||
* @param {Object} row JSON object to be converted in a CSV row
|
||||
* @returns {String} CSV string (row)
|
||||
*/
|
||||
processRow(row) {
|
||||
if (!row) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const processedRow = this.opts.fields.map(fieldInfo => this.processCell(row, fieldInfo));
|
||||
|
||||
if (!this.opts.includeEmptyRows && processedRow.every(field => field === undefined)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return fastJoin(
|
||||
processedRow,
|
||||
this.opts.delimiter
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the content of a specfic CSV row cell
|
||||
*
|
||||
* @param {Object} row JSON object representing the CSV row that the cell belongs to
|
||||
* @param {FieldInfo} fieldInfo Details of the field to process to be a CSV cell
|
||||
* @returns {String} CSV string (cell)
|
||||
*/
|
||||
processCell(row, fieldInfo) {
|
||||
return this.processValue(fieldInfo.value(row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the content of a specfic CSV row cell
|
||||
*
|
||||
* @param {Any} value Value to be included in a CSV cell
|
||||
* @returns {String} Value stringified and processed
|
||||
*/
|
||||
processValue(value) {
|
||||
if (value === null || value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const valueType = typeof value;
|
||||
if (valueType !== 'boolean' && valueType !== 'number' && valueType !== 'string') {
|
||||
value = JSON.stringify(value);
|
||||
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (value[0] === '"') {
|
||||
value = value.replace(/^"(.+)"$/,'$1');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
if (this.opts.excelStrings) {
|
||||
if(value.includes(this.opts.quote)) {
|
||||
value = value.replace(new RegExp(this.opts.quote, 'g'), `${this.opts.escapedQuote}${this.opts.escapedQuote}`);
|
||||
}
|
||||
value = `"=""${value}"""`;
|
||||
} else {
|
||||
if(value.includes(this.opts.quote)) {
|
||||
value = value.replace(new RegExp(this.opts.quote, 'g'), this.opts.escapedQuote);
|
||||
}
|
||||
value = `${this.opts.quote}${value}${this.opts.quote}`;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JSON2CSVBase;
|
||||
81
node_modules/json2csv/lib/JSON2CSVParser.js
generated
vendored
Normal file
81
node_modules/json2csv/lib/JSON2CSVParser.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
'use strict';
|
||||
|
||||
const JSON2CSVBase = require('./JSON2CSVBase');
|
||||
const { fastJoin, flattenReducer } = require('./utils');
|
||||
|
||||
class JSON2CSVParser extends JSON2CSVBase {
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
if (this.opts.fields) {
|
||||
this.opts.fields = this.preprocessFieldsInfo(this.opts.fields);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Main function that converts json to csv.
|
||||
*
|
||||
* @param {Array|Object} data Array of JSON objects to be converted to CSV
|
||||
* @returns {String} The CSV formated data as a string
|
||||
*/
|
||||
parse(data) {
|
||||
const processedData = this.preprocessData(data);
|
||||
|
||||
if (!this.opts.fields) {
|
||||
this.opts.fields = processedData
|
||||
.reduce((fields, item) => {
|
||||
Object.keys(item).forEach((field) => {
|
||||
if (!fields.includes(field)) {
|
||||
fields.push(field)
|
||||
}
|
||||
});
|
||||
|
||||
return fields
|
||||
}, []);
|
||||
|
||||
this.opts.fields = this.preprocessFieldsInfo(this.opts.fields);
|
||||
}
|
||||
|
||||
const header = this.opts.header ? this.getHeader() : '';
|
||||
const rows = this.processData(processedData);
|
||||
const csv = (this.opts.withBOM ? '\ufeff' : '')
|
||||
+ header
|
||||
+ ((header && rows) ? this.opts.eol : '')
|
||||
+ rows;
|
||||
|
||||
return csv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess the data according to the give opts (unwind, flatten, etc.)
|
||||
and calculate the fields and field names if they are not provided.
|
||||
*
|
||||
* @param {Array|Object} data Array or object to be converted to CSV
|
||||
*/
|
||||
preprocessData(data) {
|
||||
const processedData = Array.isArray(data) ? data : [data];
|
||||
|
||||
if (!this.opts.fields && (processedData.length === 0 || typeof processedData[0] !== 'object')) {
|
||||
throw new Error('Data should not be empty or the "fields" option should be included');
|
||||
}
|
||||
|
||||
if (this.opts.transforms.length === 0) return processedData;
|
||||
|
||||
return processedData
|
||||
.map(row => this.preprocessRow(row))
|
||||
.reduce(flattenReducer, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the content row by row below the header
|
||||
*
|
||||
* @param {Array} data Array of JSON objects to be converted to CSV
|
||||
* @returns {String} CSV string (body)
|
||||
*/
|
||||
processData(data) {
|
||||
return fastJoin(
|
||||
data.map(row => this.processRow(row)).filter(row => row), // Filter empty rows
|
||||
this.opts.eol
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JSON2CSVParser;
|
||||
203
node_modules/json2csv/lib/JSON2CSVTransform.js
generated
vendored
Normal file
203
node_modules/json2csv/lib/JSON2CSVTransform.js
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
'use strict';
|
||||
|
||||
const { Transform } = require('stream');
|
||||
const Parser = require('jsonparse');
|
||||
const JSON2CSVBase = require('./JSON2CSVBase');
|
||||
|
||||
class JSON2CSVTransform extends Transform {
|
||||
constructor(opts, transformOpts) {
|
||||
super(transformOpts);
|
||||
|
||||
// Inherit methods from JSON2CSVBase since extends doesn't
|
||||
// allow multiple inheritance and manually preprocess opts
|
||||
Object.getOwnPropertyNames(JSON2CSVBase.prototype)
|
||||
.forEach(key => (this[key] = JSON2CSVBase.prototype[key]));
|
||||
this.opts = this.preprocessOpts(opts);
|
||||
|
||||
this._data = '';
|
||||
this._hasWritten = false;
|
||||
|
||||
if (this._readableState.objectMode) {
|
||||
this.initObjectModeParse();
|
||||
} else if (this.opts.ndjson) {
|
||||
this.initNDJSONParse();
|
||||
} else {
|
||||
this.initJSONParser();
|
||||
}
|
||||
|
||||
if (this.opts.withBOM) {
|
||||
this.push('\ufeff');
|
||||
}
|
||||
|
||||
if (this.opts.fields) {
|
||||
this.opts.fields = this.preprocessFieldsInfo(this.opts.fields);
|
||||
this.pushHeader();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the transform with a parser to process data in object mode.
|
||||
* It receives JSON objects one by one and send them to `pushLine for processing.
|
||||
*/
|
||||
initObjectModeParse() {
|
||||
const transform = this;
|
||||
|
||||
this.parser = {
|
||||
write(line) {
|
||||
transform.pushLine(line);
|
||||
},
|
||||
getPendingData() {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the transform with a parser to process NDJSON data.
|
||||
* It maintains a buffer of received data, parses each line
|
||||
* as JSON and send it to `pushLine for processing.
|
||||
*/
|
||||
initNDJSONParse() {
|
||||
const transform = this;
|
||||
|
||||
this.parser = {
|
||||
_data: '',
|
||||
write(chunk) {
|
||||
this._data += chunk.toString();
|
||||
const lines = this._data
|
||||
.split('\n')
|
||||
.map(line => line.trim())
|
||||
.filter(line => line !== '');
|
||||
|
||||
let pendingData = false;
|
||||
lines
|
||||
.forEach((line, i) => {
|
||||
try {
|
||||
transform.pushLine(JSON.parse(line));
|
||||
} catch(e) {
|
||||
if (i === lines.length - 1) {
|
||||
pendingData = true;
|
||||
} else {
|
||||
e.message = `Invalid JSON (${line})`
|
||||
transform.emit('error', e);
|
||||
}
|
||||
}
|
||||
});
|
||||
this._data = pendingData
|
||||
? this._data.slice(this._data.lastIndexOf('\n'))
|
||||
: '';
|
||||
},
|
||||
getPendingData() {
|
||||
return this._data;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the transform with a parser to process JSON data.
|
||||
* It maintains a buffer of received data, parses each as JSON
|
||||
* item if the data is an array or the data itself otherwise
|
||||
* and send it to `pushLine` for processing.
|
||||
*/
|
||||
initJSONParser() {
|
||||
const transform = this;
|
||||
this.parser = new Parser();
|
||||
this.parser.onValue = function (value) {
|
||||
if (this.stack.length !== this.depthToEmit) return;
|
||||
transform.pushLine(value);
|
||||
}
|
||||
|
||||
this.parser._onToken = this.parser.onToken;
|
||||
|
||||
this.parser.onToken = function (token, value) {
|
||||
transform.parser._onToken(token, value);
|
||||
|
||||
if (this.stack.length === 0
|
||||
&& !transform.opts.fields
|
||||
&& this.mode !== Parser.C.ARRAY
|
||||
&& this.mode !== Parser.C.OBJECT) {
|
||||
this.onError(new Error('Data should not be empty or the "fields" option should be included'));
|
||||
}
|
||||
|
||||
if (this.stack.length === 1) {
|
||||
if(this.depthToEmit === undefined) {
|
||||
// If Array emit its content, else emit itself
|
||||
this.depthToEmit = (this.mode === Parser.C.ARRAY) ? 1 : 0;
|
||||
}
|
||||
|
||||
if (this.depthToEmit !== 0 && this.stack.length === 1) {
|
||||
// No need to store the whole root array in memory
|
||||
this.value = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.parser.getPendingData = function () {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
this.parser.onError = function (err) {
|
||||
if(err.message.includes('Unexpected')) {
|
||||
err.message = `Invalid JSON (${err.message})`;
|
||||
}
|
||||
transform.emit('error', err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function that send data to the parse to be processed.
|
||||
*
|
||||
* @param {Buffer} chunk Incoming data
|
||||
* @param {String} encoding Encoding of the incoming data. Defaults to 'utf8'
|
||||
* @param {Function} done Called when the proceesing of the supplied chunk is done
|
||||
*/
|
||||
_transform(chunk, encoding, done) {
|
||||
this.parser.write(chunk);
|
||||
done();
|
||||
}
|
||||
|
||||
_flush(done) {
|
||||
if (this.parser.getPendingData()) {
|
||||
done(new Error('Invalid data received from stdin', this.parser.getPendingData()));
|
||||
}
|
||||
|
||||
done();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the csv header and pushes it downstream.
|
||||
*/
|
||||
pushHeader() {
|
||||
if (this.opts.header) {
|
||||
const header = this.getHeader();
|
||||
this.emit('header', header);
|
||||
this.push(header);
|
||||
this._hasWritten = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an incoming json data to csv and pushes it downstream.
|
||||
*
|
||||
* @param {Object} data JSON object to be converted in a CSV row
|
||||
*/
|
||||
pushLine(data) {
|
||||
const processedData = this.preprocessRow(data);
|
||||
|
||||
if (!this._hasWritten) {
|
||||
this.opts.fields = this.opts.fields || this.preprocessFieldsInfo(Object.keys(processedData[0]));
|
||||
this.pushHeader();
|
||||
}
|
||||
|
||||
processedData.forEach(row => {
|
||||
const line = this.processRow(row, this.opts);
|
||||
if (line === undefined) return;
|
||||
this.emit('line', line);
|
||||
this.push(this._hasWritten ? this.opts.eol + line : line);
|
||||
this._hasWritten = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JSON2CSVTransform;
|
||||
44
node_modules/json2csv/lib/json2csv.js
generated
vendored
Normal file
44
node_modules/json2csv/lib/json2csv.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
const { Readable } = require('stream');
|
||||
const JSON2CSVParser = require('./JSON2CSVParser');
|
||||
const JSON2CSVAsyncParser = require('./JSON2CSVAsyncParser');
|
||||
const JSON2CSVTransform = require('./JSON2CSVTransform');
|
||||
const flatten = require('./transforms/flatten');
|
||||
const unwind = require('./transforms/unwind');
|
||||
|
||||
module.exports.Parser = JSON2CSVParser;
|
||||
module.exports.AsyncParser = JSON2CSVAsyncParser;
|
||||
module.exports.Transform = JSON2CSVTransform;
|
||||
|
||||
// Convenience method to keep the API similar to version 3.X
|
||||
module.exports.parse = (data, opts) => new JSON2CSVParser(opts).parse(data);
|
||||
module.exports.parseAsync = (data, opts, transformOpts) => {
|
||||
try {
|
||||
if (!(data instanceof Readable)) {
|
||||
transformOpts = Object.assign({}, transformOpts, { objectMode: true });
|
||||
}
|
||||
|
||||
const asyncParser = new JSON2CSVAsyncParser(opts, transformOpts);
|
||||
const promise = asyncParser.promise();
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach(item => asyncParser.input.push(item));
|
||||
asyncParser.input.push(null);
|
||||
} else if (data instanceof Readable) {
|
||||
asyncParser.fromInput(data);
|
||||
} else {
|
||||
asyncParser.input.push(data);
|
||||
asyncParser.input.push(null);
|
||||
}
|
||||
|
||||
return promise;
|
||||
} catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.transforms = {
|
||||
flatten,
|
||||
unwind,
|
||||
};
|
||||
37
node_modules/json2csv/lib/transforms/flatten.js
generated
vendored
Normal file
37
node_modules/json2csv/lib/transforms/flatten.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Performs the flattening of a data row recursively
|
||||
*
|
||||
* @param {String} separator Separator to be used as the flattened field name
|
||||
* @returns {Object => Object} Flattened object
|
||||
*/
|
||||
function flatten({ objects = true, arrays = false, separator = '.' } = {}) {
|
||||
function step (obj, flatDataRow, currentPath) {
|
||||
Object.keys(obj).forEach((key) => {
|
||||
const newPath = currentPath ? `${currentPath}${separator}${key}` : key;
|
||||
const value = obj[key];
|
||||
|
||||
if (objects
|
||||
&& typeof value === 'object'
|
||||
&& value !== null
|
||||
&& !Array.isArray(value)
|
||||
&& Object.prototype.toString.call(value.toJSON) !== '[object Function]'
|
||||
&& Object.keys(value).length) {
|
||||
step(value, flatDataRow, newPath);
|
||||
return;
|
||||
}
|
||||
|
||||
if (arrays && Array.isArray(value)) {
|
||||
step(value, flatDataRow, newPath);
|
||||
return;
|
||||
}
|
||||
|
||||
flatDataRow[newPath] = value;
|
||||
});
|
||||
|
||||
return flatDataRow;
|
||||
}
|
||||
|
||||
return dataRow => step(dataRow, {});
|
||||
}
|
||||
|
||||
module.exports = flatten;
|
||||
63
node_modules/json2csv/lib/transforms/unwind.js
generated
vendored
Normal file
63
node_modules/json2csv/lib/transforms/unwind.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
const lodashGet = require('lodash.get');
|
||||
const { setProp, unsetProp, flattenReducer } = require('../utils');
|
||||
|
||||
function getUnwindablePaths(obj, currentPath) {
|
||||
return Object.keys(obj).reduce((unwindablePaths, key) => {
|
||||
const newPath = currentPath ? `${currentPath}.${key}` : key;
|
||||
const value = obj[key];
|
||||
|
||||
if (typeof value === 'object'
|
||||
&& value !== null
|
||||
&& !Array.isArray(value)
|
||||
&& Object.prototype.toString.call(value.toJSON) !== '[object Function]'
|
||||
&& Object.keys(value).length) {
|
||||
unwindablePaths = unwindablePaths.concat(getUnwindablePaths(value, newPath));
|
||||
} else if (Array.isArray(value)) {
|
||||
unwindablePaths.push(newPath);
|
||||
unwindablePaths = unwindablePaths.concat(value
|
||||
.map(arrObj => getUnwindablePaths(arrObj, newPath))
|
||||
.reduce(flattenReducer, [])
|
||||
.filter((item, index, arr) => arr.indexOf(item) !== index));
|
||||
}
|
||||
|
||||
return unwindablePaths;
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the unwind recursively in specified sequence
|
||||
*
|
||||
* @param {String[]} unwindPaths The paths as strings to be used to deconstruct the array
|
||||
* @returns {Object => Array} Array of objects containing all rows after unwind of chosen paths
|
||||
*/
|
||||
function unwind({ paths = undefined, blankOut = false } = {}) {
|
||||
function unwindReducer(rows, unwindPath) {
|
||||
return rows
|
||||
.map(row => {
|
||||
const unwindArray = lodashGet(row, unwindPath);
|
||||
|
||||
if (!Array.isArray(unwindArray)) {
|
||||
return row;
|
||||
}
|
||||
|
||||
if (!unwindArray.length) {
|
||||
return unsetProp(row, unwindPath);
|
||||
}
|
||||
|
||||
return unwindArray.map((unwindRow, index) => {
|
||||
const clonedRow = (blankOut && index > 0)
|
||||
? {}
|
||||
: row;
|
||||
|
||||
return setProp(clonedRow, unwindPath, unwindRow);
|
||||
});
|
||||
})
|
||||
.reduce(flattenReducer, []);
|
||||
}
|
||||
|
||||
paths = Array.isArray(paths) ? paths : (paths ? [paths] : undefined);
|
||||
return dataRow => (paths || getUnwindablePaths(dataRow)).reduce(unwindReducer, [dataRow]);
|
||||
}
|
||||
|
||||
module.exports = unwind;
|
||||
72
node_modules/json2csv/lib/utils.js
generated
vendored
Normal file
72
node_modules/json2csv/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
function getProp(obj, path, defaultValue) {
|
||||
return obj[path] === undefined ? defaultValue : obj[path];
|
||||
}
|
||||
|
||||
function setProp(obj, path, value) {
|
||||
const pathArray = Array.isArray(path) ? path : path.split('.');
|
||||
const [key, ...restPath] = pathArray;
|
||||
return {
|
||||
...obj,
|
||||
[key]: pathArray.length > 1 ? setProp(obj[key] || {}, restPath, value) : value
|
||||
};
|
||||
}
|
||||
|
||||
function unsetProp(obj, path) {
|
||||
const pathArray = Array.isArray(path) ? path : path.split('.');
|
||||
const [key, ...restPath] = pathArray;
|
||||
|
||||
if (typeof obj[key] !== 'object') {
|
||||
// This will never be hit in the current code because unwind does the check before calling unsetProp
|
||||
/* istanbul ignore next */
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (pathArray.length === 1) {
|
||||
return Object.keys(obj)
|
||||
.filter(prop => prop !== key)
|
||||
.reduce((acc, prop) => Object.assign(acc, { [prop]: obj[prop] }), {});
|
||||
}
|
||||
|
||||
return Object.keys(obj)
|
||||
.reduce((acc, prop) => ({
|
||||
...acc,
|
||||
[prop]: prop !== key ? obj[prop] : unsetProp(obj[key], restPath),
|
||||
}), {});
|
||||
}
|
||||
|
||||
function flattenReducer(acc, arr) {
|
||||
try {
|
||||
// This is faster but susceptible to `RangeError: Maximum call stack size exceeded`
|
||||
acc.push(...arr);
|
||||
return acc;
|
||||
} catch (err) {
|
||||
// Fallback to a slower but safer option
|
||||
return acc.concat(arr);
|
||||
}
|
||||
}
|
||||
|
||||
function fastJoin(arr, separator) {
|
||||
let isFirst = true;
|
||||
return arr.reduce((acc, elem) => {
|
||||
if (elem === null || elem === undefined) {
|
||||
elem = '';
|
||||
}
|
||||
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
return `${elem}`;
|
||||
}
|
||||
|
||||
return `${acc}${separator}${elem}`;
|
||||
}, '');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getProp,
|
||||
setProp,
|
||||
unsetProp,
|
||||
fastJoin,
|
||||
flattenReducer
|
||||
};
|
||||
73
node_modules/json2csv/package.json
generated
vendored
Normal file
73
node_modules/json2csv/package.json
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"name": "json2csv",
|
||||
"version": "5.0.7",
|
||||
"description": "Convert JSON to CSV",
|
||||
"keywords": [
|
||||
"json",
|
||||
"to",
|
||||
"csv",
|
||||
"export",
|
||||
"convert",
|
||||
"parse"
|
||||
],
|
||||
"author": {
|
||||
"name": "Mirco Zeiss",
|
||||
"email": "mirco.zeiss@gmail.com",
|
||||
"twitter": "zeMirco"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"json2csv": "./bin/json2csv.js"
|
||||
},
|
||||
"main": "lib/json2csv.js",
|
||||
"module": "dist/json2csv.esm.js",
|
||||
"browser": "dist/json2csv.umd.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zemirco/json2csv"
|
||||
},
|
||||
"homepage": "http://zemirco.github.io/json2csv",
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"dev": "rollup -c -w",
|
||||
"test": "node test | tap-spec",
|
||||
"lint": "eslint bin lib test",
|
||||
"test-with-coverage": "nyc --reporter=text node test | tap-spec",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||
"deploy:docs": "docpress b && gh-pages -d _docpress",
|
||||
"prepublish": "in-publish && npm run before:publish || not-in-publish",
|
||||
"before:publish": "npm test && npm run build && npm run deploy:docs",
|
||||
"release": "standard-version"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": "^6.1.0",
|
||||
"jsonparse": "^1.3.1",
|
||||
"lodash.get": "^4.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.3.3",
|
||||
"@babel/preset-env": "^7.3.1",
|
||||
"coveralls": "^3.0.3",
|
||||
"docpress": "^0.8.0",
|
||||
"eslint": "^6.1.0",
|
||||
"gh-pages": "^2.0.1",
|
||||
"in-publish": "^2.0.0",
|
||||
"nyc": "^14.1.1",
|
||||
"rollup": "^1.11.0",
|
||||
"rollup-plugin-babel": "^4.3.2",
|
||||
"rollup-plugin-commonjs": "^10.0.2",
|
||||
"rollup-plugin-node-builtins": "^2.1.2",
|
||||
"rollup-plugin-node-globals": "^1.2.1",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"standard-version": "^8.0.1",
|
||||
"tap-spec": "^5.0.0",
|
||||
"tape": "^4.10.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10",
|
||||
"npm": ">= 6.13.0"
|
||||
},
|
||||
"volta": {
|
||||
"node": "10.19.0"
|
||||
}
|
||||
}
|
||||
46
node_modules/json2csv/rollup.config.js
generated
vendored
Normal file
46
node_modules/json2csv/rollup.config.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import resolve from 'rollup-plugin-node-resolve';
|
||||
import commonjs from 'rollup-plugin-commonjs';
|
||||
import globals from 'rollup-plugin-node-globals';
|
||||
import builtins from 'rollup-plugin-node-builtins';
|
||||
import babel from 'rollup-plugin-babel';
|
||||
import pkg from './package.json';
|
||||
|
||||
export default [
|
||||
{
|
||||
input: 'lib/json2csv.js',
|
||||
output: {
|
||||
file: pkg.browser,
|
||||
format: 'umd',
|
||||
name: 'json2csv'
|
||||
},
|
||||
plugins: [
|
||||
resolve({
|
||||
browser: true
|
||||
}),
|
||||
commonjs(),
|
||||
globals(),
|
||||
builtins(),
|
||||
babel({
|
||||
exclude: ['node_modules/**'],
|
||||
babelrc: false,
|
||||
presets: [['@babel/env', { modules: false }]],
|
||||
})
|
||||
]
|
||||
},
|
||||
{
|
||||
input: 'lib/json2csv.js',
|
||||
output: [
|
||||
{ file: pkg.module, format: 'es' }
|
||||
],
|
||||
external: [ 'os', 'stream' ],
|
||||
plugins: [
|
||||
resolve(),
|
||||
commonjs(),
|
||||
babel({
|
||||
exclude: ['node_modules/**'],
|
||||
babelrc: false,
|
||||
presets: [['@babel/env', { modules: false }]],
|
||||
})
|
||||
]
|
||||
}
|
||||
];
|
||||
Reference in New Issue
Block a user