Support for creating New Groups
This commit is contained in:
parent
1934120e46
commit
5de4babc0d
56 changed files with 6222 additions and 526 deletions
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue