Today's npm package: is-glob

ยท

1 min read

Today's npm package is is-glob

While creating Node.js based CLIs which is working with Files and Directories; you might wanna work with Glob .

And when working with Glob, you need to know when the passed argument is a glob or not.

The package is-glob will help you in this case and it will return true only when the passed string is a Glob

const fs = require('fs');
const path = require('path');
const isGlob = require('is-glob');
const file = process.argv.slice(2);

if (isGlob(file)) {
  // process the Glob
  return;
}

// process the file
const fileData = fs.readFileSync(path.resolve(process.cwd(), file));

Stay tuned for tomorrow's package of the Day.