diff --git a/package-lock.json b/package-lock.json index 0b484faa31..c878abdbeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "@types/node-fetch": "^2.6.9", "@types/stream-buffers": "^3.0.3", "@types/tar": "^6.1.1", - "@types/underscore": "^1.8.9", "@types/ws": "^8.5.4", "form-data": "^4.0.0", "isomorphic-ws": "^5.0.0", @@ -27,7 +26,6 @@ "tar": "^7.0.0", "tmp-promise": "^3.0.2", "tslib": "^2.5.0", - "underscore": "^1.9.1", "url-parse": "^1.4.3", "ws": "^8.18.0" }, @@ -368,11 +366,6 @@ "node": ">=8" } }, - "node_modules/@types/underscore": { - "version": "1.11.15", - "resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.11.15.tgz", - "integrity": "sha512-HP38xE+GuWGlbSRq9WrZkousaQ7dragtZCruBVMi0oX1migFZavZ3OROKHSkNp/9ouq82zrWtZpg18jFnVN96g==" - }, "node_modules/@types/unist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", @@ -2627,11 +2620,6 @@ "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==", "dev": true }, - "node_modules/underscore": { - "version": "1.13.7", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.7.tgz", - "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==" - }, "node_modules/undici-types": { "version": "6.19.6", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.6.tgz", @@ -3159,11 +3147,6 @@ } } }, - "@types/underscore": { - "version": "1.11.15", - "resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.11.15.tgz", - "integrity": "sha512-HP38xE+GuWGlbSRq9WrZkousaQ7dragtZCruBVMi0oX1migFZavZ3OROKHSkNp/9ouq82zrWtZpg18jFnVN96g==" - }, "@types/unist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", @@ -4807,11 +4790,6 @@ "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==", "dev": true }, - "underscore": { - "version": "1.13.7", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.7.tgz", - "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==" - }, "undici-types": { "version": "6.19.6", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.6.tgz", diff --git a/package.json b/package.json index e83022cc17..7164919a31 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,6 @@ "@types/node-fetch": "^2.6.9", "@types/stream-buffers": "^3.0.3", "@types/tar": "^6.1.1", - "@types/underscore": "^1.8.9", "@types/ws": "^8.5.4", "form-data": "^4.0.0", "isomorphic-ws": "^5.0.0", @@ -72,7 +71,6 @@ "tar": "^7.0.0", "tmp-promise": "^3.0.2", "tslib": "^2.5.0", - "underscore": "^1.9.1", "url-parse": "^1.4.3", "ws": "^8.18.0" }, diff --git a/src/config_types.ts b/src/config_types.ts index 5ddc887aed..b94bb13265 100644 --- a/src/config_types.ts +++ b/src/config_types.ts @@ -1,5 +1,4 @@ import * as fs from 'fs'; -import * as _ from 'underscore'; export enum ActionOnInvalid { THROW = 'throw', @@ -26,9 +25,13 @@ export interface Cluster { } export function newClusters(a: any, opts?: Partial): Cluster[] { + if (!Array.isArray(a)) { + return []; + } + const options = Object.assign(defaultNewConfigOptions(), opts || {}); - return _.compact(_.map(a, clusterIterator(options.onInvalidEntry))); + return a.map(clusterIterator(options.onInvalidEntry)).filter(Boolean) as Cluster[]; } export function exportCluster(cluster: Cluster): any { @@ -44,8 +47,10 @@ export function exportCluster(cluster: Cluster): any { }; } -function clusterIterator(onInvalidEntry: ActionOnInvalid): _.ListIterator { - return (elt: any, i: number, list: _.List): Cluster | null => { +function clusterIterator( + onInvalidEntry: ActionOnInvalid, +): (elt: any, i: number, list: any[]) => Cluster | null { + return (elt: any, i: number, list: any[]): Cluster | null => { try { if (!elt.name) { throw new Error(`clusters[${i}].name is missing`); @@ -90,9 +95,13 @@ export interface User { } export function newUsers(a: any, opts?: Partial): User[] { + if (!Array.isArray(a)) { + return []; + } + const options = Object.assign(defaultNewConfigOptions(), opts || {}); - return _.compact(_.map(a, userIterator(options.onInvalidEntry))); + return a.map(userIterator(options.onInvalidEntry)).filter(Boolean) as User[]; } export function exportUser(user: User): any { @@ -112,8 +121,8 @@ export function exportUser(user: User): any { }; } -function userIterator(onInvalidEntry: ActionOnInvalid): _.ListIterator { - return (elt: any, i: number, list: _.List): User | null => { +function userIterator(onInvalidEntry: ActionOnInvalid): (elt: any, i: number, list: any[]) => User | null { + return (elt: any, i: number, list: any[]): User | null => { try { if (!elt.name) { throw new Error(`users[${i}].name is missing`); @@ -161,9 +170,13 @@ export interface Context { } export function newContexts(a: any, opts?: Partial): Context[] { + if (!Array.isArray(a)) { + return []; + } + const options = Object.assign(defaultNewConfigOptions(), opts || {}); - return _.compact(_.map(a, contextIterator(options.onInvalidEntry))); + return a.map(contextIterator(options.onInvalidEntry)).filter(Boolean) as Context[]; } export function exportContext(ctx: Context): any { @@ -173,8 +186,10 @@ export function exportContext(ctx: Context): any { }; } -function contextIterator(onInvalidEntry: ActionOnInvalid): _.ListIterator { - return (elt: any, i: number, list: _.List): Context | null => { +function contextIterator( + onInvalidEntry: ActionOnInvalid, +): (elt: any, i: number, list: any[]) => Context | null { + return (elt: any, i: number, list: any[]): Context | null => { try { if (!elt.name) { throw new Error(`contexts[${i}].name is missing`); diff --git a/src/util.ts b/src/util.ts index 02422af9af..ce39d24238 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,4 @@ import { Response } from 'node-fetch'; -import { isNumber } from 'underscore'; import { CoreV1Api, V1Container, V1Pod } from './gen'; export async function podsForNode(api: CoreV1Api, nodeName: string): Promise { @@ -108,15 +107,15 @@ export function totalMemory(pod: V1Pod): ResourceStatus { } export function add(n1: number | bigint, n2: number | bigint): number | bigint { - if (isNumber(n1) && isNumber(n2)) { + if (typeof n1 === 'number' && typeof n2 === 'number') { return n1 + n2; } - if (isNumber(n1)) { - return BigInt(Math.round(n1)) + (n2 as bigint); - } else if (isNumber(n2)) { - return (n1 as bigint) + BigInt(Math.round(n2)); + if (typeof n1 === 'number') { + return BigInt(Math.round(n1)) + BigInt(n2); + } else if (typeof n2 === 'number') { + return BigInt(n1) + BigInt(Math.round(n2)); } - return ((n1 as bigint) + n2) as bigint; + return BigInt(n1) + BigInt(n2); } export function containerTotalForResource(container: V1Container, resource: string): ResourceStatus {