equal
deleted
inserted
replaced
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 |
3 |
3 export function isBnfLink(s) { |
4 export function isBnfLink(s) { |
4 return s.startsWith(constants.BNF_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_ID); |
5 return s && (s.startsWith(constants.BNF_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_ID)); |
5 }; |
6 }; |
|
7 |
|
8 export function isArkBnfLink(s) { |
|
9 return s && (s.startsWith(constants.BNF_BASE_URL+constants.BNF_ARK_BASE_ID) || s.startsWith(constants.BNF_ARK_BASE_URL+constants.BNF_ARK_BASE_ID)); |
|
10 }; |
|
11 |
|
12 export function switchArkBnfLink(s) { |
|
13 if(!s) { |
|
14 return s; |
|
15 } |
|
16 if(s.startsWith(constants.BNF_BASE_URL+constants.BNF_ARK_BASE_ID)) { |
|
17 return constants.BNF_ARK_BASE_URL + s.slice(constants.BNF_BASE_URL.length); |
|
18 } else if (s.startsWith(constants.BNF_ARK_BASE_URL+constants.BNF_ARK_BASE_ID)) { |
|
19 return constants.BNF_BASE_URL + s.slice(constants.BNF_ARK_BASE_URL.length); |
|
20 } else { |
|
21 return s; |
|
22 } |
|
23 }; |
|
24 |
|
25 export function calculateBnfArkControlChar(id) { |
|
26 if(!id) { |
|
27 return null; |
|
28 } |
|
29 var sum = _.reduce(id, function(s, c, i) { |
|
30 return s + (i+1) * (c in constants.NOID_CHARS_POS ? constants.NOID_CHARS_POS[c] : 0); |
|
31 }, 0); |
|
32 return constants.NOID_CHARS[sum % constants.NOID_CHARS.length]; |
|
33 }; |