mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Support for creating New Groups
This commit is contained in:
24
ts/util/parseIntOrThrow.ts
Normal file
24
ts/util/parseIntOrThrow.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
export function parseIntOrThrow(value: unknown, message: string): number {
|
||||
let result: number;
|
||||
|
||||
switch (typeof value) {
|
||||
case 'number':
|
||||
result = value;
|
||||
break;
|
||||
case 'string':
|
||||
result = parseInt(value, 10);
|
||||
break;
|
||||
default:
|
||||
result = NaN;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!Number.isInteger(result)) {
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user