common/corpus-common-addon/addon/utils/utils.js
changeset 490 76da86cf9696
parent 447 38d5789e30d0
child 502 74fba571487e
equal deleted inserted replaced
489:18613f052d56 490:76da86cf9696
    73     return s + (i + 1) * (c in constants.NOID_CHARS_POS ? constants.NOID_CHARS_POS[c] : 0);
    73     return s + (i + 1) * (c in constants.NOID_CHARS_POS ? constants.NOID_CHARS_POS[c] : 0);
    74   }, 0);
    74   }, 0);
    75 
    75 
    76   return constants.NOID_CHARS[sum % constants.NOID_CHARS.length];
    76   return constants.NOID_CHARS[sum % constants.NOID_CHARS.length];
    77 }
    77 }
       
    78 
       
    79 export function getOLACBaseUrl(literalVal) {
       
    80   let olacRes = null;
       
    81 
       
    82   if (!literalVal) {
       
    83     return null;
       
    84   }
       
    85   if (typeof literalVal !== 'object') {
       
    86     return null;
       
    87   }
       
    88   const datatype = literalVal.datatype;
       
    89 
       
    90   if (!datatype) {
       
    91     return null;
       
    92   }
       
    93 
       
    94   _.forEach(constants.OLAC_BASE_URL, function (olacDef, urlPrefix) {
       
    95     if (_.startsWith(datatype, urlPrefix)) {
       
    96       olacRes = olacDef;
       
    97       return false; // we found it, we exit early
       
    98     }
       
    99 
       
   100     return true;
       
   101   });
       
   102 
       
   103   return olacRes;
       
   104 }
       
   105 
       
   106 export function isOLACLiteral(literalDef) {
       
   107   const olacDef = getOLACBaseUrl(literalDef);
       
   108 
       
   109   return Boolean(olacDef);
       
   110 }