Skip to content
文件匹配实现
JavaScript
Latest commit fb1916a May 14, 2013 @WeweTom update version
Failed to load latest commit information.
examples surport relative path match;add examples Mar 28, 2013
lib 匹配返回的路径按顺序 May 14, 2013
tests fix windows match bug Apr 24, 2013
package.json update version May 14, 2013
readme.md update readme.md Mar 28, 2013

readme.md

一个简单文件匹配实现

Examples

最简单的完全匹配

var matchFiles = require('../lib/match-files')

// 寻找../lib下的path-matcher.js
var stream = matchFiles('../lib','path-matcher.js')

stream.on('file',function(abs,filename,extname,$){
  console.log(filename)
})

/* result

   path-patcher.js

*/

单星号匹配

var matchFiles = require('../lib/match-files')
var stream = matchFiles('../lib','*.js')
stream.on('file',function(abs,filename,extname,$){
  console.log(filename)
})
/* result 

filter-list.js
path-matcher.js
treestream.js
match-files.js
util.js

*/

双星号匹配

var matchFiles = require('../lib/match-files')

var stream = matchFiles('../../','match-files/**/treestream.js')
stream.on('file',function(abs,filename,extname,$){
  console.log(filename)
})

/* result:

treestream.js

*/

API

constructor

MatchFiles(searchDir,include,exclude)
  • searchDir {String} 搜索的起始路径,可以是绝对路径或者相对路径
  • include {String | Array} 要搜索的文件
  • exclude {String | Array} 要排除的文件

事件

  • file 回调函数中 abs,filename,extname,$ 分别表示匹配到的文件的绝对路径,文件名,后缀名,匹配到的***数组
  • end

用途

Something went wrong with that request. Please try again.