How to use the tiny-decoders.repr 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 / shared / options.js View on Github external
function validateChars(chars: string): string {
  if (/\s/.test(chars)) {
    throw new TypeError(
      `Expected chars not to contain whitespace, but got: ${repr(chars)}`
    );
  }

  const match = /(.)(?=.*\1)/.exec(chars);
  if (match != null) {
    throw new TypeError(
      `Expected chars not to contain duplicate characters, but got ${repr(
        match[1]
      )} more than once.`
    );
  }

  if (chars.length < MIN_CHARS) {
    throw new TypeError(
      `Expected at least ${repr(MIN_CHARS)} chars, but got: ${repr(
        chars.length
github lydell / LinkHints / src / worker / decoders.js View on Github external
return {
          type: "FindElements",
          token: "",
          types: field("types", decodeElementTypes),
          viewports: field("viewports", decodeViewports),
        };

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

      default:
        throw fieldError("type", `Unknown FrameMessage type: ${repr(type)}`);
    }
  }
);
github lydell / LinkHints / src / shared / options.js View on Github external
`Expected chars not to contain whitespace, but got: ${repr(chars)}`
    );
  }

  const match = /(.)(?=.*\1)/.exec(chars);
  if (match != null) {
    throw new TypeError(
      `Expected chars not to contain duplicate characters, but got ${repr(
        match[1]
      )} more than once.`
    );
  }

  if (chars.length < MIN_CHARS) {
    throw new TypeError(
      `Expected at least ${repr(MIN_CHARS)} chars, but got: ${repr(
        chars.length
      )}`
    );
  }

  return chars;
}
github lydell / LinkHints / src / shared / hints.js View on Github external
export function decodeElementTypesConstants(type: string): ElementTypes {
  switch (type) {
    case "selectable":
      return type;
    default:
      throw new TypeError(`Invalid ElementTypes constant: ${repr(type)}`);
  }
}
github lydell / LinkHints / src / shared / keyboard.js View on Github external
function requireModifier(shortcut: Shortcut): Shortcut {
  const { key, alt, cmd, ctrl, shift } = shortcut;
  if (!(alt || cmd || ctrl || (shift && key.length > 1))) {
    throw new TypeError(
      `Expected Shortcut to use a least one modifier, but got: ${repr(
        shortcut
      )}`
    );
  }
  return shortcut;
}
github lydell / LinkHints / src / shared / main.js View on Github external
export function decodeLogLevel(logLevel: mixed): LogLevel {
  switch (logLevel) {
    case "error":
    case "warn":
    case "log":
    case "debug":
      return logLevel;
    default:
      throw new TypeError(`Invalid LogLevel: ${repr(logLevel)}`);
  }
}
github lydell / LinkHints / src / shared / main.js View on Github external
export const decodeUnsignedFloat: Decoder = map(number, value => {
  if (!(Number.isFinite(value) && value >= 0)) {
    throw new TypeError(
      `Expected an unsigned finite float, but got: ${repr(value)}`
    );
  }
  return value;
});
github lydell / LinkHints / src / shared / tweakable.js View on Github external
function update(data: { [string]: mixed, ... }) {
    for (const [key, value] of Object.entries(data)) {
      try {
        if (!{}.hasOwnProperty.call(defaults, key)) {
          throw new TypeError(`Unknown key: ${repr(key)}`);
        }

        const original: TweakableValue = defaults[key];
        errors[key] = undefined;
        changed[key] = false;

        if (value == null) {
          mapping[key] = original;
          continue;
        }

        switch (original.type) {
          case "UnsignedInt": {
            const decoded = decodeUnsignedInt(value);
            mapping[key] = {
              type: "UnsignedInt",
github lydell / LinkHints / src / shared / keyboard.js View on Github external
export function decodeHintsMode(type: string): HintsMode {
  switch (type) {
    case "Click":
    case "ManyClick":
    case "ManyTab":
    case "BackgroundTab":
    case "ForegroundTab":
    case "Select":
      return type;
    default:
      throw new TypeError(`Invalid HintsMode: ${repr(type)}`);
  }
}
github lydell / LinkHints / src / shared / keyboard.js View on Github external
case "EnterHintsMode_ManyClick":
    case "EnterHintsMode_ManyTab":
    case "EnterHintsMode_Select":
    case "ReverseSelection":
    case "Escape":
    case "ActivateHint":
    case "ActivateHintAlt":
    case "Backspace":
    case "RotateHintsForward":
    case "RotateHintsBackward":
    case "RefreshHints":
    case "TogglePeek":
    case "ExitHintsMode":
      return type;
    default:
      throw new TypeError(`Invalid KeyboardAction: ${repr(type)}`);
  }
}