refactor: Use reliable packages

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
Richie Bendall 2020-01-31 21:20:04 +13:00
parent fe248a03af
commit 6688cdf96d
No known key found for this signature in database
GPG key ID: 1C6A99DFA9D306FC
11 changed files with 97 additions and 102 deletions

View file

@ -1 +0,0 @@
module.exports = require('@remy/eslint')('node');

View file

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html id="home" lang="en">
<%- include('components/header') %>
<body>
<article>
<%- gravatar %>

View file

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html id="home" lang="en">
<%- include('components/header') %>
<body>
<article>
<%- gravatar %>

View file

@ -1,3 +1,4 @@
<footer>
<p><a target="_blank" rel="noopener" href="https://github.com/remy/mit-license">Fork this project to create your own MIT license that you can always link to.</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/remy/mit-license">Fork this project to create your own
MIT license that you can always link to.</a></p>
</footer>

View file

@ -3,7 +3,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology. As a permissive license, it puts only very limited restriction on reuse and has, therefore, an excellent license compatibility.">
<meta name="description"
content="The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology. As a permissive license, it puts only very limited restriction on reuse and has, therefore, an excellent license compatibility.">
<!--
Welcome fellow open source developer. This project is here for you to
link to if you're like me and keep forgetting to include the
@ -27,9 +28,7 @@ For more options see the README in the github hosted project.
Hope you find this useful too!
- @rem
-->
<!-- for HTML5 el styling -->
<script>
document.createElement('article');
document.createElement('footer');

View file

@ -1,5 +1,4 @@
{
"author": "Remy Sharp <remy@leftlogic.com> (http://remysharp.com/)",
"name": "mit-licence",
"description": "Hosted MIT License with details controlled through this repo",
"private": true,
@ -12,12 +11,7 @@
"engines": {
"node": ">=10"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint",
"pre-push": "npm test"
}
},
"author": "Remy Sharp <remy@leftlogic.com> (http://remysharp.com/)",
"scripts": {
"start": "node .",
"dev": "nodemon .",
@ -30,28 +24,38 @@
},
"license": "MIT",
"dependencies": {
"@octokit/rest": "^16.36.0",
"@octokit/rest": "^16.41.0",
"@sindresorhus/is": "^2.0.0",
"any-size": "^1.0.0",
"btoa": "^1.2.1",
"ejs": "^3.0.1",
"escape-html": "^1.0.3",
"express": "^4.17.1",
"express-minify": "^1.0.0",
"fs-extra": "^8.1.0",
"lodash": "^4.17.15",
"html-text": "^1.0.1",
"md5": "^2.2.1",
"postcss-middleware": "^1.1.4",
"postcss-preset-env": "^6.7.0",
"serve-favicon": "^2.5.0",
"temp-dir": "^2.0.0",
"unescape-html": "^1.1.0",
"yn": "^4.0.0"
},
"devDependencies": {
"css": "^2.2.4",
"has-flag": "^4.0.0",
"husky": "^4.0.7",
"husky": "^4.2.1",
"nodemon": "^2.0.2",
"standard": "^14.3.1"
},
"resolutions": {
"postcss-middleware/vinyl-fs/glob-stream/micromatch/braces": "^3.0.2"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint",
"pre-push": "npm test"
}
}
}

View file

@ -1,12 +1,14 @@
const md5 = require('md5')
const path = require('path')
const { stripTags, escapeTags, unescapeTags } = require('./utils')
const _ = require('lodash')
const escapeTags = require('escape-html')
const unescapeTags = require('unescape-html')
const stripTags = require('html-text')
const is = require('@sindresorhus/is')
function getCopyrightHTML (user, plain) {
let html = ''
const name = _.isString(user)
const name = is.string(user)
? user
: plain
? user.name || user.copyright
@ -34,9 +36,9 @@ module.exports = (req, res) => {
// No error and valid
if (user.copyright) {
if (_.isString(user.copyright)) {
if (is.string(user.copyright)) {
name = getCopyrightHTML(user, options.format !== 'html')
} else if (_.isArray(user.copyright) && user.copyright.every(val => _.isString(val))) {
} else if (is.array(user.copyright) && user.copyright.every(val => is.string(val))) {
// Supports: ['Remy Sharp', 'Richie Bendall']
name = user.copyright
.map(v => (options.format !== 'html' ? v : escapeTags(v)))
@ -51,7 +53,7 @@ module.exports = (req, res) => {
gravatar = `<img id="gravatar" alt="Profile image" src="https://www.gravatar.com/avatar/${md5(
user.email.trim().toLowerCase()
)}" />`
} else if (_.isObject(user.copyright[0]) && user.gravatar) {
} else if (is.object(user.copyright[0]) && user.gravatar) {
// Supports multi-user format
gravatar = `<img id="gravatar" alt="Profile image" src="https://www.gravatar.com/avatar/${md5(
user.copyright[0].email.trim().toLowerCase()

View file

@ -2,7 +2,7 @@ const fs = require('fs-extra')
const path = require('path')
const btoa = require('btoa')
const { version } = require(path.join(__dirname, '..', 'package.json'))
const _ = require('lodash')
const size = require('any-size')
const github = require('@octokit/rest')({
// GitHub personal access token
auth: process.env.github_token,
@ -10,14 +10,15 @@ const github = require('@octokit/rest')({
userAgent: `mit-license v${version}`
})
const yn = require('yn')
const is = require('@sindresorhus/is')
const { validDomainId } = require('./utils')
function getUserData ({ query, body }) {
// If query parameters provided
if (_.size(query) > 0) return query
if (size(query) > 0) return query
// If the data parsed as {'{data: "value"}': ''}
if (_.size(body) === 1 && !_.first(_.values(body))) return JSON.parse(_.first(_.keys(body)))
if (size(body) === 1 && !Object.values(body)[0]) return JSON.parse(Object.keys(body)[0])
// Fallback
return body
}
@ -38,7 +39,7 @@ module.exports = async (req, res) => {
}
// Extract the name from the URL
const id = _.first(params)
const id = params[0]
if (!validDomainId(id)) {
// Return a vague error intentionally
@ -65,7 +66,7 @@ module.exports = async (req, res) => {
if (userData.gravatar) {
// Parse the string version of a boolean or similar
userData.gravatar = yn(userData.gravatar, { lenient: true })
if (_.isUndefined(userData.gravatar)) {
if (is.undefined(userData.gravatar)) {
res
.status(400)
.send(

View file

@ -1,16 +1,3 @@
const _ = require('lodash')
const tags = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;'
}
const untags = _.invert(tags)
module.exports = {
escapeTags: str => (str || '').replace(/[<>&]/g, m => tags[m]),
unescapeTags: str =>
(str || '').replace(/(&lt;|&gt;|&amp;)/g, m => untags[m]),
stripTags: str => (str || '').replace(/<(?:.|\n)*?>/gm, ''),
validDomainId: str => /^[\w-_]+$/.test(str)
}

View file

@ -9,7 +9,7 @@ const express = require('express')
const minify = require('express-minify')
const favicon = require('serve-favicon')
const postcssMiddleware = require('postcss-middleware')
const tmpdir = require('temp-dir')
const tempdir = require('temp-dir')
const path = require('path')
// Server
@ -19,7 +19,7 @@ var PORT = process.env.PORT || 8080
const app = express()
app.use(
minify({
cache: tmpdir
cache: tempdir
})
)
app.use(favicon(path.join(__dirname, 'favicon.ico')))

BIN
yarn.lock

Binary file not shown.