UNPKG

webpack-assets-manifest

Version:

This Webpack plugin will generate a JSON file that matches the original filename with the hashed version.

32 lines (31 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.asArray = asArray; exports.getSRIHash = getSRIHash; exports.getSortedObject = getSortedObject; exports.findMapKeysByValue = findMapKeysByValue; exports.group = group; const node_crypto_1 = require("node:crypto"); const type_predicate_js_1 = require("./type-predicate.js"); function asArray(data) { return Array.isArray(data) ? data : [data]; } function getSRIHash(algorithm, content) { return `${algorithm}-${(0, node_crypto_1.createHash)(algorithm).update(content).digest('base64')}`; } function getSortedObject(object, compareFunction) { return Object.fromEntries(Object.entries(object).sort(compareFunction ? (left, right) => compareFunction(left[0], right[0]) : undefined)); } function findMapKeysByValue(map) { const entries = [...map.entries()]; return (searchValue) => entries.filter(([, value]) => value === searchValue).map(([name]) => name); } function group(data, getGroup, mapper) { return data.reduce((obj, item) => { const group = getGroup(item); if ((0, type_predicate_js_1.isPropertyKey)(group)) { (obj[group] ??= []).push(mapper ? mapper(item, group) : item); } return obj; }, Object.create(null)); }