UNPKG

2.08 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.uniq = exports.omit = exports.padEnd = exports.isBetween = void 0;
4var util_1 = require("@antv/util");
5/**
6 * @ignore
7 * Determines whether between is
8 * @param value
9 * @param start
10 * @param end
11 * @returns true if between
12 */
13function isBetween(value, start, end) {
14 var min = Math.min(start, end);
15 var max = Math.max(start, end);
16 return value >= min && value <= max;
17}
18exports.isBetween = isBetween;
19/**
20 * @ignore
21 * pads the current string/array with a given value (repeated, if needed) so that the resulting reaches a given length.
22 * The padding is applied from the end of the current value.
23 *
24 * @param source
25 * @param targetLength
26 * @param padValue
27 * @returns
28 */
29function padEnd(source, targetLength, padValue) {
30 if ((0, util_1.isString)(source)) {
31 return source.padEnd(targetLength, padValue);
32 }
33 else if ((0, util_1.isArray)(source)) {
34 var sourceLength = source.length;
35 if (sourceLength < targetLength) {
36 var diff = targetLength - sourceLength;
37 for (var i = 0; i < diff; i++) {
38 source.push(padValue);
39 }
40 }
41 }
42 return source;
43}
44exports.padEnd = padEnd;
45/**
46 * @ignore
47 * omit keys of an object.
48 * @param obj
49 * @param keys
50 */
51function omit(obj, keys) {
52 if (typeof obj === 'object') {
53 keys.forEach(function (key) {
54 delete obj[key];
55 });
56 }
57 return obj;
58}
59exports.omit = omit;
60/**
61 * @ignore
62 * @param sourceArray
63 * @param targetArray
64 * @param map
65 */
66function uniq(sourceArray, targetArray, map) {
67 if (targetArray === void 0) { targetArray = []; }
68 if (map === void 0) { map = new Map(); }
69 for (var _i = 0, sourceArray_1 = sourceArray; _i < sourceArray_1.length; _i++) {
70 var source = sourceArray_1[_i];
71 if (!map.has(source)) {
72 targetArray.push(source);
73 map.set(source, true);
74 }
75 }
76 return targetArray;
77}
78exports.uniq = uniq;
79//# sourceMappingURL=helper.js.map
\No newline at end of file