gitignore-reader
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

.gitignore Reader

A utility to find, read and parse the content of the nearest .gitignore file in the current or parent directories.

Install

To use gitignore-reader, install it via npm:

npm i -D gitignore-reader
# or
yarn add -D gitignore-reader

Usage

import { findGitignore, readGitignore } from 'gitignore-reader'

// Find the nearest .gitignore file
const gitignorePath = findGitignore()

if (gitignorePath) {
  console.log('Found .gitignore file:', gitignorePath)
} else {
  console.log('No .gitignore file found.')
}

// Read and parse the content of the nearest .gitignore file
const gitignoreContent = readGitignore()

if (gitignoreContent.length > 0) {
  console.log('Gitignore content:', gitignoreContent)
} else {
  console.log('No content found in .gitignore file.')
}

API

findGitignore(maxMoves?: number): string | null

Finds the nearest .gitignore file in the current or parent directories.

  • maxMoves: The maximum number of parent directories to search (default is 3).
  • Returns the path to the found .gitignore file, or null if not found.

readGitignore(maxMoves?: number): string[]

Reads and parses the content of the nearest .gitignore file.

  • maxMoves: The maximum number of parent directories to search for the .gitignore file (default is 3).
  • Returns an array of lines from the .gitignore file, excluding empty lines and comments.

Contributing

We 💛  issues.

When committing, please conform to the semantic-release commit standards. Please install commitizen and the adapter globally, if you have not already.

npm i -g commitizen cz-conventional-changelog

Now you can use git cz or just cz instead of git commit when committing. You can also use git-cz, which is an alias for cz.

git add . && git cz

License

GitHub

A project by Stilearning © 2024.

/gitignore-reader/

    Package Sidebar

    Install

    npm i gitignore-reader

    Weekly Downloads

    9

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    6.61 kB

    Total Files

    6

    Last publish

    Collaborators

    • bent10