UNPKG

typia

Version:

Superfast runtime validators with only one line

1 lines 1.33 kB
{"version":3,"file":"__notationRename.mjs","names":[],"sources":["../../../src/internal/private/__notationRename.ts"],"sourcesContent":["/**\n * Shared outer walk for the `camel`/`pascal` notations.\n *\n * Mirrors the `CamelCase<T>` / `PascalCase<T>` typings: leading underscores are\n * preserved verbatim, an all-underscore key stays untouched, and the presence\n * of any remaining underscore — not the number of non-empty segments — selects\n * the `snake` conversion. Routing on underscore presence keeps a trailing or\n * doubled underscore (`fooBar_`) on the same path the type takes, instead of\n * collapsing it to the underscore-free `plain` path.\n */\nexport const __notationRename =\n (props: { plain: (str: string) => string; snake: (str: string) => string }) =>\n (str: string): string => {\n let prefix: string = \"\";\n while (str.startsWith(\"_\")) {\n prefix += \"_\";\n str = str.substring(1);\n }\n if (str.length === 0) return prefix;\n return `${prefix}${str.includes(\"_\") ? props.snake(str) : props.plain(str)}`;\n };\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,oBACV,WACA,QAAwB;CACvB,IAAI,SAAiB;CACrB,OAAO,IAAI,WAAW,GAAG,GAAG;EAC1B,UAAU;EACV,MAAM,IAAI,UAAU,CAAC;CACvB;CACA,IAAI,IAAI,WAAW,GAAG,OAAO;CAC7B,OAAO,GAAG,SAAS,IAAI,SAAS,GAAG,IAAI,MAAM,MAAM,GAAG,IAAI,MAAM,MAAM,GAAG;AAC3E"}