{"id":13078,"library":"documentify","title":"Modular HTML Bundler","description":"documentify is a modular HTML bundler designed to process HTML documents through a pipeline of configurable transforms. Currently at version 3.2.3, it allows developers to define custom transformations that modify HTML streams, supporting input from files, strings, or readable streams and outputting a readable stream of processed HTML. The package is noted as 'experimental' in its stability, indicating that its API or behavior might still evolve. It differentiates itself by its stream-first approach and flexible transform architecture, enabling powerful customization of the HTML bundling process. It typically sees releases as features are added or bugs are fixed, without a strict time-based cadence.","status":"active","version":"3.2.3","language":"javascript","source_language":"en","source_url":"https://github.com/stackhtml/documentify","tags":["javascript","html","document","transform","stream"],"install":[{"cmd":"npm install documentify","lang":"bash","label":"npm"},{"cmd":"yarn add documentify","lang":"bash","label":"yarn"},{"cmd":"pnpm add documentify","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for creating custom transforms that modify the HTML stream, as transforms are expected to return a 'through' stream.","package":"through2","optional":false}],"imports":[{"note":"Primary CommonJS export for creating a bundler instance. Direct ESM imports may not work without a CommonJS interop layer.","wrong":"import documentify from 'documentify'","symbol":"documentify","correct":"const documentify = require('documentify')"},{"note":"CommonJS import typically used within custom transform modules for stream manipulation, as transforms are based on `through2`.","wrong":"import through from 'through2'","symbol":"through2","correct":"const through = require('through2')"}],"quickstart":{"code":"const { writeFileSync, unlinkSync } = require('fs');\nconst { join } = require('path');\nconst documentify = require('documentify');\nconst through = require('through2'); // Used by transforms\n\n// 1. Create a simple HTML file\nconst htmlContent = `\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  <title>Original Document</title>\n</head>\n<body>\n  <h1>Hello, documentify!</h1>\n  <p>This is some original content.</p>\n</body>\n</html>\n`;\nconst entryFilePath = join(__dirname, 'index.html');\nwriteFileSync(entryFilePath, htmlContent.trim());\n\n// 2. Define a custom transform\nfunction myCustomTransform(opts) {\n  let buffer = '';\n  return through(\n    function (chunk, enc, cb) {\n      buffer += chunk.toString();\n      cb();\n    },\n    function (cb) {\n      // Modify the HTML content: add a footer\n      const modifiedHtml = buffer.replace('</body>', '<footer>Processed by documentify!</footer></body>');\n      this.push(modifiedHtml);\n      cb();\n    }\n  );\n}\n\n// 3. Run documentify\nconst bundler = documentify(entryFilePath);\n\n// Add the custom transform\nbundler.transform(myCustomTransform);\n\n// Bundle and get the output as a readable stream\nconst bundledStream = bundler.bundle();\n\nlet outputHtml = '';\nbundledStream.on('data', (chunk) => {\n  outputHtml += chunk.toString();\n});\n\nbundledStream.on('end', () => {\n  console.log('--- Bundled HTML Output ---');\n  console.log(outputHtml);\n  console.log('--- End Output ---');\n\n  // Clean up the created file\n  unlinkSync(entryFilePath);\n});\n\nbundledStream.on('error', (err) => {\n  console.error('Bundling error:', err);\n  unlinkSync(entryFilePath);\n});","lang":"javascript","description":"Demonstrates how to bundle an HTML file with a custom `through2`-based transform to modify its content and log the result."},"warnings":[{"fix":"Always test `documentify` and its transforms thoroughly when upgrading versions and be prepared for potential API adjustments.","message":"The package's stability is marked as 'experimental'. This implies that the API might not be stable, and breaking changes could occur in future minor or patch releases without following strict semantic versioning practices.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer `const documentify = require('documentify')` for consistent usage across environments.","message":"documentify is primarily a CommonJS module. While it might be used with modern build tools that transpile ESM imports, direct ESM usage (e.g., `import documentify from 'documentify'`) without proper configuration might lead to issues, especially in Node.js environments without explicit type definitions for ESM.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your transform function is structured correctly, typically returning `through(function (chunk, enc, cb) { /* ... */ }, function (cb) { /* ... */ })`.","message":"Transforms are expected to return a `through` stream. Incorrectly implemented transforms (e.g., not returning a stream, or not properly handling stream events like `push` or `cb`) can lead to silent failures, data loss, or improper HTML output.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use CommonJS require syntax: `const documentify = require('documentify');`","cause":"Trying to use ES module default import syntax (`import documentify from 'documentify'`) without proper Babel/TypeScript configuration or when the package is strictly CommonJS in a Node.js ESM context.","error":"TypeError: documentify is not a function"},{"fix":"Install `through2` in your project: `npm install through2`","cause":"A custom transform requires `through2` but it's not installed as a dependency in the project where the transform is being used.","error":"Error: Cannot find module 'through2'"},{"fix":"Ensure all parts of your stream pipeline are correctly handling backpressure and completing gracefully. Check the integrity of input files and the robustness of any custom transforms.","cause":"This error often occurs when `documentify` is used in a pipeline where a downstream process closes its input before `documentify` has finished writing, or when an upstream process (like `cat index.html`) completes prematurely.","error":"Error: read ECONNRESET / EPIPE"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"documentify"}