editorconfig 0.12.1 → 0.12.2

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.
Files changed (3) hide show
  1. package/editorconfig.js +28 -14
  2. package/lib/ini.js +36 -36
  3. package/package.json +1 -1
package/editorconfig.js CHANGED
@@ -35,6 +35,17 @@ function getConfigFileNames(filepath, options) {
35
35
  return paths;
36
36
  }
37
37
 
38
+ function getFilepathRoot(filepath) {
39
+ if (path.parse !== undefined) {
40
+ // Node.js >= 0.11.15
41
+ return path.parse(filepath).root;
42
+ }
43
+ if (os.platform() === 'win32') {
44
+ return path.resolve(filepath).match(/^(\\\\[^\\]+\\)?[^\\]+\\/)[0];
45
+ }
46
+ return '/';
47
+ }
48
+
38
49
  function processMatches(matches, version) {
39
50
  // Set indent_size to "tab" if indent_size is unspecified and
40
51
  // indent_style is set to "tab".
@@ -64,12 +75,6 @@ function processOptions(options, filepath) {
64
75
  version: new Version(options.version || pkg.version),
65
76
  root: path.resolve(options.root || getFilepathRoot(filepath))
66
77
  };
67
- function getFilepathRoot(filepath) {
68
- if (os.platform() === 'win32') {
69
- return path.resolve(filepath).match(/^[^\\]+\\/)[0];
70
- }
71
- return '/';
72
- }
73
78
  }
74
79
 
75
80
  function parseFromFiles(filepath, files, options) {
@@ -95,6 +100,11 @@ function parseFromFiles(filepath, files, options) {
95
100
  try {
96
101
  value = JSON.parse(value);
97
102
  } catch(e) {}
103
+ if (typeof value === 'undefined' || value === null) {
104
+ // null and undefined are values specific to JSON (no special meaning
105
+ // in editorconfig) & should just be returned as regular strings.
106
+ value = String(value);
107
+ }
98
108
  matches[key] = value;
99
109
  }
100
110
  });
@@ -137,15 +147,19 @@ function readConfigFiles(filepaths) {
137
147
  }
138
148
 
139
149
  module.exports.parseFromFiles = function (filepath, files, options) {
140
- filepath = path.resolve(filepath);
141
- options = processOptions(options, filepath);
142
- return parseFromFiles(filepath, files, options);
150
+ return new Promise (function (resolve, reject) {
151
+ filepath = path.resolve(filepath);
152
+ options = processOptions(options, filepath);
153
+ resolve(parseFromFiles(filepath, files, option));
154
+ });
143
155
  };
144
156
 
145
157
  module.exports.parse = function (filepath, options) {
146
- filepath = path.resolve(filepath);
147
- options = processOptions(options, filepath);
148
- var filepaths = getConfigFileNames(filepath, options);
149
- var files = readConfigFiles(filepaths);
150
- return parseFromFiles(filepath, files, options);
158
+ return new Promise (function (resolve, reject) {
159
+ filepath = path.resolve(filepath);
160
+ options = processOptions(options, filepath);
161
+ var filepaths = getConfigFileNames(filepath, options);
162
+ var files = readConfigFiles(filepaths);
163
+ resolve(parseFromFiles(filepath, files, options));
164
+ });
151
165
  };
package/lib/ini.js CHANGED
@@ -12,9 +12,9 @@ var fs = require('fs');
12
12
  * comment: ;this is a comment
13
13
  */
14
14
  var regex = {
15
- section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
16
- param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
17
- comment: /^\s*[#;].*$/
15
+ section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
16
+ param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
17
+ comment: /^\s*[#;].*$/
18
18
  };
19
19
 
20
20
  /*
@@ -23,43 +23,43 @@ var regex = {
23
23
  * @param: {Function} callback, the function that will be called when parsing is done
24
24
  * @return: none
25
25
  */
26
- module.exports.parse = function(file, callback){
27
- if(!callback){
28
- return;
29
- }
30
- fs.readFile(file, 'utf8', function(err, data){
31
- if(err){
32
- callback(err);
33
- }else{
34
- callback(null, parse(data));
35
- }
36
- });
26
+ module.exports.parse = function (file, callback) {
27
+ if (!callback) {
28
+ return;
29
+ }
30
+ fs.readFile(file, 'utf8', function (err, data) {
31
+ if (err) {
32
+ callback(err);
33
+ } else {
34
+ callback(null, parse(data));
35
+ }
36
+ });
37
37
  };
38
38
 
39
- module.exports.parseSync = function(file){
40
- return parse(fs.readFileSync(file, 'utf8'));
39
+ module.exports.parseSync = function (file) {
40
+ return parse(fs.readFileSync(file, 'utf8'));
41
41
  };
42
42
 
43
- function parse(data){
44
- var sectionBody = {};
45
- var sectionName = null;
46
- var value = [[sectionName, sectionBody]];
47
- var lines = data.split(/\r\n|\r|\n/);
48
- lines.forEach(function(line){
49
- var match;
50
- if(regex.comment.test(line)){
51
- return;
52
- }else if(regex.param.test(line)){
53
- match = line.match(regex.param);
54
- sectionBody[match[1]] = match[2];
55
- }else if(regex.section.test(line)){
56
- match = line.match(regex.section);
57
- sectionName = match[1];
58
- sectionBody = {};
59
- value.push([sectionName, sectionBody]);
60
- }
61
- });
62
- return value;
43
+ function parse (data) {
44
+ var sectionBody = {};
45
+ var sectionName = null;
46
+ var value = [[sectionName, sectionBody]];
47
+ var lines = data.split(/\r\n|\r|\n/);
48
+ lines.forEach(function (line) {
49
+ var match;
50
+ if (regex.comment.test(line)) {
51
+ return;
52
+ } else if (regex.param.test(line)) {
53
+ match = line.match(regex.param);
54
+ sectionBody[match[1]] = match[2];
55
+ } else if (regex.section.test(line)) {
56
+ match = line.match(regex.section);
57
+ sectionName = match[1];
58
+ sectionBody = {};
59
+ value.push([sectionName, sectionBody]);
60
+ }
61
+ });
62
+ return value;
63
63
  }
64
64
 
65
65
  module.exports.parseString = parse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "editorconfig",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "EditorConfig File Locator and Interpreter for Node.js",
5
5
  "keywords": [
6
6
  "editorconfig",