@canopycanopycanopy/b-ber-validator 3.0.8-next.61 → 3.0.8-next.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,9 +14,9 @@ const close = (parser, matchIndex) => (ctx) => {
14
14
  const openingRe = new RegExp(`${openingIdent}(?![^\\s])`, 'g'); // Allow dangling whitespace
15
15
  openingRe.lastIndex = nextCtx.index;
16
16
  const closingMatch = openingRe.exec(nextCtx.text);
17
- if ((closingMatch === null || closingMatch === void 0 ? void 0 : closingMatch.index) === nextCtx.index) {
18
- return (0, success_1.success)(Object.assign(Object.assign({}, ctx), { index: endIdx }), nextValue);
17
+ if (closingMatch?.index === nextCtx.index) {
18
+ return (0, success_1.success)({ ...ctx, index: endIdx }, nextValue);
19
19
  }
20
- return (0, failure_1.failure)(Object.assign(Object.assign({}, ctx), { index: endIdx }), `Closing identifier to match opening identifier ${openingIdent.trim()}`, true);
20
+ return (0, failure_1.failure)({ ...ctx, index: endIdx }, `Closing identifier to match opening identifier ${openingIdent.trim()}`, true);
21
21
  };
22
22
  exports.close = close;
@@ -8,7 +8,7 @@ const constrained = (parser1, parser2, expected = 'Valid constraint') => {
8
8
  const res2 = parser2(ctx);
9
9
  // Fails fatally if first condition is not met
10
10
  if (!res1.success) {
11
- return Object.assign(Object.assign({}, res1), { expected, fatal: true });
11
+ return { ...res1, expected, fatal: true };
12
12
  }
13
13
  // Allowed to fail normally afterwards
14
14
  return res2;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eol = void 0;
3
+ exports.eol = eol;
4
4
  const failure_1 = require("../lib/failure");
5
5
  const success_1 = require("../lib/success");
6
6
  // eol function doesn't advance index
@@ -17,4 +17,3 @@ function eol() {
17
17
  return (0, failure_1.failure)(ctx, 'End of line', true);
18
18
  };
19
19
  }
20
- exports.eol = eol;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eos = void 0;
3
+ exports.eos = eos;
4
4
  const failure_1 = require("../lib/failure");
5
5
  const success_1 = require("../lib/success");
6
6
  class EOS {
@@ -10,4 +10,3 @@ function eos() {
10
10
  ? (0, success_1.success)(ctx, new EOS())
11
11
  : (0, failure_1.failure)(ctx, 'End of string');
12
12
  }
13
- exports.eos = eos;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lazy = void 0;
3
+ exports.lazy = lazy;
4
4
  function lazy(parserFn) {
5
5
  return (ctx) => parserFn()(ctx);
6
6
  }
7
- exports.lazy = lazy;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.many = void 0;
3
+ exports.many = many;
4
4
  const success_1 = require("../lib/success");
5
5
  // Look for 0 or more of something, until we can't parse any more.
6
6
  // Note that this function never fails, it will instead succeed
@@ -22,4 +22,3 @@ function many(parser) {
22
22
  return (0, success_1.success)(nextCtx, values);
23
23
  };
24
24
  }
25
- exports.many = many;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.map = void 0;
3
+ exports.map = map;
4
4
  const success_1 = require("../lib/success");
5
5
  // Convenience method that will map a Success to callback, to let us do
6
6
  // common things like build AST nodes from input strings.
@@ -10,4 +10,3 @@ function map(parser, fn) {
10
10
  return res.success ? (0, success_1.success)(res.ctx, fn(res.value)) : res;
11
11
  };
12
12
  }
13
- exports.map = map;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.not = void 0;
3
+ exports.not = not;
4
4
  const success_1 = require("../lib/success");
5
5
  function not(parser) {
6
6
  return (ctx) => {
7
7
  const values = [];
8
- const nextCtx = Object.assign({}, ctx);
8
+ const nextCtx = { ...ctx };
9
9
  while (nextCtx.index < nextCtx.text.length) {
10
10
  const res = parser(nextCtx);
11
11
  if (res.success)
@@ -15,4 +15,3 @@ function not(parser) {
15
15
  return (0, success_1.success)(nextCtx, values);
16
16
  };
17
17
  }
18
- exports.not = not;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oneOf = void 0;
3
+ exports.oneOf = oneOf;
4
4
  // Try each matcher in order, starting from the same point in the input.
5
5
  // Return the first one that succeeds, or return the failure that got furthest
6
6
  // in the input string. which failure to return is a matter of taste, we
@@ -16,11 +16,10 @@ function oneOf(parsers) {
16
16
  return res;
17
17
  if (res.fatal)
18
18
  return res;
19
- if (!(furthestRes === null || furthestRes === void 0 ? void 0 : furthestRes.ctx) || furthestRes.ctx.index > res.ctx.index) {
19
+ if (!furthestRes?.ctx || furthestRes.ctx.index > res.ctx.index) {
20
20
  furthestRes = res;
21
21
  }
22
22
  }
23
23
  return furthestRes;
24
24
  };
25
25
  }
26
- exports.oneOf = oneOf;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.optional = void 0;
3
+ exports.optional = optional;
4
4
  const success_1 = require("../lib/success");
5
5
  const oneOf_1 = require("./oneOf");
6
6
  // Match a parser, or succeed with null
7
7
  function optional(parser) {
8
8
  return (0, oneOf_1.oneOf)([parser, (ctx) => (0, success_1.success)(ctx, null)]);
9
9
  }
10
- exports.optional = optional;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.regex = void 0;
3
+ exports.regex = regex;
4
4
  const failure_1 = require("../lib/failure");
5
5
  const success_1 = require("../lib/success");
6
6
  // Match a regexp or fail
@@ -9,9 +9,8 @@ function regex(re, expected) {
9
9
  re.lastIndex = ctx.index;
10
10
  const res = re.exec(ctx.text);
11
11
  if (res && res.index === ctx.index) {
12
- return (0, success_1.success)(Object.assign(Object.assign({}, ctx), { index: ctx.index + res[0].length }), res[0]);
12
+ return (0, success_1.success)({ ...ctx, index: ctx.index + res[0].length }, res[0]);
13
13
  }
14
14
  return (0, failure_1.failure)(ctx, expected);
15
15
  };
16
16
  }
17
- exports.regex = regex;
@@ -6,7 +6,7 @@ const required = (parser) => {
6
6
  return (ctx) => {
7
7
  const res = parser(ctx);
8
8
  if (!res.success)
9
- return Object.assign(Object.assign({}, res), { fatal: true });
9
+ return { ...res, fatal: true };
10
10
  return res;
11
11
  };
12
12
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sequence = void 0;
3
+ exports.sequence = sequence;
4
4
  const success_1 = require("../lib/success");
5
5
  // Look for an exact sequence of parsers, or fail
6
6
  function sequence(parsers) {
@@ -17,4 +17,3 @@ function sequence(parsers) {
17
17
  return (0, success_1.success)(nextCtx, values);
18
18
  };
19
19
  }
20
- exports.sequence = sequence;
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.string = void 0;
3
+ exports.string = string;
4
4
  const failure_1 = require("../lib/failure");
5
5
  const success_1 = require("../lib/success");
6
6
  function string(match, expected = '') {
7
7
  return (ctx) => {
8
8
  const endIdx = ctx.index + match.length;
9
9
  if (ctx.text.substring(ctx.index, endIdx) === match) {
10
- return (0, success_1.success)(Object.assign(Object.assign({}, ctx), { index: endIdx }), match);
10
+ return (0, success_1.success)({ ...ctx, index: endIdx }, match);
11
11
  }
12
12
  return (0, failure_1.failure)(ctx, expected || match);
13
13
  };
14
14
  }
15
- exports.string = string;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.failure = void 0;
3
+ exports.failure = failure;
4
4
  function failure(ctx, expected, fatal = false) {
5
5
  return { success: false, expected, ctx, fatal };
6
6
  }
7
- exports.failure = failure;
package/dist/lib/flat.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Polyfill Array.flat for Node < 11
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.flat = void 0;
4
+ exports.flat = flat;
5
5
  function flat(arr, d = 1) {
6
6
  if ('flat' in [])
7
7
  return arr.flat(d);
@@ -9,4 +9,3 @@ function flat(arr, d = 1) {
9
9
  ? arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flat(val, d - 1) : val), [])
10
10
  : arr.slice();
11
11
  }
12
- exports.flat = flat;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.success = void 0;
3
+ exports.success = success;
4
4
  function success(ctx, value) {
5
5
  return { success: true, value, ctx };
6
6
  }
7
- exports.success = success;
package/dist/report.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = report;
6
7
  const colors_1 = __importDefault(require("./colors"));
7
8
  function report(name, res) {
8
9
  console.log(colors_1.default.reset, '');
@@ -34,4 +35,3 @@ function report(name, res) {
34
35
  console.log(colors_1.default.dim, afterArr.join('\n'));
35
36
  console.log(colors_1.default.reset, '');
36
37
  }
37
- exports.default = report;
package/dist/validator.js CHANGED
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const b_ber_shapes_directives_1 = require("@canopycanopycanopy/b-ber-shapes-directives");
4
- const string_1 = require("./combinators/string");
4
+ const close_1 = require("./combinators/close");
5
+ const constrained_1 = require("./combinators/constrained");
6
+ const eol_1 = require("./combinators/eol");
7
+ const eos_1 = require("./combinators/eos");
8
+ const lazy_1 = require("./combinators/lazy");
5
9
  const many_1 = require("./combinators/many");
6
- const oneOf_1 = require("./combinators/oneOf");
7
- const regex_1 = require("./combinators/regex");
8
- const sequence_1 = require("./combinators/sequence");
9
10
  const map_1 = require("./combinators/map");
10
- const optional_1 = require("./combinators/optional");
11
- const eol_1 = require("./combinators/eol");
12
11
  const not_1 = require("./combinators/not");
13
- const lazy_1 = require("./combinators/lazy");
14
- const eos_1 = require("./combinators/eos");
15
- const close_1 = require("./combinators/close");
12
+ const oneOf_1 = require("./combinators/oneOf");
13
+ const optional_1 = require("./combinators/optional");
14
+ const regex_1 = require("./combinators/regex");
16
15
  const required_1 = require("./combinators/required");
17
- const constrained_1 = require("./combinators/constrained");
16
+ const sequence_1 = require("./combinators/sequence");
17
+ const string_1 = require("./combinators/string");
18
18
  const flat_1 = require("./lib/flat");
19
19
  const space = (0, string_1.string)(' ', 'Space');
20
20
  const spaces = (0, many_1.many)(space);
@@ -45,12 +45,12 @@ const attrs = (0, sequence_1.sequence)([(0, many_1.many)(attr()), (0, optional_1
45
45
  // names are made up of latin a-z and hyphen. `g` flag is set to
46
46
  // allow `lastIndex` to be used in the `regex` combinator.
47
47
  const directiveRegExp = (s) => new RegExp(`${s}\\b(?!-)`, 'g');
48
- const inlineNames = Array.from(b_ber_shapes_directives_1.INLINE_DIRECTIVES).map(s => (0, regex_1.regex)(directiveRegExp(s), s));
48
+ const inlineNames = Array.from(b_ber_shapes_directives_1.INLINE_DIRECTIVES).map((s) => (0, regex_1.regex)(directiveRegExp(s), s));
49
49
  const blockNames = Array.from(b_ber_shapes_directives_1.BLOCK_DIRECTIVES)
50
50
  .concat(Array.from(b_ber_shapes_directives_1.MISC_DIRECTIVES))
51
51
  .concat(Array.from(b_ber_shapes_directives_1.DRAFT_DIRECTIVES))
52
52
  .concat(Array.from(b_ber_shapes_directives_1.DEPRECATED_DIRECTIVES))
53
- .map(s => (0, regex_1.regex)(directiveRegExp(s), s));
53
+ .map((s) => (0, regex_1.regex)(directiveRegExp(s), s));
54
54
  const inlineDirectiveName = (0, oneOf_1.oneOf)(inlineNames);
55
55
  const blockDirectiveName = (0, oneOf_1.oneOf)(blockNames);
56
56
  const name = (0, oneOf_1.oneOf)(inlineNames.concat(blockNames).concat(exit));
@@ -88,7 +88,7 @@ function block() {
88
88
  fenceBlock,
89
89
  (0, constrained_1.constrained)(name, blockDirectiveName, 'Valid directive name'),
90
90
  (0, required_1.required)(sep),
91
- (0, required_1.required)(ident),
91
+ (0, required_1.required)(ident), // Preserve index for exit token
92
92
  attrs,
93
93
  (0, optional_1.optional)(body),
94
94
  (0, optional_1.optional)((0, lazy_1.lazy)(directives)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-validator",
3
- "version": "3.0.8-next.61+2bbec564",
3
+ "version": "3.0.8-next.96+7446845b",
4
4
  "description": "A b-ber syntax validator",
5
5
  "author": "Triple Canopy <b-ber@canopycanopycanopy.com> (https://triplecanopy.github.io/)",
6
6
  "contributors": [
@@ -26,32 +26,25 @@
26
26
  "scripts": {
27
27
  "ts-node": "ts-node",
28
28
  "clean": "rimraf dist",
29
- "prepare": "npm run build",
30
29
  "jest": "jest",
31
30
  "build": "npm run clean && npm run test && tsc --project tsconfig.build.json",
32
- "lint": "eslint --resolve-plugins-relative-to . 'src/**/*.ts' --fix",
31
+ "lint": "biome check src/",
33
32
  "test": "tsc --project tsconfig.json --noEmit && npm run lint && jest"
34
33
  },
35
34
  "bugs": {
36
35
  "url": "https://github.com/triplecanopy/b-ber/issues"
37
36
  },
38
37
  "devDependencies": {
39
- "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.61+2bbec564",
40
38
  "@types/node": "^14.14.7",
41
- "@typescript-eslint/eslint-plugin": "^4.8.1",
42
- "@typescript-eslint/parser": "^4.8.1",
43
- "babel-cli": "^6.26.0",
44
- "eslint": "^7.32.0",
45
- "eslint-config-prettier": "^6.15.0",
46
- "eslint-plugin-prettier": "^3.1.4",
47
- "jest": "^26.6.3",
39
+ "jest": "^29.7.0",
48
40
  "rimraf": "^2.7.1",
49
- "ts-jest": "^26.4.4",
50
- "typescript": "^4.0.5"
41
+ "ts-jest": "^29.4.11",
42
+ "typescript": "^6.0.3"
51
43
  },
52
44
  "dependencies": {
45
+ "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.96+7446845b",
53
46
  "lodash": "^4.17.21",
54
47
  "tar": "^6.1.11"
55
48
  },
56
- "gitHead": "2bbec5643278f53becb0d2ba1f55edfe379d5587"
49
+ "gitHead": "7446845bcda4337bfbc9f75b55a1e0ca805023eb"
57
50
  }