Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

ignore-to-acceptor

0.1.0 • Public • Published

ignoreToAcceptor

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.

USAGE

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