-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathurltolicense.js
More file actions
32 lines (25 loc) · 769 Bytes
/
urltolicense.js
File metadata and controls
32 lines (25 loc) · 769 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
/**
* Find license name from license url
*/
function getLicenseFromUrl (url) {
var regex = {
opensource: /(http(s)?:\/\/)?(www.)?opensource.org\/licenses\/([A-Za-z0-9\-._]+)$/,
spdx: /(http(s)?:\/\/)?(www.)?spdx.org\/licenses\/([A-Za-z0-9\-._]+)$/
}
for (var re in regex) {
var tokens = url.match(regex[re])
if (tokens) {
var license = tokens[tokens.length - 1]
// remove .html, .php, etc. from license name
var extensions = ['.html', '.php', '-license']
for (var i in extensions) {
if (license.slice(-extensions[i].length) === extensions[i]) {
license = license.slice(0, -extensions[i].length)
}
}
return license
}
}
return false
}
module.exports = getLicenseFromUrl