aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2018-07-23 09:40:11 +0200
committerache <ache@ache.one>2018-07-23 09:40:11 +0200
commit586d110186fe2abe6e35a1051bef2e6b35818c8d (patch)
tree4c32b322664dfc8c6627079c813413ad4998590f
parentMerge pull request #2 from Hypercubed/fix/spelling (diff)
default value config for attributes without value
-rw-r--r--src/index.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/index.js b/src/index.js
index ec155c3..8d65e40 100644
--- a/src/index.js
+++ b/src/index.js
@@ -11,11 +11,23 @@ const nothingHappend = {
eaten: '',
};
+const defaultConfig = {
+ defaultValue: () => undefined, // It's a function
+};
+
// Main function
-function parse(value, indexNext) {
+function parse(value, indexNext, userConfig) {
let letsEat = '';
let stopOnBrace = false;
let errorDetected = false;
+ let config = {...defaultConfig, ...userConfig};
+
+
+ // Make defaultValue a function if it isn't
+ if( typeof(config.defaultValue) != "function" ) {
+ const {defaultValue} = config;
+ config.defaultValue = () => defaultValue;
+ }
const prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined};
@@ -33,7 +45,7 @@ function parse(value, indexNext) {
* .azcv <- class
* #poi <- id
* dfgh=zert <- key
- * jkj <- this is also a key but with a undefined value
+ * jkj <- this is also a key but with a user defined value (default is undefined)
* jkj= <- this is also a key but with a empty value
*/
let type;
@@ -150,7 +162,12 @@ function parse(value, indexNext) {
return nothingHappend;
}
if (labelFirst !== 'id' && labelFirst !== 'class') {
- prop[labelFirst] = labelSecond;
+ if( labelSecond != undefined ) {
+ prop[labelFirst] = labelSecond;
+ } else { // Here, we have a attribute without value
+ // so it's user defined
+ prop[labelFirst] = config.defaultValue(labelFirst);
+ }
}
break;
default: