From bfed1475bbdd1941bb9b12e5ad772ab0f5840bb4 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Sun, 26 Aug 2018 13:55:39 +0900 Subject: [PATCH] Use endsWith for readability --- src/config/load.ts | 2 +- src/server/api/service/twitter.ts | 2 +- webpack/loaders/replace.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config/load.ts b/src/config/load.ts index 1c59f82b3..8929cf8d3 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -53,5 +53,5 @@ export default function load() { } function normalizeUrl(url: string) { - return url[url.length - 1] === '/' ? url.substr(0, url.length - 1) : url; + return url.endsWith('/') ? url.substr(0, url.length - 1) : url; } diff --git a/src/server/api/service/twitter.ts b/src/server/api/service/twitter.ts index 8c668e832..aad2846bb 100644 --- a/src/server/api/service/twitter.ts +++ b/src/server/api/service/twitter.ts @@ -14,7 +14,7 @@ function getUserToken(ctx: Koa.Context) { function compareOrigin(ctx: Koa.Context) { function normalizeUrl(url: string) { - return url[url.length - 1] === '/' ? url.substr(0, url.length - 1) : url; + return url.endsWith('/') ? url.substr(0, url.length - 1) : url; } const referer = ctx.headers['referer']; diff --git a/webpack/loaders/replace.js b/webpack/loaders/replace.js index fd6bb3617..9f4825e18 100644 --- a/webpack/loaders/replace.js +++ b/webpack/loaders/replace.js @@ -7,7 +7,7 @@ function trim(text, g) { export default function(src) { const fn = options => { const search = options.search; - const g = search[search.length - 1] == 'g'; + const g = search.endsWith('g'); const file = this.resourcePath.replace(/\\/g, '/'); const replace = options.i18n ? global[options.replace].bind(null, { src: file,