UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

46 lines (35 loc) 3.77 kB
import _each from "lodash/each"; function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } import assert from 'assert'; import { formatAbbreviatedNumber, formatThousands } from './formatters'; describe('formatters', function () { describe('formatAbbreviatedNumber', function () { var tests = [['negative tens', -10, '-10'], ['tens', 10, '10'], ['hundreds', 100, '100'], ['thousands', 1000, '1.0k'], ['ten thousands', 10000, '10k'], ['hundred thousands', 100000, '100k'], ['millions', 1000000, '1.0M'], ['uneven millions', 1390000, '1.4M'], ['ten millions', 10000000, '10M'], ['hundred millions', 100000000, '100M'], ['billions', 1000000000, '1.0B'], ['ten billions', 10000000000, '10B'], ['hundred billions', 100000000000, '100B'], ['trillions', 1000000000000, '1.0T'], ['ten trillions', 10000000000000, '10T'], ['hundred trillions', 100000000000000, '100T']]; _each(tests, function (_ref) { var _ref2 = _slicedToArray(_ref, 3), name = _ref2[0], value = _ref2[1], expected = _ref2[2]; it("should abbreviate in the ".concat(name), function () { assert.equal(formatAbbreviatedNumber(value), expected); }); }); }); describe('formatNumberNoDecimal', function () { var tests = [['negative tens', -10, '-10'], ['tens', 10, '10'], ['hundreds', 100, '100'], ['thousands', 1000, '1,000'], ['decimal thousands', 1000.126, '1,000'], ['ten thousands', 10000, '10,000'], ['hundred thousands', 100000, '100,000'], ['millions', 1000000, '1,000,000'], ['ten millions', 10000000, '10,000,000'], ['hundred millions', 100000000, '100,000,000'], ['billions', 1000000000, '1,000,000,000'], ['ten billions', 10000000000, '10,000,000,000'], ['hundred billions', 100000000000, '100,000,000,000'], ['trillions', 1000000000000, '1,000,000,000,000'], ['decimal trillions', 1000000000000.855, '1,000,000,000,001'], ['ten trillions', 10000000000000, '10,000,000,000,000'], ['hundred trillions', 100000000000000, '100,000,000,000,000']]; _each(tests, function (_ref3) { var _ref4 = _slicedToArray(_ref3, 3), name = _ref4[0], value = _ref4[1], expected = _ref4[2]; it("should abbreviate in the ".concat(name), function () { assert.equal(formatThousands(value), expected); }); }); }); });