@helpscout/hsds-react
Version:
React component library for Help Scout's Design System
37 lines (25 loc) • 987 B
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.formatNumber = exports.getMiddleIndex = exports.isOdd = exports.isEven = void 0;
var _lodash = _interopRequireDefault(require("lodash.isnil"));
var _lodash2 = _interopRequireDefault(require("lodash.isnumber"));
var isEven = function isEven(number) {
return Number(number) % 2 === 0;
};
exports.isEven = isEven;
var isOdd = function isOdd(number) {
return !isEven(number);
};
exports.isOdd = isOdd;
var getMiddleIndex = function getMiddleIndex(number) {
var middle = Math.floor(Number(number) / 2);
return isOdd(number) ? middle : middle - 1;
};
exports.getMiddleIndex = getMiddleIndex;
var formatNumber = function formatNumber(num) {
if ((0, _lodash.default)(num)) return num;
if (!(0, _lodash2.default)(num)) return num;
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
};
exports.formatNumber = formatNumber;
;