From c0028e1349f71077e47f85d52f6f37d3ef822cde Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 30 Apr 2018 07:46:12 +0200 Subject: Use babel to transcompil --- .babelrc | 3 +++ dist/index.js | 20 +++++++++++--------- src/index.js | 34 +++++++++++++++++----------------- 3 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..002b4aa --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["env"] +} diff --git a/dist/index.js b/dist/index.js index 4f1e925..c3b4a9e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -24,9 +24,11 @@ function parse(value, indexNext) { /* ekqsdf <- one label * qsdfqsfd=qsdfqsdf <- two */ var labelFirst = ''; - var labelSecond; + var labelSecond = void 0; - if (indexNext === undefined) indexNext = 0; + if (indexNext === undefined) { + indexNext = 0; + } /* 3 types : * .azcv <- class @@ -35,11 +37,11 @@ function parse(value, indexNext) { * jkj <- this is also a key but with a undefined value * jkj= <- this is also a key but with a empty value */ - var type; + var type = void 0; var forbidenCharacters = '\n\r{}'; // A function that detect if it's time to end the parsing - var shouldStop = function () { + var shouldStop = function shouldStop() { if (indexNext >= value.length || forbidenCharacters.indexOf(value[indexNext]) > -1) { if (stopOnBrace && value[indexNext] !== '}') { errorDetected = true; @@ -52,7 +54,7 @@ function parse(value, indexNext) { var eaten = ''; // Couple of functions that parse same kinds of characters // Used to parse spaces or identifiers - var eat = function (chars) { + var eat = function eat(chars) { eaten = ''; while (indexNext < value.length && forbidenCharacters.indexOf(value.charAt(indexNext)) < 0 && chars.indexOf(value.charAt(indexNext)) >= 0) { @@ -63,7 +65,7 @@ function parse(value, indexNext) { return shouldStop(); }; - var eatUntil = function (chars) { + var eatUntil = function eatUntil(chars) { eaten = ''; while (indexNext < value.length && forbidenCharacters.indexOf(value.charAt(indexNext)) < 0 && chars.indexOf(value.charAt(indexNext)) < 0) { @@ -85,7 +87,7 @@ function parse(value, indexNext) { // In quote, every character is valid exept the unescaped quotes and CR or LF // Same function for single and double quote - var eatInQuote = function (quote) { + var eatInQuote = function eatInQuote(quote) { eaten = ''; // First check so value[indexNext-1] will always be valid if (value[indexNext] === quote) { @@ -115,7 +117,7 @@ function parse(value, indexNext) { }; // It's realy commun to eat only one character so let's make it a function - var eatOne = function (c) { + var eatOne = function eatOne(c) { // Miam ! letsEat += c; indexNext++; @@ -123,7 +125,7 @@ function parse(value, indexNext) { return shouldStop(); }; - var addAttribute = function () { + var addAttribute = function addAttribute() { switch (type) { case 'id': // ID diff --git a/src/index.js b/src/index.js index 3e123dc..ec155c3 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ // A valid output which mean nothing has been parsed. // Used as error return / invalid output -var nothingHappend = { +const nothingHappend = { prop: { key: undefined, class: undefined, @@ -13,17 +13,17 @@ var nothingHappend = { // Main function function parse(value, indexNext) { - var letsEat = ''; - var stopOnBrace = false; - var errorDetected = false; + let letsEat = ''; + let stopOnBrace = false; + let errorDetected = false; - var prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined}; + const prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined}; /* They is at leat one label and at best two */ /* ekqsdf <- one label * qsdfqsfd=qsdfqsdf <- two */ - var labelFirst = ''; - var labelSecond; + let labelFirst = ''; + let labelSecond; if (indexNext === undefined) { indexNext = 0; @@ -36,11 +36,11 @@ function parse(value, indexNext) { * jkj <- this is also a key but with a undefined value * jkj= <- this is also a key but with a empty value */ - var type; - var forbidenCharacters = '\n\r{}'; + let type; + const forbidenCharacters = '\n\r{}'; // A function that detect if it's time to end the parsing - var shouldStop = function () { + const shouldStop = function () { if (indexNext >= value.length || forbidenCharacters.indexOf(value[indexNext]) > -1) { if (stopOnBrace && value[indexNext] !== '}') { errorDetected = true; @@ -50,10 +50,10 @@ function parse(value, indexNext) { return value[indexNext] === '}' && stopOnBrace; }; - var eaten = ''; + let eaten = ''; // Couple of functions that parse same kinds of characters // Used to parse spaces or identifiers - var eat = function (chars) { + const eat = chars => { eaten = ''; while (indexNext < value.length && @@ -66,7 +66,7 @@ function parse(value, indexNext) { return shouldStop(); }; - var eatUntil = function (chars) { + const eatUntil = chars => { eaten = ''; while (indexNext < value.length && @@ -90,7 +90,7 @@ function parse(value, indexNext) { // In quote, every character is valid exept the unescaped quotes and CR or LF // Same function for single and double quote - var eatInQuote = function (quote) { + const eatInQuote = quote => { eaten = ''; // First check so value[indexNext-1] will always be valid if (value[indexNext] === quote) { @@ -122,7 +122,7 @@ function parse(value, indexNext) { }; // It's realy commun to eat only one character so let's make it a function - var eatOne = function (c) { + const eatOne = c => { // Miam ! letsEat += c; indexNext++; @@ -130,7 +130,7 @@ function parse(value, indexNext) { return shouldStop(); }; - var addAttribute = function () { + const addAttribute = () => { switch (type) { case 'id': // ID prop.id = prop.id || labelFirst; @@ -253,7 +253,7 @@ function parse(value, indexNext) { return nothingHappend; } - return {prop: prop, eaten: letsEat}; + return {prop, eaten: letsEat}; } module.exports = parse; -- cgit v1.2.3