Package Exports
- is-there
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (is-there) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
is-there
Check if a file or directory exists in a given path.
Why? fs.exists
already does the job!
Because fs.exists
and fs.existsSync
will be are deprecated and in some cases we still need them!
fs.exists()
is an anachronism and exists only for historical reasons. There should almost never be a reason to use it in your own code. In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls tofs.exists()
andfs.open()
. Just open the file and handle the error when it's not there.fs.exists()
will be deprecated. (Source, emphasis added)
☁️ Installation
$ npm i --save is-there
📋 Example
// Dependencies
var IsThere = require("is-there");
// Paths to test
var paths = [
// exist
"dir"
, "dir/another"
, "dir/another/file"
, "dir/file"
, "file"
, "file.ext"
// don't exist
, "foo"
, "foo/bar"
, "foo.bar"
, "foo/bar.foo"
].map(function (c) {
return __dirname + "/contents/" + c;
});
// Sync
console.log("> Testing sync method.");
paths.forEach(function (c) {
console.log("> %s %s", c, IsThere(c) ? "exists" : "doesn't exist");
});
console.log("> Testing async method.");
function doSeq(i) {
i = i || 0;
var cPath = paths[i];
if (!cPath) { return; }
IsThere(cPath, function (exists) {
console.log("> %s %s", cPath, exists ? "exists" : "doesn't exist");
doSeq(i + 1);
});
}
doSeq();
📝 Documentation
isThere
Checks if a file or directory exists on given path. Use without the new keyword.
Params
- String
path
: The path to the file or directory. - Function
callback
: The callback function called with a boolean value representing if the file or directory exists. If this parameter is not a function, the function will run synchronously and return the value.
Return
- isThere|Boolean The
isThere
function if thecallback
parameter was provided, otherwise a boolean value indicating if the file/directory exists or not.
directory(path, callback)
Checks if the path exists and it is a directory.
Params
- String
path
: The path to the directory. - Function
callback
: The callback function called with a boolean value representing if the directory exists. If this parameter is not a function, the function will run synchronously and return the value.
Return
- isThere|Boolean The
isThere
function if thecallback
parameter was provided, otherwise a boolean value indicating if the directory exists or not.
file(path, callback)
Check if the path exists and it is a file.
Params
- String
path
: The path to the file. - Function
callback
: The callback function called with a boolean value representing if the file exists. If this parameter is not a function, the function will run synchronously and return the value.
Return
- isThere|Boolean The
isThere
function if thecallback
parameter was provided, otherwise a boolean value indicating if the file exists or not.
😋 How to contribute
Have an idea? Found a bug? See how to contribute.
💖 Support my projects
I open-source almost everything I can, and I try to reply everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
Starring and sharing the projects you like 🚀
—You can make one-time donations via PayPal. I'll probably buy a
coffeetea. 🍵—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
Bitcoin—You can send me bitcoins at this address (or scanning the code below):
1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6
Thanks! ❤️
💫 Where is this library used?
If you are using this library in one of your projects, add it in this list. ✨
a-csv
(by jillix)—A lightweight CSV parser.ajs
—Asynchronous templating in Node.jsali-oss-extra
(by Jacky Tang)—Extend the official ali-oss with more convenient methods, such as listing, syncing or deleting a directory, put or delete a list of files etc.artstack-downloader
—Download artworks from your following users.be-goods
(by Orlin M Bozhinov)—let there be beverage goodsbetter-history
(by Jiacai Liu)—💡 Get a better sense of browsing history via Chrome/Firefoxbible
—Read the Holy Bible via the command line.blah
—A command line tool to optimize the repetitive actions.bower-license-webpack-plugin
(by S K)—Outputs licenses from 3rd party libraries to a filebowerrc
(by Mithun Ayachit)—Switch between different .bowerrc filescaipi
(by Nathan Braun)—Caipi reactor - Isomorphic CMS based on ES6+React+webpack+mongo+etccdnjs-importer
—Easy way to import a library into CDNJS.cecil
(by Michael Burkman)—For running single-file NodeJS scripts with external dependenciesconfetti-cli
(by Andrea Mangano)—Command line interface for Confetti, a tool for enriching your online slide decks.emartech-node-sass-json-importer
—Allows importing json in sass files parsed by node-sass.engine-app
(by jillix)—Engine app related helper functions.engine-composition-crud
(by jillix)—The default module for creating, reading, updating and deleting Engine instances.engine-tools
(by jillix)—Engine Tools library and CLI app.f-watcher
—Watch files for changes.find-file-in-dirs
—Find a file in different directories.firstant2gradle
(by Philip Rader)—Automatically converts an Ant build system to Gradle for FIRST Robotics Competition teamsfontify
(by Youssef Kababe)—Copy font files from node_modules folderfriendly-typed-css-modules
(by themallen)—Creates .d.ts files from CSS Modules .css filesfwatcher
—Watch files for changes.gd-cli
(by Sylvain Baronnet)—GD Command Line Interfacegenerator-arwen
(by Jason Villalon)—Generator Atomic Restify Web NodeJSgenerator-atomus
(by Jason Villalon)—Generator React Componentsgenerator-catena
(by Damir Kusar)—Yeoman generator for Meteor and AngularJSgenerator-catena-angular-meteor-bootstrap
(by Damir Kusar)—Yeoman generator for Meteor and AngularJSgenerator-catena-angular-meteor-material
(by Damir Kusar)—Yeoman generator for Meteor and AngularJSgenerator-leptir
(by Damir Kusar)—Yeoman generator for AngularJS with gulp, browserify, bootstrap, SCSS, angular-ui, angular-translate, karma, jasmine and ftp deploymentgenerator-leptir-angular-bootstrap
(by Damir Kusar)—Yeoman generator for AngularJS with gulp, browserify, bootstrap, SCSS, angular-ui, angular-translate, karma, jasmine and ftp deploymentgenerator-leptir-angular-material
(by Damir Kusar)—Yeoman generator for AngularJS with gulp, browserify, Angular-Material, SCSS, angular-ui, angular-translate, karma, jasmine and ftp deploymentgenerator-morf
(by p1100i)—A yeoman generator to bootstrap a finely tuned project [node, angular], w/ Grunt.gif-cli
—Gif animations in your terminal!git-issues
(by Gabriel Petrovay)—Git issues extension to list issues of a Git projectgit-stats
—Local git statistics including GitHub-like contributions calendars.git-stats-importer
—Imports your commits from a repository into git-stats history.gpm
—npm + git = gpm - Install NPM packages and dependencies from git repositories.grunt-md5symlink
(by peters)—Create symlink by the md5 of given files.gulp-app-build-tasks
(by Jimmy Fortin)—This module will add standard gulp tasks to start building a web application.gulp-common-build-tasks
(by Jimmy Fortin)—You can found in this library some utilities and tasks that can be shared between multiple gulp's build processes.hal-rc
—hints-and-lints rcheroku-container-registry
(by Hunter Loftis)—Use containers to build and deploy Heroku appsheroku-container-tools
(by Hunter Loftis)—Use containers to build and deploy Heroku appsheroku-docker
(by Hunter Loftis)—DEPRECATED: use heroku-container-toolshg-plus
(by Justin Dalrymple)—A Mercurial client for Nodeidea
—A lightweight CLI tool and module for keeping ideas in a safe place quick and easy.image-to-ascii-cli
—View images in text format, in your terminal.is-git-check
(by Dominik Winter)—Simple module to check whether a directory is a git repository or notjisc_build
(by Martin Wood-Mitrovski)—Shared jisc build scripts and configuration for JJA and JHTjoomlascan
—Searches paths for Joomla installations and outputs the installed version number.kaomojify
(by kokororin)—Kaomojify Javascript codekaomojify-webpack-plugin
(by kokororin)—convert your built JavaScript code to Japanese kawaii kaomoji(かわいい顔文字)kotori-webpack-plugin
(by kokororin)—Yet another webpack pluginle-serf
(by Nathan McCallum)—Your trusty assistant in your Lacuna Expanse misadventures!low-cli
(by Jeremy Rylan)—undefinedmatanza
(by Alfredo Monteiro)—Matanza =======memories
(by data-doge)—cli for a timestamped markdown journalminipod
(by DonYang)—Customize cocoapods specs for just you need.node-dynamo
(by Louis Larry)—Easily create and recreate dynamodb tables and sample data. This package provides the cli and sdk.node-sass-json-importer
—Allows importing json in sass files parsed by node-sass.npm-interlink
(by Orlin M Bozhinov)—becausenpm link ...
can be tediouspanes
(by Joel Chu)—PANES.JS core lib and cli http://panesjs.comparent-search
—Search files and folders in parent directories.payname
(by Florian CHEVALLIER)—Module nodejs permettant d'intégrer Payname à vos projetsramda-cli
(by Raine Virta)—A command-line tool for processing JSON with Ramda and LiveScriptreindex-cli
(by Reindex)—CLI interface for Reindexsingular_sake
(by Juan Castro Fernández)—Singular MVC PHP Framework command line toolsourcegate
(by Orlin M Bozhinov)—have any json object you wantsp-load
(by pavel06081991)—Modules loader. No lots of require calls on the top of files. On demand modules loading. Local modules.tester-init
—Init tests for tester.tilda-init
—Init cli applications.tithe
—Organize and track the tithe payments.typed-css-modules
(by quramy)—Creates .d.ts files from CSS Modules .css filesunity-asset-sync
(by Chris Jaynes)—Allows safe, effective sharing of code between Unity projects.unity-link
(by Chris Jaynes)—A utility for Unity developers to symlink scripts into their Assets folders. Useful for library development.uturi-caching
—undefinedvalkctl
—simple command wrappervalkyrja
(by srcspider)—the deploy toolvimhelp
(by thinca)—Show vim help.viur-ignite-css
(by VIUR)—Core of VIUR Ignite - a less frameworkviur-ignite-html
(by VIUR)—Simple Template Render | Extension of viur-ignite-cssviur-ignite-icons
(by VIUR)—Icon libary | Extension of viur-ignite-cssviur-ignite-js
(by VIUR)—Javascript Libary | Extension of viur-ignite-cssweb-term
—A full screen terminal in your browser.wml
(by dutzi)—Replaces npm link with something that actually works!zow
(by Jeremy Rylan)—undefined