refactor: ♻️ substr -> slice

This commit is contained in:
ThatOneCalculator 2023-07-12 23:56:22 -07:00
parent 1c7a805ff1
commit 64322721b6
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
9 changed files with 10 additions and 10 deletions

View File

@ -4,7 +4,7 @@ export type Acct = {
}; };
export function parse(acct: string): 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); const split = acct.split("@", 2);
return { username: split[0], host: split[1] || null }; return { username: split[0], host: split[1] || null };
} }

View File

@ -18,7 +18,7 @@ function getUserToken(ctx: Koa.BaseContext): string | null {
function compareOrigin(ctx: Koa.BaseContext): boolean { function compareOrigin(ctx: Koa.BaseContext): boolean {
function normalizeUrl(url?: string): string { 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"]; const referer = ctx.headers["referer"];

View File

@ -18,7 +18,7 @@ function getUserToken(ctx: Koa.BaseContext): string | null {
function compareOrigin(ctx: Koa.BaseContext): boolean { function compareOrigin(ctx: Koa.BaseContext): boolean {
function normalizeUrl(url?: string): string { 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"]; const referer = ctx.headers["referer"];

View File

@ -4,7 +4,7 @@ export type Acct = {
}; };
export function parse(acct: string): 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); const split = acct.split("@", 2);
return { username: split[0], host: split[1] || null }; return { username: split[0], host: split[1] || null };
} }

View File

@ -155,7 +155,7 @@ onMounted(() => {
user.description.length > 400; user.description.length > 400;
} else { } else {
const query = props.q.startsWith("@") const query = props.q.startsWith("@")
? Acct.parse(props.q.substr(1)) ? Acct.parse(props.q.slice(1))
: { userId: props.q }; : { userId: props.q };
os.api("users/show", query).then((res) => { os.api("users/show", query).then((res) => {

View File

@ -8,7 +8,7 @@ export async function genSearchQuery(v: any, q: string) {
for (const at of q for (const at of q
.split(" ") .split(" ")
.filter((x) => x.startsWith("@")) .filter((x) => x.startsWith("@"))
.map((x) => x.substr(1))) { .map((x) => x.slice(1))) {
if (at.includes(".")) { if (at.includes(".")) {
if (at === localHost || at === ".") { if (at === localHost || at === ".") {
host = null; host = null;

View File

@ -19,7 +19,7 @@ export async function search() {
} }
if (q.startsWith("#")) { if (q.startsWith("#")) {
mainRouter.push(`/tags/${encodeURIComponent(q.substr(1))}`); mainRouter.push(`/tags/${encodeURIComponent(q.slice(1))}`);
return; return;
} }

View File

@ -35,7 +35,7 @@ export const fromThemeString = (str?: string): ThemeValue => {
} else if (str.startsWith('"')) { } else if (str.startsWith('"')) {
return { return {
type: "css", type: "css",
value: str.substr(1).trim(), value: str.slice(1).trim(),
}; };
} else { } else {
return str; return str;

View File

@ -112,7 +112,7 @@ function compile(theme: Theme): Record<string, string> {
function getColor(val: string): tinycolor.Instance { function getColor(val: string): tinycolor.Instance {
// ref (prop) // ref (prop)
if (val[0] === "@") { if (val[0] === "@") {
return getColor(theme.props[val.substr(1)]); return getColor(theme.props[val.slice(1)]);
} }
// ref (const) // ref (const)
@ -123,7 +123,7 @@ function compile(theme: Theme): Record<string, string> {
// func // func
else if (val[0] === ":") { else if (val[0] === ":") {
const parts = val.split("<"); const parts = val.split("<");
const func = parts.shift().substr(1); const func = parts.shift().slice(1);
const arg = parseFloat(parts.shift()); const arg = parseFloat(parts.shift());
const color = getColor(parts.join("<")); const color = getColor(parts.join("<"));