findAsset.js 673 B

12345678910111213141516171819202122
  1. /**
  2. * Find an asset in a map of asset names to their files. If the searched asset name has a pipe
  3. * symbol in it, the part after that is seen as the extension of the file we look for.
  4. *
  5. * @param {Object} assetFileNames
  6. * @param {string} assetName
  7. * @return {string}
  8. */
  9. function findAsset (assetFileNames, assetName) {
  10. const [assetFileName, assetExtension] = assetName.split('|');
  11. const assets = assetFileNames[assetFileName];
  12. const [asset] = assets.filter(function hasExtension (asset) {
  13. return assetExtension
  14. ? asset.split('.').pop() === assetExtension
  15. : asset;
  16. });
  17. return asset;
  18. }
  19. module.exports = findAsset;