@adonisjs/bodyparser
Version:
BodyParser middleware for AdonisJS http server to read and parse request body
50 lines (49 loc) • 1.37 kB
TypeScript
/**
* A collection of form fields that stores form data while handling
* arrays gracefully
*/
export declare class FormFields {
#private;
/**
* Creates a new FormFields instance for collecting form data.
*
* @param normalizer - Optional normalizer function to process string values
*/
constructor(normalizer?: (value: string) => string | null);
/**
* Add a new key/value pair. The keys with array-like
* expressions are handled properly.
*
* @param key - The field name, can include array notation
* @param value - The field value
*
* @example
* ```
* formfields.add('username', 'virk')
*
* // array
* formfields.add('username[]', 'virk')
* formfields.add('username[]', 'nikk')
*
* // Indexed keys are ordered properly
* formfields.add('username[1]', 'virk')
* formfields.add('username[0]', 'nikk')
* ```
*/
add(key: string, value: any): void;
/**
* Returns the collected form fields as an object.
*
* @example
* ```ts
* const fields = new FormFields()
* fields.add('username', 'virk')
* fields.add('tags[]', 'node')
* fields.add('tags[]', 'typescript')
*
* console.log(fields.get())
* // { username: 'virk', tags: ['node', 'typescript'] }
* ```
*/
get(): any;
}