Skip to content

Commit 49e8d25

Browse files
authored
Merge pull request #1906 from cjihrig/underscore
deps: remove underscore dependency
2 parents 68a4491 + 28bf7b9 commit 49e8d25

File tree

4 files changed

+31
-41
lines changed

4 files changed

+31
-41
lines changed

package-lock.json

Lines changed: 0 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"@types/node-fetch": "^2.6.9",
6060
"@types/stream-buffers": "^3.0.3",
6161
"@types/tar": "^6.1.1",
62-
"@types/underscore": "^1.8.9",
6362
"@types/ws": "^8.5.4",
6463
"form-data": "^4.0.0",
6564
"isomorphic-ws": "^5.0.0",
@@ -72,7 +71,6 @@
7271
"tar": "^7.0.0",
7372
"tmp-promise": "^3.0.2",
7473
"tslib": "^2.5.0",
75-
"underscore": "^1.9.1",
7674
"url-parse": "^1.4.3",
7775
"ws": "^8.18.0"
7876
},

src/config_types.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as fs from 'fs';
2-
import * as _ from 'underscore';
32

43
export enum ActionOnInvalid {
54
THROW = 'throw',
@@ -26,9 +25,13 @@ export interface Cluster {
2625
}
2726

2827
export function newClusters(a: any, opts?: Partial<ConfigOptions>): Cluster[] {
28+
if (!Array.isArray(a)) {
29+
return [];
30+
}
31+
2932
const options = Object.assign(defaultNewConfigOptions(), opts || {});
3033

31-
return _.compact(_.map(a, clusterIterator(options.onInvalidEntry)));
34+
return a.map(clusterIterator(options.onInvalidEntry)).filter(Boolean) as Cluster[];
3235
}
3336

3437
export function exportCluster(cluster: Cluster): any {
@@ -44,8 +47,10 @@ export function exportCluster(cluster: Cluster): any {
4447
};
4548
}
4649

47-
function clusterIterator(onInvalidEntry: ActionOnInvalid): _.ListIterator<any, Cluster | null> {
48-
return (elt: any, i: number, list: _.List<any>): Cluster | null => {
50+
function clusterIterator(
51+
onInvalidEntry: ActionOnInvalid,
52+
): (elt: any, i: number, list: any[]) => Cluster | null {
53+
return (elt: any, i: number, list: any[]): Cluster | null => {
4954
try {
5055
if (!elt.name) {
5156
throw new Error(`clusters[${i}].name is missing`);
@@ -90,9 +95,13 @@ export interface User {
9095
}
9196

9297
export function newUsers(a: any, opts?: Partial<ConfigOptions>): User[] {
98+
if (!Array.isArray(a)) {
99+
return [];
100+
}
101+
93102
const options = Object.assign(defaultNewConfigOptions(), opts || {});
94103

95-
return _.compact(_.map(a, userIterator(options.onInvalidEntry)));
104+
return a.map(userIterator(options.onInvalidEntry)).filter(Boolean) as User[];
96105
}
97106

98107
export function exportUser(user: User): any {
@@ -112,8 +121,8 @@ export function exportUser(user: User): any {
112121
};
113122
}
114123

115-
function userIterator(onInvalidEntry: ActionOnInvalid): _.ListIterator<any, User | null> {
116-
return (elt: any, i: number, list: _.List<any>): User | null => {
124+
function userIterator(onInvalidEntry: ActionOnInvalid): (elt: any, i: number, list: any[]) => User | null {
125+
return (elt: any, i: number, list: any[]): User | null => {
117126
try {
118127
if (!elt.name) {
119128
throw new Error(`users[${i}].name is missing`);
@@ -161,9 +170,13 @@ export interface Context {
161170
}
162171

163172
export function newContexts(a: any, opts?: Partial<ConfigOptions>): Context[] {
173+
if (!Array.isArray(a)) {
174+
return [];
175+
}
176+
164177
const options = Object.assign(defaultNewConfigOptions(), opts || {});
165178

166-
return _.compact(_.map(a, contextIterator(options.onInvalidEntry)));
179+
return a.map(contextIterator(options.onInvalidEntry)).filter(Boolean) as Context[];
167180
}
168181

169182
export function exportContext(ctx: Context): any {
@@ -173,8 +186,10 @@ export function exportContext(ctx: Context): any {
173186
};
174187
}
175188

176-
function contextIterator(onInvalidEntry: ActionOnInvalid): _.ListIterator<any, Context | null> {
177-
return (elt: any, i: number, list: _.List<any>): Context | null => {
189+
function contextIterator(
190+
onInvalidEntry: ActionOnInvalid,
191+
): (elt: any, i: number, list: any[]) => Context | null {
192+
return (elt: any, i: number, list: any[]): Context | null => {
178193
try {
179194
if (!elt.name) {
180195
throw new Error(`contexts[${i}].name is missing`);

src/util.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Response } from 'node-fetch';
2-
import { isNumber } from 'underscore';
32
import { CoreV1Api, V1Container, V1Pod } from './gen';
43

54
export async function podsForNode(api: CoreV1Api, nodeName: string): Promise<V1Pod[]> {
@@ -108,15 +107,15 @@ export function totalMemory(pod: V1Pod): ResourceStatus {
108107
}
109108

110109
export function add(n1: number | bigint, n2: number | bigint): number | bigint {
111-
if (isNumber(n1) && isNumber(n2)) {
110+
if (typeof n1 === 'number' && typeof n2 === 'number') {
112111
return n1 + n2;
113112
}
114-
if (isNumber(n1)) {
115-
return BigInt(Math.round(n1)) + (n2 as bigint);
116-
} else if (isNumber(n2)) {
117-
return (n1 as bigint) + BigInt(Math.round(n2));
113+
if (typeof n1 === 'number') {
114+
return BigInt(Math.round(n1)) + BigInt(n2);
115+
} else if (typeof n2 === 'number') {
116+
return BigInt(n1) + BigInt(Math.round(n2));
118117
}
119-
return ((n1 as bigint) + n2) as bigint;
118+
return BigInt(n1) + BigInt(n2);
120119
}
121120

122121
export function containerTotalForResource(container: V1Container, resource: string): ResourceStatus {

0 commit comments

Comments
 (0)