https://github.com/aduth/resolve-file-extension
Resolve a file path from a base filename
https://github.com/aduth/resolve-file-extension
Last synced: 11 months ago
JSON representation
Resolve a file path from a base filename
- Host: GitHub
- URL: https://github.com/aduth/resolve-file-extension
- Owner: aduth
- License: mit
- Created: 2021-10-03T19:09:49.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-18T01:06:09.000Z (over 4 years ago)
- Last Synced: 2025-03-13T22:35:12.977Z (about 1 year ago)
- Language: JavaScript
- Size: 58.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# `resolve-file-extension`
Resolve an absolute file path from a base filename.
## Example
For example, this can be used to emulate the legacy Node.js "automatic" module resolution behavior you may be familiar with, where a file extension can be optionally omitted for specific file extensions such as `.js` and `.json`.
```js
import { getFilePath } from 'resolve-file-extension';
await getFilePath('./example', ['.js', '.json']);
// "/path/to/example.js"
```
## Installation
Install using [npm](https://www.npmjs.com/):
```
npm install resolve-file-extension
```
## API
### `getFilePath(baseFile: string, extension?: string[]): Promise`
Given a base file name and optional file extensions constraint, returns a promise which resolves to the first file path matching that base name and extension, or undefined if no file could be found. Extensions should be provided with a leading dot (".").
## License
Copyright 2021 Andrew Duthie
Released under the [MIT License](./LICENSE.md).