![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
A for-each for Gulp that exposes the actual content of the file.
I have had to write this code many times because I wanted a "one-off" task that does "somthing quick" to each file. Or, I have wanted to write literally any module that processes code files, and had to start anew every time and figure out this logic.
Most other for-each implementations for Gulp expose the stream (of buffer) object, requiring the user to read the stream (or buffer) and write out a new stream (or buffer). Yes, I used the most annoying way to word that on purpose. This module exposes the content of the file itself, so you can directly start manipulating the content (e.g. code) directly, without worrying about the Gulp plumbing.
npm install gulp-each
var each = require('gulp-each');
gulp.task('mytask', function() {
gulp.src('*.js')
.pipe(each(function(content, file, callback) {
// content is a string containing the code
// do with it as you'd like
var newContent = '// my comment\n' + content;
// file is the original Vinyl file object
// return the new content using the callback
// the first argument is an error, if you encounter one
callback(null, newContent);
}))
.pipe(gulp.dest('output'));
});
By default, gulp-each
will assume that you are working with text files and use utf8
as the encoding, returning a string as the content
variable. At times, that will not be true. If you want to work with binary files, you can provide 'buffer'
as the second parameter:
gulp.task('mytask', function() {
gulp.src('*.png')
.pipe(each(function(content, file, callback) {
// content is a buffer containing the image
var newConent = transformTheImageBuffer(content);
// return the new content using the callback
// the first argument is an error, if you encounter one
callback(null, newContent);
}, 'buffer'))
.pipe(gulp.dest('output'));
});
FAQs
A for each that provides the raw file content.
The npm package gulp-each receives a total of 2,882 weekly downloads. As such, gulp-each popularity was classified as popular.
We found that gulp-each demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.