Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@wider/regexp-gitignore
Advanced tools
Readme
You provide the list of gitIgnore formatted definition files or JSON objects that define the files of interest
You get back a regular expression that can be used to test a well formed file path string. Returns true if the given string matches the file specification. true means that the file is to be ignored.
Alternatively, instead of a path string, you can test same functionality on a nodeJS.fs.dirent
npm install "@wider/regexp_gitignore"
The following illustrates the use of pattern .gitignore definitions that are in the run time current working directory. Here we are looking for a package.json
that is not in the gitignore folders (such as node_modules
) and not in your own !jsDoc
folder or a files whose names start .myOwn
import path from "path";
import gitIgnore from "@wider/regexp_gitignore";
const source_git = path.join(process.cwd(), "./.gitignore"); //find the standard gitignore file in the directory of the applications or wherever you may have placed it
const source_myOwn = ["!jsDoc/", ".myOwn*"]; // add in your own extras - which eg you might pick up from your own `settings.json`
const directions = {exclude : source_git, include : source_myOwn};
const myRegularExpression = gitIgnore(directions);
// you can then use this regular expression repeatedly as required
if (myRegularExpression.test(path.resolve("./whatEverYouWant")))
yourCodeForAFileToBeIgnored;
else
yourCodeForAFileToBeAccepted
The directions as to which files should be accepted or rejected are given as an object with typeDef of directionsToCreateAFilter as seen in the regexp_gitignore API.
You can provide Array objects for both include and exclude directions - if you include both then the exclude are applied first.
If you provide real gitignore files please remember that .gitignore system itself operates with a collection of ignore specifications in different locations within nodeJS and the system as indicated by the gitignore documentation. You need to provide all the file components of relevance to you in the order they are to apply so as to get an identical impact to what git tools would do. In many cases just your main ./.gitignore
file alone may suffice.
The files selected by include are not equivalent of the !
operator in .gitignore exclude file. In gitignore the !
operator can override the other directives. Placing the entry instead in the include section will only find files in locations that have not been excluded. You can still use the !
operator in both include and exclude but it may make your brain work overtime working out what you are achieving - it is more efficient to use a positive exclude than a negative include and easier for the next developer to read.
The conversion can give rise to seriously large regular expressions, but they will invariably perform faster than the equivalent code in javascript.
The characters and diphthongs such as * . / ! ** \!
and newline are recognised for their gitignore use and newlines and comments #
are stripped out.
The tutorial in the jsDoc documentation in this package includes examples.
This is a regular expression parsing of the file's full path. Paths provided via nodeJS path.resolve()
have trailing directory delimiter stripped off and so it is not possible for this tool to detect if a path you provide is intended to be a directory. If you need to detect if the reference is a directory, please use instead
import {GipDirent} from "@wider/regexp_gitignore";
const myGip = new GipDirent(sameObjectAsRegexp_gitignore);
if (myGip.test(dirEntOrFullFilePath))
yourCodeForAFileToBeIgnored;
FAQs
Convert gitIgnore files to a Regular Expression
The npm package @wider/regexp-gitignore receives a total of 9 weekly downloads. As such, @wider/regexp-gitignore popularity was classified as not popular.
We found that @wider/regexp-gitignore demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.