mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-03 18:34:49 +01:00
Merge pull request #2488 from syuilo/refactor-string
Use startsWith and endsWith for readability
This commit is contained in:
commit
a1fca2550e
7 changed files with 8 additions and 8 deletions
|
@ -48,7 +48,7 @@ export default Vue.extend({
|
||||||
this.open();
|
this.open();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const query = this.user[0] == '@' ?
|
const query = this.user.startsWith('@') ?
|
||||||
parseAcct(this.user.substr(1)) :
|
parseAcct(this.user.substr(1)) :
|
||||||
{ userId: this.user };
|
{ userId: this.user };
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ const elements: Element[] = [
|
||||||
|
|
||||||
if (thisIsNotARegexp) return null;
|
if (thisIsNotARegexp) return null;
|
||||||
if (regexp == '') return null;
|
if (regexp == '') return null;
|
||||||
if (regexp[0] == ' ' && regexp[regexp.length - 1] == ' ') return null;
|
if (regexp.startsWith(' ') && regexp.endsWith(' ')) return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
html: `<span class="regexp">/${escape(regexp)}/</span>`,
|
html: `<span class="regexp">/${escape(regexp)}/</span>`,
|
||||||
|
|
|
@ -10,7 +10,7 @@ export type TextElementHashtag = {
|
||||||
|
|
||||||
export default function(text: string, i: number) {
|
export default function(text: string, i: number) {
|
||||||
if (!(/^\s#[^\s]+/.test(text) || (i == 0 && /^#[^\s]+/.test(text)))) return null;
|
if (!(/^\s#[^\s]+/.test(text) || (i == 0 && /^#[^\s]+/.test(text)))) return null;
|
||||||
const isHead = text[0] == '#';
|
const isHead = text.startsWith('#');
|
||||||
const hashtag = text.match(/^\s?#[^\s]+/)[0];
|
const hashtag = text.match(/^\s?#[^\s]+/)[0];
|
||||||
const res: any[] = !isHead ? [{
|
const res: any[] = !isHead ? [{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
|
|
@ -13,7 +13,7 @@ export type TextElementLink = {
|
||||||
export default function(text: string) {
|
export default function(text: string) {
|
||||||
const match = text.match(/^\??\[([^\[\]]+?)\]\((https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+?)\)/);
|
const match = text.match(/^\??\[([^\[\]]+?)\]\((https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+?)\)/);
|
||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
const silent = text[0] == '?';
|
const silent = text.startsWith('?');
|
||||||
const link = match[0];
|
const link = match[0];
|
||||||
const title = match[1];
|
const title = match[1];
|
||||||
const url = match[2];
|
const url = match[2];
|
||||||
|
|
|
@ -25,9 +25,9 @@ export const replacement = (match: string, key: string) => {
|
||||||
arg == 'S' ? 'fas' :
|
arg == 'S' ? 'fas' :
|
||||||
arg == 'B' ? 'fab' :
|
arg == 'B' ? 'fab' :
|
||||||
'';
|
'';
|
||||||
} else if (arg[0] == '.') {
|
} else if (arg.startsWith('.')) {
|
||||||
classes.push('fa-' + arg.substr(1));
|
classes.push('fa-' + arg.substr(1));
|
||||||
} else if (arg[0] == '-') {
|
} else if (arg.startsWith('-')) {
|
||||||
transform = arg.substr(1).split('|').join(' ');
|
transform = arg.substr(1).split('|').join(' ');
|
||||||
} else {
|
} else {
|
||||||
name = arg;
|
name = arg;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
export default (token: string) => token[0] == '!';
|
export default (token: string) => token.startsWith('!');
|
||||||
|
|
|
@ -8,7 +8,7 @@ export const replacement = (ctx: any, _: any, key: string) => {
|
||||||
const client = '/src/client/app/';
|
const client = '/src/client/app/';
|
||||||
let name = null;
|
let name = null;
|
||||||
|
|
||||||
if (key[0] == '@') {
|
if (key.startsWith('@')) {
|
||||||
name = ctx.src.substr(ctx.src.indexOf(client) + client.length);
|
name = ctx.src.substr(ctx.src.indexOf(client) + client.length);
|
||||||
key = key.substr(1);
|
key = key.substr(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue