From 684f358fae46454d172baf09844911a67cc7b5b9 Mon Sep 17 00:00:00 2001 From: Richie Bendall Date: Wed, 7 Aug 2019 20:02:04 +1200 Subject: [PATCH] chore: Simplify github constant and normalize string variable used in utils Signed-off-by: Richie Bendall --- routes/post.js | 7 +++---- routes/utils.js | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/routes/post.js b/routes/post.js index 852ecb46..febd08bd 100644 --- a/routes/post.js +++ b/routes/post.js @@ -4,13 +4,12 @@ const { promisify } = require('util'); const access = promisify(fs.access); const writeFile = promisify(fs.writeFile); const btoa = require('btoa'); -var github = require('@octokit/rest')({ +const { version } = require(path.join(__dirname, '..', 'package.json')); +const github = require('@octokit/rest')({ // GitHub personal access token auth: process.env.github_token, // User agent with version from package.json - userAgent: - 'mit-license v' + - require(path.join(__dirname, '..', 'package.json')).version, + userAgent: `mit-license v${version}`, }); const { validDomainId } = require('./utils'); diff --git a/routes/utils.js b/routes/utils.js index 3e78ed8b..ab433bc7 100644 --- a/routes/utils.js +++ b/routes/utils.js @@ -5,4 +5,4 @@ const tags = { }; exports.escapeTags = str => (str || '').replace(/[<>&]/g, m => tags[m]); exports.stripTags = str => (str || '').replace(/<(?:.|\n)*?>/gm, ''); -exports.validDomainId = s => /^[\w-_]+$/.test(s); +exports.validDomainId = str => /^[\w-_]+$/.test(str);