import { utils } from "./utils"; export class OrderProperty { constructor(private propertyPath: string, private isDesc: boolean = null) { if (!utils.isString(propertyPath)) throw new Error("Property name is not a valid string"); propertyPath = propertyPath.trim(); const parts = propertyPath.split(" "); // parts[0] is the propertyPath; [1] would be whether descending or not. if (parts.length > 1 && isDesc !== true && isDesc !== false) { isDesc = parts[1].toLowerCase() == "desc"; if (!isDesc) { // isDesc is false but check to make sure its intended. const isAsc = parts[1].toLowerCase() == "asc"; if (!isAsc) { throw new Error("the second word in the propertyPath must begin with 'desc' or 'asc'"); } } } this.propertyPath = parts[0]; this.isDesc = isDesc; } getPropertyPath(): string { return this.propertyPath; } getDirection(): boolean { return this.isDesc; } getValue(): string { const direction = (this.isDesc) ? "desc" : "asc"; return this.propertyPath + " " + direction; } }