npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

globify-gitignore

v1.0.3

Published

Convert Gitignore to Glob patterns

Downloads

3,953

Readme

Convert Gitignore to Glob patterns

Install

npm install --save globify-gitignore

globify-gitignore is tiny and treeshakable.

Usage

Use globifyGitIgnoreFile to pass the path to a directory that has a .gitignore file.

import { globifyGitIgnoreFile, globifyGitIgnore } from "globify-gitignore"

// ./ is the path that has a .gitignore
globifyGitIgnoreFile("./")

Use globifyGitIgnore to directly globify the gitignore content

import { globifyGitIgnore } from "globify-gitignore"

const gitignoreContent = `# OS metadata
.DS_Store
Thumbs.db

# Node
node_modules
package-lock.json

# TypeScript
*.tsbuildinfo

# Build directories
dist
`
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

GlobifiedEntry (type)

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

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
}

globifyGitIgnoreFile (function)

Parse and globy the .gitingore file that exists in a directory

Parameters:

  • gitIgnoreDirectory (string) - The given directory that has the .gitignore file
  • absolute (boolean) - [false] If true, the glob will be absolute

returns: Promise<GlobifiedEntry[]>

globifyGitIgnore (function)

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 absolute

returns: Promise<GlobifiedEntry[]>

Other API

globifyPath (function)

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 absolute

returns: Promise<[GlobifiedEntry] | [GlobifiedEntry, GlobifiedEntry]>

globifyDirectory (function)

Globifies a directory

Parameters:

  • givenDirectory (string) - The given directory to be globified

returns: string

globifyGitIgnoreEntry (function)

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 absolute

returns: Promise<[GlobifiedEntry] | [GlobifiedEntry, GlobifiedEntry]>

getGlob (function)

Parameters:

  • g (GlobifiedEntry)

returns: string

globSorter (variable)

uniqueMatcher (function)

Parameters:

  • a (GlobifiedEntry)
  • b (GlobifiedEntry)

returns: boolean

uniqueGlobs (function)

Parameters:

  • globs (GlobifiedEntry[])

returns: any

uniqueSortGlobs (function)

Parameters:

  • globs (GlobifiedEntry[])

returns: any

posixifyPath (function)

Converts given path to Posix (replacing \ with /)

Parameters:

  • givenPath (string) - Path to convert

returns: string

posixifyPathNormalized (function)

Converts given path to Posix (replacing \ with /) and removing ending slashes

Parameters:

  • givenPath (string) - Path to convert

returns: string

getPathType (function)

Get the type of the given path

Parameters:

  • givenPath - Absolute path
  • filepath (string)

returns: Promise<PATH_TYPE>

🤝 Contributing

You can sponsor my work here:

https://github.com/sponsors/aminya

Pull requests, issues and feature requests are welcome. See the Contributing guide.