@point-hub/papi
Version:
Point API Framework
93 lines • 2.65 kB
TypeScript
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
* convertFieldObject(["name", "address"]) // => { name: 1, address: 1 }
* convertFieldObject(["name", "address"], -1) // => { name: -1, address: -1 }
*/
export declare function convertFieldObject(array: string[], value?: number): IFieldsObject;
/**
* Converts a flat array of string fields (with optional negative prefix for descending)
* into a single object suitable for MongoDB-style sorting.
*
* Example:
* ['-firstName', 'lastName', 'created_at']
* becomes
* { firstName: -1, lastName: 1, created_at: 1 }
*/
export declare function convertSortObject(input: string[]): Record<string, 1 | -1>;
/**
* 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;
convertFieldObject: typeof convertFieldObject;
convertSortObject: typeof convertSortObject;
};
export default _default;
//# sourceMappingURL=mongodb-querystring.d.ts.map