refactor: ♻️ substr -> slice

This commit is contained in:
ThatOneCalculator 2023-07-12 23:56:22 -07:00
parent 04efd39281
commit bfa2f045d2
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("<"));