ignoreToAcceptor
can filter a file/directory(name, not content) consistent with the .gitignore
rules.
ignoreToAcceptor
received variable parameter consist of { string|string[] }, and return an object with three functions.
-
fileAccepted(filename: string)=> boolean
: check whether a filename will be accepted under the given ignore patterns. -
dirAccepted(filename: string)=> boolean
: check whether a dirname will be accepted under the given ignore patterns. -
accepted(name: string, isDir: boolean)=> boolean
:-
name
: file/directory name -
isDir
: the name gived previous whether or not represent a dir. - return true if it's accepted under the given ignore patterns.
-
Noticed that build/
will not matched a file named build
, so that is important to distinguish the incoming parameter is a directory or file.
import { ignoreToAcceptor } from 'ignore-to-acceptor'
let ignorePatterns = [
'build/*',
'!build/config.xml',
]
let acceptor = ignoreToAcceptor(ignorePatterns)
// or let acceptor = ignoreToAcceptor(...ignorePatterns)
acceptor.fileAccepted('build/config.xml') // true
acceptor.fileAccepted('build/a') // false
acceptor.dirAccepted('build') // true