-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrepo.js
More file actions
33 lines (28 loc) · 857 Bytes
/
repo.js
File metadata and controls
33 lines (28 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { version, author: authorMeta, repository, license } = require('../package.json');
const githubRepoRegex = /github\.com[:/]+([^/]+)\/([^/#.]+)(?:\.git)?/;
const [, author = '', name = ''] = repository?.url?.match(githubRepoRegex) || [];
const slug = `${author}/${name}`;
const url = `https://github.com/${slug}`;
const nameMappings = {
sniffcat: 'SniffCat',
abuseipdb: 'AbuseIPDB',
};
const getPrettyName = repo => {
const repoLower = repo.toLowerCase();
return Object.entries(nameMappings)
.reduce((best, [key, value]) =>
repoLower.includes(key.toLowerCase()) && key.length > best.key.length
? { key, value }
: best,
{ key: '', value: repo }).value;
};
module.exports = Object.freeze({
version,
repoAuthor: author,
authorMeta,
repoName: name,
prettyName: getPrettyName(name),
repoSlug: slug,
repoUrl: url,
license,
});