8000 GitHub - cityssm/node-has-package: Tests if a package is available to be imported. Useful for checking if optional dependencies are installed.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cityssm/node-has-package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Has Package

NPM Version DeepSource codecov

Tests if a package is available to be imported. Useful for checking if optional dependencies are installed.

Unlike other packages that test whether a package is available by importing it, this package checks the file system for the corresponding package.json file. This avoids any package code from running during the check.

Installation

npm install @cityssm/has-package

Usage

import hasPackage from '@cityssm/has-package'

/*
 * Test for an existing package
 */

let packageExists = await hasPackage('eslint')
console.log(packageExists)
// => true

/*
 * Test for an nonexisting package
 */

packageExists = await hasPackage('@cityssm/non-existing-package')
console.log(packageExists)
// => false
0