Skip to content

Parse

parseQuery

Parse a query string to an efficient data structure ⚡. The output will be an object with each possible value of the Parameter enum as property key and the parsed data as value.

Type

ts
declare function parseQuery(input: ParseInput, options?: ParseOptions): string;

Example

typescript
import {
    parseQuery,
} from 'rapiq';

const output = parseQuery({
    fields: ['+age'],
    filters: {
        name: '~pe'
    }
});

console.log(output);
//{
//    fields: [
//        {key: 'age', operator: FieldOperator.INCLUDE}
//    ],
//    filters: [
//        {key: 'name', value: 'pe', operator: FilterComparisonOperator.LIKE}
//   ]
//}

Type Parameters

NameDescription

Parameters

NameTypeDescription
inputParseInputQuery input data passed e.g. via URL more.
optionsParseOptionsOptions for parsing fields, filter, include, ... more

Returns

ParseOutput

The function returns an object.

References

ParseOptions

typescript
type ParseOptions = {
    [Parameter.FIELDS]?: FieldsParseOptions<T> | boolean,
    [Parameter.FILTERS]?: FiltersParseOptions<T> | boolean,
    [Parameter.RELATIONS]?: RelationsParseOptions<T> | boolean,
    [Parameter.PAGINATION]?: PaginationParseOptions | boolean,
    [Parameter.SORT]?: SortParseOptions<T> | boolean,
    defaultPath?: string,
    throwOnFailure?: boolean
}

References

ParseInput

typescript
type ParseInput = {
    [K in Parameter | URLParameter]?: any
}

References

ParseOutput

typescript
type ParseOutput = {
    [Parameter.FIELDS]?: FieldsParseOutput,
    [Parameter.FILTERS]?: FiltersParseOutput,
    [Parameter.RELATIONS]?: RelationsParseOutput,
    [Parameter.PAGINATION]?: PaginationParseOutput,
    [Parameter.SORT]?: SortParseOutput,
}

References