Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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)}`);
}
}
);
`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;
}
export function decodeElementTypesConstants(type: string): ElementTypes {
switch (type) {
case "selectable":
return type;
default:
throw new TypeError(`Invalid ElementTypes constant: ${repr(type)}`);
}
}
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;
}
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)}`);
}
}
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;
});
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",
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)}`);
}
}
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)}`);
}
}