How to use the tiny-decoders.array function in tiny-decoders

To help you get started, we’ve selected a few tiny-decoders examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lydell / LinkHints / src / worker / decoders.js View on Github external
};

      case "UpdateElements":
        return {
          type: "UpdateElements",
          token: "",
          viewports: field("viewports", decodeViewports),
        };

      default:
        throw fieldError("type", `Unknown FrameMessage type: ${repr(type)}`);
    }
  }
);

const decodeViewports: Decoder> = array(
  autoRecord({
    // A viewport of a frame can be partially off-screen.
    x: number,
    y: number,
    width: decodeUnsignedFloat,
    height: decodeUnsignedFloat,
  })
);
github lydell / tiny-decoders / typescript / decoders.ts View on Github external
// $ExpectType { readonly [key: string]: unknown; }
mixedDict(undefined);
// $ExpectType true
constant(true)(undefined);
// $ExpectType false
constant(false)(undefined);
// $ExpectType 0
constant(0)(undefined);
// $ExpectType "const"
constant("const")(undefined);
// $ExpectType undefined
constant(undefined)(undefined);
// $ExpectType null
constant(null)(undefined);
// $ExpectType string[]
array(string)(undefined);
// $ExpectType { [key: string]: string; }
dict(string)(undefined);
// $ExpectType string
record(() => "")(undefined);
// $ExpectType { a: string; }
record(field => ({ a: field("a", string) }))(undefined);
// $ExpectType string
tuple(() => "")(undefined);
// $ExpectType string[]
tuple(item => [item(0, string)])(undefined);
// $ExpectType [string]
tuple<[string]>(item => [item(0, string)])(undefined);
// $ExpectType [string, boolean]
pair(string, boolean)(undefined);
// $ExpectType [string, boolean, boolean]
triple(string, boolean, boolean)(undefined);
github lydell / LinkHints / src / shared / tweakable.js View on Github external
    arr => new Set(array(decoder)(normalizeStringArray(arr)))
  );
github lydell / LinkHints / src / shared / hints.js View on Github external
throw new TypeError(`Invalid ElementType: ${repr(type)}`);
  }
}

export function decodeElementTypesConstants(type: string): ElementTypes {
  switch (type) {
    case "selectable":
      return type;
    default:
      throw new TypeError(`Invalid ElementTypes constant: ${repr(type)}`);
  }
}

export const decodeElementTypes: Decoder = either(
  map(string, decodeElementTypesConstants),
  array(map(string, decodeElementType))
);

export type Point = {
  x: number,
  y: number,
  align: "left" | "right",
  debug: string,
};

export type HintMeasurements = {
  ...Point,
  maxX: number,
  weight: number,
};

export type VisibleElement = {
github lydell / LinkHints / src / shared / perf.js View on Github external
});

export type Perf = Array<{
  timeToFirstPaint: number,
  timeToLastPaint: number,
  topDurations: Durations,
  collectStats: Array,
  renderDurations: Durations,
}>;

export const decodePerf: Decoder = array(
  autoRecord({
    timeToFirstPaint: number,
    timeToLastPaint: number,
    topDurations: decodeDurations,
    collectStats: array(decodeStats),
    renderDurations: decodeDurations,
  })
);

export type TabsPerf = { [tabId: string]: Perf, ... };

export const decodeTabsPerf: Decoder = dict(decodePerf);

export class TimeTracker {
  _durations: Durations = [];
  _current: ?{ label: string, timestamp: number } = undefined;

  start(label: string) {
    this.stop();

    this._current = {
github lydell / LinkHints / src / shared / perf.js View on Github external
numTrackedElements: number,
  numVisibleElements: number,
  numVisibleFrames: number,
  bailed: number,
  durations: decodeDurations,
});

export type Perf = Array<{
  timeToFirstPaint: number,
  timeToLastPaint: number,
  topDurations: Durations,
  collectStats: Array,
  renderDurations: Durations,
}>;

export const decodePerf: Decoder = array(
  autoRecord({
    timeToFirstPaint: number,
    timeToLastPaint: number,
    topDurations: decodeDurations,
    collectStats: array(decodeStats),
    renderDurations: decodeDurations,
  })
);

export type TabsPerf = { [tabId: string]: Perf, ... };

export const decodeTabsPerf: Decoder = dict(decodePerf);

export class TimeTracker {
  _durations: Durations = [];
  _current: ?{ label: string, timestamp: number } = undefined;
github lydell / LinkHints / src / shared / options.js View on Github external
default: defaults.logLevel,
    }),
    useKeyTranslations: field("useKeyTranslations", boolean, {
      default: defaults.useKeyTranslations,
    }),
    keyTranslations: field("keyTranslations", dict(decodeKeyPair, "skip"), {
      default: defaults.keyTranslations,
    }),
    normalKeyboardShortcuts: field(
      "normalKeyboardShortcuts",
      array(decodeKeyboardMappingWithModifiers, "skip"),
      { default: defaults.normalKeyboardShortcuts }
    ),
    hintsKeyboardShortcuts: field(
      "hintsKeyboardShortcuts",
      array(decodeKeyboardMapping, "skip"),
      { default: defaults.hintsKeyboardShortcuts }
    ),
  }));
}