1 // Translate for example "-name" to [ 'name', 'DESC' ]
2 function getSort (value: string) {
4 let direction: 'ASC' | 'DESC'
6 if (value.substring(0, 1) === '-') {
8 field = value.substring(1)
14 return [ field, direction ]
17 function getSortOnModel (model: any, value: string) {
18 let sort = getSort(value)
20 if (model) return [ model, sort[0], sort[1] ]
24 function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') {
25 if (validator(value) === false) {
26 throw new Error(`"${value}" is not a valid ${fieldName}.`)
30 // ---------------------------------------------------------------------------