UNPKG

typia

Version:

Superfast runtime validators with only one line

24 lines (23 loc) 914 B
//#region src/internal/private/__notationRename.ts /** * Shared outer walk for the `camel`/`pascal` notations. * * Mirrors the `CamelCase<T>` / `PascalCase<T>` typings: leading underscores are * preserved verbatim, an all-underscore key stays untouched, and the presence * of any remaining underscore — not the number of non-empty segments — selects * the `snake` conversion. Routing on underscore presence keeps a trailing or * doubled underscore (`fooBar_`) on the same path the type takes, instead of * collapsing it to the underscore-free `plain` path. */ const __notationRename = (props) => (str) => { let prefix = ""; while (str.startsWith("_")) { prefix += "_"; str = str.substring(1); } if (str.length === 0) return prefix; return `${prefix}${str.includes("_") ? props.snake(str) : props.plain(str)}`; }; //#endregion export { __notationRename }; //# sourceMappingURL=__notationRename.mjs.map