Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| /*jslint indent: 2, maxlen: 80, continue: false, unparam: false */ | ||
| /* -*- tab-width: 2 -*- */ | ||
| /*global define: true, module: true, require: true */ | ||
| ((typeof define === 'function') && define.amd ? define : function (factory) { | ||
| 'use strict'; | ||
| var m = ((typeof module === 'object') && module), e = (m && m.exports); | ||
| if (e) { m.exports = (factory(require, e, m) || m.exports); } | ||
| })(function (require) { | ||
| 'use strict'; | ||
| var EX = {}, eq = require('equal-pmb'), | ||
| augmentJsonErrmsg = require('./augment_json_errmsg.js'), | ||
| ceson = require('ceson'); | ||
| EX.fail = function () { | ||
| console.error.apply(console, ['-ERR'].concat(Array.from(arguments))); | ||
| return process.exit(2); | ||
| }; | ||
| EX.readTransformCompare = function (cesonFile, expectedData, onEqual) { | ||
| function cmp(readErr, data) { | ||
| if (readErr) { | ||
| readErr = augmentJsonErrmsg(readErr); | ||
| return EX.fail('cannot read', cesonFile, readErr); | ||
| } | ||
| eq(data, expectedData); | ||
| if (onEqual) { return onEqual(); } | ||
| } | ||
| ceson.parseFile({ path: cesonFile, synErr: true }, cmp); | ||
| }; | ||
| return EX; | ||
| }); |
+2
-2
@@ -16,3 +16,3 @@ /*jslint indent: 2, maxlen: 80, node: true */ | ||
| try { | ||
| data = parseCeson(data, deliver.syntaxErrorSymbol); | ||
| data = parseCeson(data, deliver.parseOpts); | ||
| } catch (parseErr) { | ||
@@ -29,3 +29,3 @@ return deliver(parseErr); | ||
| deliver = deliver.bind(fileOpts); | ||
| deliver.syntaxErrorSymbol = fileOpts.syntaxErrorSymbol; | ||
| deliver.parseOpts = fileOpts; | ||
| fs.readFile(fileOpts.path, fileOpts, EX.parseCallbackData.bind(deliver)); | ||
@@ -32,0 +32,0 @@ }; |
+14
-3
@@ -9,3 +9,3 @@ | ||
| * It will always be a strict subset of ECMAScript. | ||
| * It will always be a strict subset of ECMAScript version 3. | ||
| * Definition of whitespace and acceptable line endings is inherited from | ||
@@ -43,4 +43,5 @@ the ECMAScript spec, to avoid problems with Unicode line terminators. | ||
| * 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.) | ||
| lines or comments. (Read: Expect comments between parts of strings.) | ||
| * Although string concatenation in object keys is invalid (not valid in | ||
| ES3), parsers may optionally support it. | ||
| * Commas at the end of data containers, inside them: | ||
@@ -54,2 +55,12 @@ * The last value in a container may be followed by optional simplespace | ||
| validity and effect is inherited from ECMAScript. | ||
| * Wrapper code compatibility (JSONP, CommonJS, AMD): | ||
| * Only in the first line of input: A "data start marker" is any of both | ||
| characters `(` (U+0028 left parenthesis) and `=` (U+003D equals sign). | ||
| If line text starts with a letter from the "Basic Latin" Unicode block | ||
| (`A`..`Z`, `a`..`z`) and contains at least one data start marker, | ||
| line text is ignored from its start up to and including the first | ||
| data start marker. | ||
| * Only in the last non-blank line of input: Any combination of | ||
| `)` (U+0029 right parenthesis) and `;` (U+003B semicolon) at the end | ||
| of line text is ignored. | ||
@@ -56,0 +67,0 @@ |
+8
-3
| { "name": "ceson", | ||
| "version": "0.1.2", | ||
| "version": "0.1.3", | ||
| "description": "Yet another JSON derivative, aimed to be easy to use for humans as well as for low-level tools.", | ||
@@ -32,4 +32,9 @@ "keywords": [ | ||
| "dependencies": {}, | ||
| "devDependencies": { "equal-pmb": "^0.1.0" }, | ||
| "dependencies": { | ||
| "json-parse-pmb": "^1.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "async": "^2.0.1", | ||
| "equal-pmb": "^0.1.9" | ||
| }, | ||
@@ -36,0 +41,0 @@ |
+17
-37
@@ -1,11 +0,21 @@ | ||
| /*jslint indent: 2, maxlen: 80, node: true */ | ||
| /*jslint indent: 2, maxlen: 80, continue: false, unparam: false */ | ||
| /* -*- tab-width: 2 -*- */ | ||
| /*global define:true */ | ||
| (function (EX, trim) { | ||
| /*global define: true, module: true, require: true */ | ||
| ((typeof define === 'function') && define.amd ? define : function (factory) { | ||
| 'use strict'; | ||
| var m = ((typeof module === 'object') && module), e = (m && m.exports); | ||
| if (e) { m.exports = (factory(require, e, m) || m.exports); } | ||
| })(function (require) { | ||
| 'use strict'; | ||
| //function debugp() { return console.warn.apply(console, arguments); } | ||
| var startCmt = /^([\s,\[\{\}\]]*)\/(\*|\/)/, endBlkCmt = /\*\/([\s,\]\}]*)$/; | ||
| var EX, trim, parseJson = require('json-parse-pmb'), | ||
| startCmt = /^([\s,\[\{\}\]]*)\/(\*|\/)/, endBlkCmt = /\*\/([\s,\]\}]*)$/; | ||
| EX = function parseCeson(data, opts) { | ||
| return parseJson(EX.ceson2json(data), opts); | ||
| }; | ||
| trim = (''.trim ? function (s) { return s.trim(); } : function (s) { | ||
@@ -83,24 +93,2 @@ return (s && s.replace(/^\s+/, '').replace(/\s+$/, '')); | ||
| 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; | ||
@@ -111,11 +99,3 @@ EX.endBlkCmt = endBlkCmt; | ||
| // 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; }); | ||
| } | ||
| }()); | ||
| return EX; | ||
| }); |
+8
-14
@@ -41,19 +41,13 @@ | ||
| ### .parse(ceson[, syntaxErrorSymbol]) | ||
| ### .parse(ceson[, opts]) | ||
| Return the data represented by the string `ceson` if it can be parsed. | ||
| If it cannot be parsed because of a syntax error, behavior depends | ||
| on `syntaxErrorSymbol`, which can be: | ||
| Return the data represented by the string `ceson` if it can be parsed, | ||
| or `undefined` in case of a SyntaxError. Other errors are re-thrown. | ||
| * omitted: Return `undefined` for easy distinction from valid CESON values | ||
| like `null`, `false`, zero and the empty string. | ||
| * any string or false-y value: Return that value. | ||
| * `true`: Throw an error. | ||
| * a function: Experimental. | ||
| Call it with arguments `(err, input)` and return its result. | ||
| The `input` argument might differ from `ceson`. | ||
| * any other value: Fail in unreliable, mysterious ways. | ||
| You can modify the behavior by providing a config object `opts`. | ||
| The supported keys are: | ||
| Errors that cannot be verified to be syntax errors are re-thrown. | ||
| (Examples might include "cannot allocate buffer" or "too much recursion".) | ||
| * `synErr`, `othErr`: Modify error handling. Documented at module | ||
| [json-parse-pmb](https://github.com/mk-pmb/json-parse-pmb-js) | ||
| since that's used under the hood. | ||
@@ -60,0 +54,0 @@ |
+2
-0
@@ -5,2 +5,4 @@ /*jslint indent: 2, maxlen: 80, node: true */ | ||
| try { require('usnam-pmb'); } catch (ignore) {} | ||
| require('./felidae.js'); |
+12
-12
@@ -5,20 +5,18 @@ /*jslint indent: 2, maxlen: 80, node: true */ | ||
| var ceson = require('ceson'), eq = require('equal-pmb'), | ||
| var tu = require('./test-util.js'), ceson = require('ceson'), | ||
| async = require('async'), | ||
| cesonPath = require.resolve('../doc/examples/felidae.ceson'), | ||
| expectedFelidae = require('../doc/examples/felidae.json'), | ||
| augmentJsonErrmsg = require('./augment_json_errmsg.js'); | ||
| expectedFelidae = require('../doc/examples/felidae.json'); | ||
| function report(readErr, cesonData) { | ||
| if (readErr) { | ||
| readErr = augmentJsonErrmsg(readErr); | ||
| console.error('-ERR cannot read', cesonPath, readErr); | ||
| return process.exit(2); | ||
| } | ||
| eq(cesonData, expectedFelidae); | ||
| async.parallel([ | ||
| function (next) { | ||
| tu.readTransformCompare(cesonPath, expectedFelidae, next); | ||
| }, | ||
| ], function (err) { | ||
| if (err) { tu.fail(err); } | ||
| console.log("+OK felidae test passed."); //= "+OK felidae test passed." | ||
| } | ||
| }); | ||
| ceson.parseFile({ path: cesonPath, syntaxErrorSymbol: true }, report); | ||
@@ -49,2 +47,4 @@ | ||
| /* scroll */ |
-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; }); | ||
| } | ||
| }()); |
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
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
18
50%1
-50%16933
-11.57%1
Infinity%2
100%233
-28.96%84
-6.67%+ Added
+ Added