From 08a59591ae25280cf11e49d0f5eab4d5a438e147 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Sat, 25 Aug 2018 22:42:26 +0900 Subject: [PATCH] Use startsWith and endsWith for readability --- src/client/app/desktop/views/components/user-preview.vue | 2 +- src/mfm/parse/core/syntax-highlighter.ts | 2 +- src/mfm/parse/elements/hashtag.ts | 2 +- src/mfm/parse/elements/link.ts | 2 +- src/misc/fa.ts | 4 ++-- src/server/api/common/is-native-token.ts | 2 +- webpack/i18n.ts | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client/app/desktop/views/components/user-preview.vue b/src/client/app/desktop/views/components/user-preview.vue index 7ef8dff5b..1e1755ec3 100644 --- a/src/client/app/desktop/views/components/user-preview.vue +++ b/src/client/app/desktop/views/components/user-preview.vue @@ -48,7 +48,7 @@ export default Vue.extend({ this.open(); }); } else { - const query = this.user[0] == '@' ? + const query = this.user.startsWith('@') ? parseAcct(this.user.substr(1)) : { userId: this.user }; diff --git a/src/mfm/parse/core/syntax-highlighter.ts b/src/mfm/parse/core/syntax-highlighter.ts index 3fb7a3b73..2b13608d2 100644 --- a/src/mfm/parse/core/syntax-highlighter.ts +++ b/src/mfm/parse/core/syntax-highlighter.ts @@ -197,7 +197,7 @@ const elements: Element[] = [ if (thisIsNotARegexp) return null; if (regexp == '') return null; - if (regexp[0] == ' ' && regexp[regexp.length - 1] == ' ') return null; + if (regexp.startsWith(' ') && regexp.endsWith(' ')) return null; return { html: `/${escape(regexp)}/`, diff --git a/src/mfm/parse/elements/hashtag.ts b/src/mfm/parse/elements/hashtag.ts index 129041774..f4b6a78fa 100644 --- a/src/mfm/parse/elements/hashtag.ts +++ b/src/mfm/parse/elements/hashtag.ts @@ -10,7 +10,7 @@ export type TextElementHashtag = { export default function(text: string, i: number) { 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 res: any[] = !isHead ? [{ type: 'text', diff --git a/src/mfm/parse/elements/link.ts b/src/mfm/parse/elements/link.ts index b353aebc5..796aeb1ab 100644 --- a/src/mfm/parse/elements/link.ts +++ b/src/mfm/parse/elements/link.ts @@ -13,7 +13,7 @@ export type TextElementLink = { export default function(text: string) { const match = text.match(/^\??\[([^\[\]]+?)\]\((https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+?)\)/); if (!match) return null; - const silent = text[0] == '?'; + const silent = text.startsWith('?'); const link = match[0]; const title = match[1]; const url = match[2]; diff --git a/src/misc/fa.ts b/src/misc/fa.ts index 077bb51e6..8be06362c 100644 --- a/src/misc/fa.ts +++ b/src/misc/fa.ts @@ -25,9 +25,9 @@ export const replacement = (match: string, key: string) => { arg == 'S' ? 'fas' : arg == 'B' ? 'fab' : ''; - } else if (arg[0] == '.') { + } else if (arg.startsWith('.')) { classes.push('fa-' + arg.substr(1)); - } else if (arg[0] == '-') { + } else if (arg.startsWith('-')) { transform = arg.substr(1).split('|').join(' '); } else { name = arg; diff --git a/src/server/api/common/is-native-token.ts b/src/server/api/common/is-native-token.ts index 0769a4812..6afbc99ab 100644 --- a/src/server/api/common/is-native-token.ts +++ b/src/server/api/common/is-native-token.ts @@ -1 +1 @@ -export default (token: string) => token[0] == '!'; +export default (token: string) => token.startsWith('!'); diff --git a/webpack/i18n.ts b/webpack/i18n.ts index f73af7258..4fd439d1d 100644 --- a/webpack/i18n.ts +++ b/webpack/i18n.ts @@ -8,7 +8,7 @@ export const replacement = (ctx: any, _: any, key: string) => { const client = '/src/client/app/'; let name = null; - if (key[0] == '@') { + if (key.startsWith('@')) { name = ctx.src.substr(ctx.src.indexOf(client) + client.length); key = key.substr(1); }