Skip to content

Commit 93d87d1

Browse files
committed
build: 3.0.0
1 parent 5a2407a commit 93d87d1

File tree

8 files changed

+1909
-297
lines changed

8 files changed

+1909
-297
lines changed

.eslintignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ api
33
node_modules
44
samples
55
*.md
6-
*.json
7-
LICENSE
6+
*.spec.js
7+
LICENSE
8+
.DS_Store

.eslintrc.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"env": {
3-
"browser": true,
43
"node": true
54
},
65
"extends": ["plugin:prettier/recommended"],
@@ -9,7 +8,7 @@
98
"global": true
109
},
1110
"parserOptions": {
12-
"ecmaVersion": 2018,
11+
"ecmaVersion": 2021,
1312
"sourceType": "module",
1413
"ecmaFeatures": {
1514
"jsx": true
@@ -19,6 +18,16 @@
1918
"indent": ["error", 2, { "SwitchCase": 1 }],
2019
"default-case": "error",
2120
"linebreak-style": ["error", "unix"],
22-
"semi": ["error", "always"]
21+
"semi": ["error", "always"],
22+
"no-console": "error",
23+
"no-undef": "error",
24+
"no-var": "error",
25+
"no-caller": "error",
26+
"no-throw-literal": "error",
27+
"no-unneeded-ternary": "error",
28+
"prefer-const": "error",
29+
"comma-spacing": ["error", { "before": false, "after": true }],
30+
"comma-style": ["error", "last"],
31+
"handle-callback-err": ["error", "^(err|error)$"]
2332
}
2433
}

.prettierignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
node_modules
2-
.all-contributorsrc
32
.eslintignore
43
.gitignore
54
.prettierignore
5+
*.spec.js
6+
.npmignore
67
LICENSE
78
*.png
89
*.txt
910
TODO
10-
docs/functions.md
11-
*.md
12-
test.log
11+
.DS_Store

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Coderty S.L.
3+
Copyright (c) 2021 Runnerty Tech S.L.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 72 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,42 @@
22
<a href="http://runnerty.io">
33
<img height="257" src="https://runnerty.io/assets/header/logo-stroked.png">
44
</a>
5-
<p align="center">A new way for processes managing</p>
5+
<p align="center">Smart Processes Management</p>
66
</p>
77

8-
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Dependency Status][david-badge]][david-badge-url]
8+
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Dependency Status][david-badge]][david-badge-url]
99
<a href="#badge">
10-
<img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg">
10+
<img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg">
1111
</a>
1212

1313
# Executor for [Runnerty]: JSON2CSV
1414

1515
### Installation:
16+
17+
Through NPM
18+
1619
```bash
1720
npm i @runnerty/executor-json2csv
1821
```
1922

23+
You can also add modules to your project with [runnerty-cli]
24+
25+
```bash
26+
npx runnerty-cli add @runnerty/executor-json2csv
27+
```
28+
29+
This command installs the module in your project, adds example configuration in your `config.json` and creates an example plan of use.
30+
31+
If you have installed [runnerty-cli] globally you can include the module with this command:
32+
33+
```bash
34+
rty add @runnerty/executor-json2csv
35+
```
36+
2037
### Configuration sample:
38+
39+
Add in [config.json]:
40+
2141
```json
2242
{
2343
"id": "json2csv_default",
@@ -27,7 +47,10 @@ npm i @runnerty/executor-json2csv
2747

2848
### Plan sample:
2949

50+
Add in [plan.json]:
51+
3052
#### JSON Example
53+
3154
```json
3255
[
3356
{
@@ -62,32 +85,37 @@ npm i @runnerty/executor-json2csv
6285
```json
6386
{
6487
"id": "json2csv_default",
65-
"inputPath":"./planets.json",
88+
"inputPath": "./planets.json",
6689
"outputPath": "./planets.csv"
6790
}
6891
```
92+
6993
##### CSV Output
94+
7095
```
7196
"planet","radius","satellites"
7297
"Earth",6371,"[{""name"":""moon"",""radius"":1737}]"
7398
"Mars",3389,"[{""name"":""phobos"",""radius"":11267},{""name"":""deimos"",""radius"":6.2}]"
7499
```
100+
75101
#### Example 2:
102+
76103
```json
77104
{
78105
"id": "json2csv_default",
79-
"inputPath":"./planets.json",
106+
"inputPath": "./planets.json",
80107
"outputPath": "./planets.csv",
81-
"options":{
108+
"options": {
82109
"fields": ["planet", "radius", "satellites.name", "satellites.radius"]
83110
},
84-
"transforms":{
111+
"transforms": {
85112
"unwind": { "paths": ["satellites"] }
86113
}
87114
}
88115
```
89116

90117
##### CSV Ouput
118+
91119
```
92120
"planet","radius","satellites.name","satellites.radius"
93121
"Earth",6371,"moon",1737
@@ -100,10 +128,10 @@ npm i @runnerty/executor-json2csv
100128
```json
101129
{
102130
"id": "json2csv_default",
103-
"inputPath": "./input.json",
131+
"inputPath": "./input.json",
104132
"input": "@GV(MY_JSON)",
105133
"outputPath": "./output.csv",
106-
"options":{
134+
"options": {
107135
"fields": ["field1", "field2", "field3"],
108136
"defaultValue": "NULL",
109137
"header": true,
@@ -114,45 +142,54 @@ npm i @runnerty/executor-json2csv
114142
"includeEmptyRows": true,
115143
"withBOM": true
116144
},
117-
"transforms":{
118-
"unwind":{ "paths": ["items", "items.items"], "blankOut": true },
119-
"flatten":{ "objects": true, "arrays": true, "separator": "_" }
145+
"transforms": {
146+
"unwind": { "paths": ["items", "items.items"], "blankOut": true },
147+
"flatten": { "objects": true, "arrays": true, "separator": "_" }
120148
}
121149
}
122150
```
151+
123152
### Params
153+
124154
#### Options
125-
```
126-
fields List of fields to process. Defaults to field auto-detection.
127-
defaultValue Default value to use for missing fields.
128-
quote Character(s) to use as quote mark. Defaults to '"'.
129-
escapedQuote Character(s) to use as a escaped quote. Defaults to a double `quote`, '""'.
130-
delimiter Character(s) to use as delimiter. Defaults to ','. (default: ",")
131-
eol Character(s) to use as End-of-Line for separating rows. Defaults to '\n'. (default: "\n")
132-
excelStrings Wraps string data to force Excel to interpret it as string even if it contains a number.
133-
header Boolean to Enable/Disable the column name header. (Enabled by defaults)
134-
includeEmptyRows Boolean to Includes empty rows in the resulting CSV output.
135-
withBOM Boolean to Includes BOM character at the beginning of the CSV.
136-
```
155+
156+
| Option | Description |
157+
| ---------------- | ----------------------------------------------------------------------------------------- |
158+
| fields | List of fields to process. Defaults to field auto-detection. |
159+
| defaultValue | Default value to use for missing fields. |
160+
| quote | Character(s) to use as quote mark. Defaults to '"'. |
161+
| delimiter | Character(s) to use as delimiter. Defaults to ','. (default: ",") |
162+
| escapedQuote | Character(s) to use as a escaped quote. Defaults to a double `quote`, '""'. |
163+
| eol | Character(s) to use as End-of-Line for separating rows. Defaults to '\n'. (default: "\n") |
164+
| excelStrings | Wraps string data to force Excel to interpret it as string even if it contains a number. |
165+
| header | Boolean to Enable/Disable the column name header. (Enabled by defaults) |
166+
| includeEmptyRows | Boolean to Includes empty rows in the resulting CSV output. |
167+
| withBOM | Boolean to Includes BOM character at the beginning of the CSV. |
168+
137169
#### Transforms
138-
```
139-
unwind Creates multiple rows from a single JSON document similar to MongoDB unwind.
140-
paths Unwind fields path.
141-
blankOut When unwinding, blank out instead of repeating data. Defaults to false. (default: false)
142-
flatten Nested javascript objects into a single level object.
143-
object Flatten nested objects. Defaults to false. (default: false)
144-
arrays Flatten nested arrays. Defaults to false. (default: false)
145-
separator Flattened keys separator. Defaults to '.'. (default: ".")
146-
```
170+
171+
| Option | Description |
172+
| ----------- | ---------------------------------------------------------------------------------------- |
173+
| unwind | Creates multiple rows from a single JSON document similar to MongoDB unwind. |
174+
| - paths | Unwind fields path. |
175+
| - blankOut | When unwinding, blank out instead of repeating data. Defaults to false. (default: false) |
176+
| flatten | Nested javascript objects into a single level object. |
177+
| - object | Flatten nested objects. Defaults to false. (default: false) |
178+
| - arrays | Flatten nested arrays. Defaults to false. (default: false) |
179+
| - separator | Flattened keys separator. Defaults to '.'. (default: ".") |
147180

148181
### More information:
149-
This executor is a wrapper of the module json2csv (zemirco), for more information consult the website of the [json2csv].
150182

183+
This executor is a wrapper of the module json2csv (zemirco), for more information consult the website of the [json2csv].
151184

152-
[Runnerty]: http://www.runnerty.io
185+
[runnerty]: http://www.runnerty.io
153186
[downloads-image]: https://img.shields.io/npm/dm/@runnerty/executor-json2csv.svg
154187
[npm-url]: https://www.npmjs.com/package/@runnerty/executor-json2csv
155188
[npm-image]: https://img.shields.io/npm/v/@runnerty/executor-json2csv.svg
156189
[david-badge]: https://david-dm.org/runnerty/executor-json2csv.svg
157190
[david-badge-url]: https://david-dm.org/runnerty/executor-json2csv
191+
[config.json]: http://docs.runnerty.io/config/
192+
[plan.json]: http://docs.runnerty.io/plan/
193+
[ejs]: https://ejs.co
194+
[runnerty-cli]: https://www.npmjs.com/package/runnerty-cli
158195
[json2csv]: https://github.com/zemirco/json2csv

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const {
66
transforms: { unwind, flatten }
77
} = require('json2csv');
88

9-
const Execution = global.ExecutionClass;
9+
const Executor = require('@runnerty/module-core').Executor;
1010

11-
class json2csvExecutor extends Execution {
11+
class json2csvExecutor extends Executor {
1212
constructor(process) {
1313
super(process);
1414
this.endOptions = { end: 'end' };
@@ -48,7 +48,7 @@ class json2csvExecutor extends Execution {
4848
this.endOptions.end = 'error';
4949
this.endOptions.messageLog = err;
5050
this.endOptions.err_output = err;
51-
this.end(endOptions);
51+
this.end(this.endOptions);
5252
}
5353
}
5454
}

0 commit comments

Comments
 (0)