refactor: deduplicate embed utils

This commit is contained in:
Chi Vinh Le
2018-11-01 20:28:09 +01:00
parent c81d612c70
commit 625ef9cbee
6 changed files with 1 additions and 67 deletions
@@ -1,6 +1,6 @@
import qs from "query-string";
import { buildURL } from "../utils";
import { buildURL } from "talk-framework/utils";
import { Decorator } from "./types";
function getCurrentCommentID() {
@@ -1,18 +0,0 @@
import buildURL from "./buildURL";
it("should default to window.location", () => {
const url = buildURL();
expect(url).toBe("http://localhost/");
});
it("should build from parameters", () => {
const url = buildURL({
protocol: "https",
hostname: "hostname",
port: "8080",
pathname: "/pathname",
search: "search",
hash: "#hash",
});
expect(url).toBe("https//hostname:8080/pathname?search#hash");
});
-17
View File
@@ -1,17 +0,0 @@
export default function buildURL({
protocol = window.location.protocol,
hostname = window.location.hostname,
port = window.location.port,
pathname = window.location.pathname,
search = window.location.search,
hash = window.location.hash,
} = {}) {
if (search && search[0] !== "?") {
search = `?${search}`;
} else if (search === "?") {
search = "";
}
return `${protocol}//${hostname}${
port ? `:${port}` : ""
}${pathname}${search}${hash}`;
}
-2
View File
@@ -1,4 +1,2 @@
export { default as buildURL } from "./buildURL";
export { default as startsWith } from "./startsWith";
export { default as prefixStorage } from "./prefixStorage";
export { default as parseHashQuery } from "./parseHashQuery";
@@ -1,24 +0,0 @@
import parseHashQuery from "./parseHashQuery";
it("should parse hash", () => {
const testCases: Array<[string, ReturnType<typeof parseHashQuery>]> = [
[
"#commentID=comment-id",
{
commentID: "comment-id",
},
],
[
"#commentID=comment-id&storyURL=story-url",
{
commentID: "comment-id",
storyURL: "story-url",
},
],
["#", {}],
["", {}],
];
testCases.forEach(tc => {
expect(parseHashQuery(tc[0])).toEqual(tc[1]);
});
});
@@ -1,5 +0,0 @@
import qs from "query-string";
export default function parseQueryHash(hash: string): Record<string, string> {
return qs.parse(hash);
}