hkt-toolbelt
Version:
Functional and composable type utilities
24 lines (23 loc) • 650 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.digits = void 0;
const __1 = require("..");
/**
* Given a natural number, return the list of digits.
*
* @param {number} x - The natural number to convert to a list of digits.
*
* Similar to `NaturalNumber.ToList`, but returns the list of digits as numbers
* instead of strings.
*
* @example
* ```ts
* import { NaturalNumber } from "hkt-toolbelt";
*
* const result = NaturalNumber.digits(42)
* // ^? [4, 2]
* ```
*/
exports.digits = ((x) => Number.isInteger(x) && Number(x) >= 0
? `${x}`.split('').map((d) => Number(d))
: __1.Type.never);