Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

append-transform

Package Overview
Dependencies
Maintainers
5
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

append-transform

Install a transform to `require.extensions` that always runs last, even if additional extensions are added later.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.4M
decreased by-18.82%
Maintainers
5
Weekly downloads
 
Created

What is append-transform?

The append-transform npm package allows you to append transformations to the require.extensions object, enabling you to modify the behavior of require calls for specific file types. This can be useful for tasks such as transpiling code on the fly or adding custom loaders for non-JavaScript files.

What are append-transform's main functionalities?

Append a transformation to require.extensions

This feature allows you to append a transformation function to the require.extensions object. In this example, any .txt file required will be transformed into a module that exports the file's content as a string.

const appendTransform = require('append-transform');

appendTransform(function (code, filename) {
  if (filename.endsWith('.txt')) {
    return `module.exports = ${JSON.stringify(code)}`;
  }
  return code;
});

const content = require('./example.txt');
console.log(content);

Conditional transformation based on file extension

This feature demonstrates how to conditionally apply transformations based on the file extension. In this example, any .js file required will have a comment added at the top of its content.

const appendTransform = require('append-transform');

appendTransform(function (code, filename) {
  if (filename.endsWith('.js')) {
    return `// Transformed\n${code}`;
  }
  return code;
});

const script = require('./example.js');
console.log(script);

Other packages similar to append-transform

Keywords

FAQs

Package last updated on 10 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc