Skip to content

Commit db2a498

Browse files
Chase Coalwelltrivikr
authored andcommitted
feat: add isValidHostname function (#774)
1 parent 3928ca1 commit db2a498

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

packages/protocol-http/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const base = require("../../jest.config.base.js");
2+
3+
module.exports = {
4+
...base
5+
};

packages/protocol-http/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./httpResponse";
22
export * from "./httpRequest";
33
export * from "./httpHandler";
4+
export * from "./isValidHostname";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { isValidHostname } from "./isValidHostname";
2+
3+
describe("implementation selection", () => {
4+
it("should return true for valid hostnames", () => {
5+
expect(isValidHostname("foo")).toBe(true);
6+
});
7+
8+
it("should return false for invalid hostnames", () => {
9+
expect(isValidHostname("foo.com/?bar")).toBe(false);
10+
});
11+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function isValidHostname(hostname: string): boolean {
2+
const hostPattern = /^[a-zA-Z0-9]{1}$|^[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]$/;
3+
return hostPattern.test(hostname);
4+
}

0 commit comments

Comments
 (0)