Skip to content

deps: remove underscore dependency #1906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
},
Expand Down
35 changes: 25 additions & 10 deletions src/config_types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as fs from 'fs';
import * as _ from 'underscore';

export enum ActionOnInvalid {
THROW = 'throw',
Expand All @@ -26,9 +25,13 @@ export interface Cluster {
}

export function newClusters(a: any, opts?: Partial<ConfigOptions>): 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 {
Expand All @@ -44,8 +47,10 @@ export function exportCluster(cluster: Cluster): any {
};
}

function clusterIterator(onInvalidEntry: ActionOnInvalid): _.ListIterator<any, Cluster | null> {
return (elt: any, i: number, list: _.List<any>): 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`);
Expand Down Expand Up @@ -90,9 +95,13 @@ export interface User {
}

export function newUsers(a: any, opts?: Partial<ConfigOptions>): 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 {
Expand All @@ -112,8 +121,8 @@ export function exportUser(user: User): any {
};
}

function userIterator(onInvalidEntry: ActionOnInvalid): _.ListIterator<any, User | null> {
return (elt: any, i: number, list: _.List<any>): 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`);
Expand Down Expand Up @@ -161,9 +170,13 @@ export interface Context {
}

export function newContexts(a: any, opts?: Partial<ConfigOptions>): 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 {
Expand All @@ -173,8 +186,10 @@ export function exportContext(ctx: Context): any {
};
}

function contextIterator(onInvalidEntry: ActionOnInvalid): _.ListIterator<any, Context | null> {
return (elt: any, i: number, list: _.List<any>): 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`);
Expand Down
13 changes: 6 additions & 7 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -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<V1Pod[]> {
Expand Down Expand Up @@ -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 {
Expand Down
Loading