Skip to content

Commit

Permalink
chore: Remove custom prettier config
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnns committed Sep 2, 2021
1 parent 4854bee commit da961f1
Show file tree
Hide file tree
Showing 33 changed files with 1,996 additions and 2,005 deletions.
26 changes: 13 additions & 13 deletions bin/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

"use strict";

const {EOL} = require("os");
const { EOL } = require("os");

(async () => {
process.argv.push(
"--",
"../../serialized-tries",
"../../../build-esm/serialized-tries",
);
process.argv.push(
"--",
"../../serialized-tries",
"../../../build-esm/serialized-tries"
);

await require("../build-cjs/src/scripts/update-tries.js").done;
await require("../build-cjs/src/scripts/update-tries.js").done;

process.stderr.write("Running smoke test... ");
process.stderr.write("Running smoke test... ");

require("../build-cjs/src/smoke-test.js").runSmokeTest();
require("../build-cjs/src/smoke-test.js").runSmokeTest();

process.stdout.write("ok" + EOL);
process.stdout.write("ok" + EOL);
})().catch((error) => {
console.error(`parse-domain update failed: ${error}`);
// eslint-disable-next-line no-process-exit
process.exit(1);
console.error(`parse-domain update failed: ${error}`);
// eslint-disable-next-line no-process-exit
process.exit(1);
});
3 changes: 0 additions & 3 deletions prettier.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion serialized-tries/info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"updatedAt": "2020-04-24T17:18:33.648Z"}
{ "updatedAt": "2020-04-24T17:18:33.648Z" }
2 changes: 1 addition & 1 deletion src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ module.exports = {
project: "./tsconfig.json",
sourceType: "module",
},
};
};
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const PUBLIC_SUFFIX_URL =
"https://publicsuffix.org/list/public_suffix_list.dat";
"https://publicsuffix.org/list/public_suffix_list.dat";
export const PUBLIC_SUFFIX_MARKER_ICANN_START = "// ===BEGIN ICANN DOMAINS===";
export const PUBLIC_SUFFIX_MARKER_ICANN_END = "// ===END ICANN DOMAINS===";
export const PUBLIC_SUFFIX_MARKER_PRIVATE_START =
"// ===BEGIN PRIVATE DOMAINS===";
"// ===BEGIN PRIVATE DOMAINS===";
export const PUBLIC_SUFFIX_MARKER_PRIVATE_END = "// ===END PRIVATE DOMAINS===";
export const FETCH_PSL_EXPECTED_MIN_LENGTH = 214528;
146 changes: 73 additions & 73 deletions src/from-url.test.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
import {fromUrl, NO_HOSTNAME} from "./from-url";
import { fromUrl, NO_HOSTNAME } from "./from-url";

describe(fromUrl.name, () => {
test("it returns the hostname only", () => {
expect(fromUrl("https://user@www.example.com:8080/path?query")).toBe(
"www.example.com",
);
});
test("it returns the hostname only", () => {
expect(fromUrl("https://user@www.example.com:8080/path?query")).toBe(
"www.example.com"
);
});

test("it handles other protocols well", () => {
expect(fromUrl("ftp://user@www.example.com:8080/path?query")).toBe(
"www.example.com",
);
});
test("it handles other protocols well", () => {
expect(fromUrl("ftp://user@www.example.com:8080/path?query")).toBe(
"www.example.com"
);
});

test("it accepts incomplete URLs", () => {
expect(fromUrl("//user@www.example.com:8080/path?query")).toBe(
"www.example.com",
);
expect(fromUrl("user@www.example.com:8080/path?query")).toBe(
"www.example.com",
);
expect(fromUrl("@www.example.com:8080/path?query")).toBe("www.example.com");
expect(fromUrl("www.example.com:8080/path?query")).toBe("www.example.com");
expect(fromUrl("com:8080/path?query")).toBe("com");
expect(fromUrl("com/?query")).toBe("com");
expect(fromUrl("com?query")).toBe("com");
});
test("it accepts incomplete URLs", () => {
expect(fromUrl("//user@www.example.com:8080/path?query")).toBe(
"www.example.com"
);
expect(fromUrl("user@www.example.com:8080/path?query")).toBe(
"www.example.com"
);
expect(fromUrl("@www.example.com:8080/path?query")).toBe("www.example.com");
expect(fromUrl("www.example.com:8080/path?query")).toBe("www.example.com");
expect(fromUrl("com:8080/path?query")).toBe("com");
expect(fromUrl("com/?query")).toBe("com");
expect(fromUrl("com?query")).toBe("com");
});

test("it returns the root domain for URLs with just the root domain", () => {
expect(fromUrl(".:8080/path?query")).toBe(".");
expect(fromUrl("./?query")).toBe(".");
expect(fromUrl(".?query")).toBe(".");
});
test("it returns the root domain for URLs with just the root domain", () => {
expect(fromUrl(".:8080/path?query")).toBe(".");
expect(fromUrl("./?query")).toBe(".");
expect(fromUrl(".?query")).toBe(".");
});

test("it returns a puny-encoded hostname", () => {
expect(fromUrl("http://münchen.de")).toBe("xn--mnchen-3ya.de");
expect(fromUrl("münchen.de")).toBe("xn--mnchen-3ya.de");
});
test("it returns a puny-encoded hostname", () => {
expect(fromUrl("http://münchen.de")).toBe("xn--mnchen-3ya.de");
expect(fromUrl("münchen.de")).toBe("xn--mnchen-3ya.de");
});

test("it handles already puny-encoded hostnames well", () => {
expect(fromUrl("http://xn--mnchen-3ya.de")).toBe("xn--mnchen-3ya.de");
expect(fromUrl("xn--mnchen-3ya.de")).toBe("xn--mnchen-3ya.de");
});
test("it handles already puny-encoded hostnames well", () => {
expect(fromUrl("http://xn--mnchen-3ya.de")).toBe("xn--mnchen-3ya.de");
expect(fromUrl("xn--mnchen-3ya.de")).toBe("xn--mnchen-3ya.de");
});

test("it handles URLs with IPv4", () => {
expect(fromUrl("http://192.168.1.1/path?query")).toBe("192.168.1.1");
expect(fromUrl("//192.168.1.1")).toBe("192.168.1.1");
expect(fromUrl("192.168.1.1")).toBe("192.168.1.1");
});
test("it handles URLs with IPv4", () => {
expect(fromUrl("http://192.168.1.1/path?query")).toBe("192.168.1.1");
expect(fromUrl("//192.168.1.1")).toBe("192.168.1.1");
expect(fromUrl("192.168.1.1")).toBe("192.168.1.1");
});

test("it handles URLs with IPv6", () => {
expect(fromUrl("http://[1:2:3:4:5:6:7:8]/path?query")).toBe(
"[1:2:3:4:5:6:7:8]",
);
expect(fromUrl("//[1:2:3:4:5:6:7:8]")).toBe("[1:2:3:4:5:6:7:8]");
expect(fromUrl("[1:2:3:4:5:6:7:8]")).toBe("[1:2:3:4:5:6:7:8]");
});
test("it handles URLs with IPv6", () => {
expect(fromUrl("http://[1:2:3:4:5:6:7:8]/path?query")).toBe(
"[1:2:3:4:5:6:7:8]"
);
expect(fromUrl("//[1:2:3:4:5:6:7:8]")).toBe("[1:2:3:4:5:6:7:8]");
expect(fromUrl("[1:2:3:4:5:6:7:8]")).toBe("[1:2:3:4:5:6:7:8]");
});

test("it returns the NO_HOSTNAME symbol for invalid URLs", () => {
expect(fromUrl(":8080/path?query")).toBe(NO_HOSTNAME);
expect(fromUrl("/path?query")).toBe(NO_HOSTNAME);
expect(fromUrl("?query")).toBe(NO_HOSTNAME);
expect(fromUrl("")).toBe(NO_HOSTNAME);
});
test("it returns the NO_HOSTNAME symbol for invalid URLs", () => {
expect(fromUrl(":8080/path?query")).toBe(NO_HOSTNAME);
expect(fromUrl("/path?query")).toBe(NO_HOSTNAME);
expect(fromUrl("?query")).toBe(NO_HOSTNAME);
expect(fromUrl("")).toBe(NO_HOSTNAME);
});

test("it handles different schemes", () => {
expect(fromUrl("android-app://com.org.example")).toBe("com.org.example");
expect(fromUrl("file://root/.config")).toBe("root");
expect(fromUrl("mailto://person@mail.com")).toBe('mail.com');
expect(fromUrl("coap+ws://example.com")).toBe("example.com");
});
test("it handles different schemes", () => {
expect(fromUrl("android-app://com.org.example")).toBe("com.org.example");
expect(fromUrl("file://root/.config")).toBe("root");
expect(fromUrl("mailto://person@mail.com")).toBe("mail.com");
expect(fromUrl("coap+ws://example.com")).toBe("example.com");
});

test("it returns the NO_HOSTNAME symbol for invalid input types", () => {
// @ts-expect-error This is a deliberate error just for the test
expect(fromUrl(undefined)).toBe(NO_HOSTNAME);
// @ts-expect-error This is a deliberate error just for the test
// eslint-disable-next-line no-null/no-null
expect(fromUrl(null)).toBe(NO_HOSTNAME);
// @ts-expect-error This is a deliberate error just for the test
expect(fromUrl(true)).toBe(NO_HOSTNAME);
// @ts-expect-error This is a deliberate error just for the test
expect(fromUrl(1)).toBe(NO_HOSTNAME);
/* eslint-enable */
});
test("it returns the NO_HOSTNAME symbol for invalid input types", () => {
// @ts-expect-error This is a deliberate error just for the test
expect(fromUrl(undefined)).toBe(NO_HOSTNAME);
// @ts-expect-error This is a deliberate error just for the test
// eslint-disable-next-line no-null/no-null
expect(fromUrl(null)).toBe(NO_HOSTNAME);
// @ts-expect-error This is a deliberate error just for the test
expect(fromUrl(true)).toBe(NO_HOSTNAME);
// @ts-expect-error This is a deliberate error just for the test
expect(fromUrl(1)).toBe(NO_HOSTNAME);
/* eslint-enable */
});
});
48 changes: 24 additions & 24 deletions src/from-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ const urlPattern = /^[a-z][*+.a-z-]+:\/\//i;
export const NO_HOSTNAME: unique symbol = Symbol("NO_HOSTNAME");

export const fromUrl = (urlLike: string) => {
/* istanbul ignore next */
if (typeof URL !== "function") {
throw new Error(
"Looks like the new URL() constructor is not globally available in your environment. Please make sure to use a polyfill.",
);
}
/* istanbul ignore next */
if (typeof URL !== "function") {
throw new Error(
"Looks like the new URL() constructor is not globally available in your environment. Please make sure to use a polyfill."
);
}

// Extra check for non-TypeScript users
if (typeof urlLike !== "string") {
return NO_HOSTNAME;
}
// Extra check for non-TypeScript users
if (typeof urlLike !== "string") {
return NO_HOSTNAME;
}

// URLs that start with // are protocol relative
const url = urlLike.startsWith("//")
? `http:${urlLike}`
: // URLs that start with / do not have a hostname section
urlLike.startsWith("/")
? urlLike
: urlPattern.test(urlLike)
? urlLike
: `http://${urlLike}`;
// URLs that start with // are protocol relative
const url = urlLike.startsWith("//")
? `http:${urlLike}`
: // URLs that start with / do not have a hostname section
urlLike.startsWith("/")
? urlLike
: urlPattern.test(urlLike)
? urlLike
: `http://${urlLike}`;

try {
return new URL(url).hostname;
} catch {
return NO_HOSTNAME;
}
try {
return new URL(url).hostname;
} catch {
return NO_HOSTNAME;
}
};
18 changes: 9 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* istanbul ignore file */
// Jest will report function coverage errors here otherwise
export {
parseDomain,
ParseResult,
ParseResultType,
ParseResultInvalid,
ParseResultReserved,
ParseResultNotListed,
ParseResultListed,
parseDomain,
ParseResult,
ParseResultType,
ParseResultInvalid,
ParseResultReserved,
ParseResultNotListed,
ParseResultListed,
} from "./parse-domain";
export {fromUrl, NO_HOSTNAME} from "./from-url";
export {ValidationError, ValidationErrorType} from "./sanitize";
export { fromUrl, NO_HOSTNAME } from "./from-url";
export { ValidationError, ValidationErrorType } from "./sanitize";
Loading

0 comments on commit da961f1

Please sign in to comment.