@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
11 lines (9 loc) • 315 B
text/typescript
import { Get, ofGet } from './Get';
import { tryTo } from './Try';
import { isNumber } from './Is';
import { asString } from './Text';
export const asNumber = (n: unknown, alt?: Get<number>): number =>
tryTo(() => asString(n))
.map(s => parseInt(s))
.filter(n => isNumber(n))
.or(ofGet(alt) ?? NaN);