UNPKG

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