blob: 5fe39b510f690fdf075306ae5bf5ee683c99aba9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
import type { BotArgumentTypeCaster } from '#lib';
import assert from 'assert/strict';
import numeral from 'numeral';
assert(typeof numeral === 'function');
export const abbreviatedNumber: BotArgumentTypeCaster<number | null> = (_, phrase) => {
if (!phrase) return null;
const num = numeral(phrase?.toLowerCase()).value();
if (typeof num !== 'number' || isNaN(num)) return null;
return num;
};
|