src/server/utilities/encodeChunkUri/index.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
const encodeChunkFilename = ({ url: chunkUrl }) => {
  const pathParts = chunkUrl.split('/'); // Split full url at each `/`
  const fileName = pathParts.pop(); // Fetch the content after the last `/`
  const encodedFileName = encodeURIComponent(fileName); // Encode the filename

  return pathParts.join('/').concat(`/${encodedFileName}`); // reconstruct the full url with the encoded filename
};

export default encodeChunkFilename;