All files / src/transform crypto.ts

78.57% Statements 11/14
66.67% Branches 2/3
50% Functions 1/2
83.33% Lines 10/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 161x 1x 1x   1x 1x 1x       1x 1x 1x 1x    
import Utf8 from 'crypto-js/enc-utf8';
import Base64 from 'crypto-js/enc-base64';
import Md5 from 'crypto-js/md5';
 
export const crypto = (data: any, needJoin = false): string => {
  let newData = JSON.parse(JSON.stringify(data));
  Iif (needJoin) {
    const keys = Object.keys(newData).sort();
    newData = keys.map(it => `${it}=${data[it]}`).join('&');
  }
  const wordArray = Utf8.parse(newData);
  const base64 = Base64.stringify(wordArray);
  const str = Md5(base64).toString();
  return str.toUpperCase();
};