markdown-table-formatter 1.0.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE +20 -20
- package/README.md +114 -101
- package/lib/cli.js +77 -62
- package/lib/index.js +17 -17
- package/lib/markdown-table-formatter.js +73 -64
- package/lib/options.js +53 -46
- package/package.json +77 -76
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.0] 2022-01-31
|
|
4
|
+
|
|
5
|
+
- Allow to override the table columns padding number of spaces using argument **--columnpadding**
|
|
6
|
+
- CI: Upgrade MegaLinter to v5 + fix CI tests on Windows & Mac
|
|
7
|
+
|
|
8
|
+
## [1.2.0] 2021-08-20
|
|
9
|
+
|
|
10
|
+
- Allow to call markdown-table-formatter with a glob parameter to find files to format
|
|
11
|
+
- Allow to call markdown-table-formatter without arguments (**/*.md will be used by default to collect files)
|
|
12
|
+
- Fix logs format
|
|
13
|
+
|
|
14
|
+
## [1.1.0] 2021-04-05
|
|
15
|
+
|
|
16
|
+
- Upgrade markdown-table-prettify to 3.4.0 so it can take in account inline disable comments
|
|
17
|
+
|
|
3
18
|
## [1.0.2] 2021-01-19
|
|
4
19
|
|
|
5
20
|
- Fix code coverage
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Nicolas Vuillamy
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nicolas Vuillamy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,101 +1,114 @@
|
|
|
1
|
-
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[![
|
|
8
|
-
[![
|
|
9
|
-
[![
|
|
10
|
-
[![
|
|
11
|
-
[![
|
|
12
|
-
[![
|
|
13
|
-
[![
|
|
14
|
-
|
|
15
|
-
[
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
### Local
|
|
22
|
-
|
|
23
|
-
```shell
|
|
24
|
-
npm install markdown-table-formatter --save
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Global
|
|
28
|
-
|
|
29
|
-
```shell
|
|
30
|
-
npm install markdown-table-formatter -g
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Usage
|
|
34
|
-
|
|
35
|
-
```shell
|
|
36
|
-
markdown-table-formatter [OPTIONS] (file(s))
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Options
|
|
40
|
-
|
|
41
|
-
| Parameter
|
|
42
|
-
|
|
43
|
-
| -c<br/>--check
|
|
44
|
-
| -
|
|
45
|
-
| -
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
# Markdown table formatter
|
|
4
|
+
|
|
5
|
+
[](https://npmjs.org/package/markdown-table-formatter)
|
|
6
|
+
[](https://npmjs.org/package/markdown-table-formatter)
|
|
7
|
+
[](https://npmjs.org/package/markdown-table-formatter)
|
|
8
|
+
[](https://github.com/nvuillam/mega-linter#readme)
|
|
9
|
+
[](https://codecov.io/gh/nvuillam/markdown-table-formatter)
|
|
10
|
+
[](https://gitHub.com/nvuillam/markdown-table-formatter/graphs/contributors/)
|
|
11
|
+
[](https://GitHub.com/nvuillam/markdown-table-formatter/stargazers/)
|
|
12
|
+
[](https://github.com/nvuillam/markdown-table-formatter/blob/master/LICENSE)
|
|
13
|
+
[](http://makeapullrequest.com)
|
|
14
|
+
|
|
15
|
+
Format markdown tables in files, using embedded [markdown-table-prettify](https://www.npmjs.com/package/markdown-table-prettify)
|
|
16
|
+
|
|
17
|
+
[](https://github.com/nvuillam/markdown-table-formatter#readme)
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
### Local
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
npm install markdown-table-formatter --save
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Global
|
|
28
|
+
|
|
29
|
+
```shell
|
|
30
|
+
npm install markdown-table-formatter -g
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```shell
|
|
36
|
+
markdown-table-formatter [OPTIONS] (file(s) or glob expression)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Options
|
|
40
|
+
|
|
41
|
+
| Parameter | Description | Default value |
|
|
42
|
+
|----------------|-----------------------------------|---------------|
|
|
43
|
+
| -c<br/>--check | Check only, does not update files | `false` |
|
|
44
|
+
| -p<br/>--columnpadding | Override column padding number of spaces |
|
|
45
|
+
| -h<br/>--help | Displays help | <!-- --> |
|
|
46
|
+
| -v<br/>--version | Displays version | <!-- --> |
|
|
47
|
+
|
|
48
|
+
## Examples
|
|
49
|
+
|
|
50
|
+
Format all markdown files found within current directory
|
|
51
|
+
|
|
52
|
+
```shell
|
|
53
|
+
markdown-table-formatter
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Format all markdown files found with a glob expression
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
markdown-table-formatter **/docs/*.md
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Format markdown tables in a single file
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
markdown-table-formatter myfile.md
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Format markdown tables in a multiple file
|
|
69
|
+
|
|
70
|
+
```shell
|
|
71
|
+
markdown-table-formatter myfile.md anotherFile.md andAnotherFile.md
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Check if markdown table formatting is necessary in a single file
|
|
75
|
+
|
|
76
|
+
```shell
|
|
77
|
+
markdown-table-formatter --check myfile.md
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Check if markdown table formatting is necessary in a multiple files
|
|
81
|
+
|
|
82
|
+
```shell
|
|
83
|
+
markdown-table-formatter --check myfile.md anotherFile.md andAnotherFile.md
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
You can see **more examples in** [**test methods**](https://github.com/nvuillam/markdown-table-formatter/blob/master/test/markdown-table-formatter.test.js)
|
|
87
|
+
|
|
88
|
+
## Continuous Integration
|
|
89
|
+
|
|
90
|
+
You can automatically check markdown tables formatting and fix it using [Mega-Linter](https://github.com/nvuillam/mega-linter/), that embeds markdown-table-formatter out of the box
|
|
91
|
+
|
|
92
|
+
## CONTRIBUTE
|
|
93
|
+
|
|
94
|
+
Contributions are very welcome !
|
|
95
|
+
|
|
96
|
+
Please follow [Contribution instructions](https://github.com/nvuillam/markdown-table-formatter/blob/master/CONTRIBUTING.md)
|
|
97
|
+
|
|
98
|
+
## RELEASE NOTES
|
|
99
|
+
|
|
100
|
+
## [1.0.2] 2021-01-19
|
|
101
|
+
|
|
102
|
+
- Fix code coverage
|
|
103
|
+
|
|
104
|
+
## [1.0.1] 2021-01-13
|
|
105
|
+
|
|
106
|
+
- First working version :)
|
|
107
|
+
|
|
108
|
+
## [0.0.1] 2021-01-13
|
|
109
|
+
|
|
110
|
+
- Initial version
|
|
111
|
+
|
|
112
|
+
____
|
|
113
|
+
|
|
114
|
+
See complete [CHANGELOG](https://github.com/nvuillam/markdown-table-formatter/blob/master/CHANGELOG.md)
|
package/lib/cli.js
CHANGED
|
@@ -1,62 +1,77 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
const { MarkdownTableFormatter } = require("./markdown-table-formatter");
|
|
3
|
-
const optionsDefinition = require("./options");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
const { MarkdownTableFormatter } = require("./markdown-table-formatter");
|
|
3
|
+
const optionsDefinition = require("./options");
|
|
4
|
+
const glob = require("glob");
|
|
5
|
+
|
|
6
|
+
class MarkdownTableFormatterCli {
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
options = {};
|
|
10
|
+
|
|
11
|
+
async run(args) {
|
|
12
|
+
this.options = optionsDefinition.parse(args);
|
|
13
|
+
|
|
14
|
+
// Show version
|
|
15
|
+
if (this.options.version) {
|
|
16
|
+
let version = process.env.npm_package_version;
|
|
17
|
+
if (!version) {
|
|
18
|
+
try {
|
|
19
|
+
const FindPackageJson = require("find-package-json");
|
|
20
|
+
const finder = FindPackageJson(__dirname);
|
|
21
|
+
version = finder.next().value.version;
|
|
22
|
+
} catch {
|
|
23
|
+
version = "error";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const message = `markdown-table-formatter version ${version}`;
|
|
27
|
+
console.log(message);
|
|
28
|
+
return { stdout: message };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Show help ( index or for an options)
|
|
32
|
+
if (this.options.help) {
|
|
33
|
+
let helpContent = "";
|
|
34
|
+
if (this.options._.length) {
|
|
35
|
+
helpContent = optionsDefinition.generateHelpForOption(
|
|
36
|
+
this.options._[0]
|
|
37
|
+
);
|
|
38
|
+
} else {
|
|
39
|
+
helpContent = optionsDefinition.generateHelp();
|
|
40
|
+
}
|
|
41
|
+
console.info(helpContent);
|
|
42
|
+
return { stdout: helpContent };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Processing formatting
|
|
46
|
+
const formatter = new MarkdownTableFormatter(this.options);
|
|
47
|
+
let files = this.options._;
|
|
48
|
+
if (files.length === 0) {
|
|
49
|
+
// use default glob expression **/*.md
|
|
50
|
+
files = glob.sync("**/*.md", {});
|
|
51
|
+
} else if (files.length === 1 && files[0].includes("*")) {
|
|
52
|
+
// use sent glob expression
|
|
53
|
+
files = glob.sync(files[0], {});
|
|
54
|
+
}
|
|
55
|
+
const { status, updates } = await formatter.run(files, this.options);
|
|
56
|
+
// Manage result
|
|
57
|
+
if (status === 0 && updates.length === 0) {
|
|
58
|
+
console.log("No markdown table formatting has been applied.");
|
|
59
|
+
} else if (status === 0 && updates > 0) {
|
|
60
|
+
console.log(
|
|
61
|
+
`Formatted markdown tables in ${
|
|
62
|
+
updates.length
|
|
63
|
+
} files:\n- ${updates.join("\n- ")}`
|
|
64
|
+
);
|
|
65
|
+
} else if (status === 1) {
|
|
66
|
+
console.log(
|
|
67
|
+
`${
|
|
68
|
+
updates.length
|
|
69
|
+
} files contain markdown tables to format:\n- ${updates.join("\n- ")}`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
process.exitCode = status;
|
|
73
|
+
return { status, updates };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = { MarkdownTableFormatterCli };
|
package/lib/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
const { MarkdownTableFormatter } = require("./markdown-table-formatter");
|
|
5
|
-
const { MarkdownTableFormatterCli } = require("./cli");
|
|
6
|
-
|
|
7
|
-
// Run only if called by script
|
|
8
|
-
const runningAsScript = !module.parent;
|
|
9
|
-
|
|
10
|
-
// Run asynchronously to use the returned status for process.exit
|
|
11
|
-
if (runningAsScript) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = { MarkdownTableFormatter, MarkdownTableFormatterCli };
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { MarkdownTableFormatter } = require("./markdown-table-formatter");
|
|
5
|
+
const { MarkdownTableFormatterCli } = require("./cli");
|
|
6
|
+
|
|
7
|
+
// Run only if called by script
|
|
8
|
+
const runningAsScript = !module.parent;
|
|
9
|
+
|
|
10
|
+
// Run asynchronously to use the returned status for process.exit
|
|
11
|
+
if (runningAsScript) {
|
|
12
|
+
(async () => {
|
|
13
|
+
await new MarkdownTableFormatterCli().run(process.argv);
|
|
14
|
+
})();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { MarkdownTableFormatter, MarkdownTableFormatterCli };
|
|
@@ -1,64 +1,73 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
const debug = require("debug")("markdown-table-formatter");
|
|
3
|
-
const fse = require("fs-extra");
|
|
4
|
-
const { CliPrettify } = require("markdown-table-prettify");
|
|
5
|
-
|
|
6
|
-
class MarkdownTableFormatter {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
const debug = require("debug")("markdown-table-formatter");
|
|
3
|
+
const fse = require("fs-extra");
|
|
4
|
+
const { CliPrettify } = require("markdown-table-prettify");
|
|
5
|
+
|
|
6
|
+
class MarkdownTableFormatter {
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a MarkdownTableFormatter instance
|
|
11
|
+
* @param {object} [opts] - Run options
|
|
12
|
+
* @param {string} [opts.check] - Define if we check only
|
|
13
|
+
*/
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
this.checkOnly = opts.check;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Runs markdown table formatter
|
|
20
|
+
* @param {string[]} [files] - List of files to format
|
|
21
|
+
* @return {Promise<any>} - Command result (status, stdout, stderr, childJavaProcess)
|
|
22
|
+
*/
|
|
23
|
+
async run(files, options = {}) {
|
|
24
|
+
const fileResults = [];
|
|
25
|
+
// Read files and call prettify on each of them
|
|
26
|
+
for (const file of files) {
|
|
27
|
+
if (debug.enabled) {
|
|
28
|
+
debug(`[file] ${file}`);
|
|
29
|
+
}
|
|
30
|
+
const markdown = await fse.readFile(file);
|
|
31
|
+
const markdownString = markdown.toString();
|
|
32
|
+
if (debug.enabled) {
|
|
33
|
+
debug(`[file before]\n${markdownString}`);
|
|
34
|
+
}
|
|
35
|
+
const prettifyOptions = {};
|
|
36
|
+
if (options.columnpadding) {
|
|
37
|
+
prettifyOptions.columnPadding = options.columnpadding;
|
|
38
|
+
}
|
|
39
|
+
const markdownStringPrettified = CliPrettify.prettify(
|
|
40
|
+
markdownString,
|
|
41
|
+
prettifyOptions
|
|
42
|
+
);
|
|
43
|
+
const updated = markdownStringPrettified !== markdownString;
|
|
44
|
+
// Update file if necessary
|
|
45
|
+
if (updated && !this.checkOnly) {
|
|
46
|
+
await fse.writeFile(file, markdownStringPrettified);
|
|
47
|
+
debug(`[updated] ${file} with:\n${markdownStringPrettified}`);
|
|
48
|
+
}
|
|
49
|
+
const fileResult = {
|
|
50
|
+
file,
|
|
51
|
+
updated,
|
|
52
|
+
before: updated ? markdownString : null,
|
|
53
|
+
after: updated ? markdownStringPrettified : null,
|
|
54
|
+
};
|
|
55
|
+
fileResults.push(fileResult);
|
|
56
|
+
}
|
|
57
|
+
const updates = fileResults
|
|
58
|
+
.filter((fileResult) => fileResult.updated)
|
|
59
|
+
.map((fileResult) => fileResult.file);
|
|
60
|
+
let status = 0;
|
|
61
|
+
if (this.checkOnly && updates.length > 0) {
|
|
62
|
+
status = 1;
|
|
63
|
+
}
|
|
64
|
+
const result = {
|
|
65
|
+
status,
|
|
66
|
+
fileResults,
|
|
67
|
+
updates,
|
|
68
|
+
};
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { MarkdownTableFormatter };
|
package/lib/options.js
CHANGED
|
@@ -1,46 +1,53 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Options configuration for optionator.
|
|
3
|
-
* @author Nicolas Vuillamy
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
"use strict";
|
|
7
|
-
|
|
8
|
-
//------------------------------------------------------------------------------
|
|
9
|
-
// Requirements
|
|
10
|
-
//------------------------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
const optionator = require("optionator");
|
|
13
|
-
|
|
14
|
-
//------------------------------------------------------------------------------
|
|
15
|
-
// Initialization and Public Interface
|
|
16
|
-
//------------------------------------------------------------------------------
|
|
17
|
-
|
|
18
|
-
// exports "parse(args)", "generateHelp()", and "generateHelpForOption(optionName)"
|
|
19
|
-
module.exports = optionator({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Options configuration for optionator.
|
|
3
|
+
* @author Nicolas Vuillamy
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
// Requirements
|
|
10
|
+
//------------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
const optionator = require("optionator");
|
|
13
|
+
|
|
14
|
+
//------------------------------------------------------------------------------
|
|
15
|
+
// Initialization and Public Interface
|
|
16
|
+
//------------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
// exports "parse(args)", "generateHelp()", and "generateHelpForOption(optionName)"
|
|
19
|
+
module.exports = optionator({
|
|
20
|
+
prepend: "markdown-table-formatter [options]",
|
|
21
|
+
defaults: {
|
|
22
|
+
concatRepeatedArrays: true,
|
|
23
|
+
mergeRepeatedObjects: true,
|
|
24
|
+
},
|
|
25
|
+
options: [
|
|
26
|
+
{
|
|
27
|
+
option: "check",
|
|
28
|
+
alias: "c",
|
|
29
|
+
type: "Boolean",
|
|
30
|
+
description:
|
|
31
|
+
"Check only (exits 1 if wrongly formatted markdown tables are found)",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
option: "columnpadding",
|
|
35
|
+
alias: "p",
|
|
36
|
+
type: "Int",
|
|
37
|
+
description: "Override table columns padding number of spaces",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
option: "help",
|
|
41
|
+
alias: "h",
|
|
42
|
+
type: "Boolean",
|
|
43
|
+
description: "Show help",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
option: "version",
|
|
47
|
+
alias: "v",
|
|
48
|
+
type: "Boolean",
|
|
49
|
+
description: "Show version",
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
mutuallyExclusive: [["check", "help", "version"]],
|
|
53
|
+
});
|
package/package.json
CHANGED
|
@@ -1,76 +1,77 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "markdown-table-formatter",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Format markdown tables in files",
|
|
5
|
-
"main": "./lib/index.js",
|
|
6
|
-
"files": [
|
|
7
|
-
"lib/"
|
|
8
|
-
],
|
|
9
|
-
"bin": {
|
|
10
|
-
"markdown-table-formatter": "lib/index.js"
|
|
11
|
-
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"lint:fix": "eslint **/*.js --fix && prettier --write \"./lib/**/*.{js,jsx,json}\" --tab-width 4 --print-width 150",
|
|
14
|
-
"test": "mocha \"test/**/*.test.js\"",
|
|
15
|
-
"test:coverage": "nyc npm run test",
|
|
16
|
-
"test:debug": "env DEBUG=markdown-table-formatter mocha --reporter spec \"test/**/*.test.js\""
|
|
17
|
-
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/nvuillam/markdown-table-formatter.git"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"markdown",
|
|
24
|
-
"table",
|
|
25
|
-
"formatter",
|
|
26
|
-
"format",
|
|
27
|
-
"prettify"
|
|
28
|
-
],
|
|
29
|
-
"author": "Nicolas Vuillamy",
|
|
30
|
-
"license": "MIT",
|
|
31
|
-
"bugs": {
|
|
32
|
-
"url": "https://github.com/nvuillam/markdown-table-formatter/issues"
|
|
33
|
-
},
|
|
34
|
-
"homepage": "https://github.com/nvuillam/markdown-table-formatter#readme",
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"debug": "^4.1.1",
|
|
37
|
-
"find-package-json": "^1.2.0",
|
|
38
|
-
"fs-extra": "^9.0.1",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"eslint": "^7.
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown-table-formatter",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Format markdown tables in files",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/"
|
|
8
|
+
],
|
|
9
|
+
"bin": {
|
|
10
|
+
"markdown-table-formatter": "lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"lint:fix": "eslint **/*.js --fix && prettier --write \"./lib/**/*.{js,jsx,json}\" --tab-width 4 --print-width 150",
|
|
14
|
+
"test": "mocha \"test/**/*.test.js\"",
|
|
15
|
+
"test:coverage": "nyc npm run test",
|
|
16
|
+
"test:debug": "env DEBUG=markdown-table-formatter mocha --reporter spec \"test/**/*.test.js\""
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/nvuillam/markdown-table-formatter.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"markdown",
|
|
24
|
+
"table",
|
|
25
|
+
"formatter",
|
|
26
|
+
"format",
|
|
27
|
+
"prettify"
|
|
28
|
+
],
|
|
29
|
+
"author": "Nicolas Vuillamy",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/nvuillam/markdown-table-formatter/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/nvuillam/markdown-table-formatter#readme",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"debug": "^4.1.1",
|
|
37
|
+
"find-package-json": "^1.2.0",
|
|
38
|
+
"fs-extra": "^9.0.1",
|
|
39
|
+
"glob": "^7.1.6",
|
|
40
|
+
"markdown-table-prettify": "^3.6.0",
|
|
41
|
+
"optionator": "^0.9.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@babel/eslint-parser": "^7.16.5",
|
|
45
|
+
"eslint": "^7.6.0",
|
|
46
|
+
"mega-linter-runner": "^4.23.1",
|
|
47
|
+
"mocha": "^8.1.1",
|
|
48
|
+
"nyc": "^15.1.0",
|
|
49
|
+
"which": "^2.0.2"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=12.0.0"
|
|
53
|
+
},
|
|
54
|
+
"mocha": {
|
|
55
|
+
"require": [
|
|
56
|
+
"test/helpers/init.js"
|
|
57
|
+
],
|
|
58
|
+
"watch-extensions": [
|
|
59
|
+
"js"
|
|
60
|
+
],
|
|
61
|
+
"recursive": true,
|
|
62
|
+
"reporter": "spec",
|
|
63
|
+
"timeout": "300000"
|
|
64
|
+
},
|
|
65
|
+
"nyc": {
|
|
66
|
+
"include": [
|
|
67
|
+
"lib/**"
|
|
68
|
+
],
|
|
69
|
+
"extension": [
|
|
70
|
+
".js"
|
|
71
|
+
],
|
|
72
|
+
"reporter": [
|
|
73
|
+
"html"
|
|
74
|
+
],
|
|
75
|
+
"all": true
|
|
76
|
+
}
|
|
77
|
+
}
|