tags.Pattern
type has been changed like below.
By such changement, tags.Pattern
type no more misses escaped characters.
Before
export type Pattern<Value extends string> = TagBase<{
target: "string";
kind: "pattern";
value: Value;
validate: `/${Value}/.test($input)`;
exclusive: ["format", "pattern"];
schema: {
pattern: Value;
};
}>;
After
export type Pattern<Value extends string> = TagBase<{
target: "string";
kind: "pattern";
value: Value;
validate: `RegExp("${Serialize<Value>}").test($input)`;
exclusive: ["format", "pattern"];
schema: {
pattern: Value;
};
}>;
/// reference: https://github.com/type-challenges/type-challenges/issues/22394#issuecomment-1397158205
type Serialize<T extends string, Output extends string = ""> = string extends T
? never
: T extends ""
? Output
: T extends `${infer P}${infer R}`
? Serialize<R, `${Output}${P extends keyof Escaper ? Escaper[P] : P}`>
: never;
type Escaper = {
'"': '\\"';
"\\": "\\\\";
"\b": "\\b";
"\f": "\\f";
"\n": "\\n";
"\r": "\\r";
"\t": "\\t";
};
What's Changed
- Adjust samchon/openapi#40 update to playground. by @samchon in #1231
- Fix #1232: enhance
tags.Pattern
type by type level JSON stringify. by @samchon in #1233
Full Changelog: v6.8.0...v6.9.0