aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2018-04-24 05:36:34 +0200
committerache <ache@ache.one>2018-04-24 06:03:09 +0200
commit85f2579ee2c240794294c15d61418f448054f71b (patch)
treea9b518c1625f554746323794da34f8f5a007fec4
parentUse babel to distribut (diff)
Compatibility work
-rw-r--r--dist/index.js38
-rw-r--r--package.json6
-rw-r--r--src/index.js40
3 files changed, 46 insertions, 38 deletions
diff --git a/dist/index.js b/dist/index.js
index aa0a693..4f1e925 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -3,7 +3,7 @@
// A valid output which mean nothing has been parsed.
// Used as error return / invalid output
-const nothingHappend = {
+var nothingHappend = {
prop: {
key: undefined,
class: undefined,
@@ -13,18 +13,20 @@ const nothingHappend = {
};
// Main function
-function parse(value, indexNext = 0) {
- let letsEat = '';
- let stopOnBrace = false;
- let errorDetected = false;
+function parse(value, indexNext) {
+ var letsEat = '';
+ var stopOnBrace = false;
+ var errorDetected = false;
- const prop = { key: undefined /* {} */, class: undefined /* [] */, id: undefined };
+ var prop = { key: undefined /* {} */, class: undefined /* [] */, id: undefined };
/* They is at leat one label and at best two */
/* ekqsdf <- one label
* qsdfqsfd=qsdfqsdf <- two */
- let labelFirst = '';
- let labelSecond;
+ var labelFirst = '';
+ var labelSecond;
+
+ if (indexNext === undefined) indexNext = 0;
/* 3 types :
* .azcv <- class
@@ -33,11 +35,11 @@ function parse(value, indexNext = 0) {
* jkj <- this is also a key but with a undefined value
* jkj= <- this is also a key but with a empty value
*/
- let type;
- const forbidenCharacters = '\n\r{}';
+ var type;
+ var forbidenCharacters = '\n\r{}';
// A function that detect if it's time to end the parsing
- const shouldStop = () => {
+ var shouldStop = function () {
if (indexNext >= value.length || forbidenCharacters.indexOf(value[indexNext]) > -1) {
if (stopOnBrace && value[indexNext] !== '}') {
errorDetected = true;
@@ -47,10 +49,10 @@ function parse(value, indexNext = 0) {
return value[indexNext] === '}' && stopOnBrace;
};
- let eaten = '';
+ var eaten = '';
// Couple of functions that parse same kinds of characters
// Used to parse spaces or identifiers
- const eat = chars => {
+ var eat = function (chars) {
eaten = '';
while (indexNext < value.length && forbidenCharacters.indexOf(value.charAt(indexNext)) < 0 && chars.indexOf(value.charAt(indexNext)) >= 0) {
@@ -61,7 +63,7 @@ function parse(value, indexNext = 0) {
return shouldStop();
};
- const eatUntil = chars => {
+ var eatUntil = function (chars) {
eaten = '';
while (indexNext < value.length && forbidenCharacters.indexOf(value.charAt(indexNext)) < 0 && chars.indexOf(value.charAt(indexNext)) < 0) {
@@ -83,7 +85,7 @@ function parse(value, indexNext = 0) {
// In quote, every character is valid exept the unescaped quotes and CR or LF
// Same function for single and double quote
- const eatInQuote = quote => {
+ var eatInQuote = function (quote) {
eaten = '';
// First check so value[indexNext-1] will always be valid
if (value[indexNext] === quote) {
@@ -113,7 +115,7 @@ function parse(value, indexNext = 0) {
};
// It's realy commun to eat only one character so let's make it a function
- const eatOne = c => {
+ var eatOne = function (c) {
// Miam !
letsEat += c;
indexNext++;
@@ -121,7 +123,7 @@ function parse(value, indexNext = 0) {
return shouldStop();
};
- const addAttribute = () => {
+ var addAttribute = function () {
switch (type) {
case 'id':
// ID
@@ -249,7 +251,7 @@ function parse(value, indexNext = 0) {
return nothingHappend;
}
- return { prop, eaten: letsEat };
+ return { prop: prop, eaten: letsEat };
}
module.exports = parse; \ No newline at end of file
diff --git a/package.json b/package.json
index 4168dd6..ffce496 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "md-attr-parser",
- "version": "1.1.1",
+ "version": "1.1.5",
"description": "A parser for markdown's attributes",
"main": "dist/index.js",
"scripts": {
@@ -31,7 +31,9 @@
"comma-dangle": [
"error",
"always-multiline"
- ]
+ ],
+ "no-var": "warn",
+ "object-shorthand": "warn"
}
},
"author": "ache <ache@ache.one>"
diff --git a/src/index.js b/src/index.js
index 9992704..3e123dc 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
-const nothingHappend = {
+var nothingHappend = {
prop: {
key: undefined,
class: undefined,
@@ -12,18 +12,22 @@ const nothingHappend = {
};
// Main function
-function parse(value, indexNext = 0) {
- let letsEat = '';
- let stopOnBrace = false;
- let errorDetected = false;
+function parse(value, indexNext) {
+ var letsEat = '';
+ var stopOnBrace = false;
+ var errorDetected = false;
- const prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined};
+ var prop = {key: undefined /* {} */, class: undefined /* [] */, id: undefined};
/* They is at leat one label and at best two */
/* ekqsdf <- one label
* qsdfqsfd=qsdfqsdf <- two */
- let labelFirst = '';
- let labelSecond;
+ var labelFirst = '';
+ var labelSecond;
+
+ if (indexNext === undefined) {
+ indexNext = 0;
+ }
/* 3 types :
* .azcv <- class
@@ -32,11 +36,11 @@ function parse(value, indexNext = 0) {
* jkj <- this is also a key but with a undefined value
* jkj= <- this is also a key but with a empty value
*/
- let type;
- const forbidenCharacters = '\n\r{}';
+ var type;
+ var forbidenCharacters = '\n\r{}';
// A function that detect if it's time to end the parsing
- const shouldStop = () => {
+ var shouldStop = function () {
if (indexNext >= value.length || forbidenCharacters.indexOf(value[indexNext]) > -1) {
if (stopOnBrace && value[indexNext] !== '}') {
errorDetected = true;
@@ -46,10 +50,10 @@ function parse(value, indexNext = 0) {
return value[indexNext] === '}' && stopOnBrace;
};
- let eaten = '';
+ var eaten = '';
// Couple of functions that parse same kinds of characters
// Used to parse spaces or identifiers
- const eat = chars => {
+ var eat = function (chars) {
eaten = '';
while (indexNext < value.length &&
@@ -62,7 +66,7 @@ function parse(value, indexNext = 0) {
return shouldStop();
};
- const eatUntil = chars => {
+ var eatUntil = function (chars) {
eaten = '';
while (indexNext < value.length &&
@@ -86,7 +90,7 @@ function parse(value, indexNext = 0) {
// In quote, every character is valid exept the unescaped quotes and CR or LF
// Same function for single and double quote
- const eatInQuote = quote => {
+ var eatInQuote = function (quote) {
eaten = '';
// First check so value[indexNext-1] will always be valid
if (value[indexNext] === quote) {
@@ -118,7 +122,7 @@ function parse(value, indexNext = 0) {
};
// It's realy commun to eat only one character so let's make it a function
- const eatOne = c => {
+ var eatOne = function (c) {
// Miam !
letsEat += c;
indexNext++;
@@ -126,7 +130,7 @@ function parse(value, indexNext = 0) {
return shouldStop();
};
- const addAttribute = () => {
+ var addAttribute = function () {
switch (type) {
case 'id': // ID
prop.id = prop.id || labelFirst;
@@ -249,7 +253,7 @@ function parse(value, indexNext = 0) {
return nothingHappend;
}
- return {prop, eaten: letsEat};
+ return {prop: prop, eaten: letsEat};
}
module.exports = parse;