UNPKG

@gitlab/ui

Version:
66 lines (51 loc) 2.16 kB
import curry from 'lodash/fp/curry'; import flatMap from 'lodash/fp/flatMap'; function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } 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 };