terkelg / tiny-glob

Super tiny and ~350% faster alternative to node-glob
MIT License
855 stars 25 forks source link

Feature Request : allow an optional constructor to build the result #25

Open zipang opened 6 years ago

zipang commented 6 years ago

It would be awesome to allow an optional constructor in the options, to return whatever types the user really needs, ie : an array of vfile instead of an array of paths.

Example :

const glob = require('tiny-glob')
const vfile = require('to-vfile')

let files = glob('*.md', {mount: vfile})
terkelg commented 6 years ago

I would like to keep tiny glob as simple as possible. What would a implementation for this look like and what are the benefits? It's easy to map the returned array to get basename, extension etc.

zipang commented 6 years ago

Hi @terkelg ! I do agree that mapping on the returned array is pretty easy in term of coding, but i did believe that your package's implementation was all about performances !?

To load a vfile, i need the full path of a file. So right now, the implementation is allready doing a full re-map on the matched elements just to return their absolute path. So mapping again on all the matched elements returned by glob to convert them to vfile.. and it would be 2 unnecessary loops involved.

I can submit a PR if you are interested..

terkelg commented 6 years ago

I would love to see some code, but I can't promise I'll merge it into master. All PRs are very welcome. Can you do it without introducing dependencies?