Sha256: 854b0dbb1aec2fb19ffc95b48aed1646d5df6bf28666154aa5268443ad591cb0

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

/* This is generated by ts_routes-rails */

type ScalarType = string | number | boolean;

function $buildOptions(options: any, names: string[]): string {
  if (options) {
    let anchor = "";
    const q = [];
    for (const key of Object.keys(options)) {
      if (names.indexOf(key) !== -1) {
        // the key is already consumed
        continue;
      }

      const value = options[ key ];

      if (key === "anchor") {
        anchor = `#${$encode(value)}`;
      } else if ($isScalarType(value)) {
        q.push(`${$encode(key)}=${$encode(value)}`);
      } else if (Array.isArray(value)) {
        for (const v of value) {
          const k = `${key}[]`;
          q.push(`${$encode(k)}=${$encode(v)}`);
        }
      } else if($isNotNull(value)) { // i.e. non-null, non-scalar, non-array type
        for (const k of Object.keys(value)) {
          const hk = `${key}[${k}]`;
          q.push(`${$encode(hk)}=${$encode(value[k])}`);
        }
      }
    }
    return (q.length > 0 ? "?" + q.join("&") : "") + anchor;
  } else {
    return "";
  }
}

function $encode(value: any): string {
  return encodeURIComponent(value);
}

function $isNotNull(value: any): boolean {
  return value !== undefined && value !== null;
}

function $isScalarType(value: any): value is ScalarType {
  return typeof(value) === "string" || typeof(value) === "number" || typeof(value) === "boolean";
}

function $isPresent(value: any): boolean {
  return $isNotNull(value) && ("" + value).length > 0;
}

function $hasPresentOwnProperty(options: any, key: string): boolean {
  return options && options.hasOwnProperty(key) && $isPresent(options[key]);
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ts_routes-0.6.0 lib/ts_routes/runtime.ts