[{"data":1,"prerenderedAt":452},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-valibot\u002Fguides\u002Fcoercion":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":451,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-valibot\u002Fguides\u002Fcoercion.md",{},"Coerce input with Valibot",{"type":8,"value":9,"toc":442},"minimark",[10,19,24,45,234,309,313,326,359,363,371,413,417,431],[11,12,13,14,18],"p",{},"Set ",[15,16,17],"code",{},"coercion"," to convert form data and query strings before Valibot validates them, and see which checks each key changes.",[20,21,23],"h2",{"id":22},"turn-on-coercion","Turn on coercion",[11,25,26,27,30,31,34,35,38,39,44],{},"Pass ",[15,28,29],{},"true"," to coerce strings, numbers, and dates, or an object to pick the primitives. A coerced schema starts from ",[15,32,33],{},"v.unknown()"," and converts with a ",[15,36,37],{},"to*"," action. See ",[40,41,43],"a",{"href":42},"https:\u002F\u002Fvalibot.dev\u002Fapi\u002FtoNumber\u002F","toNumber"," in the Valibot docs.",[46,47,48,115,175],"code-group",{},[49,50,55],"pre",{"language":51,"filename":52,"code":53,"class":54},"typescript","kubb.config.ts","import { pluginValibot } from '@kubb\u002Fplugin-valibot'\n\npluginValibot({ coercion: { numbers: true } })","highlights",[15,56,58,85,86,85,88],{"class":57},"language-typescript",[59,60,63,67,71,75,78,81],"span",{"class":61,"style":62},"line","display: inline",[59,64,66],{"style":65},"color:#d73a49;--hls-dark:#f97583","import ",[59,68,70],{"style":69},"color:#005cc5;--hls-dark:#79b8ff","{ ",[59,72,74],{"style":73},"color:#24292e;--hls-dark:#e1e4e8","pluginValibot ",[59,76,77],{"style":69},"} ",[59,79,80],{"style":65},"from ",[59,82,84],{"style":83},"color:#032f62;--hls-dark:#9ecbff","'@kubb\u002Fplugin-valibot'","\n",[59,87],{"class":61,"style":62},[59,89,90,94,97,99,102,104,107,109,112],{"class":61,"style":62},[59,91,93],{"style":92},"color:#6f42c1;--hls-dark:#b392f0","pluginValibot",[59,95,96],{"style":69},"({ ",[59,98,17],{"style":69},[59,100,101],{"style":65},": ",[59,103,70],{"style":69},[59,105,106],{"style":69},"numbers",[59,108,101],{"style":65},[59,110,111],{"style":69},"true ",[59,113,114],{"style":69},"} })",[49,116,119],{"language":51,"filename":117,"code":118,"class":54},"Before","limit: v.optional(v.pipe(v.number(), v.integer())),",[15,120,121],{"class":57},[59,122,123,126,128,131,134,137,140,142,144,147,149,151,153,156,159,162,164,166,169,172],{"class":61,"style":62},[59,124,125],{"style":73},"limit",[59,127,101],{"style":65},[59,129,130],{"style":73},"v",[59,132,133],{"style":65},".",[59,135,136],{"style":92},"optional",[59,138,139],{"style":69},"(",[59,141,130],{"style":73},[59,143,133],{"style":65},[59,145,146],{"style":92},"pipe",[59,148,139],{"style":69},[59,150,130],{"style":73},[59,152,133],{"style":65},[59,154,155],{"style":92},"number",[59,157,158],{"style":69},"()",[59,160,161],{"style":65},", ",[59,163,130],{"style":73},[59,165,133],{"style":65},[59,167,168],{"style":92},"integer",[59,170,171],{"style":69},"()))",[59,173,174],{"style":65},",",[49,176,179],{"language":51,"filename":177,"code":178,"class":54},"After","limit: v.optional(v.pipe(v.unknown(), v.toNumber(), v.integer())),",[15,180,181],{"class":57},[59,182,183,185,187,189,191,193,195,197,199,201,203,205,207,210,212,214,216,218,220,222,224,226,228,230,232],{"class":61,"style":62},[59,184,125],{"style":73},[59,186,101],{"style":65},[59,188,130],{"style":73},[59,190,133],{"style":65},[59,192,136],{"style":92},[59,194,139],{"style":69},[59,196,130],{"style":73},[59,198,133],{"style":65},[59,200,146],{"style":92},[59,202,139],{"style":69},[59,204,130],{"style":73},[59,206,133],{"style":65},[59,208,209],{"style":92},"unknown",[59,211,158],{"style":69},[59,213,161],{"style":65},[59,215,130],{"style":73},[59,217,133],{"style":65},[59,219,43],{"style":92},[59,221,158],{"style":69},[59,223,161],{"style":65},[59,225,130],{"style":73},[59,227,133],{"style":65},[59,229,168],{"style":92},[59,231,171],{"style":69},[59,233,174],{"style":65},[235,236,237,250],"table",{},[238,239,240],"thead",{},[241,242,243,247],"tr",{},[244,245,246],"th",{},"Value",[244,248,249],{},"Effect",[251,252,253,280,299],"tbody",{},[241,254,255,262],{},[256,257,258,261],"td",{},[15,259,260],{},"false"," (default)",[256,263,264,265,268,269,272,273,276,277,133],{},"No coercion, except ",[15,266,267],{},"format: int64"," fields, which use ",[15,270,271],{},"v.toBigint()"," because JSON holds a number or a string. With the adapter's ",[15,274,275],{},"integerType: 'number'",", they print ",[15,278,279],{},"v.pipe(v.number(), v.integer())",[241,281,282,286],{},[256,283,284],{},[15,285,29],{},[256,287,288,289,161,292,295,296,133],{},"Coerces strings, numbers, and dates with ",[15,290,291],{},"v.toString()",[15,293,294],{},"v.toNumber()",", and ",[15,297,298],{},"v.toDate()",[241,300,301,306],{},[256,302,303],{},[15,304,305],{},"{ dates?, strings?, numbers? }",[256,307,308],{},"Coerces only the primitives you pick.",[20,310,312],{"id":311},"coerce-strings","Coerce strings",[11,314,315,318,319,322,323,133],{},[15,316,317],{},"strings"," prints a plain ",[15,320,321],{},"string"," field as ",[15,324,325],{},"v.pipe(v.unknown(), v.toString())",[327,328,329,337],"ul",{},[330,331,332,333,336],"li",{},"Length and ",[15,334,335],{},"pattern"," checks stay, and run on the converted string.",[330,338,339,161,342,161,345,161,348,295,351,354,355,358],{},[15,340,341],{},"email",[15,343,344],{},"url",[15,346,347],{},"uuid",[15,349,350],{},"ipv4",[15,352,353],{},"ipv6"," fields keep ",[15,356,357],{},"v.string()"," and are not coerced.",[20,360,362],{"id":361},"coerce-numbers","Coerce numbers",[11,364,365,367,368,133],{},[15,366,106],{}," prints number and integer fields as ",[15,369,370],{},"v.pipe(v.unknown(), v.toNumber())",[327,372,373,401],{},[330,374,375,376,295,379,161,382,161,385,388,389,392,393,396,397,400],{},"Integers keep ",[15,377,378],{},"v.integer()",[15,380,381],{},"format: int8",[15,383,384],{},"int16",[15,386,387],{},"int32",", and their ",[15,390,391],{},"uint"," forms keep the ",[15,394,395],{},"v.minValue()"," and ",[15,398,399],{},"v.maxValue()"," of the format's range.",[330,402,403,405,406,409,410,412],{},[15,404,267],{}," fields typed as ",[15,407,408],{},"bigint",", the adapter default, keep ",[15,411,271],{}," with or without this option.",[20,414,416],{"id":415},"coerce-dates","Coerce dates",[11,418,419,422,423,426,427,430],{},[15,420,421],{},"dates"," coerces only response fields typed as ",[15,424,425],{},"Date",", which needs ",[15,428,429],{},"dateType: 'date'"," on the adapter.",[327,432,433,436],{},[330,434,435],{},"Fields kept as ISO strings are never coerced.",[330,437,438,439,441],{},"A request schema writes a ",[15,440,425],{}," back to a string, so it is not coerced either.",{"title":443,"searchDepth":444,"depth":444,"links":445},"",5,[446,448,449,450],{"id":22,"depth":447,"text":23},2,{"id":311,"depth":447,"text":312},{"id":361,"depth":447,"text":362},{"id":415,"depth":447,"text":416},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-valibot\u002Fguides\u002Fcoercion",1795015656097]