Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
@humanwhocodes/gitignore-to-minimatch
Advanced tools
Utility to convert gitignore patterns to minimatch patterns
@humanwhocodes/gitignore-to-minimatch is an npm package that converts .gitignore patterns to minimatch patterns. This allows developers to use .gitignore syntax for file matching in other contexts, such as build tools or custom scripts.
Convert .gitignore patterns to minimatch patterns
This feature allows you to convert an array of .gitignore patterns into an array of minimatch patterns. This is useful for reusing .gitignore patterns in other tools that use minimatch for pattern matching.
const { convert } = require('@humanwhocodes/gitignore-to-minimatch');
const gitignorePatterns = [
'*.log',
'node_modules/',
'dist/'
];
const minimatchPatterns = convert(gitignorePatterns);
console.log(minimatchPatterns);
Convert .gitignore file to minimatch patterns
This feature allows you to convert the patterns in a .gitignore file directly into minimatch patterns. This is useful for dynamically loading and converting patterns from a .gitignore file.
const { convertFile } = require('@humanwhocodes/gitignore-to-minimatch');
const minimatchPatterns = convertFile('.gitignore');
console.log(minimatchPatterns);
The 'ignore' package is a JavaScript implementation of the .gitignore file format. It provides a way to filter file paths based on .gitignore rules. Unlike @humanwhocodes/gitignore-to-minimatch, it does not convert patterns to minimatch but directly uses .gitignore syntax for filtering.
The 'minimatch' package is a glob matcher in JavaScript. It is used to match file paths against glob patterns. While it does not directly handle .gitignore patterns, it is often used in conjunction with other tools to perform pattern matching. @humanwhocodes/gitignore-to-minimatch can convert .gitignore patterns to minimatch patterns, making them compatible.
The 'micromatch' package is a powerful globbing library that supports advanced glob patterns and matching features. It can be used as an alternative to minimatch with more features and better performance. However, it does not directly convert .gitignore patterns, which is a specific feature of @humanwhocodes/gitignore-to-minimatch.
If you find this useful, please consider supporting my work with a donation.
A function that converts a gitignore pattern into a minimatch pattern. There are subtle differences between these two formats, and depending on the utilities you're using, you may need one or the other.
npm install @humanwhocodes/gitignore-to-minimatch --save
# or
yarn add @humanwhocodes/gitignore-to-minimatch
Import into your Node.js project:
// CommonJS
const { gitignoreToMinimatch } = require("@humanwhocodes/gitignore-to-minimatch");
// ESM
import { gitignoreToMinimatch } from "@humanwhocodes/gitignore-to-minimatch";
Import into your Deno project:
import { gitignoreToMinimatch } from "https://cdn.skypack.dev/@humanwhocodes/gitignore-to-minimatch?dts";
It's recommended to import the minified version to save bandwidth:
import { gitignoreToMinimatch } from "https://cdn.skypack.dev/@humanwhocodes/gitignore-to-minimatch?min";
However, you can also import the unminified version for debugging purposes:
import { gitignoreToMinimatch } from "https://cdn.skypack.dev/@humanwhocodes/gitignore-to-minimatch";
After importing, call gitignoreToMinimatch
with a string argument, like this:
const minimatchPattern = gitignoreToMinimatch("foo");
console.log(minimatchPattern); // "**/foo"
npm install
to setup dependenciesnpm test
to run testsApache 2.0
FAQs
Utility to convert gitignore patterns to minimatch patterns
The npm package @humanwhocodes/gitignore-to-minimatch receives a total of 426,117 weekly downloads. As such, @humanwhocodes/gitignore-to-minimatch popularity was classified as popular.
We found that @humanwhocodes/gitignore-to-minimatch 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
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.