1 | # EditorConfig JavaScript Core
|
2 |
|
3 | [![Build Status](https://travis-ci.org/editorconfig/editorconfig-core-js.svg?branch=master)](https://travis-ci.org/editorconfig/editorconfig-core-js)
|
4 |
|
5 | The EditorConfig JavaScript core will provide the same functionality as the
|
6 | [EditorConfig C Core][] and [EditorConfig Python Core][].
|
7 |
|
8 |
|
9 | ## Installation
|
10 |
|
11 | You need [node][] to use this package.
|
12 |
|
13 | To install this package (system-wide):
|
14 |
|
15 | ```bash
|
16 | $ npm install editorconfig
|
17 | ```
|
18 |
|
19 | To install the package system-wide:
|
20 |
|
21 | ```bash
|
22 | $ npm install -g editorconfig
|
23 | ```
|
24 |
|
25 | ## Usage
|
26 |
|
27 | ### in Node.js:
|
28 |
|
29 | #### parse(filePath[, options])
|
30 |
|
31 | options is an object with the following defaults:
|
32 |
|
33 | ```js
|
34 | {
|
35 | config: '.editorconfig',
|
36 | version: pkg.version,
|
37 | root: '/'
|
38 | };
|
39 | ```
|
40 |
|
41 | Search for `.editorconfig` starting from the current directory to the root directory.
|
42 |
|
43 | Example:
|
44 |
|
45 | ```js
|
46 | var editorconfig = require('editorconfig');
|
47 | var path = require('path');
|
48 | var filePath = path.join(__dirname, '/sample.js');
|
49 | var promise = editorconfig.parse(filePath);
|
50 | promise.then(function onFulfilled(result) {
|
51 | console.log(result);
|
52 | });
|
53 |
|
54 | /*
|
55 | {
|
56 | indent_style: 'space',
|
57 | indent_size: 2,
|
58 | end_of_line: 'lf',
|
59 | charset: 'utf-8',
|
60 | trim_trailing_whitespace: true,
|
61 | insert_final_newline: true,
|
62 | tab_width: 2
|
63 | };
|
64 | */
|
65 | ```
|
66 |
|
67 | #### parseSync(filePath[, options])
|
68 |
|
69 | Synchronous version of `editorconfig.parse()`.
|
70 |
|
71 | #### parseFromFiles(filePath, configs[, options])
|
72 |
|
73 | options is an object with the following defaults:
|
74 |
|
75 | ```js
|
76 | {
|
77 | config: '.editorconfig',
|
78 | version: pkg.version,
|
79 | root: '/'
|
80 | };
|
81 | ```
|
82 |
|
83 | Specify the `.editorconfig`.
|
84 |
|
85 | Example:
|
86 |
|
87 | ```js
|
88 | var editorconfig = require('editorconfig');
|
89 | var fs = require('fs');
|
90 | var path = require('path');
|
91 | var configPath = path.join(__dirname, '/.editorconfig');
|
92 | var configs = [
|
93 | {
|
94 | name: configPath,
|
95 | contents: fs.readFileSync(configPath, 'utf8')
|
96 | }
|
97 | ];
|
98 | var filePath = path.join(__dirname, '/sample.js');
|
99 | var promise = editorconfig.parseFromFiles(filePath, configs);
|
100 | promise.then(function onFulfilled(result) {
|
101 | console.log(result)
|
102 | });
|
103 |
|
104 | /*
|
105 | {
|
106 | indent_style: 'space',
|
107 | indent_size: 2,
|
108 | end_of_line: 'lf',
|
109 | charset: 'utf-8',
|
110 | trim_trailing_whitespace: true,
|
111 | insert_final_newline: true,
|
112 | tab_width: 2
|
113 | };
|
114 | */
|
115 | ```
|
116 |
|
117 | #### parseFromFilesSync(filePath, configs[, options])
|
118 |
|
119 | Synchronous version of `editorconfig.parseFromFiles()`.
|
120 |
|
121 | ### in Command Line
|
122 |
|
123 | ```bash
|
124 | $ ./bin/editorconfig
|
125 |
|
126 | Usage: editorconfig [OPTIONS] FILEPATH1 [FILEPATH2 FILEPATH3 ...]
|
127 |
|
128 | EditorConfig Node.js Core Version 0.11.4-development
|
129 |
|
130 | FILEPATH can be a hyphen (-) if you want path(s) to be read from stdin.
|
131 |
|
132 | Options:
|
133 |
|
134 | -h, --help output usage information
|
135 | -V, --version output the version number
|
136 | -f <path> Specify conf filename other than ".editorconfig"
|
137 | -b <version> Specify version (used by devs to test compatibility)
|
138 | ```
|
139 |
|
140 | Example:
|
141 |
|
142 | ```bash
|
143 | $ ./bin/editorconfig /home/zoidberg/humans/anatomy.md
|
144 | charset=utf-8
|
145 | insert_final_newline=true
|
146 | end_of_line=lf
|
147 | tab_width=8
|
148 | trim_trailing_whitespace=sometimes
|
149 | ```
|
150 |
|
151 | ## Development
|
152 |
|
153 | To install dependencies for this package run this in the package directory:
|
154 |
|
155 | ```bash
|
156 | $ npm install
|
157 | ```
|
158 |
|
159 | Next, run:
|
160 |
|
161 | ```bash
|
162 | $ npm link
|
163 | ```
|
164 |
|
165 | The global editorconfig will now point to the files in your development
|
166 | repository instead of a globally-installed version from npm. You can now use
|
167 | editorconfig directly to test your changes.
|
168 |
|
169 | If you ever update from the central repository and there are errors, it might
|
170 | be because you are missing some dependencies. If that happens, just run npm
|
171 | link again to get the latest dependencies.
|
172 |
|
173 | To test the command line interface:
|
174 |
|
175 | ```bash
|
176 | $ editorconfig <filepath>
|
177 | ```
|
178 |
|
179 | # Testing
|
180 |
|
181 | [CMake][] must be installed to run the tests.
|
182 |
|
183 | To run the tests:
|
184 |
|
185 | ```bash
|
186 | $ npm test
|
187 | ```
|
188 |
|
189 | To run the tests with increased verbosity (for debugging test failures):
|
190 |
|
191 | ```bash
|
192 | $ npm run-script test-verbose
|
193 | ```
|
194 |
|
195 | [EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core
|
196 | [EditorConfig Python Core]: https://github.com/editorconfig/editorconfig-core-py
|
197 | [node]: http://nodejs.org/
|
198 | [cmake]: http://www.cmake.org
|