{"library":"middleware-rename-file","title":"Front-Matter Based File Renaming Middleware","description":"middleware-rename-file is a Node.js middleware designed for dynamically renaming Vinyl file objects by leveraging properties defined within their YAML front-matter. Currently at version 1.0.0, the package appears to be in a maintenance state, with no active feature development. It targets older Node.js environments (engines >=0.10.0) and is primarily integrated with established templating and static site generation frameworks such as Assemble, Verb, Generate, and Templates. The core functionality allows developers to specify new `basename` and `dirname` attributes directly in a file's front-matter, which the middleware then applies to the file's destination path early in the build pipeline, typically via an `onLoad` event. This declarative approach to file renaming is a key differentiator, providing a structured way to manage file output within its target ecosystems.","language":"javascript","status":"maintenance","last_verified":"Thu Apr 23","install":{"commands":["npm install middleware-rename-file"],"cli":null},"imports":["const renameMiddleware = require('middleware-rename-file');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const renameMiddleware = require('middleware-rename-file');\n\n// Mock a Vinyl-like file object with front-matter\nconst fileWithFrontMatter = {\n  path: 'scaffolds/layouts/base.hbs',\n  contents: Buffer.from('---\\nrename:\\n  basename: default.hbs\\n  dirname: templates\\n---\\n\\n<!DOCTYPE html>...'),\n  data: { // `data` property where front-matter is usually parsed\n    rename: {\n      basename: 'default.hbs',\n      dirname: 'templates'\n    }\n  },\n  // Simulate Vinyl file properties\n  basename: 'base.hbs',\n  dirname: 'scaffolds/layouts',\n  extname: '.hbs',\n  stem: 'base'\n};\n\nconst fileWithoutFrontMatter = {\n  path: 'src/pages/index.html',\n  contents: Buffer.from('<html>...</html>'),\n  data: {},\n  basename: 'index.html',\n  dirname: 'src/pages',\n  extname: '.html',\n  stem: 'index'\n};\n\nconst mockApp = {\n  emit: (event, file) => {\n    // In a real app, this would be `app.emit('file', file)`\n    // or similar, passing the transformed file down the pipeline.\n    console.log(`\nProcessed file: ${file.path}`);\n    console.log(`  New basename: ${file.basename}`);\n    console.log(`  New dirname: ${file.dirname}`);\n  }\n};\n\n// Initialize the middleware\nconst rename = renameMiddleware();\n\n// Apply middleware to the first file\nrename(fileWithFrontMatter, mockApp);\n\n// Apply middleware to the second file with a filter that prevents renaming 'index' files\nconst renameWithFilter = renameMiddleware(file => file.stem !== 'index');\nrenameWithFilter(fileWithoutFrontMatter, mockApp);\n","lang":"javascript","description":"Demonstrates how to use the `middleware-rename-file` function by mocking a Vinyl file object and applying renaming based on front-matter properties, including an example with a filter function.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}