Skip to content

Commit

Permalink
style: lint with prettier defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 3, 2024
1 parent 0c67673 commit 666091d
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 26 deletions.
4 changes: 1 addition & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{
"trailingComma": "es5"
}
{}
4 changes: 2 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface ParsedHost {
*/
export function parseURL(input = "", defaultProto?: string): ParsedURL {
const _specialProtoMatch = input.match(
/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i
/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i,
);
if (_specialProtoMatch) {
const [, _proto, _pathname = ""] = _specialProtoMatch;
Expand All @@ -71,7 +71,7 @@ export function parseURL(input = "", defaultProto?: string): ParsedURL {
.match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
const [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
const { pathname, search, hash } = parsePath(
path.replace(/\/(?=[A-Za-z]:)/, "")
path.replace(/\/(?=[A-Za-z]:)/, ""),
);

return {
Expand Down
4 changes: 2 additions & 2 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type ParsedQuery = Record<string, string | string[]>;
* @group Query_utils
*/
export function parseQuery<T extends ParsedQuery = ParsedQuery>(
parametersString = ""
parametersString = "",
): T {
const object: ParsedQuery = {};
if (parametersString[0] === "?") {
Expand Down Expand Up @@ -65,7 +65,7 @@ export function parseQuery<T extends ParsedQuery = ParsedQuery>(
*/
export function encodeQueryItem(
key: string,
value: QueryValue | QueryValue[]
value: QueryValue | QueryValue[],
): string {
if (typeof value === "number" || typeof value === "boolean") {
value = String(value);
Expand Down
4 changes: 2 additions & 2 deletions src/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class $URL implements URL {
constructor(input = "") {
if (typeof input !== "string") {
throw new TypeError(
`URL input should be string received ${typeof input} (${input})`
`URL input should be string received ${typeof input} (${input})`,
);
}

Expand Down Expand Up @@ -77,7 +77,7 @@ export class $URL implements URL {
} else {
p.append(
name,
typeof value === "string" ? value : JSON.stringify(value)
typeof value === "string" ? value : JSON.stringify(value),
);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ export interface HasProtocolOptions {
*/
export function hasProtocol(
inputString: string,
opts?: HasProtocolOptions
opts?: HasProtocolOptions,
): boolean;
/** @deprecated Same as { hasProtocol(inputString, { acceptRelative: true }) */
export function hasProtocol(
inputString: string,
acceptRelative: boolean
acceptRelative: boolean,
): boolean;
export function hasProtocol(
inputString: string,
opts: boolean | HasProtocolOptions = {}
opts: boolean | HasProtocolOptions = {},
): boolean {
if (typeof opts === "boolean") {
opts = { acceptRelative: opts };
Expand Down Expand Up @@ -82,7 +82,7 @@ export function isScriptProtocol(protocol?: string) {
*/
export function hasTrailingSlash(
input = "",
respectQueryAndFragment?: boolean
respectQueryAndFragment?: boolean,
): boolean {
if (!respectQueryAndFragment) {
return input.endsWith("/");
Expand All @@ -107,7 +107,7 @@ export function hasTrailingSlash(
*/
export function withoutTrailingSlash(
input = "",
respectQueryAndFragment?: boolean
respectQueryAndFragment?: boolean,
): string {
if (!respectQueryAndFragment) {
return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
Expand Down Expand Up @@ -146,7 +146,7 @@ export function withoutTrailingSlash(
*/
export function withTrailingSlash(
input = "",
respectQueryAndFragment?: boolean
respectQueryAndFragment?: boolean,
): string {
if (!respectQueryAndFragment) {
return input.endsWith("/") ? input : input + "/";
Expand Down Expand Up @@ -283,7 +283,7 @@ export function withQuery(input: string, query: QueryObject): string {
* @group utils
*/
export function getQuery<T extends ParsedQuery = ParsedQuery>(
input: string
input: string,
): T {
return parseQuery<T>(parseURL(input).search);
}
Expand Down Expand Up @@ -506,7 +506,7 @@ export function normalizeURL(input: string): string {
export function resolveURL(base = "", ...inputs: string[]): string {
if (typeof base !== "string") {
throw new TypeError(
`URL input should be string received ${typeof base} (${base})`
`URL input should be string received ${typeof base} (${base})`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("normalizeURL", () => {
for (const input of validURLS) {
test(input, () => {
expect(withoutTrailingSlash(normalizeURL(input))).toBe(
withoutTrailingSlash(new URL(input).href)
withoutTrailingSlash(new URL(input).href),
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe("parseFilename", () => {
for (const t of tests) {
test(t.input.toString(), () => {
expect(
parseFilename(t.input[0].toString(), { strict: t.input[1] })
parseFilename(t.input[0].toString(), { strict: t.input[1] }),
).toStrictEqual(t.out);
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ describe("resolveURL", () => {
test("invalid URL (null)", () => {
// eslint-disable-next-line unicorn/no-null
expect(() => resolveURL(null as any)).toThrow(
"URL input should be string received object (null)"
"URL input should be string received object (null)",
);
});

test("invalid URL (array)", () => {
expect(() => resolveURL([])).toThrow(
"URL input should be string received object ()"
"URL input should be string received object ()",
);
});

Expand Down
4 changes: 2 additions & 2 deletions test/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ describe("$URL", () => {

test("append", () => {
const url = new $URL(
"https://john:[email protected]:1080/path?query=value#hash"
"https://john:[email protected]:1080/path?query=value#hash",
);
const path = new $URL("/newpath?newquery=newvalue#newhash");

url.append(path);

expect(url.toString()).toEqual(
"https://john:[email protected]:1080/path/newpath?query=value&newquery=newvalue#newhash"
"https://john:[email protected]:1080/path/newpath?query=value&newquery=newvalue#newhash",
);
});

Expand Down
6 changes: 3 additions & 3 deletions test/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("hasProtocol", () => {
expect(hasProtocol(t.input)).toBe(withDefault);
expect(hasProtocol(t.input, { strict: true })).toBe(withStrict);
expect(hasProtocol(t.input, { acceptRelative: true })).toBe(
withAcceptRelative
withAcceptRelative,
);
expect(hasProtocol(t.input, true)).toBe(withAcceptRelative);
});
Expand Down Expand Up @@ -128,8 +128,8 @@ describe("stringifyParsedURL", () => {
test(t.input.toString(), () => {
expect(
stringifyParsedURL(
typeof t.input === "string" ? parsePath(t.input) : t.input
)
typeof t.input === "string" ? parsePath(t.input) : t.input,
),
).toBe(t.out);
});
}
Expand Down

0 comments on commit 666091d

Please sign in to comment.