1 import * as constants from 'corpus-common-addon/utils/constants'; |
1 import * as constants from 'corpus-common-addon/utils/constants'; |
2 import _ from "lodash/lodash"; |
2 import _ from 'lodash/lodash'; |
3 |
3 |
4 export function isLexvoLink(s) { |
4 export function isLexvoLink(s) { |
5 return s && typeof s === 'string' && s.startsWith(constants.LEXVO_BASE_URL); |
5 return s && typeof s === 'string' && s.startsWith(constants.LEXVO_BASE_URL); |
6 }; |
6 }; |
7 |
7 |
8 export function isBnfLink(s) { |
8 export function isBnfLink(s) { |
9 return s && typeof s === 'string' && (s.startsWith(constants.BNF_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_ID)); |
9 return s && typeof s === 'string' && (s.startsWith(constants.BNF_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_ID)); |
10 }; |
10 }; |
11 |
11 |
12 export function isArkBnfLink(s) { |
12 export function isArkBnfLink(s) { |
13 return s && typeof s === 'string' && (s.startsWith(constants.BNF_BASE_URL+constants.BNF_ARK_BASE_ID) || s.startsWith(constants.BNF_ARK_BASE_URL+constants.BNF_ARK_BASE_ID)); |
13 return s && typeof s === 'string' && (s.startsWith(constants.BNF_BASE_URL + constants.BNF_ARK_BASE_ID) || s.startsWith(constants.BNF_ARK_BASE_URL + constants.BNF_ARK_BASE_ID)); |
14 }; |
14 }; |
15 |
15 |
|
16 export function isGeonamesLink(s) { |
|
17 return (typeof s === 'string') && (s.match(constants.GEONAMES_BASE_URLS) !== null); |
|
18 } |
|
19 |
16 export function switchArkBnfLink(s) { |
20 export function switchArkBnfLink(s) { |
17 if(!s) { |
21 if (!s) { |
18 return s; |
22 return s; |
19 } |
23 } |
20 if(typeof s === 'string' && s.startsWith(constants.BNF_BASE_URL+constants.BNF_ARK_BASE_ID)) { |
24 if (typeof s === 'string' && s.startsWith(constants.BNF_BASE_URL + constants.BNF_ARK_BASE_ID)) { |
21 return constants.BNF_ARK_BASE_URL + s.slice(constants.BNF_BASE_URL.length); |
25 return constants.BNF_ARK_BASE_URL + s.slice(constants.BNF_BASE_URL.length); |
22 } else if (typeof s === 'string' && s.startsWith(constants.BNF_ARK_BASE_URL+constants.BNF_ARK_BASE_ID)) { |
26 } else if (typeof s === 'string' && s.startsWith(constants.BNF_ARK_BASE_URL + constants.BNF_ARK_BASE_ID)) { |
23 return constants.BNF_BASE_URL + s.slice(constants.BNF_ARK_BASE_URL.length); |
27 return constants.BNF_BASE_URL + s.slice(constants.BNF_ARK_BASE_URL.length); |
24 } else { |
28 } else { |
25 return s; |
29 return s; |
26 } |
30 } |
27 }; |
31 }; |
28 |
32 |
29 export function calculateBnfArkControlChar(id) { |
33 export function calculateBnfArkControlChar(id) { |
30 if(!id) { |
34 if (!id) { |
31 return null; |
35 return null; |
32 } |
36 } |
33 var sum = _.reduce(id, function(s, c, i) { |
37 var sum = _.reduce(id, function(s, c, i) { |
34 return s + (i+1) * (c in constants.NOID_CHARS_POS ? constants.NOID_CHARS_POS[c] : 0); |
38 return s + (i + 1) * (c in constants.NOID_CHARS_POS ? constants.NOID_CHARS_POS[c] : 0); |
35 }, 0); |
39 }, 0); |
36 return constants.NOID_CHARS[sum % constants.NOID_CHARS.length]; |
40 return constants.NOID_CHARS[sum % constants.NOID_CHARS.length]; |
37 }; |
41 }; |