UNPKG

@gitlab/ui

Version:
79 lines (61 loc) 2.9 kB
import curry from 'lodash/fp/curry'; import flatMap from 'lodash/fp/flatMap'; function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } 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 _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } 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."); } var getRepeatingValue = function getRepeatingValue(index) { var values = [100, 500, 400, 200, 100, 800, 400, 500, 600, 300, 800, 900, 110, 700, 400, 300, 500, 300, 400, 600, 700]; return index < values.length ? values[index] : values[index % values.length]; }; var generateTimeSeries = function generateTimeSeries() { return new Array(100).fill(0).map(function (el, i) { return [new Date(2018, 0, i), getRepeatingValue(i)]; }); }; // takes an element and a list and `intersperses' that element between the elements of the list. // (',' ['a', 'b', 'c']) -> ['a', ',', 'b', ',', 'c'] var intersperse = curry(function (separator, items) { var _items = _toArray(items), head = _items[0], rest = _items.slice(1); return [head].concat(_toConsumableArray(flatMap(function (item) { return [separator, item]; }, rest))); }); // inserts a value at a given index into an array // (1, 2, [1, 3, 4]) -> [1, 2, 3, 4] var insert = curry(function (index, newItem, items) { return [].concat(_toConsumableArray(items.slice(0, index)), [newItem], _toConsumableArray(items.slice(index))); }); var data_utils = {}; export default data_utils; export { generateTimeSeries, insert, intersperse };