UNPKG

typia

Version:

Superfast runtime validators with only one line

1 lines 2.19 kB
{"version":3,"file":"_notationCamel.mjs","names":[],"sources":["../../src/internal/_notationCamel.ts"],"sourcesContent":["import { __notationRename } from \"./private/__notationRename\";\n\nconst _notationCamelSnake = (str: string): string => {\n while (str.startsWith(\"_\")) str = str.substring(1);\n if (str.length === 0) return \"\";\n const index: number = str.indexOf(\"_\");\n if (index < 0) return str.toLowerCase();\n const middle: string | undefined = str[index + 1];\n // A trailing underscore has no character to uppercase, so `CamelizeSnakeString`\n // falls through to lowercasing the whole key (`foo_` -> `foo_`).\n if (middle === undefined) return str.toLowerCase();\n // A doubled underscore collapses to a single one before continuing.\n return middle === \"_\"\n ? _notationCamelSnake(\n `${str.substring(0, index)}_${str.substring(index + 2)}`,\n )\n : `${str\n .substring(0, index)\n .toLowerCase()}${middle.toUpperCase()}${_notationCamelSnake(\n str.substring(index + 2),\n )}`;\n};\n\nexport const _notationCamel = __notationRename({\n // `CamelCase<T>` lowercases an all-caps key and otherwise lowercases only the\n // first character of an underscore-free key (`HTTP` -> `http`, `userID` stays).\n plain: (str) =>\n str === str.toUpperCase()\n ? str.toLowerCase()\n : `${str[0]!.toLowerCase()}${str.substring(1)}`,\n // With an underscore present, the character after each underscore is\n // uppercased and the rest lowercased, matching `CamelizeSnakeString`.\n snake: _notationCamelSnake,\n});\n"],"mappings":";;AAEA,MAAM,uBAAuB,QAAwB;CACnD,OAAO,IAAI,WAAW,GAAG,GAAG,MAAM,IAAI,UAAU,CAAC;CACjD,IAAI,IAAI,WAAW,GAAG,OAAO;CAC7B,MAAM,QAAgB,IAAI,QAAQ,GAAG;CACrC,IAAI,QAAQ,GAAG,OAAO,IAAI,YAAY;CACtC,MAAM,SAA6B,IAAI,QAAQ;CAG/C,IAAI,WAAW,KAAA,GAAW,OAAO,IAAI,YAAY;CAEjD,OAAO,WAAW,MACd,oBACE,GAAG,IAAI,UAAU,GAAG,KAAK,EAAE,GAAG,IAAI,UAAU,QAAQ,CAAC,GACvD,IACA,GAAG,IACA,UAAU,GAAG,KAAK,CAAC,CACnB,YAAY,IAAI,OAAO,YAAY,IAAI,oBACxC,IAAI,UAAU,QAAQ,CAAC,CACzB;AACN;AAEA,MAAa,iBAAiB,iBAAiB;CAG7C,QAAQ,QACN,QAAQ,IAAI,YAAY,IACpB,IAAI,YAAY,IAChB,GAAG,IAAI,EAAE,CAAE,YAAY,IAAI,IAAI,UAAU,CAAC;CAGhD,OAAO;AACT,CAAC"}