signal-desktop/ts/util/parseIntWithFallback.ts

13 lines
325 B
TypeScript
Raw Normal View History

2021-03-03 20:09:58 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { parseIntOrThrow } from './parseIntOrThrow';
export function parseIntWithFallback(value: unknown, fallback: number): number {
try {
return parseIntOrThrow(value, 'Failed to parse');
} catch (err) {
return fallback;
}
}