From 6e27869c090c9dae5f73daf6b1a3f722c545202f Mon Sep 17 00:00:00 2001 From: G r e y Date: Sun, 9 Aug 2020 00:06:18 -0500 Subject: [PATCH] Add str param to plural util Adds a str param to common/util::plural for pluralizing a string. Applies plural to entry.ts. --- src/common/util.ts | 6 +++++- src/node/entry.ts | 3 ++- src/node/http.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/util.ts b/src/common/util.ts index 4c9366b4..338a59a1 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -16,7 +16,11 @@ export const split = (str: string, delimiter: string): [string, string] => { return index !== -1 ? [str.substring(0, index).trim(), str.substring(index + 1)] : [str, ""] } -export const plural = (count: number): string => (count === 1 ? "" : "s") +/** + * Appends an 's' to the provided string if count is greater than one; + * otherwise the string is returned + */ +export const plural = (count: number, str: string): string => (count === 1 ? str : `${str}s`) export const generateUuid = (length = 24): string => { const possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" diff --git a/src/node/entry.ts b/src/node/entry.ts index a030cb49..252727fa 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -11,6 +11,7 @@ import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile import { AuthType, HttpServer, HttpServerOptions } from "./http" import { generateCertificate, hash, open, humanPath } from "./util" import { ipcMain, wrap } from "./wrapper" +import { plural } from "../common/util" process.on("uncaughtException", (error) => { logger.error(`Uncaught exception: ${error.message}`) @@ -110,7 +111,7 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise } if (httpServer.proxyDomains.size > 0) { - logger.info(` - Proxying the following domain${httpServer.proxyDomains.size === 1 ? "" : "s"}:`) + logger.info(` - ${plural(httpServer.proxyDomains.size, "Proxying the following domain")}:`) httpServer.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`)) } diff --git a/src/node/http.ts b/src/node/http.ts index 216ff5a2..eae13b9f 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -481,7 +481,7 @@ export class HttpServer { this.proxyDomains = new Set((options.proxyDomains || []).map((d) => d.replace(/^\*\./, ""))) this.heart = new Heart(path.join(paths.data, "heartbeat"), async () => { const connections = await this.getConnections() - logger.trace(`${connections} active connection${plural(connections)}`) + logger.trace(plural(connections, `${connections} active connection`)) return connections !== 0 }) this.protocol = this.options.cert ? "https" : "http"