Ramda Adjunct 5.0.1

isNaturalNumber.js

import { both, complement, curryN } from 'ramda';

import isInteger from './isInteger.js';
import isNegative from './isNegative.js';

/**
 * Checks if value is a natural number.
 * Natural numbers correspond to all non-negative integers and 0.
 *
 * @func isNaturalNumber
 * @memberOf RA
 * @since {@link https://char0n.github.io/ramda-adjunct/2.29.0|v2.29.0}
 * @category Type
 * @sig * -> Boolean
 * @param {*} val The value to test
 * @return {boolean}
 * @example
 *
 * RA.isNaturalNumber(5); // => true
 * RA.isNaturalNumber(Number.MAX_VALUE); // => true
 * RA.isNaturalNumber(0); // => true
 * RA.isNaturalNumber(-1); // => false
 * RA.isNaturalNumber(0.9); // => false
 */

const isNaturalNumber = curryN(1, both(isInteger, complement(isNegative)));

export default isNaturalNumber;