Use startsWith and endsWith for readability

This commit is contained in:
Aya Morisawa
2018-08-25 22:42:26 +09:00
parent bf7875bfaa
commit 08a59591ae
7 changed files with 8 additions and 8 deletions

View File

@@ -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: `<span class="regexp">/${escape(regexp)}/</span>`,

View File

@@ -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',

View File

@@ -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];