UNPKG

@eightshone/sshman

Version:
23 lines 1.01 kB
import findServer from "./findServer.js"; import normalizeServerName from "./normalizeServerName.js"; function validateServerName(serverName, servers) { // regex for allowed characters const allowedPattern = /^[a-zA-Z0-9 \.:_\-]*$/; // check for allowed characters if (!allowedPattern.test(serverName)) { return "The string contains invalid characters."; } // check if the string starts or ends with invalid characters const invalidStartOrEndPattern = /^[ \.:_\-]|[ \.:_\-]$/; if (invalidStartOrEndPattern.test(serverName)) { return "The string cannot start or end with spaces, dots, colons, dashes, or underscores."; } // check if server exists in the servers list if (findServer(servers, serverName)) { return `The name "${serverName}" (normailzed as "${normalizeServerName(serverName)}") already exists`; } // if all validations pass return true; } export default validateServerName; //# sourceMappingURL=validateServerName.js.map