|
1 | | -const LicenseUtilities = { |
| 1 | +const CC0Attributes = { BY: false, NC: false, ND: false, SA: false } |
| 2 | +const CCBYAttributes = { BY: true, NC: false, ND: false, SA: false } |
| 3 | +const visibleSetters = { |
| 4 | + FS: { |
| 5 | + true: ['FS', 'DD', 'AD'], |
| 6 | + false: ['FS', 'BY', 'NC', 'ND', 'SA', 'AD'] |
| 7 | + }, |
| 8 | + BY: { |
| 9 | + // Decide if NC/ND/SA should be disabled or removed on CC0 |
| 10 | + true: ['FS', 'BY', 'NC', 'ND', 'SA', 'AD'], |
| 11 | + false: ['FS', 'BY', 'CW', 'NC', 'ND', 'SA', 'AD'] |
| 12 | + }, |
| 13 | + ND: { |
| 14 | + true: ['FS', 'BY', 'NC', 'ND', 'SA', 'AD'] |
| 15 | + } |
| 16 | +} |
| 17 | +const disabledSetters = { |
| 18 | + // Steps that should be disabled if other steps are selected/not selected |
| 19 | + BY: { |
| 20 | + false: ['NC', 'ND', 'SA'] |
| 21 | + }, |
| 22 | + ND: { |
| 23 | + true: ['SA'] |
| 24 | + } |
| 25 | +} |
2 | 26 |
|
3 | | - install(Vue) { |
4 | | - const defaultLicenseAttributes = { |
5 | | - BY: true, |
6 | | - NC: false, |
7 | | - ND: false, |
8 | | - SA: false |
9 | | - } |
| 27 | +function shortToAttr(shortLicenseName) { |
| 28 | + const short = shortLicenseName |
| 29 | + if (short.includes('CC0')) { |
| 30 | + return { ...CC0Attributes } |
| 31 | + } |
| 32 | + const nc = short.includes('NC') |
| 33 | + const nd = short.includes('ND') |
| 34 | + const sa = short.includes('SA') |
| 35 | + return { ...CCBYAttributes, NC: nc, ND: nd, SA: sa } |
| 36 | +} |
10 | 37 |
|
11 | | - Vue.prototype.$shortToAttributes = function(shortLicenseName) { |
12 | | - const short = shortLicenseName |
13 | | - if (short.includes('CC0')) { |
14 | | - return { ...defaultLicenseAttributes, BY: false } |
15 | | - } |
16 | | - const nc = short.includes('NC') |
17 | | - const nd = short.includes('ND') |
18 | | - const sa = short.includes('SA') |
19 | | - return { ...defaultLicenseAttributes, NC: nc, ND: nd, SA: sa } |
20 | | - } |
21 | | - Vue.prototype.$attrToShort = function(attr) { |
22 | | - if (!attr.BY) { return 'CC0 1.0' } |
23 | | - let base = 'CC BY' |
24 | | - if (attr.NC) { base += '-NC' } |
25 | | - if (!attr.ND && attr.SA) { |
26 | | - base += '-SA' |
27 | | - } else if (attr.ND) { |
28 | | - base += '-ND' |
29 | | - } |
30 | | - base += ' 4.0' |
31 | | - return base |
32 | | - } |
33 | | - Vue.prototype.$attrToFull = function(attr) { |
34 | | - if (!attr.BY) { return 'CC0 1.0 Universal' } |
35 | | - let base = 'Attribution' |
36 | | - if (attr.NC) { base += '-NonCommercial' } |
37 | | - if (!attr.ND && attr.SA) { |
38 | | - base += '-ShareAlike' |
39 | | - } else if (attr.ND) { |
40 | | - base += '-NoDerivatives' |
41 | | - } |
42 | | - base += ' 4.0 International' |
43 | | - return base |
44 | | - } |
45 | | - Vue.prototype.$licenseUrl = function(shortLicenseName) { |
46 | | - // Returns url to license |
47 | | - if (shortLicenseName.includes('CC0')) { |
48 | | - return 'https://creativecommons.org/publicdomain/zero/1.0/?ref=ccchooser' |
49 | | - } |
50 | | - const short = shortLicenseName.toLowerCase().slice(3, shortLicenseName.length - 4) |
51 | | - return 'https://creativecommons.org/licenses/' + short + '/4.0/?ref=ccchooser' |
52 | | - } |
53 | | - Vue.prototype.$licenseSlug = function(shortLicenseName) { |
54 | | - // Returns lower case slugified string of license name without the version number |
55 | | - return shortLicenseName |
56 | | - .toLowerCase() |
57 | | - .replace(' ', '-') |
58 | | - .slice(0, shortLicenseName.length - 4) |
59 | | - } |
60 | | - Vue.prototype.$licenseIconsArr = function(shortLicenseName) { |
61 | | - if (shortLicenseName.includes('CC0')) { |
62 | | - return ['zero'] |
63 | | - } |
64 | | - return shortLicenseName |
65 | | - .toLowerCase() |
66 | | - .slice(3, shortLicenseName.length - 4) |
67 | | - .split('-') |
| 38 | +function attrToShort(attr) { |
| 39 | + if (!attr.BY) { return 'CC0 1.0' } |
| 40 | + let base = 'CC BY' |
| 41 | + if (attr.NC) { base += '-NC' } |
| 42 | + if (!attr.ND && attr.SA) { |
| 43 | + base += '-SA' |
| 44 | + } else if (attr.ND) { |
| 45 | + base += '-ND' |
| 46 | + } |
| 47 | + base += ' 4.0' |
| 48 | + return base |
| 49 | +} |
| 50 | + |
| 51 | +function attrToFull(attr) { |
| 52 | + if (!attr.BY) { return 'CC0 1.0 Universal' } |
| 53 | + let base = 'Attribution' |
| 54 | + if (attr.NC) { base += '-NonCommercial' } |
| 55 | + if (!attr.ND && attr.SA) { |
| 56 | + base += '-ShareAlike' |
| 57 | + } else if (attr.ND) { |
| 58 | + base += '-NoDerivatives' |
| 59 | + } |
| 60 | + base += ' 4.0 International' |
| 61 | + return base |
| 62 | +} |
| 63 | +// function licenseUrl(shortLicenseName) { |
| 64 | +// Returns url to license from short license name with version number (eg. 'CC BY 4.0') |
| 65 | +// TODO: check how it works: it doesn't use '-' to join elements ? |
| 66 | +// if (shortLicenseName.includes('CC0')) { |
| 67 | +// return 'https://creativecommons.org/publicdomain/zero/1.0/?ref=ccchooser' |
| 68 | +// } |
| 69 | +// const short = shortLicenseName.toLowerCase().slice(3, shortLicenseName.length - 4) |
| 70 | +// return 'https://creativecommons.org/licenses/' + short + '/4.0/?ref=ccchooser' |
| 71 | +// } |
| 72 | +function licenseUrl(attr) { |
| 73 | + // Returns url to license from short license name with version number (eg. 'CC BY 4.0') |
| 74 | + if (!attr.BY) { |
| 75 | + return 'https://creativecommons.org/publicdomain/zero/1.0/?ref=ccchooser' |
| 76 | + } |
| 77 | + let short = attrToShort(attr).toLowerCase().slice(3) |
| 78 | + short = short.slice(0, short.length - 4) |
| 79 | + return 'https://creativecommons.org/licenses/' + short + '/4.0/?ref=ccchooser' |
| 80 | +} |
| 81 | + |
| 82 | +function licenseSlug(shortLicenseName) { |
| 83 | + // Returns lower case slugified string of license name without the version number |
| 84 | + // 'CC BY 4.0' -> 'cc-by' |
| 85 | + return shortLicenseName |
| 86 | + .toLowerCase() |
| 87 | + .replace(' ', '-') |
| 88 | + .slice(0, shortLicenseName.length - 4) |
| 89 | +} |
| 90 | + |
| 91 | +function licenseIconsArr(licenseAttributes) { |
| 92 | + if (!licenseAttributes.BY) { |
| 93 | + return ['zero'] |
| 94 | + } |
| 95 | + const iconsArray = [] |
| 96 | + for (const key in licenseAttributes) { |
| 97 | + if (licenseAttributes[key]) { |
| 98 | + iconsArray.push(key.toLowerCase()) |
68 | 99 | } |
69 | 100 | } |
| 101 | + return iconsArray |
70 | 102 | } |
71 | 103 |
|
72 | | -export default LicenseUtilities |
| 104 | +export { CC0Attributes, CCBYAttributes, visibleSetters, disabledSetters, shortToAttr, attrToShort, attrToFull, licenseUrl, licenseSlug, licenseIconsArr } |
0 commit comments