chore: Lint shared directory

This commit is contained in:
Tom Moor
2020-06-22 21:29:21 -07:00
parent 26f6961c82
commit 9be5597f4b
27 changed files with 342 additions and 341 deletions

View File

@@ -1,5 +1,5 @@
// @flow
import { trim } from 'lodash';
import { trim } from "lodash";
type Domain = {
tld: string,
@@ -11,14 +11,14 @@ type Domain = {
// a large list of possible TLD's which increase the size of the bundle
// unneccessarily for our usecase of trusted input.
export function parseDomain(url: string): ?Domain {
if (typeof url !== 'string') return null;
if (typeof url !== "string") return null;
// strip extermeties and whitespace from input
const normalizedDomain = trim(url.replace(/(https?:)?\/\//, ''));
const parts = normalizedDomain.split('.');
const normalizedDomain = trim(url.replace(/(https?:)?\/\//, ""));
const parts = normalizedDomain.split(".");
// ensure the last part only includes something that looks like a TLD
function cleanTLD(tld = '') {
function cleanTLD(tld = "") {
return tld.split(/[/:?]/)[0];
}
@@ -28,14 +28,14 @@ export function parseDomain(url: string): ?Domain {
return {
subdomain: parts[0],
domain: parts[1],
tld: cleanTLD(parts.slice(2).join('.')),
tld: cleanTLD(parts.slice(2).join(".")),
};
}
if (parts.length === 2) {
return {
subdomain: '',
subdomain: "",
domain: parts[0],
tld: cleanTLD(parts.slice(1).join('.')),
tld: cleanTLD(parts.slice(1).join(".")),
};
}
@@ -44,7 +44,7 @@ export function parseDomain(url: string): ?Domain {
export function getCookieDomain(domain: string) {
// TODO: All the process.env parsing needs centralizing
return process.env.SUBDOMAINS_ENABLED === 'true' ||
return process.env.SUBDOMAINS_ENABLED === "true" ||
process.env.SUBDOMAINS_ENABLED === true
? stripSubdomain(domain)
: domain;
@@ -61,69 +61,69 @@ export function stripSubdomain(hostname: string) {
export function isCustomSubdomain(hostname: string) {
const parsed = parseDomain(hostname);
if (!parsed) return false;
if (!parsed.subdomain || parsed.subdomain === 'www') return false;
if (!parsed.subdomain || parsed.subdomain === "www") return false;
return true;
}
export const RESERVED_SUBDOMAINS = [
'about',
'account',
'admin',
'advertising',
'api',
'assets',
'archive',
'beta',
'billing',
'blog',
'cache',
'cdn',
'code',
'community',
'dashboard',
'developer',
'developers',
'forum',
'help',
'home',
'http',
'https',
'imap',
'localhost',
'mail',
'marketing',
'mobile',
'new',
'news',
'newsletter',
'ns1',
'ns2',
'ns3',
'ns4',
'password',
'profile',
'sandbox',
'script',
'scripts',
'setup',
'signin',
'signup',
'site',
'smtp',
'support',
'status',
'static',
'stats',
'test',
'update',
'updates',
'ws',
'wss',
'web',
'websockets',
'www',
'www1',
'www2',
'www3',
'www4',
"about",
"account",
"admin",
"advertising",
"api",
"assets",
"archive",
"beta",
"billing",
"blog",
"cache",
"cdn",
"code",
"community",
"dashboard",
"developer",
"developers",
"forum",
"help",
"home",
"http",
"https",
"imap",
"localhost",
"mail",
"marketing",
"mobile",
"new",
"news",
"newsletter",
"ns1",
"ns2",
"ns3",
"ns4",
"password",
"profile",
"sandbox",
"script",
"scripts",
"setup",
"signin",
"signup",
"site",
"smtp",
"support",
"status",
"static",
"stats",
"test",
"update",
"updates",
"ws",
"wss",
"web",
"websockets",
"www",
"www1",
"www2",
"www3",
"www4",
];