/** * @file number 相关 utils */ export { default as ceil } from 'lodash/ceil' export { default as clamp } from 'lodash/clamp' export { default as floor } from 'lodash/floor' export { default as isInteger } from 'lodash/isInteger' export { default as isNaN } from 'lodash/isNaN' export { default as isNumber } from 'lodash/isNumber' export { default as max } from 'lodash/max' export { default as min } from 'lodash/min' export { default as round } from 'lodash/round' export { default as shuffle } from 'lodash/shuffle' export { default as sum } from 'lodash/sum' export { default as sumBy } from 'lodash/sumBy' export { default as inRange } from 'lodash/inRange' /** * 检查一个变量是否是数字或数字字符串 * * @param n - 检查对象 * @returns 检查结果 * @example * ```javascript * isNumeric('1.1') // true * isNumeric('1s') // false * ``` */ export const isNumeric = (n: number | string) => // eslint-disable-next-line n !== '' && !isNaN(n as any) /** * 判断数字是否为偶数. * * @param n - 数字 * @returns 是否为偶数 */ export const isEven = (n: number) => n % 2 === 0 /** * 判断数字是否为奇数. * * @param n - 数字 * @returns 是否为奇数 */ export const isOdd = (n: number) => Math.abs(n % 2) === 1 /** * 判断数字是否为正数 * * @param n - 数字 * @returns 是否为正数 */ export const isPositive = (n?: number | string | null) => Number(n) >= 0