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

@ -142,7 +142,7 @@ const StyledNavLink = styled(NavLink)`
&:focus {
color: ${props => props.theme.text};
background: ${props => props.theme.sidebarItemBackground};
background: ${props => props.theme.black05};
outline: none;
}

View File

@ -9,7 +9,7 @@
"build": "npm run clean && npm run build:webpack",
"start": "NODE_ENV=production node index.js",
"dev": "NODE_ENV=development nodemon --watch server index.js",
"lint": "eslint app server",
"lint": "eslint app server shared",
"flow": "flow",
"deploy": "git push heroku master",
"heroku-postbuild": "npm run build && npm run sequelize:migrate",

View File

@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
import styled from 'styled-components';
import OutlineLogo from './OutlineLogo';
import * as React from "react";
import styled from "styled-components";
import OutlineLogo from "./OutlineLogo";
type Props = {
href?: string,

View File

@ -1,17 +1,17 @@
// @flow
import * as React from 'react';
import { observer, inject } from 'mobx-react';
import breakpoint from 'styled-components-breakpoint';
import styled from 'styled-components';
import { Link } from 'react-router-dom';
import { PadlockIcon, GoToIcon, MoreIcon } from 'outline-icons';
import * as React from "react";
import { observer, inject } from "mobx-react";
import breakpoint from "styled-components-breakpoint";
import styled from "styled-components";
import { Link } from "react-router-dom";
import { PadlockIcon, GoToIcon, MoreIcon } from "outline-icons";
import Document from 'models/Document';
import CollectionsStore from 'stores/CollectionsStore';
import { collectionUrl } from 'utils/routeHelpers';
import Flex from 'shared/components/Flex';
import BreadcrumbMenu from './BreadcrumbMenu';
import CollectionIcon from 'components/CollectionIcon';
import Document from "models/Document";
import CollectionsStore from "stores/CollectionsStore";
import { collectionUrl } from "utils/routeHelpers";
import Flex from "shared/components/Flex";
import BreadcrumbMenu from "./BreadcrumbMenu";
import CollectionIcon from "components/CollectionIcon";
type Props = {
document: Document,
@ -30,7 +30,7 @@ const Breadcrumb = observer(({ document, collections, onlyText }: Props) => {
<React.Fragment>
{collection.private && (
<React.Fragment>
<SmallPadlockIcon color="currentColor" size={16} />{' '}
<SmallPadlockIcon color="currentColor" size={16} />{" "}
</React.Fragment>
)}
{collection.name}
@ -51,7 +51,7 @@ const Breadcrumb = observer(({ document, collections, onlyText }: Props) => {
return (
<Wrapper justify="flex-start" align="center">
<CollectionName to={collectionUrl(collection.id)}>
<CollectionIcon collection={collection} expanded />{' '}
<CollectionIcon collection={collection} expanded />{" "}
<span>{collection.name}</span>
</CollectionName>
{isNestedDocument && (
@ -61,7 +61,7 @@ const Breadcrumb = observer(({ document, collections, onlyText }: Props) => {
)}
{lastPath && (
<React.Fragment>
<Slash />{' '}
<Slash />{" "}
<Crumb to={lastPath.url} title={lastPath.title}>
{lastPath.title}
</Crumb>
@ -74,7 +74,7 @@ const Breadcrumb = observer(({ document, collections, onlyText }: Props) => {
const Wrapper = styled(Flex)`
display: none;
${breakpoint('tablet')`
${breakpoint("tablet")`
display: flex;
`};
`;
@ -130,4 +130,4 @@ const CollectionName = styled(Link)`
overflow: hidden;
`;
export default inject('collections')(Breadcrumb);
export default inject("collections")(Breadcrumb);

View File

@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
import { Link } from 'react-router-dom';
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
import * as React from "react";
import { Link } from "react-router-dom";
import { DropdownMenu, DropdownMenuItem } from "components/DropdownMenu";
type Props = {
label: React.Node,

View File

@ -1,20 +1,20 @@
// @flow
import * as React from 'react';
import styled from 'styled-components';
import * as React from "react";
import styled from "styled-components";
type JustifyValues =
| 'center'
| 'space-around'
| 'space-between'
| 'flex-start'
| 'flex-end';
| "center"
| "space-around"
| "space-between"
| "flex-start"
| "flex-end";
type AlignValues =
| 'stretch'
| 'center'
| 'baseline'
| 'flex-start'
| 'flex-end';
| "stretch"
| "center"
| "baseline"
| "flex-start"
| "flex-end";
type Props = {
column?: ?boolean,
@ -33,11 +33,11 @@ const Flex = (props: Props) => {
const Container = styled.div`
display: flex;
flex: ${({ auto }) => (auto ? '1 1 auto' : 'initial')};
flex-direction: ${({ column }) => (column ? 'column' : 'row')};
flex: ${({ auto }) => (auto ? "1 1 auto" : "initial")};
flex-direction: ${({ column }) => (column ? "column" : "row")};
align-items: ${({ align }) => align};
justify-content: ${({ justify }) => justify};
flex-shrink: ${({ shrink }) => (shrink ? 1 : 'initial')};
flex-shrink: ${({ shrink }) => (shrink ? 1 : "initial")};
min-height: 0;
min-width: 0;
`;

View File

@ -1,5 +1,5 @@
// @flow
import * as React from 'react';
import * as React from "react";
type Props = {
size?: number,
@ -7,7 +7,7 @@ type Props = {
className?: string,
};
function GithubLogo({ size = 34, fill = '#FFF', className }: Props) {
function GithubLogo({ size = 34, fill = "#FFF", className }: Props) {
return (
<svg
fill={fill}

View File

@ -1,5 +1,5 @@
// @flow
import * as React from 'react';
import * as React from "react";
type Props = {
size?: number,
@ -7,7 +7,7 @@ type Props = {
className?: string,
};
function GoogleLogo({ size = 34, fill = '#FFF', className }: Props) {
function GoogleLogo({ size = 34, fill = "#FFF", className }: Props) {
return (
<svg
fill={fill}

View File

@ -1,11 +1,11 @@
// @flow
import styled from 'styled-components';
import styled from "styled-components";
const Notice = styled.p`
background: ${props =>
props.muted ? props.theme.sidebarBackground : props.theme.yellow};
color: ${props =>
props.muted ? props.theme.sidebarText : 'hsla(46, 100%, 20%, 1)'};
props.muted ? props.theme.sidebarText : "hsla(46, 100%, 20%, 1)"};
padding: 10px 12px;
border-radius: 4px;
`;

View File

@ -1,5 +1,5 @@
// @flow
import * as React from 'react';
import * as React from "react";
type Props = {
size?: number,
@ -7,7 +7,7 @@ type Props = {
className?: string,
};
function OutlineLogo({ size = 32, fill = '#333', className }: Props) {
function OutlineLogo({ size = 32, fill = "#333", className }: Props) {
return (
<svg
fill={fill}

View File

@ -1,5 +1,5 @@
// @flow
import * as React from 'react';
import * as React from "react";
type Props = {
size?: number,
@ -7,7 +7,7 @@ type Props = {
className?: string,
};
function SlackLogo({ size = 34, fill = '#FFF', className }: Props) {
function SlackLogo({ size = 34, fill = "#FFF", className }: Props) {
return (
<svg
fill={fill}

View File

@ -1,5 +1,5 @@
// @flow
import styled from 'styled-components';
import styled from "styled-components";
const TeamLogo = styled.img`
width: 38px;

View File

@ -1,8 +1,8 @@
// @flow
import * as React from 'react';
import Tooltip from 'components/Tooltip';
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import format from 'date-fns/format';
import * as React from "react";
import Tooltip from "components/Tooltip";
import distanceInWordsToNow from "date-fns/distance_in_words_to_now";
import format from "date-fns/format";
let callbacks = [];
@ -41,7 +41,7 @@ class Time extends React.Component<Props> {
render() {
return (
<Tooltip
tooltip={format(this.props.dateTime, 'MMMM Do, YYYY h:mm a')}
tooltip={format(this.props.dateTime, "MMMM Do, YYYY h:mm a")}
placement="bottom"
>
<time dateTime={this.props.dateTime}>

View File

@ -1,5 +1,5 @@
// @flow
import { keyframes } from 'styled-components';
import { keyframes } from "styled-components";
export const fadeIn = keyframes`
from { opacity: 0; }

View File

@ -1,6 +1,6 @@
// @flow
import styledNormalize from 'styled-normalize';
import { createGlobalStyle } from 'styled-components';
import styledNormalize from "styled-normalize";
import { createGlobalStyle } from "styled-components";
export default createGlobalStyle`
${styledNormalize}

View File

@ -1,44 +1,44 @@
// @flow
import { darken, lighten } from 'polished';
import { darken, lighten } from "polished";
const colors = {
almostBlack: '#111319',
lightBlack: '#2F3336',
almostWhite: '#E6E6E6',
veryDarkBlue: '#08090C',
almostBlack: "#111319",
lightBlack: "#2F3336",
almostWhite: "#E6E6E6",
veryDarkBlue: "#08090C",
slate: '#9BA6B2',
slateLight: '#DAE1E9',
slateDark: '#4E5C6E',
slate: "#9BA6B2",
slateLight: "#DAE1E9",
slateDark: "#4E5C6E",
smoke: '#F4F7FA',
smokeLight: '#F9FBFC',
smokeDark: '#E8EBED',
smoke: "#F4F7FA",
smokeLight: "#F9FBFC",
smokeDark: "#E8EBED",
white: '#FFF',
white10: 'rgba(255, 255, 255, 0.1)',
white50: 'rgba(255, 255, 255, 0.5)',
black: '#000',
black05: 'rgba(0, 0, 0, 0.05)',
black10: 'rgba(0, 0, 0, 0.1)',
black50: 'rgba(0, 0, 0, 0.50)',
primary: '#0366d6',
yellow: '#FBCA04',
warmGrey: '#EDF2F7',
white: "#FFF",
white10: "rgba(255, 255, 255, 0.1)",
white50: "rgba(255, 255, 255, 0.5)",
black: "#000",
black05: "rgba(0, 0, 0, 0.05)",
black10: "rgba(0, 0, 0, 0.1)",
black50: "rgba(0, 0, 0, 0.50)",
primary: "#0366d6",
yellow: "#FBCA04",
warmGrey: "#EDF2F7",
danger: '#D0021B',
warning: '#f08a24',
success: '#2f3336',
info: '#a0d3e8',
danger: "#D0021B",
warning: "#f08a24",
success: "#2f3336",
info: "#a0d3e8",
};
const spacing = {
padding: '1.5vw 1.875vw',
vpadding: '1.5vw',
hpadding: '1.875vw',
sidebarWidth: '280px',
sidebarMinWidth: '250px',
sidebarMaxWidth: '350px',
padding: "1.5vw 1.875vw",
vpadding: "1.5vw",
hpadding: "1.875vw",
sidebarWidth: "280px",
sidebarMinWidth: "250px",
sidebarMaxWidth: "350px",
};
export const base = {
@ -49,29 +49,29 @@ export const base = {
fontFamilyMono:
"'SFMono-Regular',Consolas,'Liberation Mono', Menlo, Courier,monospace",
fontWeight: 400,
backgroundTransition: 'background 100ms ease-in-out',
backgroundTransition: "background 100ms ease-in-out",
zIndex: 100,
selected: colors.primary,
buttonBackground: colors.primary,
buttonText: colors.white,
textHighlight: '#B3E7FF',
textHighlight: "#B3E7FF",
codeComment: '#6a737d',
codePunctuation: '#5e6687',
codeNumber: '#d73a49',
codeProperty: '#c08b30',
codeTag: '#3d8fd1',
codeString: '#032f62',
codeSelector: '#6679cc',
codeAttr: '#c76b29',
codeEntity: '#22a2c9',
codeKeyword: '#d73a49',
codeFunction: '#6f42c1',
codeStatement: '#22a2c9',
codePlaceholder: '#3d8fd1',
codeInserted: '#202746',
codeImportant: '#c94922',
codeComment: "#6a737d",
codePunctuation: "#5e6687",
codeNumber: "#d73a49",
codeProperty: "#c08b30",
codeTag: "#3d8fd1",
codeString: "#032f62",
codeSelector: "#6679cc",
codeAttr: "#c76b29",
codeEntity: "#22a2c9",
codeKeyword: "#d73a49",
codeFunction: "#6f42c1",
codeStatement: "#22a2c9",
codePlaceholder: "#3d8fd1",
codeInserted: "#202746",
codeImportant: "#c94922",
blockToolbarBackground: colors.white,
blockToolbarTrigger: colors.slate,
@ -98,16 +98,16 @@ export const light = {
text: colors.almostBlack,
textSecondary: colors.slateDark,
textTertiary: colors.slate,
placeholder: '#B1BECC',
placeholder: "#B1BECC",
sidebarBackground: colors.warmGrey,
sidebarItemBackground: colors.black05,
sidebarText: 'rgb(78, 92, 110)',
shadow: 'rgba(0, 0, 0, 0.2)',
sidebarItemBackground: colors.black10,
sidebarText: "rgb(78, 92, 110)",
shadow: "rgba(0, 0, 0, 0.2)",
menuBackground: colors.white,
menuShadow:
'0 0 0 1px rgba(0, 0, 0, 0.05), 0 4px 8px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.08)',
"0 0 0 1px rgba(0, 0, 0, 0.05), 0 4px 8px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.08)",
divider: colors.slateLight,
inputBorder: colors.slateLight,
inputBorderFocused: colors.slate,
@ -120,7 +120,7 @@ export const light = {
tableDivider: colors.smokeDark,
tableSelected: colors.primary,
tableSelectedBackground: '#E5F7FF',
tableSelectedBackground: "#E5F7FF",
buttonNeutralBackground: colors.white,
buttonNeutralText: colors.almostBlack,
@ -135,7 +135,7 @@ export const light = {
quote: colors.slateLight,
codeBackground: colors.smoke,
codeBorder: colors.smokeDark,
embedBorder: '#DDD #DDD #CCC',
embedBorder: "#DDD #DDD #CCC",
horizontalRule: colors.smokeDark,
};
@ -153,12 +153,12 @@ export const dark = {
sidebarBackground: colors.veryDarkBlue,
sidebarItemBackground: colors.veryDarkBlue,
sidebarText: colors.slate,
shadow: 'rgba(0, 0, 0, 0.6)',
shadow: "rgba(0, 0, 0, 0.6)",
menuBorder: lighten(0.1, colors.almostBlack),
menuBackground: lighten(0.015, colors.almostBlack),
menuShadow:
'0 0 0 1px rgba(0, 0, 0, 0.1), 0 8px 16px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.08), inset 0 0 1px rgba(255,255,255,.2)',
"0 0 0 1px rgba(0, 0, 0, 0.1), 0 8px 16px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.08), inset 0 0 1px rgba(255,255,255,.2)",
divider: darken(0.2, colors.slate),
inputBorder: colors.slateDark,
inputBorderFocused: colors.slate,
@ -171,7 +171,7 @@ export const dark = {
tableDivider: colors.lightBlack,
tableSelected: colors.primary,
tableSelectedBackground: '#002333',
tableSelectedBackground: "#002333",
buttonNeutralBackground: colors.almostBlack,
buttonNeutralText: colors.white,
@ -186,7 +186,7 @@ export const dark = {
quote: colors.almostWhite,
codeBackground: colors.black,
codeBorder: colors.black50,
codeString: '#3d8fd1',
codeString: "#3d8fd1",
embedBorder: colors.black50,
horizontalRule: darken(0.2, colors.slate),
};

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",
];

View File

@ -1,149 +1,149 @@
/* eslint-disable flowtype/require-valid-file-annotation */
import { stripSubdomain, parseDomain, isCustomSubdomain } from './domains';
import { stripSubdomain, parseDomain, isCustomSubdomain } from "./domains";
// test suite is based on subset of parse-domain module we want to support
// https://github.com/peerigon/parse-domain/blob/master/test/parseDomain.test.js
describe('#parseDomain', () => {
it('should remove the protocol', () => {
expect(parseDomain('http://example.com')).toMatchObject({
subdomain: '',
domain: 'example',
tld: 'com',
describe("#parseDomain", () => {
it("should remove the protocol", () => {
expect(parseDomain("http://example.com")).toMatchObject({
subdomain: "",
domain: "example",
tld: "com",
});
expect(parseDomain('//example.com')).toMatchObject({
subdomain: '',
domain: 'example',
tld: 'com',
expect(parseDomain("//example.com")).toMatchObject({
subdomain: "",
domain: "example",
tld: "com",
});
expect(parseDomain('https://example.com')).toMatchObject({
subdomain: '',
domain: 'example',
tld: 'com',
expect(parseDomain("https://example.com")).toMatchObject({
subdomain: "",
domain: "example",
tld: "com",
});
});
it('should remove sub-domains', () => {
expect(parseDomain('www.example.com')).toMatchObject({
subdomain: 'www',
domain: 'example',
tld: 'com',
it("should remove sub-domains", () => {
expect(parseDomain("www.example.com")).toMatchObject({
subdomain: "www",
domain: "example",
tld: "com",
});
});
it('should remove the path', () => {
expect(parseDomain('example.com/some/path?and&query')).toMatchObject({
subdomain: '',
domain: 'example',
tld: 'com',
it("should remove the path", () => {
expect(parseDomain("example.com/some/path?and&query")).toMatchObject({
subdomain: "",
domain: "example",
tld: "com",
});
expect(parseDomain('example.com/')).toMatchObject({
subdomain: '',
domain: 'example',
tld: 'com',
expect(parseDomain("example.com/")).toMatchObject({
subdomain: "",
domain: "example",
tld: "com",
});
});
it('should remove the query string', () => {
expect(parseDomain('example.com?and&query')).toMatchObject({
subdomain: '',
domain: 'example',
tld: 'com',
it("should remove the query string", () => {
expect(parseDomain("example.com?and&query")).toMatchObject({
subdomain: "",
domain: "example",
tld: "com",
});
});
it('should remove special characters', () => {
expect(parseDomain('http://m.example.com\r')).toMatchObject({
subdomain: 'm',
domain: 'example',
tld: 'com',
it("should remove special characters", () => {
expect(parseDomain("http://m.example.com\r")).toMatchObject({
subdomain: "m",
domain: "example",
tld: "com",
});
});
it('should remove the port', () => {
expect(parseDomain('example.com:8080')).toMatchObject({
subdomain: '',
domain: 'example',
tld: 'com',
it("should remove the port", () => {
expect(parseDomain("example.com:8080")).toMatchObject({
subdomain: "",
domain: "example",
tld: "com",
});
});
it('should allow @ characters in the path', () => {
expect(parseDomain('https://medium.com/@username/')).toMatchObject({
subdomain: '',
domain: 'medium',
tld: 'com',
it("should allow @ characters in the path", () => {
expect(parseDomain("https://medium.com/@username/")).toMatchObject({
subdomain: "",
domain: "medium",
tld: "com",
});
});
it('should also work with three-level domains like .co.uk', () => {
expect(parseDomain('www.example.co.uk')).toMatchObject({
subdomain: 'www',
domain: 'example',
tld: 'co.uk',
it("should also work with three-level domains like .co.uk", () => {
expect(parseDomain("www.example.co.uk")).toMatchObject({
subdomain: "www",
domain: "example",
tld: "co.uk",
});
});
it('should not include private domains like blogspot.com by default', () => {
expect(parseDomain('foo.blogspot.com')).toMatchObject({
subdomain: 'foo',
domain: 'blogspot',
tld: 'com',
it("should not include private domains like blogspot.com by default", () => {
expect(parseDomain("foo.blogspot.com")).toMatchObject({
subdomain: "foo",
domain: "blogspot",
tld: "com",
});
});
it('should also work with the minimum', () => {
expect(parseDomain('example.com')).toMatchObject({
subdomain: '',
domain: 'example',
tld: 'com',
it("should also work with the minimum", () => {
expect(parseDomain("example.com")).toMatchObject({
subdomain: "",
domain: "example",
tld: "com",
});
});
it('should return null if the given value is not a string', () => {
it("should return null if the given value is not a string", () => {
expect(parseDomain(undefined)).toBe(null);
expect(parseDomain({})).toBe(null);
expect(parseDomain('')).toBe(null);
expect(parseDomain("")).toBe(null);
});
it('should work with custom top-level domains (eg .local)', () => {
expect(parseDomain('mymachine.local')).toMatchObject({
subdomain: '',
domain: 'mymachine',
tld: 'local',
it("should work with custom top-level domains (eg .local)", () => {
expect(parseDomain("mymachine.local")).toMatchObject({
subdomain: "",
domain: "mymachine",
tld: "local",
});
});
});
describe('#stripSubdomain', () => {
test('to work with localhost', () => {
expect(stripSubdomain('localhost')).toBe('localhost');
describe("#stripSubdomain", () => {
test("to work with localhost", () => {
expect(stripSubdomain("localhost")).toBe("localhost");
});
test('to return domains without a subdomain', () => {
expect(stripSubdomain('example')).toBe('example');
expect(stripSubdomain('example.com')).toBe('example.com');
expect(stripSubdomain('example.org:3000')).toBe('example.org');
test("to return domains without a subdomain", () => {
expect(stripSubdomain("example")).toBe("example");
expect(stripSubdomain("example.com")).toBe("example.com");
expect(stripSubdomain("example.org:3000")).toBe("example.org");
});
test('to remove subdomains', () => {
expect(stripSubdomain('test.example.com')).toBe('example.com');
expect(stripSubdomain('test.example.com:3000')).toBe('example.com');
test("to remove subdomains", () => {
expect(stripSubdomain("test.example.com")).toBe("example.com");
expect(stripSubdomain("test.example.com:3000")).toBe("example.com");
});
});
describe('#isCustomSubdomain', () => {
test('to work with localhost', () => {
expect(isCustomSubdomain('localhost')).toBe(false);
describe("#isCustomSubdomain", () => {
test("to work with localhost", () => {
expect(isCustomSubdomain("localhost")).toBe(false);
});
test('to return false for domains without a subdomain', () => {
expect(isCustomSubdomain('example')).toBe(false);
expect(isCustomSubdomain('example.com')).toBe(false);
expect(isCustomSubdomain('example.org:3000')).toBe(false);
test("to return false for domains without a subdomain", () => {
expect(isCustomSubdomain("example")).toBe(false);
expect(isCustomSubdomain("example.com")).toBe(false);
expect(isCustomSubdomain("example.org:3000")).toBe(false);
});
test('to return false for www', () => {
expect(isCustomSubdomain('www.example.com')).toBe(false);
expect(isCustomSubdomain('www.example.com:3000')).toBe(false);
test("to return false for www", () => {
expect(isCustomSubdomain("www.example.com")).toBe(false);
expect(isCustomSubdomain("www.example.com:3000")).toBe(false);
});
test('to return true for subdomains', () => {
expect(isCustomSubdomain('test.example.com')).toBe(true);
expect(isCustomSubdomain('test.example.com:3000')).toBe(true);
test("to return true for subdomains", () => {
expect(isCustomSubdomain("test.example.com")).toBe(true);
expect(isCustomSubdomain("test.example.com:3000")).toBe(true);
});
});

View File

@ -1,11 +1,12 @@
// @flow
export default function getQueryVariable(variable: string) {
var query = window.location.search.substring(1);
var vars = query.split('&');
const query = window.location.search.substring(1);
const vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (pair[0] == variable) {
const pair = vars[i].split("=");
if (pair[0] === variable) {
return pair[1];
}
}

View File

@ -1,10 +1,10 @@
// @flow
import { deburr } from 'lodash';
import naturalSort from 'natural-sort';
import { deburr } from "lodash";
import naturalSort from "natural-sort";
type NaturalSortOptions = {
caseSensitive?: boolean,
direction?: 'asc' | 'desc',
direction?: "asc" | "desc",
};
const sorter = naturalSort();
@ -13,7 +13,7 @@ function getSortByField<T: Object>(
item: T,
keyOrCallback: string | (T => string)
) {
if (typeof keyOrCallback === 'string') {
if (typeof keyOrCallback === "string") {
return deburr(item[keyOrCallback]);
}

View File

@ -1,5 +1,5 @@
// @flow
import { parser } from 'rich-markdown-editor';
import { parser } from "rich-markdown-editor";
export default function parseDocumentIds(text: string): string[] {
const value = parser.parse(text);
@ -7,15 +7,15 @@ export default function parseDocumentIds(text: string): string[] {
function findLinks(node) {
// get text nodes
if (node.type.name === 'text') {
if (node.type.name === "text") {
// get marks for text nodes
node.marks.forEach(mark => {
// any of the marks links?
if (mark.type.name === 'link') {
if (mark.type.name === "link") {
const { href } = mark.attrs;
// any of the links to other docs?
if (href.startsWith('/doc')) {
const tokens = href.replace(/\/$/, '').split('/');
if (href.startsWith("/doc")) {
const tokens = href.replace(/\/$/, "").split("/");
const lastToken = tokens[tokens.length - 1];
// don't return the same link more than once

View File

@ -1,21 +1,21 @@
/* eslint-disable flowtype/require-valid-file-annotation */
import parseDocumentIds from './parseDocumentIds';
import parseDocumentIds from "./parseDocumentIds";
it('should not return non links', () => {
it("should not return non links", () => {
expect(parseDocumentIds(`# Header`).length).toBe(0);
});
it('should return an array of document ids', () => {
it("should return an array of document ids", () => {
const result = parseDocumentIds(`# Header
[internal](/doc/test-456733)
`);
expect(result.length).toBe(1);
expect(result[0]).toBe('test-456733');
expect(result[0]).toBe("test-456733");
});
it('should not return duplicate document ids', () => {
it("should not return duplicate document ids", () => {
expect(parseDocumentIds(`# Header`).length).toBe(0);
const result = parseDocumentIds(`# Header
@ -26,13 +26,13 @@ it('should not return duplicate document ids', () => {
`);
expect(result.length).toBe(1);
expect(result[0]).toBe('test-456733');
expect(result[0]).toBe("test-456733");
});
it('should not return non document links', () => {
it("should not return non document links", () => {
expect(parseDocumentIds(`[google](http://www.google.com)`).length).toBe(0);
});
it('should not return non document relative links', () => {
it("should not return non document relative links", () => {
expect(parseDocumentIds(`[relative](/developers)`).length).toBe(0);
});

View File

@ -1,13 +1,13 @@
// @flow
import emojiRegex from 'emoji-regex';
import unescape from './unescape';
import emojiRegex from "emoji-regex";
import unescape from "./unescape";
export default function parseTitle(text: string = '') {
export default function parseTitle(text: string = "") {
const regex = emojiRegex();
// find and extract title
const firstLine = text.trim().split(/\r?\n/)[0];
const trimmedTitle = firstLine.replace(/^#/, '').trim();
const trimmedTitle = firstLine.replace(/^#/, "").trim();
// remove any escape characters
const title = unescape(trimmedTitle);

View File

@ -1,28 +1,28 @@
/* eslint-disable flowtype/require-valid-file-annotation */
import parseTitle from './parseTitle';
import parseTitle from "./parseTitle";
it('should trim the title', () => {
expect(parseTitle(`# Lots of space `).title).toBe('Lots of space');
it("should trim the title", () => {
expect(parseTitle(`# Lots of space `).title).toBe("Lots of space");
});
it('should extract first title', () => {
expect(parseTitle(`# Title one\n# Title two`).title).toBe('Title one');
it("should extract first title", () => {
expect(parseTitle(`# Title one\n# Title two`).title).toBe("Title one");
});
it('should remove escape characters', () => {
expect(parseTitle(`# Thing \\- one`).title).toBe('Thing - one');
expect(parseTitle(`# \\[wip\\] Title`).title).toBe('[wip] Title');
expect(parseTitle(`# \\> Title`).title).toBe('> Title');
it("should remove escape characters", () => {
expect(parseTitle(`# Thing \\- one`).title).toBe("Thing - one");
expect(parseTitle(`# \\[wip\\] Title`).title).toBe("[wip] Title");
expect(parseTitle(`# \\> Title`).title).toBe("> Title");
});
it('should parse emoji if first character', () => {
it("should parse emoji if first character", () => {
const parsed = parseTitle(`# 😀 Title`);
expect(parsed.title).toBe('😀 Title');
expect(parsed.emoji).toBe('😀');
expect(parsed.title).toBe("😀 Title");
expect(parsed.emoji).toBe("😀");
});
it('should not parse emoji if not first character', () => {
it("should not parse emoji if not first character", () => {
const parsed = parseTitle(`# Title 🌈`);
expect(parsed.title).toBe('Title 🌈');
expect(parsed.title).toBe("Title 🌈");
expect(parsed.emoji).toBe(undefined);
});

View File

@ -3,54 +3,54 @@
export function slackAuth(
state: string,
scopes: string[] = [
'identity.email',
'identity.basic',
'identity.avatar',
'identity.team',
"identity.email",
"identity.basic",
"identity.avatar",
"identity.team",
],
redirectUri: string = `${process.env.URL}/auth/slack.callback`
): string {
const baseUrl = 'https://slack.com/oauth/authorize';
const baseUrl = "https://slack.com/oauth/authorize";
const params = {
client_id: process.env.SLACK_KEY,
scope: scopes ? scopes.join(' ') : '',
scope: scopes ? scopes.join(" ") : "",
redirect_uri: redirectUri,
state,
};
const urlParams = Object.keys(params)
.map(key => `${key}=${encodeURIComponent(params[key])}`)
.join('&');
.join("&");
return `${baseUrl}?${urlParams}`;
}
export function githubUrl(): string {
return 'https://www.github.com/outline';
return "https://www.github.com/outline";
}
export function githubIssuesUrl(): string {
return 'https://www.github.com/outline/outline/issues';
return "https://www.github.com/outline/outline/issues";
}
export function slackAppStoreUrl(): string {
return 'https://goabstract.slack.com/apps/A0W3UMKBQ-outline';
return "https://goabstract.slack.com/apps/A0W3UMKBQ-outline";
}
export function blogUrl(): string {
return 'https://medium.com/getoutline';
return "https://medium.com/getoutline";
}
export function twitterUrl(): string {
return 'https://twitter.com/outlinewiki';
return "https://twitter.com/outlinewiki";
}
export function spectrumUrl(): string {
return 'https://spectrum.chat/outline';
return "https://spectrum.chat/outline";
}
export function mailToUrl(): string {
return 'mailto:hello@getoutline.com';
return "mailto:hello@getoutline.com";
}
export function features(): string {
@ -65,7 +65,7 @@ export function changelog(): string {
return `https://www.getoutline.com/changelog`;
}
export function signin(service: string = 'slack'): string {
export function signin(service: string = "slack"): string {
return `${process.env.URL}/auth/${service}`;
}

View File

@ -1,8 +1,8 @@
// @flow
import slugify from 'slugify';
import slugify from "slugify";
// Slugify, escape, and remove periods from headings so that they are
// compatible with url hashes AND dom selectors
export default function safeSlugify(text: string) {
return `h-${escape(slugify(text, { lower: true }).replace('.', '-'))}`;
return `h-${escape(slugify(text, { lower: true }).replace(".", "-"))}`;
}

View File

@ -2,8 +2,8 @@
const unescape = (text: string) => {
return text
.replace(/\\([\\`*{}[\]()#+\-.!_>])/g, '$1')
.replace(/\n\\\n/g, '\n\n');
.replace(/\\([\\`*{}[\]()#+\-.!_>])/g, "$1")
.replace(/\n\\\n/g, "\n\n");
};
export default unescape;