(encoded: Schema.Any, schema: Schema.Any)
| 883 | } |
| 884 | |
| 885 | function getTemplateLiteralParserCoercedElement(encoded: Schema.Any, schema: Schema.Any): Schema.Any | undefined { |
| 886 | const ast = encoded.ast |
| 887 | switch (ast._tag) { |
| 888 | case "Literal": { |
| 889 | const literal = ast.literal |
| 890 | if (!Predicate.isString(literal)) { |
| 891 | const s = String(literal) |
| 892 | return transform(Literal(s), schema, { |
| 893 | strict: true, |
| 894 | decode: () => literal, |
| 895 | encode: () => s |
| 896 | }) |
| 897 | } |
| 898 | break |
| 899 | } |
| 900 | case "NumberKeyword": |
| 901 | return compose(NumberFromString, schema) |
| 902 | case "Union": { |
| 903 | const members: Array<Schema.Any> = [] |
| 904 | let hasCoercions = false |
| 905 | for (const member of ast.types) { |
| 906 | const schema = make(member) |
| 907 | const encoded = encodedSchema(schema) |
| 908 | const coerced = getTemplateLiteralParserCoercedElement(encoded, schema) |
| 909 | if (coerced) { |
| 910 | hasCoercions = true |
| 911 | } |
| 912 | members.push(coerced ?? schema) |
| 913 | } |
| 914 | return hasCoercions ? compose(Union(...members), schema) : schema |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | /** |
| 920 | * @category template literal |
no test coverage detected
searching dependent graphs…