{"record":{"id":"5a3b49af59f380c2","repo":"parallax/jsPDF","slug":"don-t-know-what-to-do-with-value-type-typeof-val","errorCode":null,"errorMessage":"Don't know what to do with value type ${typeof value}.","messagePattern":"Don't know what to do with value type (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/standard_fonts_metrics.js","lineNumber":98,"sourceCode":"      }\n\n      if (typeof value == \"number\") {\n        if (value < 0) {\n          valuestring = hex(value).slice(3);\n          numberprefix = \"-\";\n        } else {\n          valuestring = hex(value).slice(2);\n          numberprefix = \"\";\n        }\n        valuestring =\n          numberprefix +\n          valuestring.slice(0, -1) +\n          mappingCompress[valuestring.slice(-1)];\n      } else {\n        if (typeof value === \"object\") {\n          valuestring = compress(value);\n        } else {\n          throw new Error(\n            \"Don't know what to do with value type \" + typeof value + \".\"\n          );\n        }\n      }\n      vals.push(keystring + valuestring);\n    }\n    vals.push(\"}\");\n    return vals.join(\"\");\n  });\n\n  /**\n   * Uncompresses data compressed into custom, base16-like format.\n   *\n   * @public\n   * @function\n   * @param\n   * @returns {Type}\n   */","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/standard_fonts_metrics.js#L80-L116","documentation":"The internal font-metrics compress() walker only knows how to encode two value types: numbers (hex-encoded) and objects (recursed). Any other type — string, boolean, function, symbol, or null/undefined as a non-object — falls to the else branch and throws 'Don't know what to do with value type <typeof>.' This is part of jsPDF's private __fontmetrics__ compression used to serialize font metric tables.","triggerScenarios":"Calling API.__fontmetrics__.compress() (or feeding custom font-metric data into it) with a structure containing string/boolean/function/null leaf values instead of numbers or nested objects. Most commonly hit by third-party or hand-built metric tables fed into the compress path.","commonSituations":"Injecting custom font metrics that include string annotations or boolean flags; feeding a parsed/mutated metrics object whose leaves are not numbers; version skew where a metrics schema added non-numeric fields.","solutions":["Ensure every leaf value passed to compress() is a number or a nested object of numbers.","Strip or convert string/boolean leaves before compressing.","Prefer using jsPDF's standard font APIs (addFont with .ttf) rather than calling compress() directly.","Validate the metric tree shape (all leaves numeric) before invoking compress."],"exampleFix":"// before\nAPI.__fontmetrics__.compress({ width: 500, name: 'Roboto' }); // 'Roboto' is a string -> throws [118]\n\n// after\nAPI.__fontmetrics__.compress({ width: 500 }); // drop non-numeric metadata","handlingStrategy":"validation","validationCode":"function metricsTreeIsCompressible(obj) {\n  for (const k in obj) {\n    const v = obj[k];\n    if (typeof v === 'number') continue;\n    if (v && typeof v === 'object') { if (!metricsTreeIsCompressible(v)) return false; }\n    else return false; // string, boolean, function, null, undefined\n  }\n  return true;\n}","typeGuard":"function isCompressibleMetrics(value) {\n  if (typeof value === 'number') return true;\n  if (value && typeof value === 'object') {\n    return Object.values(value).every(isCompressibleMetrics);\n  }\n  return false;\n}","tryCatchPattern":"try {\n  compressed = API.__fontmetrics__.compress(metrics);\n} catch (e) {\n  if (/Don't know what to do with value type/.test(e.message)) {\n    // strip non-numeric leaves and retry, or use standard addFont instead\n  } else throw e;\n}","preventionTips":["Keep metric-table leaves strictly numeric (or nested numeric objects).","Avoid calling compress() directly — use addFont with .ttf.","Validate a custom metric tree shape before feeding it to the compress path."],"tags":["font-metrics","internal","validation","type","pdf"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}