UNPKG

@point-hub/papi

Version:

Point API Framework

82 lines 2.26 kB
import { SortDirection } from 'mongodb'; interface IFieldsObject { [key: string]: number; } interface ISortObject { [key: string]: SortDirection; } /** * Parse query string to number * * @example * page("10") // => 10 * page(10) // => 10 */ export declare function page(page?: string | number): number; /** * Parse query string to number * * @example * limit("10") // => 10 * limit(10) // => 10 */ export declare function limit(pageSize?: string | number): number; /** * Skip number of data from page * * @example * skip(1, 10) // => 0 * skip(2, 10) // => 10 * skip(3, 10) // => 20 */ export declare function skip(currentPage: string | number, pageSize: string | number): number; export declare function filter(filter: any): any; /** * Convert string param to mongodb field object * * @example * fields("name, address") // => { name: 1, address: 1 } */ export declare function fields(fields?: string, excludeFields?: string[]): IFieldsObject; /** * Convert string to array * * @example * convertStringToArray("name, address") // => ["name", "address"] */ export declare function convertStringToArray(fields: string): string[]; /** * Convert array to mongodb field object * * @example * convertArrayToObject(["name", "address"]) // => { name: 1, address: 1 } * convertArrayToObject(["name", "address"], -1) // => { name: -1, address: -1 } */ export declare function convertArrayToObject(array: string[], value?: number): IFieldsObject; /** * Remove excluded fields * * @example * ex: { password: 0 } */ export declare function filterExludeFields(obj: IFieldsObject, excludeFields: string[]): IFieldsObject; /** * Convert string param to mongodb sort object * * @example * sort("name, -createdAt") // => { name: 1, createdAt: -1 } */ export declare function sort(fields: string): ISortObject; declare const _default: { page: typeof page; limit: typeof limit; skip: typeof skip; sort: typeof sort; fields: typeof fields; filter: typeof filter; filterExludeFields: typeof filterExludeFields; convertStringToArray: typeof convertStringToArray; convertArrayToObject: typeof convertArrayToObject; }; export default _default; //# sourceMappingURL=mongodb-querystring.d.ts.map