ignore-to-acceptor
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • 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

Package Sidebar

Install

npm i ignore-to-acceptor

Weekly Downloads

0

Version

0.3.2

License

MIT

Last publish

Collaborators

  • lemonclown
  • lemon-clown-owner