aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2018-02-01 14:22:43 +0100
committerache <ache@ache.one>2018-02-01 14:22:43 +0100
commitef53d5643a78fb9b6fbac270cbfba67351c58033 (patch)
tree2e803ae484b7ce6c455491e5861b43f4ccb3cd9c
parentWTF with classes (diff)
Clean of the code with xo linter
-rw-r--r--app.js216
-rw-r--r--package.json5
2 files changed, 99 insertions, 122 deletions
diff --git a/app.js b/app.js
index 24f0254..4e33c09 100644
--- a/app.js
+++ b/app.js
@@ -1,144 +1,119 @@
'use strict';
-
const START = '[__';
-const END = '__]';
+const END = '__]';
function locator(value, fromIndex) {
- var index = value.indexOf(START, fromIndex);
+ const index = value.indexOf(START, fromIndex);
return index;
}
-function prop2HTML( prop ) {
- let html = '';
-
- if( 'id' in prop && prop['id'] ) {
- html += 'id=' + prop['id'];
- }
- if( 'class' in prop ) {
- if( html ) html += ' '
- html='class="' + prop['class'].join(' ') + '"';
- }
- if( 'key' in prop ) {
- Object.entries(prop['key']).forEach(
- (key, value) => {
- if(html) html += ' '
- if(value) {
- html += key+'"'+value+'"';
- }else{
- html +=key
- }
- }
- )
- }
-
- return html
-}
-
-function parseHTMLparam( value, indexNext ) {
- let lets_eat = "{";
+function parseHTMLparam(value, indexNext) {
+ let letsEat = '{';
indexNext++;
- const eat = ( ( chars ) => {
- let eaten = ""
- while(chars.indexOf(value.charAt(indexNext)) >= 0) {
- lets_eat+=value.charAt(indexNext);
- eaten +=value.charAt(indexNext);
+ const eat = (chars => {
+ let eaten = '';
+ while (chars.indexOf(value.charAt(indexNext)) >= 0) {
+ letsEat += value.charAt(indexNext);
+ eaten += value.charAt(indexNext);
indexNext++;
}
return eaten;
});
- const eat_until = ( ( chars ) => {
- let eaten = ""
- while(chars.indexOf(value.charAt(indexNext)) < 0) {
- lets_eat+=value.charAt(indexNext);
- eaten +=value.charAt(indexNext);
+ const eatUntil = (chars => {
+ let eaten = '';
+ while (chars.indexOf(value.charAt(indexNext)) < 0) {
+ letsEat += value.charAt(indexNext);
+ eaten += value.charAt(indexNext);
indexNext++;
}
return eaten;
});
-
-
- let prop = {key:undefined /* {} */, 'class':undefined /*[]*/,id:undefined /*""*/}
+ const prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined};
let type;
-
- while(true) {
- let labelFirst = "";
- let labelSecond = undefined;
+
+ while (value.charAt(indexNext) !== '}') {
+ let labelFirst = '';
+ let labelSecond;
eat(' \t\n\r\v');
- if( value.charAt(indexNext) == '}' ) { // Fin l'accolade
- break;
- } else if( value.charAt(indexNext) == '.' ) { // Classes
+ if (value.charAt(indexNext) === '}') { // Fin l'accolade
+ continue;
+ } else if (value.charAt(indexNext) === '.') { // Classes
type = 'class';
indexNext++;
- lets_eat+='.'
- } else if( value.charAt(indexNext) == '#' ) { // ID
+ letsEat += '.';
+ } else if (value.charAt(indexNext) === '#') { // ID
type = 'id';
indexNext++;
- lets_eat+='#'
+ letsEat += '#';
} else { // Key
type = 'key';
}
// Extract name
- labelFirst = eat_until( '=\t\b\r\v  }')
+ labelFirst = eatUntil('=\t\b\r\v  }');
- if( value.charAt(indexNext) == '=' ) { // Set labelSecond
+ if (value.charAt(indexNext) === '=') { // Set labelSecond
indexNext++;
- lets_eat+='=';
+ letsEat += '=';
- if( value.charAt(indexNext) == '"' ) {
+ if (value.charAt(indexNext) === '"') {
indexNext++;
- lets_eat+='"';
- labelSecond = eat_until('"}\n')
+ letsEat += '"';
+ labelSecond = eatUntil('"}\n');
- if( value.charAt(indexNext) != '"' ) {
- // Erreur
- }else{
+ if (value.charAt(indexNext) === '"') {
indexNext++;
- lets_eat+='"';
+ letsEat += '"';
+ } else {
+ // Erreur
}
- } else if( value.charAt(indexNext) == "'" ) {
+ } else if (value.charAt(indexNext) === '\'') {
indexNext++;
- lets_eat+="'";
- labelSecond = eat_until("'}\n")
+ letsEat += '\'';
+ labelSecond = eatUntil('\'}\n');
- if( value.charAt(indexNext) !="'" ) {
- // Erreur
- }else{
+ if (value.charAt(indexNext) === '\'') {
indexNext++;
- lets_eat+="'";
+ letsEat += '\'';
+ } else {
+ // Erreur
}
} else {
- labelSecond = eat_until(' \t\n\r\v=}');
+ labelSecond = eatUntil(' \t\n\r\v=}');
}
}
- switch( type ) {
+ switch (type) {
case 'id': // ID
- prop['id']=labelFirst;
- break;
+ prop.id = labelFirst;
+ break;
case 'class':
- if( ! prop['class'] )
- prop['class'] = []
- prop['class'].push(labelFirst);
- break;
+ if (!prop.class) {
+ prop.class = [];
+ }
+ prop.class.push(labelFirst);
+ break;
case 'key':
- if( labelFirst != 'id' && labelFirst != 'class' )
- prop[labelFirst] = labelSecond ? labelSecond : '';
- break;
- }
- if( labelSecond )
- console.log("{{" + labelFirst + "=" + labelSecond + "}}");
- else
- console.log("{{" + labelFirst + "}}");
- }
- lets_eat+="}";
+ if (labelFirst !== 'id' && labelFirst !== 'class') {
+ prop[labelFirst] = labelSecond ? labelSecond : '';
+ }
+ break;
+ default:
- return {type:type, prop:prop, eaten:lets_eat};
+ }
+ if (labelSecond) {
+ console.log('{{' + labelFirst + '=' + labelSecond + '}}');
+ } else {
+ console.log('{{' + labelFirst + '}}');
+ }
+ }
+ letsEat += '}';
+ return {type, prop, eaten: letsEat};
}
function plugin() {
@@ -147,69 +122,68 @@ function plugin() {
return;
}
- var character = '';
- var previous = '';
- var preceding = '';
- var subvalue = '';
- var index = 1;
- var length = value.length;
- var now = eat.now();
+ let subvalue = '';
+ let index = 1;
+ const length = value.length;
+ const now = eat.now();
now.column += 2;
now.offset += 2;
while (!value.startsWith(END, index) && ++index < length) {
- subvalue+=value.charAt(index);
- if( value.charAt(index) == '\n' )
+ subvalue += value.charAt(index);
+ if (value.charAt(index) === '\n') {
return true;
-
+ }
}
- let lets_eat = ""
- let prop = {key:undefined /* {} */, 'class':undefined /*[]*/,id:undefined /*""*/}
- if( value.charAt(index+END.length) == '{' ) {
- let res = parseHTMLparam( value, index+END.length)
- lets_eat = res.eaten;
+ let letsEat = '';
+ let prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined};
+ if (value.charAt(index + END.length) === '{') {
+ const res = parseHTMLparam(value, index + END.length);
+ letsEat = res.eaten;
console.log(res.eaten);
- prop=res.prop
+ prop = res.prop;
}
/* istanbul ignore if - never used (yet) */
- if (silent) return true;
+ if (silent) {
+ return true;
+ }
- if( prop['type'] != 'password' )
- prop['type'] = 'text';
+ if (prop.type !== 'password') {
+ prop.type = 'text';
+ }
- prop['placeholder'] = subvalue.replace(/^_*/g, '').replace(/_*$/g, ''),
+ prop.placeholder = subvalue.replace(/^_*/g, '').replace(/_*$/g, '');
console.log(prop);
- if( index < length )
- return eat(START + subvalue.slice(1) + END.slice(1)+lets_eat)({
+ if (index < length) {
+ return eat(START + subvalue.slice(1) + END.slice(1) + letsEat)({
type: 'line-input',
children: [],
data: {
hName: 'input',
- hProperties: prop
+ hProperties: prop
}
});
- else
- return true;
-
+ }
+ return true;
}
inlineTokenizer.locator = locator;
- var Parser = this.Parser;
+ const Parser = this.Parser;
// Inject inlineTokenizer
- var inlineTokenizers = Parser.prototype.inlineTokenizers;
- var inlineMethods = Parser.prototype.inlineMethods;
+ const inlineTokenizers = Parser.prototype.inlineTokenizers;
+ const inlineMethods = Parser.prototype.inlineMethods;
inlineTokenizers.input = inlineTokenizer;
inlineMethods.splice(inlineMethods.indexOf('url'), 0, 'input');
- var Compiler = this.Compiler;
+ const Compiler = this.Compiler;
// Stringify
if (Compiler) {
- var visitors = Compiler.prototype.visitors;
+ const visitors = Compiler.prototype.visitors;
visitors.lineinput = function (node) {
return '[__' + this.all(node).join('') + '__]';
};
diff --git a/package.json b/package.json
index c28d895..7522f46 100644
--- a/package.json
+++ b/package.json
@@ -15,5 +15,8 @@
"line",
"input",
"remark"
- ]
+ ],
+ "devDependencies": {
+ "xo": "^0.18.2"
+ }
}