Skip to content
Browse files

tab to spaces

  • Loading branch information...
1 parent c54346d commit 8ca39aa9fcd12ddcce3002b006f99fa3f7d9e007 Gabriel Llamas committed Dec 7, 2013
View
38 examples/include/include.js
@@ -3,26 +3,26 @@
var properties = require ("../../lib");
var options = {
- path: true,
- include: true,
- sections: true
+ path: true,
+ include: true,
+ sections: true
};
properties.parse (".", options, function (error, p){
- if (error) return console.error (error);
-
- console.log (p);
-
- /*
- {
- web: {
- hostname: "10.10.10.10",
- port: 1234
- },
- db: {
- hostname: "10.10.10.20",
- port: 4321
- }
- }
- */
+ if (error) return console.error (error);
+
+ console.log (p);
+
+ /*
+ {
+ web: {
+ hostname: "10.10.10.10",
+ port: 1234
+ },
+ db: {
+ hostname: "10.10.10.20",
+ port: 4321
+ }
+ }
+ */
});
View
52 examples/ini/parse-ini.js
@@ -5,10 +5,10 @@ var properties = require ("../../lib");
var data = fs.readFileSync ("ini", { encoding: "utf8" });
var options = {
- sections: true,
- comments: ";",
- separators: "=",
- strict: true
+ sections: true,
+ comments: ";",
+ separators: "=",
+ strict: true
};
var obj = properties.parse (data, options);
@@ -17,27 +17,27 @@ console.log (obj);
/*
{
- server: {
- host: "localhost",
- port: 8080,
- log: "web.log"
- },
- session: {
- secret: "brainfuck",
- key_id: "sid",
- max_age: 31536000000
- },
- database: {
- host: "localhost",
- port: 27017,
- min_pool: 10,
- max_pool: 100,
- timeout: 10000
- },
- i18n: {
- default: "en-US",
- cache: true,
- timeout: 3600000
- }
+ server: {
+ host: "localhost",
+ port: 8080,
+ log: "web.log"
+ },
+ session: {
+ secret: "brainfuck",
+ key_id: "sid",
+ max_age: 31536000000
+ },
+ database: {
+ host: "localhost",
+ port: 27017,
+ min_pool: 10,
+ max_pool: 100,
+ timeout: 10000
+ },
+ i18n: {
+ default: "en-US",
+ cache: true,
+ timeout: 3600000
+ }
}
*/
View
12 examples/ini/stringify-ini.js
@@ -3,12 +3,12 @@
var properties = require ("../../lib");
var stringifier = properties.stringifier ()
- .header ("Stringifier example")
- .property ({ comment: "Global property", key: "a", value: 1 })
- .section ("empty")
- .section ({ comment: "Section", name: "a" })
- .property ({ key: "a", value: 1 })
- .property ({ key: "b", value: 1 });
+ .header ("Stringifier example")
+ .property ({ comment: "Global property", key: "a", value: 1 })
+ .section ("empty")
+ .section ({ comment: "Section", name: "a" })
+ .property ({ key: "a", value: 1 })
+ .property ({ key: "b", value: 1 });
var options = { comment: ";" };
View
72 examples/namespaces/namespaces.js
@@ -4,43 +4,43 @@ var util = require ("util");
var properties = require ("../../lib");
var options = {
- path: true,
- variables: true,
- sections: true,
- namespaces: true
+ path: true,
+ variables: true,
+ sections: true,
+ namespaces: true
};
properties.parse ("namespaces", options, function (error, p){
- if (error) return console.error (error);
-
- console.log (util.inspect (p, { depth: null }));
-
- /*
- {
- app: {
- name: "App",
- version: "0.0.1",
- title: "App v0.0.1"
- },
- path: {
- home: "./app",
- test: "./app/test",
- web: "./app/web"
- },
- log: {
- basename: "app",
- max_size: "1kb",
- type: "cycle",
- backups: 1
- },
- db: {
- host: "10.10.10.10",
- port: 1234,
- pool: {
- min: 5,
- max: 10
- }
- }
- }
- */
+ if (error) return console.error (error);
+
+ console.log (util.inspect (p, { depth: null }));
+
+ /*
+ {
+ app: {
+ name: "App",
+ version: "0.0.1",
+ title: "App v0.0.1"
+ },
+ path: {
+ home: "./app",
+ test: "./app/test",
+ web: "./app/web"
+ },
+ log: {
+ basename: "app",
+ max_size: "1kb",
+ type: "cycle",
+ backups: 1
+ },
+ db: {
+ host: "10.10.10.10",
+ port: 1234,
+ pool: {
+ min: 5,
+ max: 10
+ }
+ }
+ }
+ */
});
View
34 examples/private-vars/private-vars.js
@@ -3,24 +3,24 @@
var properties = require ("../../lib");
var options = {
- path: true,
- reviver: function (key, value, section){
- if (this.isSection) return this.assert ();
- //If the key begins with _ the property is not added
- if (key[0] === "_") return;
- return this.assert ();
- }
+ path: true,
+ reviver: function (key, value, section){
+ if (this.isSection) return this.assert ();
+ //If the key begins with _ the property is not added
+ if (key[0] === "_") return;
+ return this.assert ();
+ }
};
properties.parse ("private-vars", options, function (error, p){
- if (error) return console.error (error);
-
- console.log (p);
-
- /*
- {
- c: 1,
- d: 1
- }
- */
+ if (error) return console.error (error);
+
+ console.log (p);
+
+ /*
+ {
+ c: 1,
+ d: 1
+ }
+ */
});
View
40 examples/replacer.js
@@ -3,28 +3,28 @@
var properties = require ("../lib");
var stringifier = properties.stringifier ()
- .property ({ key: "a", value: 1 })
- .section ("s1")
- .property ({ key: "a", value: 1 })
- .section ("s2")
- .property ({ key: "a", value: 1 })
- .section ("s3")
- .property ({ key: "a", value: 1 });
+ .property ({ key: "a", value: 1 })
+ .section ("s1")
+ .property ({ key: "a", value: 1 })
+ .section ("s2")
+ .property ({ key: "a", value: 1 })
+ .section ("s3")
+ .property ({ key: "a", value: 1 });
var options = {
- replacer: function (key, value, section){
- //The global property "a" is removed
- if (this.isProperty && !section && key === "a") return;
-
- //Section "a" is removed
- if (this.isSection && section === "s1") return;
-
- //The value of the property "a" from the section "b" is modified
- if (this.isProperty && section === "s2" && key === "a") return value + 1;
-
- //Returns the rest of the lines
- return this.assert ();
- }
+ replacer: function (key, value, section){
+ //The global property "a" is removed
+ if (this.isProperty && !section && key === "a") return;
+
+ //Section "a" is removed
+ if (this.isSection && section === "s1") return;
+
+ //The value of the property "a" from the section "b" is modified
+ if (this.isProperty && section === "s2" && key === "a") return value + 1;
+
+ //Returns the rest of the lines
+ return this.assert ();
+ }
};
var data = properties.stringify (stringifier, options);
View
58 examples/reviver/reviver.js
@@ -3,36 +3,36 @@
var properties = require ("../../lib");
var options = {
- path: true,
- sections: true,
- reviver: function (key, value, section){
- //The global property "a" is removed
- if (this.isProperty && !section && key === "a") return;
-
- //Section "a" is removed
- if (this.isSection && section === "s1") return;
-
- //The value of the property "a" from the section "b" is modified
- if (this.isProperty && section === "s2" && key === "a") return value + 1;
-
- //Returns the rest of the lines
- return this.assert ();
- }
+ path: true,
+ sections: true,
+ reviver: function (key, value, section){
+ //The global property "a" is removed
+ if (this.isProperty && !section && key === "a") return;
+
+ //Section "a" is removed
+ if (this.isSection && section === "s1") return;
+
+ //The value of the property "a" from the section "b" is modified
+ if (this.isProperty && section === "s2" && key === "a") return value + 1;
+
+ //Returns the rest of the lines
+ return this.assert ();
+ }
};
properties.parse ("reviver", options, function (error, p){
- if (error) return console.error (error);
-
- console.log (p);
-
- /*
- {
- s2: {
- a: 2
- },
- s3: {
- a: 1
- }
- }
- */
+ if (error) return console.error (error);
+
+ console.log (p);
+
+ /*
+ {
+ s2: {
+ a: 2
+ },
+ s3: {
+ a: 1
+ }
+ }
+ */
});
View
132 examples/variables/environment-vars.js
@@ -19,75 +19,75 @@ NODE_ENV=production node environment-vars.js
var file;
if (process.env.NODE_ENV === "production"){
- file = "environment-vars-production";
+ file = "environment-vars-production";
}else{
- file = "environment-vars-development";
+ file = "environment-vars-development";
}
//First load the specific environment data
properties.parse (file, { path: true, sections: true }, function (error, env){
- if (error) return console.error (error);
-
- //Load the main configuration using as external vars the specific environment
- //properties
- //Tip: If the namespaces option is enabled you can read a value like this:
- //${web.hostname}, so you can pass the env object as an external var and read
- //from it using the dot separated keys nomenclature
- var options = {
- path: true,
- variables: true,
- sections: true,
- namespaces: true,
- vars: env
- };
-
- properties.parse ("environment-vars", options, function (error, p){
- if (error) return console.error (error);
-
- console.log (p);
-
- /*
- NODE_ENV=development
-
- {
- app: {
- name: "App",
- version: "0.0.1"
- },
- web: {
- hostname: "localhost",
- port: 1337
- },
- db: {
- hostname: "10.10.10.10",
- port: 1234,
- pool: {
- min: 5,
- max: 10
- }
- }
- }
-
- NODE_ENV=production
-
- {
- app: {
- name: "App",
- version: "0.0.1"
- },
- web: {
- hostname: "0.0.0.0",
- port: 80
- },
- db: {
- hostname: "10.10.10.20",
- port: 1234,
- pool: {
- min: 5,
- max: 10
- }
- }
- }
- */
- });
+ if (error) return console.error (error);
+
+ //Load the main configuration using as external vars the specific environment
+ //properties
+ //Tip: If the namespaces option is enabled you can read a value like this:
+ //${web.hostname}, so you can pass the env object as an external var and read
+ //from it using the dot separated keys nomenclature
+ var options = {
+ path: true,
+ variables: true,
+ sections: true,
+ namespaces: true,
+ vars: env
+ };
+
+ properties.parse ("environment-vars", options, function (error, p){
+ if (error) return console.error (error);
+
+ console.log (p);
+
+ /*
+ NODE_ENV=development
+
+ {
+ app: {
+ name: "App",
+ version: "0.0.1"
+ },
+ web: {
+ hostname: "localhost",
+ port: 1337
+ },
+ db: {
+ hostname: "10.10.10.10",
+ port: 1234,
+ pool: {
+ min: 5,
+ max: 10
+ }
+ }
+ }
+
+ NODE_ENV=production
+
+ {
+ app: {
+ name: "App",
+ version: "0.0.1"
+ },
+ web: {
+ hostname: "0.0.0.0",
+ port: 80
+ },
+ db: {
+ hostname: "10.10.10.20",
+ port: 1234,
+ pool: {
+ min: 5,
+ max: 10
+ }
+ }
+ }
+ */
+ });
});
View
106 examples/variables/variables.js
@@ -3,60 +3,60 @@
var properties = require ("../../lib");
var options = {
- path: true,
- variables: true,
- sections: true
+ path: true,
+ variables: true,
+ sections: true
};
properties.parse ("variables", options, function (error, p){
- if (error) return console.error (error);
-
- console.log (p);
-
- /*
- {
- domain1: "app1",
- domain2: "app2",
- users: {
- guest: "guest",
- admin: "gagle"
- },
- locales: {
- "en-US": "english",
- "es-ES": "spanish"
- },
- paths: {
- guest: "paths.guest",
- admin: "paths.gagle"
- },
- "paths.guest": {
- home: "some/path",
- logs: "some/path/logs/app1",
- conf: "some/path/conf/app1",
- locales_english: "some/path/locales/app2"
- },
- "paths.gagle": {
- home: "some/path",
- logs: "some/path/logs/app1",
- conf: "some/path/conf/app1",
- locales_spanish: "some/path/locales/app2"
- },
- permissions: {
- guest: "permissions.guest",
- admin: "permissions.gagle"
- },
- "permissions.guest": {
- "some/path": 400,
- "some/path/logs/app1": 400,
- "some/path/conf/app1": 400,
- "some/path/locales/app2": 400
- },
- "permissions.gagle": {
- "some/path": 755,
- "some/path/logs/app1": 777,
- "some/path/conf/app1": 400,
- "some/path/locales/app2": 700
- }
- }
- */
+ if (error) return console.error (error);
+
+ console.log (p);
+
+ /*
+ {
+ domain1: "app1",
+ domain2: "app2",
+ users: {
+ guest: "guest",
+ admin: "gagle"
+ },
+ locales: {
+ "en-US": "english",
+ "es-ES": "spanish"
+ },
+ paths: {
+ guest: "paths.guest",
+ admin: "paths.gagle"
+ },
+ "paths.guest": {
+ home: "some/path",
+ logs: "some/path/logs/app1",
+ conf: "some/path/conf/app1",
+ locales_english: "some/path/locales/app2"
+ },
+ "paths.gagle": {
+ home: "some/path",
+ logs: "some/path/logs/app1",
+ conf: "some/path/conf/app1",
+ locales_spanish: "some/path/locales/app2"
+ },
+ permissions: {
+ guest: "permissions.guest",
+ admin: "permissions.gagle"
+ },
+ "permissions.guest": {
+ "some/path": 400,
+ "some/path/logs/app1": 400,
+ "some/path/conf/app1": 400,
+ "some/path/locales/app2": 400
+ },
+ "permissions.gagle": {
+ "some/path": 755,
+ "some/path/logs/app1": 777,
+ "some/path/conf/app1": 400,
+ "some/path/locales/app2": 700
+ }
+ }
+ */
});
View
32 examples/variables/vars.js
@@ -3,23 +3,23 @@
var properties = require ("../../lib");
var options = {
- path: true,
- variables: true,
- vars: {
- A: "external var"
- }
+ path: true,
+ variables: true,
+ vars: {
+ A: "external var"
+ }
};
properties.parse ("vars", options, function (error, p){
- if (error) return console.error (error);
-
- console.log (p);
-
- /*
- {
- a: "internal var",
- b: "internal var",
- c: "external var"
- }
- */
+ if (error) return console.error (error);
+
+ console.log (p);
+
+ /*
+ {
+ a: "internal var",
+ b: "internal var",
+ c: "external var"
+ }
+ */
});
View
86 lib/escape.js
@@ -1,50 +1,50 @@
"use strict";
var unicode = function (code){
- var unicode = code.toString (16);
- while (unicode.length !== 4){
- unicode = "0" + unicode;
- }
- return "\\u" + unicode;
+ var unicode = code.toString (16);
+ while (unicode.length !== 4){
+ unicode = "0" + unicode;
+ }
+ return "\\u" + unicode;
};
module.exports = function (c, code, meta, options){
- //Encode characters to their unicode representation to be compatible with
- //ISO 8859-1 (latin1)
-
- //code 61: =
- //code 58: :
- if (meta.key && (code === 61 || code === 58 || code === meta.separator)){
- //Escape the separator in the key string
- return "\\" + c;
- }
-
- //ASCII printable characters
- if (code > 31 && code < 127){
- //Space at the begining of a word
- //If whitespace is true the space needs to be escaped
- //In comments, meta.whitespace is always false
- if (code === 32 && meta.whitespace){
- return "\\ ";
- }
- //Backslash
- if (code === 92) return "\\\\";
- return c;
- }
-
- //ASCII non-printable characters
- //Escaped
- if (code === 9) return meta.comment ? c : "\\t";
- if (code === 10) return "\\n";
- if (code === 12) return meta.comment ? c : "\\f";
- if (code === 13) return meta.comment ? c : "\\r";
-
- //Control sets 0 and 1
- if (code < 160) return unicode (code);
-
- //Printable 8-bit character
- if (code < 256) return c;
-
- //Latin1 multibyte character
- return options.unicode ? unicode (code) : c;
+ //Encode characters to their unicode representation to be compatible with
+ //ISO 8859-1 (latin1)
+
+ //code 61: =
+ //code 58: :
+ if (meta.key && (code === 61 || code === 58 || code === meta.separator)){
+ //Escape the separator in the key string
+ return "\\" + c;
+ }
+
+ //ASCII printable characters
+ if (code > 31 && code < 127){
+ //Space at the begining of a word
+ //If whitespace is true the space needs to be escaped
+ //In comments, meta.whitespace is always false
+ if (code === 32 && meta.whitespace){
+ return "\\ ";
+ }
+ //Backslash
+ if (code === 92) return "\\\\";
+ return c;
+ }
+
+ //ASCII non-printable characters
+ //Escaped
+ if (code === 9) return meta.comment ? c : "\\t";
+ if (code === 10) return "\\n";
+ if (code === 12) return meta.comment ? c : "\\f";
+ if (code === 13) return meta.comment ? c : "\\r";
+
+ //Control sets 0 and 1
+ if (code < 160) return unicode (code);
+
+ //Printable 8-bit character
+ if (code < 256) return c;
+
+ //Latin1 multibyte character
+ return options.unicode ? unicode (code) : c;
};
View
10 lib/index.js
@@ -3,9 +3,9 @@
var Stringifier = require ("./stringifier");
module.exports = {
- parse: require ("./read"),
- stringify: require ("./write"),
- createStringifier: function (){
- return new Stringifier ();
- }
+ parse: require ("./read"),
+ stringify: require ("./write"),
+ createStringifier: function (){
+ return new Stringifier ();
+ }
};
View
534 lib/parse.js
@@ -4,276 +4,276 @@
//have a size less than a block (default is 16KB)
var hex = function (c){
- switch (c){
- case "0": return 0;
- case "1": return 1;
- case "2": return 2;
- case "3": return 3;
- case "4": return 4;
- case "5": return 5;
- case "6": return 6;
- case "7": return 7;
- case "8": return 8;
- case "9": return 9;
- case "a": case "A": return 10;
- case "b": case "B": return 11;
- case "c": case "C": return 12;
- case "d": case "D": return 13;
- case "e": case "E": return 14;
- case "f": case "F": return 15;
- }
+ switch (c){
+ case "0": return 0;
+ case "1": return 1;
+ case "2": return 2;
+ case "3": return 3;
+ case "4": return 4;
+ case "5": return 5;
+ case "6": return 6;
+ case "7": return 7;
+ case "8": return 8;
+ case "9": return 9;
+ case "a": case "A": return 10;
+ case "b": case "B": return 11;
+ case "c": case "C": return 12;
+ case "d": case "D": return 13;
+ case "e": case "E": return 14;
+ case "f": case "F": return 15;
+ }
};
module.exports = function (data, options, handlers, control){
- var c;
- var code;
- var escape;
- var skipSpace = true;
- var isCommentLine;
- var isSectionLine;
- var newLine = true;
- var multiLine;
- var isKey = true;
- var key = "";
- var value = "";
- var section;
- var unicode;
- var unicodeRemaining;
- var escapingUnicode;
- var keySpace;
- var sep;
- var ignoreLine;
-
- var line = function (){
- if (key || value || sep){
- handlers.line (key, value);
- key = "";
- value = "";
- sep = false;
- }
- };
-
- var escapeString = function (key, c, code){
- if (escapingUnicode && unicodeRemaining){
- unicode = (unicode<<4) + hex (c);
- if (--unicodeRemaining) return key;
- escape = false;
- escapingUnicode = false;
- return key + String.fromCharCode (unicode);
- }
-
- //code 117: u
- if (code === 117){
- unicode = 0;
- escapingUnicode = true;
- unicodeRemaining = 4;
- return key;
- }
-
- escape = false;
-
- //code 116: t
- //code 114: r
- //code 110: n
- //code 102: f
- if (code === 116) return key + "\t";
- else if (code === 114) return key + "\r";
- else if (code === 110) return key + "\n";
- else if (code === 102) return key + "\f";
-
- return key + c;
- };
-
- var isComment;
- var isSeparator;
-
- if (options._strict){
- isComment = function (c, code, options){
- return options._comments[c];
- };
+ var c;
+ var code;
+ var escape;
+ var skipSpace = true;
+ var isCommentLine;
+ var isSectionLine;
+ var newLine = true;
+ var multiLine;
+ var isKey = true;
+ var key = "";
+ var value = "";
+ var section;
+ var unicode;
+ var unicodeRemaining;
+ var escapingUnicode;
+ var keySpace;
+ var sep;
+ var ignoreLine;
+
+ var line = function (){
+ if (key || value || sep){
+ handlers.line (key, value);
+ key = "";
+ value = "";
+ sep = false;
+ }
+ };
+
+ var escapeString = function (key, c, code){
+ if (escapingUnicode && unicodeRemaining){
+ unicode = (unicode<<4) + hex (c);
+ if (--unicodeRemaining) return key;
+ escape = false;
+ escapingUnicode = false;
+ return key + String.fromCharCode (unicode);
+ }
+
+ //code 117: u
+ if (code === 117){
+ unicode = 0;
+ escapingUnicode = true;
+ unicodeRemaining = 4;
+ return key;
+ }
+
+ escape = false;
+
+ //code 116: t
+ //code 114: r
+ //code 110: n
+ //code 102: f
+ if (code === 116) return key + "\t";
+ else if (code === 114) return key + "\r";
+ else if (code === 110) return key + "\n";
+ else if (code === 102) return key + "\f";
+
+ return key + c;
+ };
+
+ var isComment;
+ var isSeparator;
+
+ if (options._strict){
+ isComment = function (c, code, options){
+ return options._comments[c];
+ };
- isSeparator = function (c, code, options){
- return options._separators[c];
- };
- }else{
- isComment = function (c, code, options){
- //code 35: #
- //code 33: !
- return code === 35 || code === 33 || options._comments[c];
- };
+ isSeparator = function (c, code, options){
+ return options._separators[c];
+ };
+ }else{
+ isComment = function (c, code, options){
+ //code 35: #
+ //code 33: !
+ return code === 35 || code === 33 || options._comments[c];
+ };
- isSeparator = function (c, code, options){
- //code 61: =
- //code 58: :
- return code === 61 || code === 58 || options._separators[c];
- };
- }
-
- for (var i=~~control.resume, ii=data.length; i<ii; i++){
- if (control.abort) return;
- if (control.pause){
- //The next index is always the start of a new line, it's a like a fresh
- //start, there's no need to save the current state
- control.resume = i;
- return;
- }
-
- c = data[i];
- code = data.charCodeAt (i);
-
- //code 13: \r
- if (code === 13) continue;
-
- if (isCommentLine){
- //code 10: \n
- if (code === 10){
- isCommentLine = false;
- newLine = true;
- skipSpace = true;
- }
- continue;
- }
-
- //code 93: ]
- if (isSectionLine && code === 93){
- handlers.section (section);
- //Ignore chars after the section in the same line
- ignoreLine = true;
- continue;
- }
-
- if (skipSpace){
- //code 32: " " (space)
- //code 9: \t
- //code 12: \f
- if (code === 32 || code === 9 || code === 12){
- continue;
- }
- //code 10: \n
- if (!multiLine && code === 10){
- //Empty line or key w/ separator and w/o value
- isKey = true;
- keySpace = false;
- newLine = true;
- line ();
- continue;
- }
- skipSpace = false;
- multiLine = false;
- }
-
- if (newLine){
- newLine = false;
- if (isComment (c, code, options)){
- isCommentLine = true;
- continue;
- }
- //code 91: [
- if (options.sections && code === 91){
- section = "";
- isSectionLine = true;
- control.skipSection = false;
- continue;
- }
- }
-
- //code 10: \n
- if (code !== 10){
- if (control.skipSection || ignoreLine) continue;
-
- if (!isSectionLine){
- if (!escape && isKey && isSeparator (c, code, options)){
- //sep is needed to detect empty key and empty value with a
- //non-whitespace separator
- sep = true;
- isKey = false;
- keySpace = false;
- //Skip whitespace between separator and value
- skipSpace = true;
- continue;
- }
- }
-
- //code 92: "\" (backslash)
- if (code === 92){
- if (escape){
- if (escapingUnicode) continue;
-
- if (keySpace){
- //Line with whitespace separator
- keySpace = false;
- isKey = false;
- }
-
- if (isSectionLine) section += "\\";
- else if (isKey) key += "\\";
- else value += "\\";
- }
- escape = !escape;
- }else{
- if (keySpace){
- //Line with whitespace separator
- keySpace = false;
- isKey = false;
- }
-
- if (isSectionLine){
- if (escape) section = escapeString (section, c, code);
- else section += c;
- }else if (isKey){
- if (escape){
- key = escapeString (key, c, code);
- }else{
- //code 32: " " (space)
- //code 9: \t
- //code 12: \f
- if (code === 32 || code === 9 || code === 12){
- keySpace = true;
- //Skip whitespace between key and separator
- skipSpace = true;
- continue;
- }
- key += c;
- }
- }else{
- if (escape) value = escapeString (value, c, code);
- else value += c;
- }
- }
- }else{
- if (escape){
- if (!escapingUnicode){
- escape = false;
- }
- skipSpace = true;
- multiLine = true;
- }else{
- if (isSectionLine){
- isSectionLine = false;
- if (!ignoreLine){
- //The section doesn't end with ], it's a key
- control.error = new Error ("The section line \"" + section +
- "\" must end with \"]\"");
- return;
- }
- ignoreLine = false;
- }
- newLine = true;
- skipSpace = true;
- isKey = true;
-
- line ();
- }
- }
- }
-
- control.parsed = true;
-
- if (isSectionLine && !ignoreLine){
- //The section doesn't end with ], it's a key
- control.error = new Error ("The section line \"" + section + "\" must end" +
- "with \"]\"");
- return;
- }
- line ();
+ isSeparator = function (c, code, options){
+ //code 61: =
+ //code 58: :
+ return code === 61 || code === 58 || options._separators[c];
+ };
+ }
+
+ for (var i=~~control.resume, ii=data.length; i<ii; i++){
+ if (control.abort) return;
+ if (control.pause){
+ //The next index is always the start of a new line, it's a like a fresh
+ //start, there's no need to save the current state
+ control.resume = i;
+ return;
+ }
+
+ c = data[i];
+ code = data.charCodeAt (i);
+
+ //code 13: \r
+ if (code === 13) continue;
+
+ if (isCommentLine){
+ //code 10: \n
+ if (code === 10){
+ isCommentLine = false;
+ newLine = true;
+ skipSpace = true;
+ }
+ continue;
+ }
+
+ //code 93: ]
+ if (isSectionLine && code === 93){
+ handlers.section (section);
+ //Ignore chars after the section in the same line
+ ignoreLine = true;
+ continue;
+ }
+
+ if (skipSpace){
+ //code 32: " " (space)
+ //code 9: \t
+ //code 12: \f
+ if (code === 32 || code === 9 || code === 12){
+ continue;
+ }
+ //code 10: \n
+ if (!multiLine && code === 10){
+ //Empty line or key w/ separator and w/o value
+ isKey = true;
+ keySpace = false;
+ newLine = true;
+ line ();
+ continue;
+ }
+ skipSpace = false;
+ multiLine = false;
+ }
+
+ if (newLine){
+ newLine = false;
+ if (isComment (c, code, options)){
+ isCommentLine = true;
+ continue;
+ }
+ //code 91: [
+ if (options.sections && code === 91){
+ section = "";
+ isSectionLine = true;
+ control.skipSection = false;
+ continue;
+ }
+ }
+
+ //code 10: \n
+ if (code !== 10){
+ if (control.skipSection || ignoreLine) continue;
+
+ if (!isSectionLine){
+ if (!escape && isKey && isSeparator (c, code, options)){
+ //sep is needed to detect empty key and empty value with a
+ //non-whitespace separator
+ sep = true;
+ isKey = false;
+ keySpace = false;
+ //Skip whitespace between separator and value
+ skipSpace = true;
+ continue;
+ }
+ }
+
+ //code 92: "\" (backslash)
+ if (code === 92){
+ if (escape){
+ if (escapingUnicode) continue;
+
+ if (keySpace){
+ //Line with whitespace separator
+ keySpace = false;
+ isKey = false;
+ }
+
+ if (isSectionLine) section += "\\";
+ else if (isKey) key += "\\";
+ else value += "\\";
+ }
+ escape = !escape;
+ }else{
+ if (keySpace){
+ //Line with whitespace separator
+ keySpace = false;
+ isKey = false;
+ }
+
+ if (isSectionLine){
+ if (escape) section = escapeString (section, c, code);
+ else section += c;
+ }else if (isKey){
+ if (escape){
+ key = escapeString (key, c, code);
+ }else{
+ //code 32: " " (space)
+ //code 9: \t
+ //code 12: \f
+ if (code === 32 || code === 9 || code === 12){
+ keySpace = true;
+ //Skip whitespace between key and separator
+ skipSpace = true;
+ continue;
+ }
+ key += c;
+ }
+ }else{
+ if (escape) value = escapeString (value, c, code);
+ else value += c;
+ }
+ }
+ }else{
+ if (escape){
+ if (!escapingUnicode){
+ escape = false;
+ }
+ skipSpace = true;
+ multiLine = true;
+ }else{
+ if (isSectionLine){
+ isSectionLine = false;
+ if (!ignoreLine){
+ //The section doesn't end with ], it's a key
+ control.error = new Error ("The section line \"" + section +
+ "\" must end with \"]\"");
+ return;
+ }
+ ignoreLine = false;
+ }
+ newLine = true;
+ skipSpace = true;
+ isKey = true;
+
+ line ();
+ }
+ }
+ }
+
+ control.parsed = true;
+
+ if (isSectionLine && !ignoreLine){
+ //The section doesn't end with ], it's a key
+ control.error = new Error ("The section line \"" + section + "\" must end" +
+ "with \"]\"");
+ return;
+ }
+ line ();
};
View
802 lib/read.js
@@ -8,426 +8,426 @@ var INCLUDE_KEY = "include";
var INDEX_FILE = "index.properties";
var cast = function (value){
- if (value === null || value === "null") return null;
- if (value === "undefined") return undefined;
- if (value === "true") return true;
- if (value === "false") return false;
- var v = Number (value);
- return isNaN (v) ? value : v;
+ if (value === null || value === "null") return null;
+ if (value === "undefined") return undefined;
+ if (value === "true") return true;
+ if (value === "false") return false;
+ var v = Number (value);
+ return isNaN (v) ? value : v;
};
var expand = function (o, str, options, cb){
- if (!options.variables || !str) return cb (null, str);
-
- var stack = [];
- var c;
- var cp;
- var key = "";
- var section = null;
- var v;
- var holder;
- var t;
- var n;
-
- for (var i=0, ii=str.length; i<ii; i++){
- c = str[i];
-
- if (cp === "$" && c === "{"){
- key = key.substring (0, key.length - 1);
- stack.push ({
- key: key,
- section: section
- });
- key = "";
- section = null;
- continue;
- }else if (stack.length){
- if (options.sections && c === "|"){
- section = key;
- key = "";
- continue;
- }else if (c === "}"){
- holder = section !== null ? o[section] : o;
- if (!holder){
- return cb (new Error ("The section \"" + section + "\" does not " +
- "exist"));
- }
-
- v = holder[key];
- if (v === undefined){
- //Read the external vars
- if (options.namespaces){
- v = namespaceValue (options._vars, key);
- }else{
- v = options._vars[key];
- }
-
- if (v === undefined){
- return cb (new Error ("The property \"" + key + "\" does not " +
- "exist"));
- }
- }
-
- t = stack.pop ();
- section = t.section;
- key = t.key + (v === null ? "" : v);
- continue;
- }
- }
-
- cp = c;
- key += c;
- }
-
- if (stack.length !== 0){
- return cb (new Error ("Malformed variable: " + str));
- }
-
- cb (null, key);
+ if (!options.variables || !str) return cb (null, str);
+
+ var stack = [];
+ var c;
+ var cp;
+ var key = "";
+ var section = null;
+ var v;
+ var holder;
+ var t;
+ var n;
+
+ for (var i=0, ii=str.length; i<ii; i++){
+ c = str[i];
+
+ if (cp === "$" && c === "{"){
+ key = key.substring (0, key.length - 1);
+ stack.push ({
+ key: key,
+ section: section
+ });
+ key = "";
+ section = null;
+ continue;
+ }else if (stack.length){
+ if (options.sections && c === "|"){
+ section = key;
+ key = "";
+ continue;
+ }else if (c === "}"){
+ holder = section !== null ? o[section] : o;
+ if (!holder){
+ return cb (new Error ("The section \"" + section + "\" does not " +
+ "exist"));
+ }
+
+ v = holder[key];
+ if (v === undefined){
+ //Read the external vars
+ if (options.namespaces){
+ v = namespaceValue (options._vars, key);
+ }else{
+ v = options._vars[key];
+ }
+
+ if (v === undefined){
+ return cb (new Error ("The property \"" + key + "\" does not " +
+ "exist"));
+ }
+ }
+
+ t = stack.pop ();
+ section = t.section;
+ key = t.key + (v === null ? "" : v);
+ continue;
+ }
+ }
+
+ cp = c;
+ key += c;
+ }
+
+ if (stack.length !== 0){
+ return cb (new Error ("Malformed variable: " + str));
+ }
+
+ cb (null, key);
};
var namespaceValue = function (p, key){
- var n = key.split (".");
- var str;
-
- for (var i=0, ii=n.length-1; i<ii; i++){
- str = n[i];
- if (p[str] === undefined) return;
- p = p[str];
- }
-
- return p[n[n.length - 1]];
+ var n = key.split (".");
+ var str;
+
+ for (var i=0, ii=n.length-1; i<ii; i++){
+ str = n[i];
+ if (p[str] === undefined) return;
+ p = p[str];
+ }
+
+ return p[n[n.length - 1]];
};
var namespace = function (p, key, value){
- var n = key.split (".");
- var str;
-
- for (var i=0, ii=n.length-1; i<ii; i++){
- str = n[i];
- if (p[str] === undefined){
- p[str] = {};
- }else if (typeof p[str] !== "object"){
- return new Error ("Invalid namespace chain, the key must contain an " +
- "object: " + key);
- }
- p = p[str];
- }
-
- p[n[n.length - 1]] = value;
+ var n = key.split (".");
+ var str;
+
+ for (var i=0, ii=n.length-1; i<ii; i++){
+ str = n[i];
+ if (p[str] === undefined){
+ p[str] = {};
+ }else if (typeof p[str] !== "object"){
+ return new Error ("Invalid namespace chain, the key must contain an " +
+ "object: " + key);
+ }
+ p = p[str];
+ }
+
+ p[n[n.length - 1]] = value;
};
var merge = function (o1, o2){
- for (var p in o2){
- try{
- if (o1[p].constructor === Object){
- o1[p] = merge (o1[p], o2[p]);
- }else{
- o1[p] = o2[p];
- }
- }catch (e){
- o1[p] = o2[p];
- }
- }
- return o1;
+ for (var p in o2){
+ try{
+ if (o1[p].constructor === Object){
+ o1[p] = merge (o1[p], o2[p]);
+ }else{
+ o1[p] = o2[p];
+ }
+ }catch (e){
+ o1[p] = o2[p];
+ }
+ }
+ return o1;
}
var build = function (data, options, dirname, cb){
- var o = {};
-
- if (options.namespaces){
- var n = {};
- }
-
- var control = {
- abort: false,
- skipSection: false
- };
-
- if (options.include){
- var remainingIncluded = 0;
-
- var include = function (value){
- if (currentSection !== null){
- return abort (new Error ("Cannot include files from inside a " +
- "section: " + currentSection));
- }
-
- var p = path.resolve (dirname, value);
- if (options._included[p]) return;
-
- options._included[p] = true;
- remainingIncluded++;
- control.pause = true;
-
- read (p, options, function (error, included){
- if (error) return abort (error);
-
- remainingIncluded--;
- merge (options.namespaces ? n : o, included);
- control.pause = false;
-
- if (!control.parsed){
- parse (data, options, handlers, control);
- if (control.error) return abort (control.error);
- }
-
- if (!remainingIncluded) cb (null, options.namespaces ? n : o);
- });
- };
- }
-
- if (!data){
- if (cb) return cb (null, o);
- return o;
- }
-
- var currentSection = null;
-
- var abort = function (error){
- control.abort = true;
- if (cb) return cb (error);
- throw error;
- };
-
- var handlers = {};
- var reviver = {
- assert: function (){
- return this.isProperty ? reviverLine.value : true;
- }
- };
- var reviverLine = {};
-
- //Line handler
- //For speed reasons, if namespaces are enabled the old object is still
- //populated, e.g.: ${a.b} reads the "a.b" property from { "a.b": 1 }, instead
- //of having a unique object { a: { b: 1 } } which is slower to search for
- //the "a.b" value
- //If "a.b" is not found, then the external vars are read. If "namespaces" is
- //enabled the var "a.b" is split and it searches for a.b. If it is not enabled
- //then the var "a.b" searches for "a.b"
-
- var line;
- var error;
-
- if (options.reviver){
- if (options.sections){
- line = function (key, value){
- if (options.include && key === INCLUDE_KEY) return include (value);
-
- reviverLine.value = value;
- reviver.isProperty = true;
- reviver.isSection = false;
-
- value = options.reviver.call (reviver, key, value, currentSection);
- if (value !== undefined){
- if (currentSection === null) o[key] = value;
- else o[currentSection][key] = value;
-
- if (options.namespaces){
- error = namespace (currentSection === null ? n : n[currentSection],
- key, value);
- if (error) abort (error);
- }
- }
- };
- }else{
- line = function (key, value){
- if (options.include && key === INCLUDE_KEY) return include (value);
-
- reviverLine.value = value;
- reviver.isProperty = true;
- reviver.isSection = false;
-
- value = options.reviver.call (reviver, key, value);
- if (value !== undefined){
- o[key] = value;
-
- if (options.namespaces){
- error = namespace (n, key, value);
- if (error) abort (error);
- }
- }
- };
- }
- }else{
- if (options.sections){
- line = function (key, value){
- if (options.include && key === INCLUDE_KEY) return include (value);
-
- if (currentSection === null) o[key] = value;
- else o[currentSection][key] = value;
-
- if (options.namespaces){
- error = namespace (currentSection === null ? n : n[currentSection],
- key, value);
- if (error) abort (error);
- }
- };
- }else{
- line = function (key, value){
- if (options.include && key === INCLUDE_KEY) return include (value);
-
- o[key] = value;
-
- if (options.namespaces){
- error = namespace (n, key, value);
- if (error) abort (error);
- }
- };
- }
- }
-
- //Section handler
- var section;
- if (options.sections){
- if (options.reviver){
- section = function (section){
- reviverLine.section = section;
- reviver.isProperty = false;
- reviver.isSection = true;
-
- var add = options.reviver.call (reviver, null, null, section);
- if (add){
- currentSection = section;
- o[currentSection] = {};
-
- if (options.namespaces){
- n[currentSection] = {};
- }
- }else{
- control.skipSection = true;
- }
- };
- }else{
- section = function (section){
- currentSection = section;
- o[currentSection] = {};
-
- if (options.namespaces){
- n[currentSection] = {};
- }
- };
- }
- }
-
- //Variables
- if (options.variables){
- handlers.line = function (key, value){
- expand (o, key, options, function (error, key){
- if (error) return abort (error);
-
- expand (o, value, options, function (error, value){
- if (error) return abort (error);
-
- line (key, cast (value || null));
- });
- });
- };
-
- if (options.sections){
- handlers.section = function (s){
- expand (o, s, options, function (error, s){
- if (error) return abort (error);
-
- section (s);
- });
- };
- }
- }else{
- handlers.line = function (key, value){
- line (key, cast (value || null));
- };
-
- if (options.sections){
- handlers.section = section;
- }
- }
-
- parse (data, options, handlers, control);
- if (control.error) return abort (control.error);
-
- if (control.abort || control.pause) return;
-
- if (cb) return cb (null, options.namespaces ? n : o);
- return options.namespaces ? n : o;
+ var o = {};
+
+ if (options.namespaces){
+ var n = {};
+ }
+
+ var control = {
+ abort: false,
+ skipSection: false
+ };
+
+ if (options.include){
+ var remainingIncluded = 0;
+
+ var include = function (value){
+ if (currentSection !== null){
+ return abort (new Error ("Cannot include files from inside a " +
+ "section: " + currentSection));
+ }
+
+ var p = path.resolve (dirname, value);
+ if (options._included[p]) return;
+
+ options._included[p] = true;
+ remainingIncluded++;
+ control.pause = true;
+
+ read (p, options, function (error, included){
+ if (error) return abort (error);
+
+ remainingIncluded--;
+ merge (options.namespaces ? n : o, included);
+ control.pause = false;
+
+ if (!control.parsed){
+ parse (data, options, handlers, control);
+ if (control.error) return abort (control.error);
+ }
+
+ if (!remainingIncluded) cb (null, options.namespaces ? n : o);
+ });
+ };
+ }
+
+ if (!data){
+ if (cb) return cb (null, o);
+ return o;
+ }
+
+ var currentSection = null;
+
+ var abort = function (error){
+ control.abort = true;
+ if (cb) return cb (error);
+ throw error;
+ };
+
+ var handlers = {};
+ var reviver = {
+ assert: function (){
+ return this.isProperty ? reviverLine.value : true;
+ }
+ };
+ var reviverLine = {};
+
+ //Line handler
+ //For speed reasons, if namespaces are enabled the old object is still
+ //populated, e.g.: ${a.b} reads the "a.b" property from { "a.b": 1 }, instead
+ //of having a unique object { a: { b: 1 } } which is slower to search for
+ //the "a.b" value
+ //If "a.b" is not found, then the external vars are read. If "namespaces" is
+ //enabled the var "a.b" is split and it searches for a.b. If it is not enabled
+ //then the var "a.b" searches for "a.b"
+
+ var line;
+ var error;
+
+ if (options.reviver){
+ if (options.sections){
+ line = function (key, value){
+ if (options.include && key === INCLUDE_KEY) return include (value);
+
+ reviverLine.value = value;
+ reviver.isProperty = true;
+ reviver.isSection = false;
+
+ value = options.reviver.call (reviver, key, value, currentSection);
+ if (value !== undefined){
+ if (currentSection === null) o[key] = value;
+ else o[currentSection][key] = value;
+
+ if (options.namespaces){
+ error = namespace (currentSection === null ? n : n[currentSection],
+ key, value);
+ if (error) abort (error);
+ }
+ }
+ };
+ }else{
+ line = function (key, value){
+ if (options.include && key === INCLUDE_KEY) return include (value);
+
+ reviverLine.value = value;
+ reviver.isProperty = true;
+ reviver.isSection = false;
+
+ value = options.reviver.call (reviver, key, value);
+ if (value !== undefined){
+ o[key] = value;
+
+ if (options.namespaces){
+ error = namespace (n, key, value);
+ if (error) abort (error);
+ }
+ }
+ };
+ }
+ }else{
+ if (options.sections){
+ line = function (key, value){
+ if (options.include && key === INCLUDE_KEY) return include (value);
+
+ if (currentSection === null) o[key] = value;
+ else o[currentSection][key] = value;
+
+ if (options.namespaces){
+ error = namespace (currentSection === null ? n : n[currentSection],
+ key, value);
+ if (error) abort (error);
+ }
+ };
+ }else{
+ line = function (key, value){
+ if (options.include && key === INCLUDE_KEY) return include (value);
+
+ o[key] = value;
+
+ if (options.namespaces){
+ error = namespace (n, key, value);
+ if (error) abort (error);
+ }
+ };
+ }
+ }
+
+ //Section handler
+ var section;
+ if (options.sections){
+ if (options.reviver){
+ section = function (section){
+ reviverLine.section = section;
+ reviver.isProperty = false;
+ reviver.isSection = true;
+
+ var add = options.reviver.call (reviver, null, null, section);
+ if (add){
+ currentSection = section;
+ o[currentSection] = {};
+
+ if (options.namespaces){
+ n[currentSection] = {};
+ }
+ }else{
+ control.skipSection = true;
+ }
+ };
+ }else{
+ section = function (section){
+ currentSection = section;
+ o[currentSection] = {};
+
+ if (options.namespaces){
+ n[currentSection] = {};
+ }
+ };
+ }
+ }
+
+ //Variables
+ if (options.variables){
+ handlers.line = function (key, value){
+ expand (o, key, options, function (error, key){
+ if (error) return abort (error);
+
+ expand (o, value, options, function (error, value){
+ if (error) return abort (error);
+
+ line (key, cast (value || null));
+ });
+ });
+ };
+
+ if (options.sections){
+ handlers.section = function (s){
+ expand (o, s, options, function (error, s){
+ if (error) return abort (error);
+
+ section (s);
+ });
+ };
+ }
+ }else{
+ handlers.line = function (key, value){
+ line (key, cast (value || null));
+ };
+
+ if (options.sections){
+ handlers.section = section;
+ }
+ }
+
+ parse (data, options, handlers, control);
+ if (control.error) return abort (control.error);
+
+ if (control.abort || control.pause) return;
+
+ if (cb) return cb (null, options.namespaces ? n : o);
+ return options.namespaces ? n : o;
};
var read = function (f, options, cb){
- fs.stat (f, function (error, stats){
- if (error) return cb (error);
-
- var dirname;
-
- if (stats.isDirectory ()){
- dirname = f;
- f = path.join (f, INDEX_FILE);
- }else{
- dirname = path.dirname (f);
- }
-
- fs.readFile (f, { encoding: "utf8" }, function (error, data){
- if (error) return cb (error);
- build (data, options, dirname, cb);
- });
- });
+ fs.stat (f, function (error, stats){
+ if (error) return cb (error);
+
+ var dirname;
+
+ if (stats.isDirectory ()){
+ dirname = f;
+ f = path.join (f, INDEX_FILE);
+ }else{
+ dirname = path.dirname (f);
+ }
+
+ fs.readFile (f, { encoding: "utf8" }, function (error, data){
+ if (error) return cb (error);
+ build (data, options, dirname, cb);
+ });
+ });
};
module.exports = function (data, options, cb){
- if (typeof options === "function"){
- cb = options;
- options = {};
- }
-
- options = options || {};
- var code;
-
- if (options.include){
- options._included = {};
- }
-
- options = options || {};
- options._strict = options.strict && (options.comments || options.separators);
- options._vars = options.vars || {};
-
- var comments = options.comments || [];
- if (!Array.isArray (comments)) comments = [comments];
- var c = {};
- comments.forEach (function (comment){
- code = comment.charCodeAt (0);
- if (comment.length > 1 || code < 33 || code > 126){
- throw new Error ("The comment token must be a single printable ASCII " +
- "character");
- }
- c[comment] = true;
- });
- options._comments = c;
-
- var separators = options.separators || [];
- if (!Array.isArray (separators)) separators = [separators];
- var s = {};
- separators.forEach (function (separator){
- code = separator.charCodeAt (0);
- if (separator.length > 1 || code < 33 || code > 126){
- throw new Error ("The separator token must be a single printable ASCII " +
- "character");
- }
- s[separator] = true;
- });
- options._separators = s;
-
- if (options.path){
- if (!cb) throw new Error ("A callback must be passed if the data is a " +
- "path");
- if (options.include){
- read (data, options, cb);
- }else{
- fs.readFile (data, { encoding: "utf8" }, function (error, data){
- if (error) return cb (error);
- build (data, options, ".", cb);
- });
- }
- }else{
- return build (data, options, ".", cb);
- }
+ if (typeof options === "function"){
+ cb = options;
+ options = {};
+ }
+
+ options = options || {};
+ var code;
+
+ if (options.include){
+ options._included = {};
+ }
+
+ options = options || {};
+ options._strict = options.strict && (options.comments || options.separators);
+ options._vars = options.vars || {};
+
+ var comments = options.comments || [];
+ if (!Array.isArray (comments)) comments = [comments];
+ var c = {};
+ comments.forEach (function (comment){
+ code = comment.charCodeAt (0);
+ if (comment.length > 1 || code < 33 || code > 126){
+ throw new Error ("The comment token must be a single printable ASCII " +
+ "character");
+ }
+ c[comment] = true;
+ });
+ options._comments = c;
+
+ var separators = options.separators || [];
+ if (!Array.isArray (separators)) separators = [separators];
+ var s = {};
+ separators.forEach (function (separator){
+ code = separator.charCodeAt (0);
+ if (separator.length > 1 || code < 33 || code > 126){
+ throw new Error ("The separator token must be a single printable ASCII " +
+ "character");
+ }
+ s[separator] = true;
+ });
+ options._separators = s;
+
+ if (options.path){
+ if (!cb) throw new Error ("A callback must be passed if the data is a " +
+ "path");
+ if (options.include){
+ read (data, options, cb);
+ }else{
+ fs.readFile (data, { encoding: "utf8" }, function (error, data){
+ if (error) return cb (error);
+ build (data, options, ".", cb);
+ });
+ }
+ }else{
+ return build (data, options, ".", cb);
+ }
};
View
26 lib/stringifier.js
@@ -1,26 +1,26 @@
"use strict";
var Stringifier = module.exports = function (){
- this._header = null;
- this._lines = [];
+ this._header = null;
+ this._lines = [];
};
Stringifier.prototype.header = function (comment){
- this._header = comment;
- return this;
+ this._header = comment;
+ return this;
};
Stringifier.prototype.property = function (p){
- p.property = true;
- this._lines.push (p);
- return this;
+ p.property = true;
+ this._lines.push (p);
+ return this;
};
Stringifier.prototype.section = function (p){
- if (typeof p === "string"){
- p = { name: p };
- }
- p.section = true;
- this._lines.push (p);
- return this;
+ if (typeof p === "string"){
+ p = { name: p };
+ }
+ p.section = true;
+ this._lines.push (p);
+ return this;
};
View
368 lib/stringify.js
@@ -9,204 +9,204 @@ var Stringifier = require ("./stringifier");
var EOL = process.platform === "win32" ? "\r\n" : "\n";
var stringifyComment = function (comment, meta, options){
- var c;
- var code;
- var str = options._comment;
-
- for (var i=0, ii=comment.length; i<ii; i++){
- c = comment[i];
- code = comment.charCodeAt (i);
-
- //code 13: \r
- if (code === 13) continue;
-
- if (code === 10){
- //code 10: \n
- str += EOL + options._comment;
- }else{
- str += escape (c, code, meta, options);
- }
- }
-
- return str;
+ var c;
+ var code;
+ var str = options._comment;
+