All files / src/commons/utils cryptographic.js

100% Statements 8/8
100% Branches 4/4
100% Functions 3/3
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  1x 1x 1x 1x         9x       4x 4x       2x    
 
import md5 from 'md5';
import uuidV4 from 'uuid/v4';
import shortid from 'shortid';
import { stripProps } from './misc';
 
// Integrity of short unique identifiers: https://github.com/dylang/shortid/issues/81#issuecomment-259812835
 
export function genUuid(ifShortUuid) {
  return ifShortUuid ?  shortid.generate() : uuidV4();
}
 
export function hash(value) {
  value = typeof value === 'string' ? value : JSON.stringify(value);
  return md5(value);
}
 
export function hashOfRecord(record) {
  return hash(stripProps(record, ['id', '_id']));
}