From bfa2f045d2c0f937cbc9756844ba834b1478f0d2 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Wed, 12 Jul 2023 23:56:22 -0700 Subject: [PATCH] refactor: :recycle: substr -> slice --- packages/backend/src/misc/acct.ts | 2 +- packages/backend/src/server/api/service/discord.ts | 2 +- packages/backend/src/server/api/service/github.ts | 2 +- packages/calckey-js/src/acct.ts | 2 +- packages/client/src/components/MkUserPreview.vue | 2 +- packages/client/src/scripts/gen-search-query.ts | 2 +- packages/client/src/scripts/search.ts | 2 +- packages/client/src/scripts/theme-editor.ts | 2 +- packages/client/src/scripts/theme.ts | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/misc/acct.ts b/packages/backend/src/misc/acct.ts index 5b7767a10..cb6808b4b 100644 --- a/packages/backend/src/misc/acct.ts +++ b/packages/backend/src/misc/acct.ts @@ -4,7 +4,7 @@ export type Acct = { }; export function parse(acct: string): Acct { - if (acct.startsWith("@")) acct = acct.substr(1); + if (acct.startsWith("@")) acct = acct.slice(1); const split = acct.split("@", 2); return { username: split[0], host: split[1] || null }; } diff --git a/packages/backend/src/server/api/service/discord.ts b/packages/backend/src/server/api/service/discord.ts index 9906d2f7c..296e9cb48 100644 --- a/packages/backend/src/server/api/service/discord.ts +++ b/packages/backend/src/server/api/service/discord.ts @@ -18,7 +18,7 @@ function getUserToken(ctx: Koa.BaseContext): string | null { function compareOrigin(ctx: Koa.BaseContext): boolean { function normalizeUrl(url?: string): string { - return url ? (url.endsWith("/") ? url.substr(0, url.length - 1) : url) : ""; + return slice( url.length - 1) : url) : ""; } const referer = ctx.headers["referer"]; diff --git a/packages/backend/src/server/api/service/github.ts b/packages/backend/src/server/api/service/github.ts index f77c5f795..da9d0931a 100644 --- a/packages/backend/src/server/api/service/github.ts +++ b/packages/backend/src/server/api/service/github.ts @@ -18,7 +18,7 @@ function getUserToken(ctx: Koa.BaseContext): string | null { function compareOrigin(ctx: Koa.BaseContext): boolean { function normalizeUrl(url?: string): string { - return url ? (url.endsWith("/") ? url.substr(0, url.length - 1) : url) : ""; + return slice( url.length - 1) : url) : ""; } const referer = ctx.headers["referer"]; diff --git a/packages/calckey-js/src/acct.ts b/packages/calckey-js/src/acct.ts index 5b7767a10..cb6808b4b 100644 --- a/packages/calckey-js/src/acct.ts +++ b/packages/calckey-js/src/acct.ts @@ -4,7 +4,7 @@ export type Acct = { }; export function parse(acct: string): Acct { - if (acct.startsWith("@")) acct = acct.substr(1); + if (acct.startsWith("@")) acct = acct.slice(1); const split = acct.split("@", 2); return { username: split[0], host: split[1] || null }; } diff --git a/packages/client/src/components/MkUserPreview.vue b/packages/client/src/components/MkUserPreview.vue index 6c3838fd2..7aec66136 100644 --- a/packages/client/src/components/MkUserPreview.vue +++ b/packages/client/src/components/MkUserPreview.vue @@ -155,7 +155,7 @@ onMounted(() => { user.description.length > 400; } else { const query = props.q.startsWith("@") - ? Acct.parse(props.q.substr(1)) + ? Acct.parse(props.q.slice(1)) : { userId: props.q }; os.api("users/show", query).then((res) => { diff --git a/packages/client/src/scripts/gen-search-query.ts b/packages/client/src/scripts/gen-search-query.ts index 822572d3e..fcf1f727e 100644 --- a/packages/client/src/scripts/gen-search-query.ts +++ b/packages/client/src/scripts/gen-search-query.ts @@ -8,7 +8,7 @@ export async function genSearchQuery(v: any, q: string) { for (const at of q .split(" ") .filter((x) => x.startsWith("@")) - .map((x) => x.substr(1))) { + .map((x) => x.slice(1))) { if (at.includes(".")) { if (at === localHost || at === ".") { host = null; diff --git a/packages/client/src/scripts/search.ts b/packages/client/src/scripts/search.ts index 34318ab0e..ecea1ff2d 100644 --- a/packages/client/src/scripts/search.ts +++ b/packages/client/src/scripts/search.ts @@ -19,7 +19,7 @@ export async function search() { } if (q.startsWith("#")) { - mainRouter.push(`/tags/${encodeURIComponent(q.substr(1))}`); + mainRouter.push(`/tags/${encodeURIComponent(q.slice(1))}`); return; } diff --git a/packages/client/src/scripts/theme-editor.ts b/packages/client/src/scripts/theme-editor.ts index 482841017..fc015b6ac 100644 --- a/packages/client/src/scripts/theme-editor.ts +++ b/packages/client/src/scripts/theme-editor.ts @@ -35,7 +35,7 @@ export const fromThemeString = (str?: string): ThemeValue => { } else if (str.startsWith('"')) { return { type: "css", - value: str.substr(1).trim(), + value: str.slice(1).trim(), }; } else { return str; diff --git a/packages/client/src/scripts/theme.ts b/packages/client/src/scripts/theme.ts index 383deb34c..c52c2c217 100644 --- a/packages/client/src/scripts/theme.ts +++ b/packages/client/src/scripts/theme.ts @@ -112,7 +112,7 @@ function compile(theme: Theme): Record { function getColor(val: string): tinycolor.Instance { // ref (prop) if (val[0] === "@") { - return getColor(theme.props[val.substr(1)]); + return getColor(theme.props[val.slice(1)]); } // ref (const) @@ -123,7 +123,7 @@ function compile(theme: Theme): Record { // func else if (val[0] === ":") { const parts = val.split("<"); - const func = parts.shift().substr(1); + const func = parts.shift().slice(1); const arg = parseFloat(parts.shift()); const color = getColor(parts.join("<"));