{"record":{"id":"14a8c0074af55122","repo":"Dogfalo/materialize","slug":"nouislider-format-requires-to-and-from-meth","errorCode":null,"errorMessage":"noUiSlider: 'format' requires 'to' and 'from' methods.","messagePattern":"noUiSlider: 'format' requires 'to' and 'from' methods\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"extras/noUiSlider/nouislider.js","lineNumber":740,"sourceCode":"\n            parsed.tooltips.forEach(function(formatter){\n                if ( typeof formatter !== 'boolean' && (typeof formatter !== 'object' || typeof formatter.to !== 'function') ) {\n                    throw new Error(\"noUiSlider: 'tooltips' must be passed a formatter or 'false'.\");\n                }\n            });\n        }\n    }\n\n    function testFormat ( parsed, entry ) {\n\n        parsed.format = entry;\n\n        // Any object with a to and from method is supported.\n        if ( typeof entry.to === 'function' && typeof entry.from === 'function' ) {\n            return true;\n        }\n\n        throw new Error(\"noUiSlider: 'format' requires 'to' and 'from' methods.\");\n    }\n\n    function testCssPrefix ( parsed, entry ) {\n\n        if ( entry !== undefined && typeof entry !== 'string' && entry !== false ) {\n            throw new Error(\"noUiSlider: 'cssPrefix' must be a string or `false`.\");\n        }\n\n        parsed.cssPrefix = entry;\n    }\n\n    function testCssClasses ( parsed, entry ) {\n\n        if ( entry !== undefined && typeof entry !== 'object' ) {\n            throw new Error(\"noUiSlider: 'cssClasses' must be an object.\");\n        }\n\n        if ( typeof parsed.cssPrefix === 'string' ) {","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/Dogfalo/materialize/blob/824e78248b3de81e383445e76ffb04cc3264fe7d/extras/noUiSlider/nouislider.js#L722-L758","documentation":"The 'format' option must be an object implementing BOTH a to(value) method (for display) and a from(value) method (for parsing user input back to a number). noUiSlider uses the pair to round-trip values, so missing either one is a hard failure.","triggerScenarios":"Pass options.format as an object that lacks .to or .from, e.g. { to: v => v }, a class instance missing one method, or a plain wNumb config object {decimals:0} instead of wNumb({decimals:0}).","commonSituations":"Developers pass the wNumb configuration object instead of the wNumb instance, hand-write a formatter with only to: (forgetting from:), or swap in a third-party formatter that only implements one direction.","solutions":["Use wNumb(...) to get an object that exposes both to and from, e.g. format: wNumb({ decimals: 0 }).","If writing a custom formatter, implement both methods: { to: v => ..., from: s => ... }.","Verify with typeof entry.to === 'function' && typeof entry.from === 'function' before passing."],"exampleFix":"// before\nnoUiSlider.create(el, { start: 0, range:{min:0,max:100}, format: { decimals: 0 } });\n// after\nnoUiSlider.create(el, { start: 0, range:{min:0,max:100}, format: wNumb({ decimals: 0 }) });","handlingStrategy":"type-guard","validationCode":"function assertFormat(opts) {\n  const f = opts.format;\n  if (f && typeof f.to === 'function' && typeof f.from === 'function') return;\n  throw new TypeError('format must expose to() and from()');\n}","typeGuard":"function isFormatter(f) {\n  return !!f && typeof f.to === 'function' && typeof f.from === 'function';\n}","tryCatchPattern":null,"preventionTips":["Always construct the formatter with wNumb({...}), never pass the raw config object.","Type the option as { to(v:number):string; from(s:string):number }.","Unit-test the formatter's round trip before wiring it into the slider."],"tags":["nouislider","validation","configuration","formatter","wnumb"],"backgroundTag":null,"analyzedSha":"824e78248b3de81e383445e76ffb04cc3264fe7d","analyzedAt":"2026-08-13T04:14:22.506Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}