Equation.js/dist/helpers.js

118 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2015-04-20 09:28:11 +00:00
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var parseFormat = function parseFormat(a) {
var split = a.split('1');
return {
left: split[0].length,
right: split[1].length
};
};
exports.parseFormat = parseFormat;
var isNumber = function isNumber(a) {
return !isNaN(+a);
};
exports.isNumber = isNumber;
2020-06-09 13:58:42 +00:00
var parseNumbers = function parseNumbers(a) {
2015-04-20 09:28:11 +00:00
return a.map(function (b) {
if (isNumber(b)) {
return parseFloat(b);
}
if (Array.isArray(b)) {
return parseNumbers(b);
}
return b;
});
2020-06-09 13:58:42 +00:00
};
2015-04-20 09:28:11 +00:00
exports.parseNumbers = parseNumbers;
var dive = function dive(arr, n) {
var result = arr;
for (var i = 0; i < n; ++i) {
result = result[result.length - 1];
}
return result;
};
exports.dive = dive;
2020-06-09 13:58:42 +00:00
var deep = function deep(arr, n) {
var index = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
2015-04-20 09:28:11 +00:00
if (n < 2) {
return { arr: arr, index: index };
}
var d = arr.reduce(function (a, b, i) {
if (Array.isArray(b)) {
2020-06-09 13:58:42 +00:00
var _deep = deep(b, n - 1, i);
2015-04-20 09:28:11 +00:00
2020-06-09 13:58:42 +00:00
var _arr = _deep.arr;
var x = _deep.index;
2015-04-20 09:28:11 +00:00
var merged = a.concat(_arr);
index = x;
return merged;
}
return a;
}, []);
return { arr: d, index: index };
2020-06-09 13:58:42 +00:00
};
2015-04-20 09:28:11 +00:00
exports.deep = deep;
2020-06-09 13:58:42 +00:00
var diveTo = function diveTo(arr, indexes, replace) {
2015-04-20 09:28:11 +00:00
var answer = [];
if (indexes.some(Array.isArray)) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = indexes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var index = _step.value;
answer.push(diveTo(arr, index, replace));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
} else {
arr[indexes[0]] = replace;
return replace;
}
return answer;
2020-06-09 13:58:42 +00:00
};
2015-04-20 09:28:11 +00:00
exports.diveTo = diveTo;
2020-06-09 13:58:42 +00:00
var flatten = function flatten(arr) {
2015-04-20 09:28:11 +00:00
if (!Array.isArray(arr) || !arr.some(Array.isArray)) {
return arr;
}
return arr.reduce(function (a, b) {
return a.concat(flatten(b));
}, []);
2020-06-09 13:58:42 +00:00
};
2015-04-20 09:28:11 +00:00
exports.flatten = flatten;
var removeSymbols = function removeSymbols(string) {
2015-04-21 12:31:07 +00:00
return string.toString().replace(/\W/g, '');
2015-04-20 09:28:11 +00:00
};
2020-06-09 13:58:42 +00:00
exports.removeSymbols = removeSymbols;