| 11 | * String type |
| 12 | */ |
| 13 | export class StringType implements Type<string> { |
| 14 | readonly name = 'string'; |
| 15 | |
| 16 | isInstance(value: any): boolean { |
| 17 | return value == null || typeof value === 'string'; |
| 18 | } |
| 19 | |
| 20 | isCoercible(value: any): boolean { |
| 21 | return true; |
| 22 | } |
| 23 | |
| 24 | defaultValue(): string { |
| 25 | return ''; |
| 26 | } |
| 27 | |
| 28 | coerce(value: any): string { |
| 29 | if (value == null) return value; |
| 30 | if (typeof value.toJSON === 'function') { |
| 31 | value = value.toJSON(); |
| 32 | } |
| 33 | if (typeof value === 'object') { |
| 34 | return JSON.stringify(value); |
| 35 | } |
| 36 | return String(value); |
| 37 | } |
| 38 | |
| 39 | serialize(value: string | null | undefined) { |
| 40 | return value; |
| 41 | } |
| 42 | } |
nothing calls this directly
no outgoing calls
no test coverage detected