未验证 提交 8d03c22c 编写于 作者: G G r e y 提交者: GitHub

Merge pull request #1956 from cdr/plural

Update common/util::plural
...@@ -16,7 +16,11 @@ export const split = (str: string, delimiter: string): [string, string] => { ...@@ -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, ""] 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 => { export const generateUuid = (length = 24): string => {
const possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" const possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
......
...@@ -11,6 +11,7 @@ import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile ...@@ -11,6 +11,7 @@ import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile
import { AuthType, HttpServer, HttpServerOptions } from "./http" import { AuthType, HttpServer, HttpServerOptions } from "./http"
import { generateCertificate, hash, open, humanPath } from "./util" import { generateCertificate, hash, open, humanPath } from "./util"
import { ipcMain, wrap } from "./wrapper" import { ipcMain, wrap } from "./wrapper"
import { plural } from "../common/util"
process.on("uncaughtException", (error) => { process.on("uncaughtException", (error) => {
logger.error(`Uncaught exception: ${error.message}`) logger.error(`Uncaught exception: ${error.message}`)
...@@ -110,7 +111,7 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void> ...@@ -110,7 +111,7 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void>
} }
if (httpServer.proxyDomains.size > 0) { 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}`)) httpServer.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`))
} }
......
...@@ -481,7 +481,7 @@ export class HttpServer { ...@@ -481,7 +481,7 @@ export class HttpServer {
this.proxyDomains = new Set((options.proxyDomains || []).map((d) => d.replace(/^\*\./, ""))) this.proxyDomains = new Set((options.proxyDomains || []).map((d) => d.replace(/^\*\./, "")))
this.heart = new Heart(path.join(paths.data, "heartbeat"), async () => { this.heart = new Heart(path.join(paths.data, "heartbeat"), async () => {
const connections = await this.getConnections() const connections = await this.getConnections()
logger.trace(`${connections} active connection${plural(connections)}`) logger.trace(plural(connections, `${connections} active connection`))
return connections !== 0 return connections !== 0
}) })
this.protocol = this.options.cert ? "https" : "http" this.protocol = this.options.cert ? "https" : "http"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册