UNPKG

gatsby-core-utils

Version:

A collection of gatsby utils used in different gatsby packages

28 lines (26 loc) 627 B
import crypto from "crypto"; import objectHash from "node-object-hash"; const hasher = objectHash({ coerce: false, alg: `md5`, enc: `hex`, sort: { map: true, object: true, array: false, set: false } }); const hashPrimitive = input => crypto.createHash(`md5`).update(input).digest(`hex`); /** * Hashes an input using md5 hash of hexadecimal digest. * * @param input The input to encrypt * @return The content digest */ export const createContentDigest = input => { if (typeof input === `object` && !Buffer.isBuffer(input)) { return hasher.hash(input); } return hashPrimitive(input); };