Comparing version 0.8.1 to 0.8.2
@@ -23,3 +23,3 @@ 'use strict'; | ||
optTrim = options && options.trim, // 'trim' option; | ||
EOL = utils.getEOL(code, options && options.platform), | ||
EOL = utils.getEOL(code), // get EOL from the code; | ||
isHtml, // set when the input is recognized as HTML; | ||
@@ -26,0 +26,0 @@ regEx; // regular expression details; |
@@ -6,27 +6,6 @@ 'use strict'; | ||
/////////////////////////////////////////////////// | ||
// Returns the End Of Line based on the 'platform' | ||
// option, the text and the current environment. | ||
function getEOL(text, platform) { | ||
if (typeof platform === 'string') { | ||
var type = platform.trim().toLowerCase(); | ||
if (type === 'auto') { | ||
type = getLineBreakType(text); | ||
} | ||
switch (type) { | ||
case 'windows': | ||
return '\r\n'; | ||
case 'unix': | ||
return '\n'; | ||
default: | ||
break; | ||
} | ||
} | ||
return os.EOL; | ||
} | ||
///////////////////////////////////// | ||
// Automatically determines the type | ||
// of line breaks used in the text. | ||
function getLineBreakType(text) { | ||
//////////////////////////////////////////////////// | ||
// Automatically calculates and returns End of Line, | ||
// based on the input text. | ||
function getEOL(text) { | ||
var idx = 0, unix = 0, windows = 0; | ||
@@ -46,5 +25,5 @@ while (idx < text.length) { | ||
if (unix === windows) { | ||
return 'unknown'; | ||
return os.EOL; | ||
} | ||
return unix > windows ? 'unix' : 'windows'; | ||
return unix > windows ? '\n' : '\r\n'; | ||
} | ||
@@ -51,0 +30,0 @@ |
{ | ||
"name": "decomment", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "Removes comments from JSON, JavaScript, CSS, HTML, etc.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -119,18 +119,2 @@ decomment | ||
##### options.platform ⇒ String | ||
Overrides the environment platform settings. | ||
By default, this library processes line breaks according to the environment OS, | ||
which this option overrides, according to the value specified: | ||
* `auto` - determine the platform automatically from the text | ||
* `unix` - force Unix notation for the line breaks | ||
* `windows` - force Windows notation for the line breaks | ||
When `auto` is specified, `text` is scanned to determine the platform | ||
according to the frequency of the line break notations used in it. | ||
When it is impossible to determine automatically, the library defaults | ||
back to the environment-based settings. | ||
### decomment.text(text, [options]) ⇒ String | ||
@@ -137,0 +121,0 @@ |
@@ -57,2 +57,19 @@ 'use strict'; | ||
describe("Automatic EOL", function () { | ||
it("must always ignore solo \\r symbols", function () { | ||
expect(decomment("//comment\r\rtext", {trim: true})).toBe(""); | ||
expect(decomment("/*comment*/\r\rtext", {trim: true})).toBe("\r\rtext"); | ||
}); | ||
it("must determine Unix and break on \\n", function () { | ||
expect(decomment("//comment\n\ntext", {trim: true})).toBe("text"); | ||
expect(decomment("/*comment*/\n\ntext", {trim: true})).toBe("text"); | ||
}); | ||
it("must determine Windows and break on \\r\\n", function () { | ||
expect(decomment("//comment\r\n\r\ntext", {trim: true})).toBe("text"); | ||
expect(decomment("/*comment*/\r\n\r\ntext", {trim: true})).toBe("text"); | ||
}); | ||
}); | ||
}); |
46575
12
953
153