import { Md5 } from 'ts-md5'; export class HashHelper { public static fromObject(obj: any | null): string | null { if (!obj) { return null; } if (obj instanceof Array) { const strs: Array = (obj as Array).map((x) => this.fromObject(x) ); return new Md5().appendStr(strs.join('')).end().toString(); } if (typeof obj === 'number') { return new Md5().appendStr(obj.toString()).end().toString(); } if (typeof obj === 'string') { return new Md5().appendStr(obj).end().toString(); } const keys: Array = Object.keys(obj); const str: string = keys .map((key: string) => this.fromObject(obj[key])) .join(''); return new Md5().appendStr(str).end().toString(); } }