1 | module.exports = function(contents, options, callback) {
|
2 | if(callback) {
|
3 | if(contents.length === 1)
|
4 | callback(null, "module.exports = " + stringify(contents[0]));
|
5 | else {
|
6 | contents.forEach(function(content, index) {
|
7 | contents[index] = stringify(content);
|
8 | });
|
9 | callback(null, "module.exports = [" + contents.join(",\n\t") + "]");
|
10 | }
|
11 | } else {
|
12 | return contents.length === 1 ? contents[0] : contents;
|
13 | }
|
14 | }
|
15 | function stringify(str) {
|
16 | return '"' + str.replace(/\\/g, "\\\\")
|
17 | .replace(/\t/g, "\\t")
|
18 | .replace(/\r/g, "\\r")
|
19 | .replace(/\n/g, "\\n")
|
20 | .replace(/\"/g, "\\\"") + '"';
|
21 | } |
\ | No newline at end of file |