Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 2.22 KB

README.md

File metadata and controls

48 lines (33 loc) · 2.22 KB

gitignore-to-minimatch

npm version minzip jsdocs license

Convert gitignore patterns to minimatch patterns.

Installation

npm install gitignore-to-minimatch

Usage

import { gitignoreToMinimatch } from 'gitignore-to-minimatch'

// provide a single gitignore pattern string, return an array of minimatch patterns
const minimatchPatterns = gitignoreToMinimatch('dist')
// => [ '/**/dist', '/**/dist/**' ]

Why Array?

However, if you set the pattern dist in .gitignore, it may match the file dist and the directory dist/ at the same time. A single minimatch pattern can't represent this situation.

For the result ['/**/dist', '/**/dist/**'], /**/dist matches the file or directory dist without its contents, and /**/dist/** matches the whole directory dist/ with all its contents.

Motivation

In my another repository ncreate, I need to duplicate an existing local repository to a new one but ignore some files based on the .gitignore file. I found that there is a few differences between .gitignore and minimatch patterns. So...

Reference

gitignore documentation