add: safeFloatParserを追加

This commit is contained in:
yukineko 2024-01-03 19:02:54 +09:00
parent 4893cce43c
commit 12fcc1c4a4
1 changed files with 11 additions and 0 deletions

View File

@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
export function safeParseFloat(str: unknown): number | null {
if (typeof str !== 'string' || str === '') return null;
const num = parseFloat(str);
if (isNaN(num)) return null;
return num;
}