Skip to main content

Command Palette

Search for a command to run...

Today's npm package: is-glob

Updated
โ€ข1 min read
P

I am developer from India currently based in Berlin, Germany.

I am very interested in Design, though I don't design ๐Ÿ˜‰ I take care of it while making my apps.

Photography, videography and having random conversation over beer are my activities of spare time. Timelapses and hyperlapses make me wonder all the time ๐Ÿ˜Š

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.

More from this blog

P

Pankaj Patel - @heypankaj_

63 posts

Sharing my learnings and thoughts on Blogging, Personal Branding and Programming