aboutsummaryrefslogtreecommitdiff
path: root/src/arguments/abbreviatedNumber.ts
blob: a98699c6a6305967fcccd61acb523e3cd97cb3c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
import { type BushArgumentTypeCaster } from '#lib';
import assert from 'assert';
import numeral from 'numeral';
assert(typeof numeral === 'function');

export const abbreviatedNumber: BushArgumentTypeCaster<number | null> = (_, phrase) => {
	if (!phrase) return null;
	const num = numeral(phrase?.toLowerCase()).value();

	if (num === undefined || num === null || isNaN(num)) return null;

	return num;
};