+120
| /*jslint indent: 2, maxlen: 80, node: true */ | ||
| /* -*- tab-width: 2 -*- */ | ||
| /*global define:true */ | ||
| (function (EX, trim) { | ||
| 'use strict'; | ||
| Light: | ||
| line comments at start of line text, or at end if | ||
| white space before them and no / or " in them | ||
| trailing comma if simple | ||
| no error catch | ||
| var startCmt = /^([\s,\[\{\}\]]*)\/(\*|\/)/, endBlkCmt = /\*\/([\s,\]\}]*)$/; | ||
| trim = (''.trim ? function (s) { return s.trim(); } : function (s) { | ||
| return (s && s.replace(/^\s+/, '').replace(/\s+$/, '')); | ||
| }); | ||
| function chopPrevChar(lines, chop) { | ||
| var prevIdx = lines.length - 1, prevLn = lines[prevIdx]; | ||
| if (!prevLn) { return; } | ||
| if (prevLn.slice(-1) === chop) { lines[prevIdx] = prevLn.slice(0, -1); } | ||
| } | ||
| function ceson2json(ceson) { | ||
| if (!ceson) { return false; } | ||
| if (typeof ceson !== 'string') { return false; } | ||
| var json = [], inBlockComment = false, strConcat = false, afterCmt; | ||
| ceson = ceson.split(/\n\s*/); | ||
| if (ceson[0].slice(0, 1) === '\uFEFF') { ceson[0] = ceson[0].slice(1); } | ||
| function parseLine(ln) { | ||
| ln = trim(ln); | ||
| if (!ln) { return; } | ||
| if (inBlockComment) { | ||
| afterCmt = endBlkCmt.exec(ln); | ||
| if (!afterCmt) { return; } | ||
| inBlockComment = false; | ||
| ln = trim(afterCmt[1]); | ||
| } | ||
| inBlockComment = startCmt.exec(ln); | ||
| if (inBlockComment) { | ||
| ln = inBlockComment[1]; | ||
| if (inBlockComment[2] === '/') { | ||
| // line comment. there can't be anything after it. | ||
| inBlockComment = false; | ||
| } else { | ||
| // block comment. does it end in the same line? | ||
| afterCmt = endBlkCmt.exec(ln); | ||
| inBlockComment = !afterCmt; | ||
| if (afterCmt) { ln += afterCmt[1]; } | ||
| } | ||
| ln = trim(ln); | ||
| } | ||
| switch (ln[0]) { | ||
| case undefined: | ||
| return; | ||
| case '}': | ||
| case ']': | ||
| chopPrevChar(json, ','); | ||
| break; | ||
| case '+': | ||
| chopPrevChar(json, '"'); | ||
| ln = json.pop() + ln.replace(/^\+\s*"/, ''); | ||
| break; | ||
| case '"': | ||
| if (strConcat) { ln = json.pop() + ln.slice(1); } | ||
| break; | ||
| } | ||
| strConcat = (ln.slice(-1) === '+'); | ||
| if (strConcat) { ln = ln.replace(/"\s*\+$/, ''); } | ||
| json.push(ln); | ||
| } | ||
| ceson.forEach(parseLine); | ||
| return json.join('\n'); | ||
| } | ||
| EX = function parseCeson(data, syntaxErrorSymbol) { | ||
| data = String(data || ''); | ||
| if (!data) { return syntaxErrorSymbol; } | ||
| data = ceson2json(data); | ||
| if (!data) { return syntaxErrorSymbol; } | ||
| try { | ||
| data = JSON.parse(data); | ||
| } catch (jsonErr) { | ||
| if (jsonErr && (typeof jsonErr === 'object')) { jsonErr.input = data; } | ||
| if (syntaxErrorSymbol === true) { throw jsonErr; } | ||
| if (typeof syntaxErrorSymbol === 'function') { | ||
| return syntaxErrorSymbol(jsonErr, data); | ||
| } | ||
| if (jsonErr instanceof SyntaxError) { return syntaxErrorSymbol; } | ||
| data = String(jsonErr); | ||
| if (/^\S*syntax(error|)\b/i.exec(data)) { return syntaxErrorSymbol; } | ||
| throw jsonErr; | ||
| } | ||
| return data; | ||
| }; | ||
| EX.startCmt = startCmt; | ||
| EX.endBlkCmt = endBlkCmt; | ||
| EX.ceson2json = ceson2json; | ||
| // Unified export | ||
| if (typeof module === 'object') { | ||
| if (typeof ((module || false).exports || false) === 'object') { | ||
| module.exports = EX; | ||
| } | ||
| } | ||
| if ((typeof define === 'function') && define.amd) { | ||
| define(function () { return EX; }); | ||
| } | ||
| }()); |
| { "": "family", "id": "Felidae", "wp-en-oldid": 742264157, | ||
| "Pantherinae": { | ||
| "": "subfamily", "wp-en-oldid": 736789580, | ||
| "Panthera": {} | ||
| "Panthera": {}, | ||
| "Neofelis": { | ||
| "nebulosa": { "": "species", "wp-en-oldid": 742251401 }, | ||
| "": "genus", "wp-en-oldid": 734888346 | ||
| }, | ||
| "": "subfamily", "wp-en-oldid": 736789580 | ||
| }, | ||
@@ -6,0 +10,0 @@ "Felinae": { |
+10
-2
@@ -38,4 +38,8 @@ | ||
| operator (`+`). | ||
| * The plus sign has to be at the start or end of line text. | ||
| A line can have plus signs on both sides of its line text. | ||
| * The plus sign has to be on the same line as one of the string parts. | ||
| * The plus sign is allowed only at the start or end or on both sides of | ||
| line text. (Read: not in the middle.) | ||
| * String continuation does not impose any implicit limits about blank | ||
| lines or comments, or about what kinds of strings can be concatenated. | ||
| (Read: Expect comments between parts of strings, even in object keys.) | ||
| * Commas at the end of data containers, inside them: | ||
@@ -52,3 +56,7 @@ * The last value in a container may be followed by optional simplespace | ||
| Variant: CESON light | ||
| -------------------- | ||
| * No block comments. | ||
| * String continuation's plus sign is allowed only at the end of line text. | ||
@@ -55,0 +63,0 @@ |
+1
-1
| { "name": "ceson", | ||
| "version": "0.1.0", | ||
| "version": "0.1.2", | ||
| "description": "Yet another JSON derivative, aimed to be easy to use for humans as well as for low-level tools.", | ||
@@ -4,0 +4,0 @@ "keywords": [ |
+11
-3
@@ -8,2 +8,3 @@ /*jslint indent: 2, maxlen: 80, node: true */ | ||
| //function debugp() { return console.warn.apply(console, arguments); } | ||
| var startCmt = /^([\s,\[\{\}\]]*)\/(\*|\/)/, endBlkCmt = /\*\/([\s,\]\}]*)$/; | ||
@@ -29,7 +30,9 @@ | ||
| if (ceson[0].slice(0, 1) === '\uFEFF') { ceson[0] = ceson[0].slice(1); } | ||
| function parseLine(ln) { | ||
| function parseLine(ln, lnIdx) { | ||
| ln = trim(ln); | ||
| if (!ln) { return; } | ||
| //debugp(lnIdx + 1, { trimmed: ln }); | ||
| if (!ln) { return lnIdx; } | ||
| if (inBlockComment) { | ||
| afterCmt = endBlkCmt.exec(ln); | ||
| //debugp(' ', { inBlkEnd: (afterCmt && afterCmt[0]) }); | ||
| if (!afterCmt) { return; } | ||
@@ -40,6 +43,7 @@ inBlockComment = false; | ||
| inBlockComment = startCmt.exec(ln); | ||
| //debugp(' ', { startCmt: (inBlockComment && inBlockComment[0]) }); | ||
| if (inBlockComment) { | ||
| ln = inBlockComment[1]; | ||
| if (inBlockComment[2] === '/') { | ||
| // line comment. there can't be anything after it. | ||
| ln = inBlockComment[1]; | ||
| inBlockComment = false; | ||
@@ -49,2 +53,4 @@ } else { | ||
| afterCmt = endBlkCmt.exec(ln); | ||
| ln = inBlockComment[1]; | ||
| //debugp(' ', { oneLnBlk: (afterCmt && afterCmt[1]) }); | ||
| inBlockComment = !afterCmt; | ||
@@ -55,2 +61,3 @@ if (afterCmt) { ln += afterCmt[1]; } | ||
| } | ||
| //debugp(' ', { SWITCHING: ln, concat: strConcat }); | ||
| switch (ln[0]) { | ||
@@ -73,2 +80,3 @@ case undefined: | ||
| if (strConcat) { ln = ln.replace(/"\s*\+$/, ''); } | ||
| //debugp(' ', { ln: ln }, (strConcat ? '+CONCAT+' : '-')); | ||
| json.push(ln); | ||
@@ -75,0 +83,0 @@ } |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
19149
32.2%12
9.09%328
53.99%2
100%