refactor: substr -> substring (#11273)

This commit is contained in:
okayurisotto 2023-07-14 07:59:54 +09:00 committed by GitHub
parent af30959cb9
commit c0dbc3b53f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 38 additions and 38 deletions

View file

@ -31,7 +31,7 @@ function greet() {
console.log(themeColor(' | |_|___ ___| |_ ___ _ _ ')); console.log(themeColor(' | |_|___ ___| |_ ___ _ _ '));
console.log(themeColor(' | | | | |_ -|_ -| \'_| -_| | |')); console.log(themeColor(' | | | | |_ -|_ -| \'_| -_| | |'));
console.log(themeColor(' |_|_|_|_|___|___|_,_|___|_ |')); console.log(themeColor(' |_|_|_|_|___|___|_,_|___|_ |'));
console.log(' ' + chalk.gray(v) + themeColor(' |___|\n'.substr(v.length))); console.log(' ' + chalk.gray(v) + themeColor(' |___|\n'.substring(v.length)));
//#endregion //#endregion
console.log(' Misskey is an open-source decentralized microblogging platform.'); console.log(' Misskey is an open-source decentralized microblogging platform.');

View file

@ -254,7 +254,7 @@ export default abstract class Chart<T extends Schema> {
private convertRawRecord(x: RawRecord<T>): KVs<T> { private convertRawRecord(x: RawRecord<T>): KVs<T> {
const kvs = {} as Record<string, number>; const kvs = {} as Record<string, number>;
for (const k of Object.keys(x).filter((k) => k.startsWith(COLUMN_PREFIX)) as (keyof Columns<T>)[]) { for (const k of Object.keys(x).filter((k) => k.startsWith(COLUMN_PREFIX)) as (keyof Columns<T>)[]) {
kvs[(k as string).substr(COLUMN_PREFIX.length).split(COLUMN_DELIMITER).join('.')] = x[k] as unknown as number; kvs[(k as string).substring(COLUMN_PREFIX.length).split(COLUMN_DELIMITER).join('.')] = x[k] as unknown as number;
} }
return kvs as KVs<T>; return kvs as KVs<T>;
} }

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.substring(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

@ -25,8 +25,8 @@
<MkDriveFileThumbnail :class="$style.thumbnail" :file="file" fit="contain"/> <MkDriveFileThumbnail :class="$style.thumbnail" :file="file" fit="contain"/>
<p :class="$style.name"> <p :class="$style.name">
<span>{{ file.name.lastIndexOf('.') != -1 ? file.name.substr(0, file.name.lastIndexOf('.')) : file.name }}</span> <span>{{ file.name.lastIndexOf('.') != -1 ? file.name.substring(0, file.name.lastIndexOf('.')) : file.name }}</span>
<span v-if="file.name.lastIndexOf('.') != -1" style="opacity: 0.5;">{{ file.name.substr(file.name.lastIndexOf('.')) }}</span> <span v-if="file.name.lastIndexOf('.') != -1" style="opacity: 0.5;">{{ file.name.substring(file.name.lastIndexOf('.')) }}</span>
</p> </p>
</div> </div>
</div> </div>

View file

@ -1,6 +1,6 @@
<template> <template>
<component <component
:is="self ? 'MkA' : 'a'" ref="el" style="word-break: break-all;" class="_link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target" :is="self ? 'MkA' : 'a'" ref="el" style="word-break: break-all;" class="_link" :[attr]="self ? url.substring(local.length) : url" :rel="rel" :target="target"
:title="url" :title="url"
> >
<slot></slot> <slot></slot>

View file

@ -564,7 +564,7 @@ async function onPaste(ev: ClipboardEvent) {
return; return;
} }
quoteId = paste.substr(url.length).match(/^\/notes\/(.+?)\/?$/)[1]; quoteId = paste.substring(url.length).match(/^\/notes\/(.+?)\/?$/)[1];
}); });
} }
} }

View file

@ -6,7 +6,7 @@
:class="[$style.root, { [$style.reacted]: note.myReaction == reaction, [$style.canToggle]: canToggle, [$style.large]: defaultStore.state.largeNoteReactions }]" :class="[$style.root, { [$style.reacted]: note.myReaction == reaction, [$style.canToggle]: canToggle, [$style.large]: defaultStore.state.largeNoteReactions }]"
@click="toggleReaction()" @click="toggleReaction()"
> >
<MkReactionIcon :class="$style.icon" :reaction="reaction" :emojiUrl="note.reactionEmojis[reaction.substr(1, reaction.length - 2)]"/> <MkReactionIcon :class="$style.icon" :reaction="reaction" :emojiUrl="note.reactionEmojis[reaction.substring(1, reaction.length - 1)]"/>
<span :class="$style.count">{{ count }}</span> <span :class="$style.count">{{ count }}</span>
</button> </button>
</template> </template>

View file

@ -32,7 +32,7 @@
</div> </div>
</template> </template>
<div v-else> <div v-else>
<component :is="self ? 'MkA' : 'a'" :class="[$style.link, { [$style.compact]: compact }]" :[attr]="self ? url.substr(local.length) : url" rel="nofollow noopener" :target="target" :title="url"> <component :is="self ? 'MkA' : 'a'" :class="[$style.link, { [$style.compact]: compact }]" :[attr]="self ? url.substring(local.length) : url" rel="nofollow noopener" :target="target" :title="url">
<div v-if="thumbnail" :class="$style.thumbnail" :style="`background-image: url('${thumbnail}')`"> <div v-if="thumbnail" :class="$style.thumbnail" :style="`background-image: url('${thumbnail}')`">
</div> </div>
<article :class="$style.body"> <article :class="$style.body">

View file

@ -88,7 +88,7 @@ onMounted(() => {
user = props.q; user = props.q;
} else { } else {
const query = props.q.startsWith('@') ? const query = props.q.startsWith('@') ?
Acct.parse(props.q.substr(1)) : Acct.parse(props.q.substring(1)) :
{ userId: props.q }; { userId: props.q };
os.api('users/show', query).then(res => { os.api('users/show', query).then(res => {

View file

@ -18,7 +18,7 @@ const props = defineProps<{
useOriginalSize?: boolean; useOriginalSize?: boolean;
}>(); }>();
const customEmojiName = computed(() => (props.name[0] === ':' ? props.name.substr(1, props.name.length - 2) : props.name).replace('@.', '')); const customEmojiName = computed(() => (props.name[0] === ':' ? props.name.substring(1, props.name.length - 1) : props.name).replace('@.', ''));
const isLocal = computed(() => !props.host && (customEmojiName.value.endsWith('@.') || !customEmojiName.value.includes('@'))); const isLocal = computed(() => !props.host && (customEmojiName.value.endsWith('@.') || !customEmojiName.value.includes('@')));
const rawUrl = computed(() => { const rawUrl = computed(() => {

View file

@ -11,13 +11,13 @@ export default function(props: { src: string; tag?: string; textTag?: string; },
parsed.push(str); parsed.push(str);
break; break;
} else { } else {
if (nextBracketOpen > 0) parsed.push(str.substr(0, nextBracketOpen)); if (nextBracketOpen > 0) parsed.push(str.substring(0, nextBracketOpen));
parsed.push({ parsed.push({
arg: str.substring(nextBracketOpen + 1, nextBracketClose), arg: str.substring(nextBracketOpen + 1, nextBracketClose),
}); });
} }
str = str.substr(nextBracketClose + 1); str = str.substring(nextBracketClose + 1);
} }
return h(props.tag ?? 'span', parsed.map(x => typeof x === 'string' ? (props.textTag ? h(props.textTag, x) : x) : slots[x.arg]())); return h(props.tag ?? 'span', parsed.map(x => typeof x === 'string' ? (props.textTag ? h(props.textTag, x) : x) : slots[x.arg]()));

View file

@ -85,7 +85,7 @@ onMounted(() => {
connection.on('stats', onStats); connection.on('stats', onStats);
connection.on('statsLog', onStatsLog); connection.on('statsLog', onStatsLog);
connection.send('requestLog', { connection.send('requestLog', {
id: Math.random().toString().substr(2, 8), id: Math.random().toString().substring(2, 10),
length: 100, length: 100,
}); });
}); });

View file

@ -156,7 +156,7 @@ onMounted(async () => {
nextTick(() => { nextTick(() => {
queueStatsConnection.send('requestLog', { queueStatsConnection.send('requestLog', {
id: Math.random().toString().substr(2, 8), id: Math.random().toString().substring(2, 10),
length: 100, length: 100,
}); });
}); });

View file

@ -106,7 +106,7 @@ onMounted(() => {
connection.on('stats', onStats); connection.on('stats', onStats);
connection.on('statsLog', onStatsLog); connection.on('statsLog', onStatsLog);
connection.send('requestLog', { connection.send('requestLog', {
id: Math.random().toString().substr(2, 8), id: Math.random().toString().substring(2, 10),
length: 200, length: 200,
}); });
}); });

View file

@ -65,7 +65,7 @@ export class Autocomplete {
*/ */
private onInput() { private onInput() {
const caretPos = this.textarea.selectionStart; const caretPos = this.textarea.selectionStart;
const text = this.text.substr(0, caretPos).split('\n').pop()!; const text = this.text.substring(0, caretPos).split('\n').pop()!;
const mentionIndex = text.lastIndexOf('@'); const mentionIndex = text.lastIndexOf('@');
const hashtagIndex = text.lastIndexOf('#'); const hashtagIndex = text.lastIndexOf('#');
@ -91,7 +91,7 @@ export class Autocomplete {
let opened = false; let opened = false;
if (isMention) { if (isMention) {
const username = text.substr(mentionIndex + 1); const username = text.substring(mentionIndex + 1);
if (username !== '' && username.match(/^[a-zA-Z0-9_]+$/)) { if (username !== '' && username.match(/^[a-zA-Z0-9_]+$/)) {
this.open('user', username); this.open('user', username);
opened = true; opened = true;
@ -102,7 +102,7 @@ export class Autocomplete {
} }
if (isHashtag && !opened) { if (isHashtag && !opened) {
const hashtag = text.substr(hashtagIndex + 1); const hashtag = text.substring(hashtagIndex + 1);
if (!hashtag.includes(' ')) { if (!hashtag.includes(' ')) {
this.open('hashtag', hashtag); this.open('hashtag', hashtag);
opened = true; opened = true;
@ -110,7 +110,7 @@ export class Autocomplete {
} }
if (isEmoji && !opened) { if (isEmoji && !opened) {
const emoji = text.substr(emojiIndex + 1); const emoji = text.substring(emojiIndex + 1);
if (!emoji.includes(' ')) { if (!emoji.includes(' ')) {
this.open('emoji', emoji); this.open('emoji', emoji);
opened = true; opened = true;
@ -118,7 +118,7 @@ export class Autocomplete {
} }
if (isMfmTag && !opened) { if (isMfmTag && !opened) {
const mfmTag = text.substr(mfmTagIndex + 1); const mfmTag = text.substring(mfmTagIndex + 1);
if (!mfmTag.includes(' ')) { if (!mfmTag.includes(' ')) {
this.open('mfmTag', mfmTag.replace('[', '')); this.open('mfmTag', mfmTag.replace('[', ''));
opened = true; opened = true;
@ -208,9 +208,9 @@ export class Autocomplete {
if (type === 'user') { if (type === 'user') {
const source = this.text; const source = this.text;
const before = source.substr(0, caret); const before = source.substring(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf('@')); const trimmedBefore = before.substring(0, before.lastIndexOf('@'));
const after = source.substr(caret); const after = source.substring(caret);
const acct = value.host === null ? value.username : `${value.username}@${toASCII(value.host)}`; const acct = value.host === null ? value.username : `${value.username}@${toASCII(value.host)}`;
@ -226,9 +226,9 @@ export class Autocomplete {
} else if (type === 'hashtag') { } else if (type === 'hashtag') {
const source = this.text; const source = this.text;
const before = source.substr(0, caret); const before = source.substring(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf('#')); const trimmedBefore = before.substring(0, before.lastIndexOf('#'));
const after = source.substr(caret); const after = source.substring(caret);
// 挿入 // 挿入
this.text = `${trimmedBefore}#${value} ${after}`; this.text = `${trimmedBefore}#${value} ${after}`;
@ -242,9 +242,9 @@ export class Autocomplete {
} else if (type === 'emoji') { } else if (type === 'emoji') {
const source = this.text; const source = this.text;
const before = source.substr(0, caret); const before = source.substring(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf(':')); const trimmedBefore = before.substring(0, before.lastIndexOf(':'));
const after = source.substr(caret); const after = source.substring(caret);
// 挿入 // 挿入
this.text = trimmedBefore + value + after; this.text = trimmedBefore + value + after;
@ -258,9 +258,9 @@ export class Autocomplete {
} else if (type === 'mfmTag') { } else if (type === 'mfmTag') {
const source = this.text; const source = this.text;
const before = source.substr(0, caret); const before = source.substring(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf('$')); const trimmedBefore = before.substring(0, before.lastIndexOf('$'));
const after = source.substr(caret); const after = source.substring(caret);
// 挿入 // 挿入
this.text = `${trimmedBefore}$[${value} ]${after}`; this.text = `${trimmedBefore}$[${value} ]${after}`;

View file

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

View file

@ -18,7 +18,7 @@ export async function lookup(router?: Router) {
} }
if (query.startsWith('#')) { if (query.startsWith('#')) {
_router.push(`/tags/${encodeURIComponent(query.substr(1))}`); _router.push(`/tags/${encodeURIComponent(query.substring(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.substring(1).trim(),
}; };
} else { } else {
return str; return str;

View file

@ -98,7 +98,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.substring(1)]);
} }
// ref (const) // ref (const)
@ -109,7 +109,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().substring(1);
const arg = parseFloat(parts.shift()); const arg = parseFloat(parts.shift());
const color = getColor(parts.join('<')); const color = getColor(parts.join('<'));

View file

@ -124,7 +124,7 @@ connection.on('stats', onStats);
connection.on('statsLog', onStatsLog); connection.on('statsLog', onStatsLog);
connection.send('requestLog', { connection.send('requestLog', {
id: Math.random().toString().substr(2, 8), id: Math.random().toString().substring(2, 10),
length: 1, length: 1,
}); });

View file

@ -100,7 +100,7 @@ onMounted(() => {
props.connection.on('stats', onStats); props.connection.on('stats', onStats);
props.connection.on('statsLog', onStatsLog); props.connection.on('statsLog', onStatsLog);
props.connection.send('requestLog', { props.connection.send('requestLog', {
id: Math.random().toString().substr(2, 8), id: Math.random().toString().substring(2, 10),
}); });
}); });

View file

@ -70,7 +70,7 @@ onMounted(() => {
props.connection.on('stats', onStats); props.connection.on('stats', onStats);
props.connection.on('statsLog', onStatsLog); props.connection.on('statsLog', onStatsLog);
props.connection.send('requestLog', { props.connection.send('requestLog', {
id: Math.random().toString().substr(2, 8), id: Math.random().toString().substring(2, 10),
}); });
}); });

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.substring(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 };
} }