UNPKG

2.04 kBTypeScriptView Raw
1import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface';
2import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
3/**
4 * @publicApi
5 */
6export interface ParseBoolPipeOptions {
7 /**
8 * The HTTP status code to be used in the response when the validation fails.
9 */
10 errorHttpStatusCode?: ErrorHttpStatusCode;
11 /**
12 * A factory function that returns an exception object to be thrown
13 * if validation fails.
14 * @param error Error message
15 * @returns The exception object
16 */
17 exceptionFactory?: (error: string) => any;
18 /**
19 * If true, the pipe will return null or undefined if the value is not provided
20 * @default false
21 */
22 optional?: boolean;
23}
24/**
25 * Defines the built-in ParseBool Pipe
26 *
27 * @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
28 *
29 * @publicApi
30 */
31export declare class ParseBoolPipe implements PipeTransform<string | boolean, Promise<boolean>> {
32 protected readonly options?: ParseBoolPipeOptions | undefined;
33 protected exceptionFactory: (error: string) => any;
34 constructor(options?: ParseBoolPipeOptions | undefined);
35 /**
36 * Method that accesses and performs optional transformation on argument for
37 * in-flight requests.
38 *
39 * @param value currently processed route argument
40 * @param metadata contains metadata about the currently processed route argument
41 */
42 transform(value: string | boolean, metadata: ArgumentMetadata): Promise<boolean>;
43 /**
44 * @param value currently processed route argument
45 * @returns `true` if `value` is said 'true', ie., if it is equal to the boolean
46 * `true` or the string `"true"`
47 */
48 protected isTrue(value: string | boolean): boolean;
49 /**
50 * @param value currently processed route argument
51 * @returns `true` if `value` is said 'false', ie., if it is equal to the boolean
52 * `false` or the string `"false"`
53 */
54 protected isFalse(value: string | boolean): boolean;
55}