UNPKG

@netlify/content-engine

Version:
34 lines 1.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createContentDigest = void 0; const crypto_1 = __importDefault(require("crypto")); const node_object_hash_1 = __importDefault(require("node-object-hash")); const hasher = (0, node_object_hash_1.default)({ coerce: false, alg: `md5`, enc: `hex`, sort: { map: true, object: true, array: false, set: false, }, }); const hashPrimitive = (input) => crypto_1.default.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 */ const createContentDigest = (input) => { if (typeof input === `object` && !Buffer.isBuffer(input)) { return hasher.hash(input); } return hashPrimitive(input); }; exports.createContentDigest = createContentDigest; //# sourceMappingURL=create-content-digest.js.map