Move to single quotes
This commit is contained in:
+26
-26
@@ -7,57 +7,57 @@ import {
|
||||
verifiers,
|
||||
identifyTypeFromRegex,
|
||||
toURL,
|
||||
} from "./parser";
|
||||
} from './parser';
|
||||
|
||||
import { LinkKind } from "./types";
|
||||
import { LinkKind } from './types';
|
||||
|
||||
const identifierType = (id: string): LinkKind =>
|
||||
identifyTypeFromRegex(id, verifiers, LinkKind.ParseFailed);
|
||||
|
||||
it("types identifiers correctly", () => {
|
||||
expect(identifierType("@user:matrix.org")).toEqual(LinkKind.UserId);
|
||||
expect(identifierType("!room:matrix.org")).toEqual(LinkKind.RoomId);
|
||||
expect(identifierType("!somewhere:example.org/$event:example.org")).toEqual(
|
||||
it('types identifiers correctly', () => {
|
||||
expect(identifierType('@user:matrix.org')).toEqual(LinkKind.UserId);
|
||||
expect(identifierType('!room:matrix.org')).toEqual(LinkKind.RoomId);
|
||||
expect(identifierType('!somewhere:example.org/$event:example.org')).toEqual(
|
||||
LinkKind.Permalink
|
||||
);
|
||||
expect(identifierType("+group:matrix.org")).toEqual(LinkKind.GroupId);
|
||||
expect(identifierType("#alias:matrix.org")).toEqual(LinkKind.Alias);
|
||||
expect(identifierType('+group:matrix.org')).toEqual(LinkKind.GroupId);
|
||||
expect(identifierType('#alias:matrix.org')).toEqual(LinkKind.Alias);
|
||||
});
|
||||
|
||||
it("types garbage as such", () => {
|
||||
expect(identifierType("sdfa;fdlkja")).toEqual(LinkKind.ParseFailed);
|
||||
expect(identifierType("$event$matrix.org")).toEqual(LinkKind.ParseFailed);
|
||||
expect(identifierType("/user:matrix.org")).toEqual(LinkKind.ParseFailed);
|
||||
it('types garbage as such', () => {
|
||||
expect(identifierType('sdfa;fdlkja')).toEqual(LinkKind.ParseFailed);
|
||||
expect(identifierType('$event$matrix.org')).toEqual(LinkKind.ParseFailed);
|
||||
expect(identifierType('/user:matrix.org')).toEqual(LinkKind.ParseFailed);
|
||||
});
|
||||
|
||||
it("parses args correctly", () => {
|
||||
it('parses args correctly', () => {
|
||||
expect(
|
||||
parseArgs("via=example.org&via=alt.example.org")
|
||||
).toHaveProperty("vias", ["example.org", "alt.example.org"]);
|
||||
expect(parseArgs("sharer=blah")).toHaveProperty("sharer", "blah");
|
||||
expect(parseArgs("client=blah.com")).toHaveProperty("client", "blah.com");
|
||||
parseArgs('via=example.org&via=alt.example.org')
|
||||
).toHaveProperty('vias', ['example.org', 'alt.example.org']);
|
||||
expect(parseArgs('sharer=blah')).toHaveProperty('sharer', 'blah');
|
||||
expect(parseArgs('client=blah.com')).toHaveProperty('client', 'blah.com');
|
||||
});
|
||||
|
||||
it("parses permalinks", () => {
|
||||
expect(parsePermalink("!somewhere:example.org/$event:example.org")).toEqual(
|
||||
it('parses permalinks', () => {
|
||||
expect(parsePermalink('!somewhere:example.org/$event:example.org')).toEqual(
|
||||
{
|
||||
roomKind: LinkKind.RoomId,
|
||||
roomLink: "!somewhere:example.org",
|
||||
eventId: "$event:example.org",
|
||||
roomLink: '!somewhere:example.org',
|
||||
eventId: '$event:example.org',
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("formats links correctly", () => {
|
||||
it('formats links correctly', () => {
|
||||
const bigLink =
|
||||
"!somewhere:example.org/$event:example.org?via=dfasdf&via=jfjafjaf";
|
||||
const origin = "https://matrix.org";
|
||||
const prefix = origin + "/#/";
|
||||
'!somewhere:example.org/$event:example.org?via=dfasdf&via=jfjafjaf';
|
||||
const origin = 'https://matrix.org';
|
||||
const prefix = origin + '/#/';
|
||||
const parse = parseHash(bigLink);
|
||||
|
||||
switch (parse.kind) {
|
||||
case LinkKind.ParseFailed:
|
||||
fail("Parse failed");
|
||||
fail('Parse failed');
|
||||
default:
|
||||
expect(toURL(origin, parse).toString()).toEqual(prefix + bigLink);
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,4 +1,4 @@
|
||||
import forEach from "lodash/forEach";
|
||||
import forEach from 'lodash/forEach';
|
||||
|
||||
import {
|
||||
LinkKind,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
LinkContent,
|
||||
Arguments,
|
||||
Permalink,
|
||||
} from "./types";
|
||||
} from './types';
|
||||
|
||||
/*
|
||||
* Verifiers are regexes which will match valid
|
||||
@@ -58,8 +58,8 @@ export function identifyTypeFromRegex<T, F>(
|
||||
*/
|
||||
export function parsePermalink(
|
||||
identifier: string
|
||||
): Pick<Permalink, "roomKind" | "roomLink" | "eventId"> {
|
||||
const [roomLink, eventId] = identifier.split("/");
|
||||
): Pick<Permalink, 'roomKind' | 'roomLink' | 'eventId'> {
|
||||
const [roomLink, eventId] = identifier.split('/');
|
||||
const roomKind = identifyTypeFromRegex(
|
||||
roomLink,
|
||||
roomVerifiers,
|
||||
@@ -89,9 +89,9 @@ export function parseArgs(args: string): Arguments {
|
||||
const params = new URLSearchParams(args);
|
||||
|
||||
return {
|
||||
vias: params.getAll("via"),
|
||||
client: bottomExchange(params.get("client")),
|
||||
sharer: bottomExchange(params.get("sharer")),
|
||||
vias: params.getAll('via'),
|
||||
client: bottomExchange(params.get('client')),
|
||||
sharer: bottomExchange(params.get('sharer')),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ export function parseArgs(args: string): Arguments {
|
||||
* be ParseFailed
|
||||
*/
|
||||
export function parseHash(hash: string): Link {
|
||||
const [identifier, args] = hash.split("?");
|
||||
const [identifier, args] = hash.split('?');
|
||||
|
||||
const kind = identifyTypeFromRegex(
|
||||
identifier,
|
||||
@@ -150,9 +150,9 @@ export function toURL(origin: string, link: SafeLink): URL {
|
||||
forEach(link.arguments, (value, key) => {
|
||||
if (value === undefined) {
|
||||
// do nothing
|
||||
} else if (key === "vias") {
|
||||
} else if (key === 'vias') {
|
||||
(value as string[]).forEach((via) =>
|
||||
params.append("via", via)
|
||||
params.append('via', via)
|
||||
);
|
||||
} else {
|
||||
params.append(key, value.toString());
|
||||
|
||||
+6
-6
@@ -13,12 +13,12 @@ export interface LinkContent {
|
||||
}
|
||||
|
||||
export enum LinkKind {
|
||||
Alias = "ALIAS",
|
||||
RoomId = "ROOM_ID",
|
||||
UserId = "USER_ID",
|
||||
Permalink = "PERMALINK",
|
||||
GroupId = "GROUP_ID",
|
||||
ParseFailed = "PARSE_FAILED",
|
||||
Alias = 'ALIAS',
|
||||
RoomId = 'ROOM_ID',
|
||||
UserId = 'USER_ID',
|
||||
Permalink = 'PERMALINK',
|
||||
GroupId = 'GROUP_ID',
|
||||
ParseFailed = 'PARSE_FAILED',
|
||||
}
|
||||
|
||||
export interface Alias extends LinkContent {
|
||||
|
||||
Reference in New Issue
Block a user