Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
broccoli-directory
Advanced tools
Broccoli Directory provides familiar map/reduce/filter APIs for working with Broccoli Trees. It allows to chain broccoli tree transformations in the same way that you would chain array operations.
Broccoli Directory provides familiar map/reduce/filter APIs for working with Broccoli Trees. It allows to chain broccoli tree transformations in the same way that you would chain array operations.
For example, given a directory like this,
my-files/
some-file.txt
other-file.txt
yet-another-file.txt
You can get a new directory with whitespace removed from every file by doing the following,
// Broccoli.js
const $d = require('broccoli-directory');
// map will receive content of the file, returned value will be written to the new file
module.exports = $d('my-files')
.map(text => text.replace(/\s/g,''))
You can chain these operations in same way as you would with arrays.
// Broccoli.js
const $d = require('broccoli-directory');
module.exports = $d('my-files')
// exclude other-file.txt from build
.filter((text, relativePath) => relativePath !== 'other-file.txt')
// remote whitespace from remaining files
.map(text => text.replace(/\s/g,''));
// this will produce a directory with
// some-file.txt
// yet-another-file.txt
You can also reduce a directory into a single file.
// Broccoli.js
const $d = require('broccoli-directory');
module.exports = $d('my-files')
.reduce((accumulator, text) => accumulator + text, '', 'result.txt');
// will build a directoryw result.txt that has content from all files in it
You can use this library to process a directory of files in any node.js script.
// index.js
const $d = require('broccoli-directory');
// map will receive content of the file, returned value will be written to the new file
$d('my-files')
.map(text => text.replace(/\s/g,''))
.build('dist') // where should the build result be copied (omit this argument to skip copying)
.then(builder => {
// builder.outputPath is path to a tmp directory where the built result is
return builder.cleanup(); // call builder.cleanup() to remove all temp directories that were created.
});
You must begin by selecting a directory,
const $d = require('broccoli-directory');
$d('src')
find
operator allows you to select specific files from the current tree.
const $d = require('broccoli-directory');
$d('src')
.find('**/*.js')
// will create a tree of only javascript files
merge
operation can be used to merge multiple directories together. You must
return a tree from the merge callback. This tree will be merged into your existing tree.
const $d = require('broccoli-directory');
$d('src')
.merge(() => $('lib')) // merge lib directory with src directory
use
operation exects a callback. This callback will be invoked and current tree will be passed as the first argument. You can use this operator to apply Broccoli plugins to the tree.
import $d = require('broccoli-directory');
import Filter = require('broccoli-filter');
class Empasize extends Filter {
processString(contents) {
return `*${contents}*`;
}
}
$d('src')
.use((tree) => new Empasize(tree));
// resulting directory will have * wrapping the content
map
operation allows to transform every file in the directory. map
expects a callback which receives a string and returns a string.
$d('src')
.map(content => `<a>${content}</a>`)
// resulting directory will have <a></a> wrapping the content
filter
operation allows to remove files from a directory. It expects a callback which will accept the file content and relative path. If the callback returns a falsy value then the file will be excluded from the output.
$d('src')
.filter((content, relativePath) => !relativePath.startsWith('fixtures'))
reduce
operation allows to concatinate all files in a tree into as single file.
It expects 3 arguments:
$d('src')
.reduce((accumulator, content) => `${accumulator}${content}`, '', 'result.txt')
log
operator will output the state of the tree to console. This is useful when you're debugging a tree build.
$d('src')
.log()
/**
* tree = log(tree, {output: 'tree'});
* // /Users/chietala/workspace/broccoli-stew/tmp/funnel-dest_Q1EeTD.tmp
* // ├── cat.js
* // └── dog.js
*/
FAQs
Broccoli Directory provides familiar map/reduce/filter APIs for working with Broccoli Trees. It allows to chain broccoli tree transformations in the same way that you would chain array operations.
The npm package broccoli-directory receives a total of 2 weekly downloads. As such, broccoli-directory popularity was classified as not popular.
We found that broccoli-directory 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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.