Skip to content

Commit 6e27869

Browse files
committed
Add str param to plural util
Adds a str param to common/util::plural for pluralizing a string. Applies plural to entry.ts.
1 parent c78d164 commit 6e27869

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/common/util.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export const split = (str: string, delimiter: string): [string, string] => {
1616
return index !== -1 ? [str.substring(0, index).trim(), str.substring(index + 1)] : [str, ""]
1717
}
1818

19-
export const plural = (count: number): string => (count === 1 ? "" : "s")
19+
/**
20+
* Appends an 's' to the provided string if count is greater than one;
21+
* otherwise the string is returned
22+
*/
23+
export const plural = (count: number, str: string): string => (count === 1 ? str : `${str}s`)
2024

2125
export const generateUuid = (length = 24): string => {
2226
const possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

src/node/entry.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile
1111
import { AuthType, HttpServer, HttpServerOptions } from "./http"
1212
import { generateCertificate, hash, open, humanPath } from "./util"
1313
import { ipcMain, wrap } from "./wrapper"
14+
import { plural } from "../common/util"
1415

1516
process.on("uncaughtException", (error) => {
1617
logger.error(`Uncaught exception: ${error.message}`)
@@ -110,7 +111,7 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void>
110111
}
111112

112113
if (httpServer.proxyDomains.size > 0) {
113-
logger.info(` - Proxying the following domain${httpServer.proxyDomains.size === 1 ? "" : "s"}:`)
114+
logger.info(` - ${plural(httpServer.proxyDomains.size, "Proxying the following domain")}:`)
114115
httpServer.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`))
115116
}
116117

src/node/http.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ export class HttpServer {
481481
this.proxyDomains = new Set((options.proxyDomains || []).map((d) => d.replace(/^\*\./, "")))
482482
this.heart = new Heart(path.join(paths.data, "heartbeat"), async () => {
483483
const connections = await this.getConnections()
484-
logger.trace(`${connections} active connection${plural(connections)}`)
484+
logger.trace(plural(connections, `${connections} active connection`))
485485
return connections !== 0
486486
})
487487
this.protocol = this.options.cert ? "https" : "http"

0 commit comments

Comments
 (0)