( parser: (v: unknown, k: string) => ParseResult<V>, key: string, )
| 247 | // Parses a single key out of an object, returning |
| 248 | // undefined if the key doesn't exist. |
| 249 | export function optionalObjectKeyParser<V>( |
| 250 | parser: (v: unknown, k: string) => ParseResult<V>, |
| 251 | key: string, |
| 252 | ): (v: unknown) => ParseResult<V | undefined> { |
| 253 | return (value: unknown) => { |
| 254 | if (typeof value === 'object' && !Array.isArray(value) && value != null) { |
| 255 | const withErrorParser = objectValueParserWithError(parser) |
| 256 | const valueAsObject: any = value |
| 257 | if (key in valueAsObject) { |
| 258 | return withErrorParser(valueAsObject[key], key) |
| 259 | } else { |
| 260 | return right(undefined) |
| 261 | } |
| 262 | } else { |
| 263 | return left(descriptionParseError('Not an object.')) |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | export function parseObject<V>( |
| 269 | objectValueParser: (v: unknown, key: string) => ParseResult<V>, |
no test coverage detected