summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/safe-parse.ts
blob: 7bce1f79ca03d3853186513ad70c45bbdf753803 (plain)
1
2
3
4
5
6
7
8
9
10
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;
}