diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 00000000..00cf4cd6
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1 @@
+module.exports = require('@remy/eslint')('node');
diff --git a/.eslintrc.json b/.eslintrc.json
deleted file mode 100644
index 7df192a5..00000000
--- a/.eslintrc.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "env": {
- "browser": true,
- "es6": true,
- "node": true
- },
- "plugins": [
- "node"
- ],
- "extends": [
- "plugin:prettier/recommended",
- "eslint:recommended",
- "plugin:node/recommended"
- ],
- "parserOptions": {
- "ecmaVersion": 2018,
- "sourceType": "module",
- "warnOnUnsupportedTypeScriptVersion": false
- },
- "rules": {
- "prettier/prettier": "error",
- "node/no-deprecated-api": 0,
- "no-console": 0
- }
-}
diff --git a/.prettierrc.yaml b/.prettierrc.yaml
deleted file mode 100644
index 8e1ecf74..00000000
--- a/.prettierrc.yaml
+++ /dev/null
@@ -1,3 +0,0 @@
-# use the prettier defaults except for:
-trailingComma: "es5"
-singleQuote: true
diff --git a/package.json b/package.json
index 93fcfbf2..eb7dbf11 100644
--- a/package.json
+++ b/package.json
@@ -30,33 +30,34 @@
},
"license": "MIT",
"dependencies": {
- "@octokit/rest": "^16.33.1",
+ "@octokit/rest": "^16.34.1",
"btoa": "^1.2.1",
"ejs": "^2.7.1",
"express": "^4.17.1",
"express-minify": "^1.0.0",
+ "lodash": "^4.17.15",
"md5": "^2.2.1",
"postcss-middleware": "^1.1.4",
"postcss-preset-env": "^6.7.0",
"serve-favicon": "^2.5.0"
},
"devDependencies": {
+ "@remy/eslint": "^3.2.2",
"@types/btoa": "^1.2.3",
"@types/css": "^0.0.31",
"@types/ejs": "^2.6.3",
- "@types/express": "^4.17.1",
+ "@types/express": "^4.17.2",
"@types/express-minify": "^0.1.34",
+ "@types/lodash": "^4.14.144",
"@types/md5": "^2.1.33",
- "@types/node": "^12.11.1",
+ "@types/node": "^12.12.6",
+ "babel-eslint": "^10.0.3",
"css": "^2.2.4",
- "eslint": "^6.5.1",
- "eslint-config-prettier": "^6.4.0",
+ "eslint": "^6.6.0",
"eslint-plugin-node": "^10.0.0",
- "eslint-plugin-prettier": "^3.1.1",
"has-flag": "^4.0.0",
"husky": "^3.0.9",
- "nodemon": "^1.19.4",
- "prettier": "^1.18.2"
+ "nodemon": "^1.19.4"
},
"resolutions": {
"postcss-middleware/vinyl-fs/glob-stream/micromatch/braces": "^3.0.2"
diff --git a/routes/get.js b/routes/get.js
index f30b5269..eddd0c0e 100644
--- a/routes/get.js
+++ b/routes/get.js
@@ -1,14 +1,14 @@
const md5 = require('md5');
const path = require('path');
-const { stripTags, escapeTags } = require('./utils');
+const { stripTags, escapeTags, unescapeTags } = require('./utils');
+const _ = require('lodash');
function getCopyrightHTML(user, plain) {
let html = '';
- const name =
- typeof user === 'string'
- ? user
- : plain
+ const name = _.isString(user)
+ ? user
+ : plain
? user.name || user.copyright
: escapeTags(user.name || user.copyright);
@@ -34,9 +34,9 @@ module.exports = (req, res) => {
// No error and valid
if (user.copyright) {
- if (typeof user.copyright === 'string') {
+ if (_.isString(user.copyright)) {
name = getCopyrightHTML(user, options.format !== 'html');
- } else if (user.copyright.every(val => typeof val === 'string')) {
+ } else if (user.copyright.every(val => _.isString(val))) {
// Supports: ['Remy Sharp', 'Richie Bendall']
name = user
.map(_ => (options.format !== 'html' ? _ : escapeTags(_)))
@@ -51,7 +51,7 @@ module.exports = (req, res) => {
gravatar = `
`;
- } else if (typeof user.copyright[0] === 'object' && user.gravatar) {
+ } else if (_.isObject(user.copyright[0]) && user.gravatar) {
// Supports multi-user format
gravatar = `
{
}
// Extract the name from the URL
- const id = params[0];
+ const id = _.first(params);
if (!validDomainId(id)) {
// Return a vague error intentionally
diff --git a/routes/utils.js b/routes/utils.js
index ab433bc7..72ae9d02 100644
--- a/routes/utils.js
+++ b/routes/utils.js
@@ -1,8 +1,16 @@
+const _ = require('lodash');
+
const tags = {
'<': '<',
'>': '>',
'&': '&',
};
-exports.escapeTags = str => (str || '').replace(/[<>&]/g, m => tags[m]);
-exports.stripTags = str => (str || '').replace(/<(?:.|\n)*?>/gm, '');
-exports.validDomainId = str => /^[\w-_]+$/.test(str);
+const untags = _.invert(tags);
+
+module.exports = {
+ escapeTags: str => (str || '').replace(/[<>&]/g, m => tags[m]),
+ unescapeTags: str =>
+ (str || '').replace(/(<|>|&)/g, m => untags[m]),
+ stripTags: str => (str || '').replace(/<(?:.|\n)*?>/gm, ''),
+ validDomainId: str => /^[\w-_]+$/.test(str),
+};
diff --git a/yarn.lock b/yarn.lock
index 0aa7fdb8..53a3dd64 100644
Binary files a/yarn.lock and b/yarn.lock differ