hash.ts 394 B

123456789101112131415161718
  1. import { createHash } from 'node:crypto';
  2. /**
  3. * 生产基于内容的 hash,可自定义长度
  4. * @param content
  5. * @param hashLSize
  6. */
  7. function generatorContentHash(content: string, hashLSize?: number) {
  8. const hash = createHash('md5').update(content, 'utf8').digest('hex');
  9. if (hashLSize) {
  10. return hash.slice(0, hashLSize);
  11. }
  12. return hash;
  13. }
  14. export { generatorContentHash };