math-exercises 3.0.120 → 3.0.121

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.
@@ -1 +1 @@
1
- {"version":3,"file":"useFormula.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/formulas/useFormula.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EACL,eAAe,EAEhB,MAAM,qCAAqC,CAAC;AAsI7C,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B,CAAC;AAoKF,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,WAAW,CAkB5C,CAAC"}
1
+ {"version":3,"file":"useFormula.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/calculLitteral/formulas/useFormula.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAeT,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EACL,eAAe,EAEhB,MAAM,qCAAqC,CAAC;AAsI7C,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B,CAAC;AAuKF,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,WAAW,CAkB5C,CAAC"}
@@ -189,7 +189,10 @@ const isAnswerValid = (ans, { answer }) => {
189
189
  const getUseFormulaQuestion = () => {
190
190
  const formula = random(FORMULAS);
191
191
  const values = formula.variables.map(() => new NumberNode(randint(1, 10)).toIdentifiers());
192
- const identifiers = { formulaId: formula.id, values };
192
+ const identifiers = {
193
+ formulaId: formula.id,
194
+ values,
195
+ };
193
196
  return getQuestionFromIdentifiers(identifiers);
194
197
  };
195
198
  const getQuestionFromIdentifiers = (identifiers) => {
@@ -0,0 +1,2 @@
1
+ export declare const assertJsonStringifiable: (obj: unknown) => void;
2
+ //# sourceMappingURL=assertJsonStringifiable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertJsonStringifiable.d.ts","sourceRoot":"","sources":["../../src/tests/assertJsonStringifiable.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,GAAI,KAAK,OAAO,KAAG,IA6BtD,CAAC"}
@@ -0,0 +1,25 @@
1
+ export const assertJsonStringifiable = (obj) => {
2
+ const visited = new WeakSet();
3
+ function check(value, path) {
4
+ if (value === null)
5
+ return;
6
+ const t = typeof value;
7
+ if (t === "function" || t === "symbol" || t === "bigint") {
8
+ throw new Error(`Value at "${path}" is not JSON stringifiable (found ${t}).`);
9
+ }
10
+ if (t === "object") {
11
+ if (visited.has(value))
12
+ return; // avoid cycles
13
+ visited.add(value);
14
+ if (Array.isArray(value)) {
15
+ value.forEach((item, i) => check(item, `${path}[${i}]`));
16
+ }
17
+ else {
18
+ for (const [k, v] of Object.entries(value)) {
19
+ check(v, `${path}.${k}`);
20
+ }
21
+ }
22
+ }
23
+ }
24
+ check(obj, "root");
25
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"questionTest.d.ts","sourceRoot":"","sources":["../../src/tests/questionTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAIjE,eAAO,MAAM,YAAY,GACvB,KAAK,QAAQ,CAAC,MAAM,CAAC,EACrB,UAAU,QAAQ,CAAC,MAAM,CAAC;;;CAmP3B,CAAC"}
1
+ {"version":3,"file":"questionTest.d.ts","sourceRoot":"","sources":["../../src/tests/questionTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAKjE,eAAO,MAAM,YAAY,GACvB,KAAK,QAAQ,CAAC,MAAM,CAAC,EACrB,UAAU,QAAQ,CAAC,MAAM,CAAC;;;CAwP3B,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { latexTester } from "../latexTester.js";
2
+ import { assertJsonStringifiable } from "./assertJsonStringifiable.js";
2
3
  import { formatMarkdownToLatex } from "./pdfs/formatMdToLatex.js";
3
4
  export const questionTest = (exo, question) => {
4
5
  let qcmTime = -1;
@@ -31,6 +32,12 @@ export const questionTest = (exo, question) => {
31
32
  }
32
33
  if (!question.identifiers || !Object.keys(question.identifiers).length)
33
34
  throw new Error(`exo ${exo.id} has no identifiers`);
35
+ try {
36
+ assertJsonStringifiable(question.identifiers);
37
+ }
38
+ catch (err) {
39
+ throw new Error(`exo ${exo.id} : ${err}`);
40
+ }
34
41
  const dotDecimalPattern = /\d+\.\d+/;
35
42
  if (question.studentGgbOptions?.coords?.length) {
36
43
  if (exo.answerType !== "GGB") {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "math-exercises",
3
3
  "type": "module",
4
- "version": "3.0.120",
4
+ "version": "3.0.121",
5
5
  "description": "Math exercises generator for middle school and high school",
6
6
  "main": "lib/index.js",
7
7
  "files": [