Socket
Socket
Sign inDemoInstall

detect-file

Package Overview
Dependencies
0
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-file

Detects if a file exists and returns the resolved filepath.


Version published
Maintainers
2
Weekly downloads
5,649,539
increased by1.36%
Install size
9.22 kB

Weekly downloads

Package description

What is detect-file?

The detect-file npm package is designed to help developers determine if a file exists in a given path. It provides a simple and efficient way to check for the presence of files without having to manually handle file system operations. This can be particularly useful in build scripts, file validation processes, or any scenario where ensuring the existence of a file is necessary.

What are detect-file's main functionalities?

Check if a file exists

This feature allows you to check if a specific file exists at a given path. The function returns a boolean indicating the presence of the file.

const detectFile = require('detect-file');

const filePath = 'path/to/your/file.txt';
const exists = detectFile(filePath);

if (exists) {
  console.log('File exists.');
} else {
  console.log('File does not exist.');
}

Other packages similar to detect-file

Readme

Source

detect-file NPM version NPM monthly downloads NPM total downloads Linux Build Status Windows Build Status

Detects if a file exists and returns the resolved filepath.

Install

Install with npm:

$ npm install --save detect-file

Install with yarn:

$ yarn add detect-file

Usage

var detect = require('detect-file');

API

detect

Detect the given filepath if it exists.

Params

  • filepath {String}: filepath to detect.
  • options {Object}: Additional options.
  • options.nocase {Boolean}: Set this to true to force case-insensitive filename checks. This is useful on case sensitive file systems.
  • returns {String}: Returns the detected filepath if it exists, otherwise returns null.

Example

var res = detect('package.json');
console.log(res);
//=> "package.json"

var res = detect('fake-file.json');
console.log(res)
//=> null

Case sensitive file systems

When using the nocase option, this library will attempt to detect the filepath with the following methods:

  1. Try to read all files in the filepath using fs.readdirSync. If successful and filepath is a directory, return the filepath.
  2. Try to read all files in the filepath's directory using fs.readdirSync. If successful, do case insensitive comparasions of the filepath to the files in filepath's directory.

About

fs-exists-sync: Drop-in replacement for fs.existsSync with zero dependencies. Other libs I found either have crucial differences… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Brian Woodward

License

Copyright © 2017, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on August 05, 2017.

Keywords

FAQs

Last updated on 06 Aug 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc