简体   繁体   English

模式匹配标准(例如.gitignore)

[英]pattern matching standards (eg .gitignore)

I've worked with a bunch of different tools that have the intention of searching a codebase for files of some type or another and then performing operations on files within.我使用过许多不同的工具,它们的目的是在代码库中搜索某种类型的文件,然后对其中的文件执行操作。 Test libs that find all the files that need to be executed for example.例如,可以找到所有需要执行的文件的测试库。 Or the prototypical example is git, which does all kinds of things with all the files in it's project directory.或者原型示例是 git,它对项目目录中的所有文件执行各种操作。

Most of these products have an equivalent of.gitignore, which has a pattern matching system to make it relatively easy to define which files or subdirectories in a certain directory will be processed vs which would would not.这些产品中的大多数都有一个等效的.gitignore,它有一个模式匹配系统,可以相对容易地定义某个目录中的哪些文件或子目录将被处理,哪些不被处理。

The pattern matching is simpler than regex (which I assume is good because regex would be overkill) and I'm guessing one of the advantages of the simpler pattern matcher is that it is faster?模式匹配比正则表达式更简单(我认为这很好,因为正则表达式会矫枉过正),我猜更简单的模式匹配器的优点之一是它更快? It makes sense that since every file or directory being crawled in the directory structure needs to be checked against every possible pattern match in the ignore file.这是有道理的,因为在目录结构中被爬取的每个文件或目录都需要针对忽略文件中的每个可能的模式匹配进行检查。

I have a TypeScript project where I want to do a similar type of processing of many files in a directory tree.我有一个 TypeScript 项目,我想对目录树中的许多文件进行类似类型的处理。 To crawl the directories I'm currently using fdir https://github.com/thecodrr/fdir .要抓取我目前正在使用的目录 fdir https://github.com/thecodrr/fdir The question is, is there a name for the.gitignore style pattern matching language?问题是,.gitignore 风格的模式匹配语言有名字吗? Is there libraries for Typescript or Javascript I can use to implement this pattern matching the the maximum possible performance?是否有用于 Typescript 或 Javascript 的库,我可以使用它来实现与最大可能性能匹配的这种模式?

https://www.npmjs.com/package/ignore seems to be a very common library for this. https://www.npmjs.com/package/ignore似乎是一个非常常见的库。 48M weekly downloads, used by eslint so you're probably in good company.每周 4800 万次下载,被 eslint 使用,所以你可能是个好伙伴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM