
{{> ../common}}

export function jsonReviver(key:string, value:any) {
    if (typeof value === 'string') {
        if (value.startsWith("20") && /^\d{4}-\d{2}-\d{2}/.test(value)) {
            const d= new Date(value);
            return d;
        }
    }
    return value;
}

export function pad(n: number) {
  return n < 10 ? "0" + n : n;
}

export function toISOString(d: Date) {
  return (
    d.getUTCFullYear() + "-" +
    pad(d.getUTCMonth() + 1) + "-" +
    pad(d.getUTCDate()) + "T" +
    pad(d.getUTCHours()) + ":" +
    pad(d.getUTCMinutes()) + ":" +
    pad(d.getUTCSeconds()) + "Z"
  );
}

function formatParam(p: unknown) {
  if (Object.prototype.toString.call(p) === "[object Date]") {
    return toISOString(p as Date);
  }
  return p;
}


export type AjaxMethod = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS";
