Skip to content

Commit

Permalink
feat: add isValidHostname function (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Coalwell authored and trivikr committed Jan 22, 2020
1 parent 3928ca1 commit db2a498
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/protocol-http/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const base = require("../../jest.config.base.js");

module.exports = {
...base
};
1 change: 1 addition & 0 deletions packages/protocol-http/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./httpResponse";
export * from "./httpRequest";
export * from "./httpHandler";
export * from "./isValidHostname";
11 changes: 11 additions & 0 deletions packages/protocol-http/src/isValidHostname.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { isValidHostname } from "./isValidHostname";

describe("implementation selection", () => {
it("should return true for valid hostnames", () => {
expect(isValidHostname("foo")).toBe(true);
});

it("should return false for invalid hostnames", () => {
expect(isValidHostname("foo.com/?bar")).toBe(false);
});
});
4 changes: 4 additions & 0 deletions packages/protocol-http/src/isValidHostname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function isValidHostname(hostname: string): boolean {
const hostPattern = /^[a-zA-Z0-9]{1}$|^[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]$/;
return hostPattern.test(hostname);
}

0 comments on commit db2a498

Please sign in to comment.