lepu-test-platform-web/node_modules/is-resolvable
zhangbo db3ebd0df0 把之前百度云的代码移植过来 2024-01-03 15:23:47 +08:00
..
LICENSE 把之前百度云的代码移植过来 2024-01-03 15:23:47 +08:00
README.md 把之前百度云的代码移植过来 2024-01-03 15:23:47 +08:00
index.js 把之前百度云的代码移植过来 2024-01-03 15:23:47 +08:00
package.json 把之前百度云的代码移植过来 2024-01-03 15:23:47 +08:00

README.md

is-resolvable

npm version Build Status Build status Coverage Status

A Node.js module to check if a given module ID is resolvable with require()

const isResolvable = require('is-resolvable');

isResolvable('fs'); //=> true
isResolvable('path'); //=> true

// When ./index.js exists
isResolvable('./index.js') //=> true
isResolvable('./index') //=> true
isResolvable('.') //=> true

Installation

Use npm.

npm install is-resolvable

API

const isResolvable = require('is-resolvable');

isResolvable(moduleId [, options])

moduleId: string (module ID)
options: Object (require.resolve options)
Return: boolean

It returns true if require() can load a file form a given module ID, otherwise false.

const isResolvable = require('is-resolvable');

// When ./foo.json exists
isResolvable('./foo.json'); //=> true
isResolvable('./foo'); //=> true

isResolvable('./foo.js'); //=> false

// When `eslint` module is installed but `jshint` isn't
isResolvable('eslint'); //=> true
isResolvable('jshint'); //=> false

// When `lodash` module is installed
isResolvable('lodash/isObject'); //=> true
isResolvable('lodash/fp/reject.js'); //=> true

The second argument accepts an options object for require.resolve().

// When ./bar/baz.js exists

isResolvable('./baz.js'); //=> false
isResolvable('./baz.js', {paths: ['bar']}); //=> true

License

ISC License © 2018 Shinnosuke Watanabe