Convert Gitignore to Glob patterns
npm install globify-gitignore> Convert Gitignore to Glob patterns
- Install
- Usage
- Main API
- GlobifiedEntry (type)
- globifyGitIgnoreFile (function)
- globifyGitIgnore (function)
- Other API
- globifyPath (function)
- globifyDirectory (function)
- globifyGitIgnoreEntry (function)
- getGlob (function)
- globSorter (variable)
- uniqueMatcher (function)
- uniqueGlobs (function)
- uniqueSortGlobs (function)
- posixifyPath (function)
- posixifyPathNormalized (function)
- getPathType (function)
- 🤝 Contributing
``sh`
npm install --save globify-gitignore
globify-gitignore is tiny and treeshakable.
Use globifyGitIgnoreFile to pass the path to a directory that has a .gitignore file.
`ts
import { globifyGitIgnoreFile, globifyGitIgnore } from "globify-gitignore"
// ./ is the path that has a .gitignore
globifyGitIgnoreFile("./")
`
Use globifyGitIgnore to directly globify the gitignore content
`ts
import { globifyGitIgnore } from "globify-gitignore"
const gitignoreContent = # OS metadata
.DS_Store
Thumbs.db
const gitignoreDirectory = __dirname// An array of
GlobifiedEntry objects. Each object has a glob property and an included property
const globifiedEntries = await globifyGitIgnore(gitignoreContent, gitignoreDirectory)
`Main API
$3
The result of a globified gitignore entry. The glob pattern is in the
glob property, and the included property tells if the pattern is an included file or an excluded file`ts
export type GlobifiedEntry = {
/* The glob pattern calculated from the gitignore pattern /
glob: string
/**
* If true, this means that the pattern was prepended by ! in the gitignore file, and so it is an included file
* Otherwise, it is an excluded file
*/
included: boolean
}
`$3
Parse and globy the
.gitingore file that exists in a directoryParameters:
- gitIgnoreDirectory (
string) - The given directory that has the .gitignore file
- absolute (boolean) - [false] If true, the glob will be absolutereturns: Promise
$3
Globify the content of a gitignore string
Parameters:
- gitIgnoreContent (
string) - The content of the gitignore file
- gitIgnoreDirectory (string) - The directory of gitignore
- absolute (boolean) - [false] If true, the glob will be absolutereturns: Promise
Other API
$3
Parameters:
- givenPath (
string) - The given path to be globified
- givenDirectory (string) - [process.cwd()] The cwd to use to resolve relative path names
- absolute (boolean) - [false] If true, the glob will be absolutereturns: Promise<[GlobifiedEntry] | [GlobifiedEntry, GlobifiedEntry]>
$3
Globifies a directory
Parameters:
- givenDirectory (
string) - The given directory to be globifiedreturns: string
$3
Parameters:
- gitIgnoreEntry (
string) - One git ignore entry (it expects a valid non-comment gitignore entry with no
surrounding whitespace)
- gitIgnoreDirectory (string) - The directory of gitignore
- absolute (boolean) - [false] If true, the glob will be absolutereturns: Promise<[GlobifiedEntry] | [GlobifiedEntry, GlobifiedEntry]>
$3
Parameters:
- g (
GlobifiedEntry)returns: string
$3
$3
Parameters:
- a (
GlobifiedEntry)
- b (GlobifiedEntry)returns: boolean
$3
Parameters:
- globs (
GlobifiedEntry[])returns: any
$3
Parameters:
- globs (
GlobifiedEntry[])returns: any
$3
Converts given path to Posix (replacing \ with /)
Parameters:
- givenPath (
string) - Path to convertreturns: string
$3
Converts given path to Posix (replacing \ with /) and removing ending slashes
Parameters:
- givenPath (
string) - Path to convertreturns: string
$3
Get the type of the given path
Parameters:
- givenPath - Absolute path
- filepath (
string`)returns: Promise
You can sponsor my work here:
https://github.com/sponsors/aminya
Pull requests, issues and feature requests are welcome.
See the Contributing guide.