Skip to content

Commit

Permalink
chore: Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored and actions-user committed Oct 31, 2021
1 parent 221118c commit b4d3f5a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 113 deletions.
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ var opts = {
name: '.app',
cwd: '.',
extensions: {
'rc': 'default-rc-loader',
rc: 'default-rc-loader',
'.yml': 'default-yml-loader',
},
};

fined({ path: '.' }, opts);
// => { path: '/absolute/of/cwd/.app.yml', extension: { '.yml': 'default-yml-loader' } }

fined({ path: '~', extensions: { 'rc': 'some-special-rc-loader' } }, opts);
fined({ path: '~', extensions: { rc: 'some-special-rc-loader' } }, opts);
// => { path: '/User/home/.apprc', extension: { 'rc': 'some-special-rc-loader' } }
```

Expand All @@ -41,24 +41,23 @@ fined({ path: '~', extensions: { 'rc': 'some-special-rc-loader' } }, opts);

#### Arguments:

* **pathObj** [string | object] : a path setting for finding a file.
* **opts** [object] : a plain object supplements `pathObj`.
- **pathObj** [string | object] : a path setting for finding a file.
- **opts** [object] : a plain object supplements `pathObj`.

`pathObj` and `opts` can have same properties:
`pathObj` and `opts` can have same properties:

* **path** [string] : a path string.
* **name** [string] : a basename.
* **extensions**: [string | array | object] : extensions.
* **cwd**: a base directory of `path` and for finding up.
* **findUp**: [boolean] : a flag to find up.
- **path** [string] : a path string.
- **name** [string] : a basename.
- **extensions**: [string | array | object] : extensions.
- **cwd**: a base directory of `path` and for finding up.
- **findUp**: [boolean] : a flag to find up.

#### Return:

This function returns a plain object which consists of following properties if a file exists otherwise null.

* **path** : an absolute path
* **extension** : a string or a plain object of extension.

- **path** : an absolute path
- **extension** : a string or a plain object of extension.

## License

Expand All @@ -75,4 +74,3 @@ MIT
[coveralls-url]: https://coveralls.io/r/gulpjs/fined
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/fined/master.svg
<!-- prettier-ignore-end -->

14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var defaults = require('object.defaults/immutable');
var expandTilde = require('expand-tilde');
var parsePath = require('parse-filepath');


function fined(pathObj, defaultObj) {
var expandedPath = expandPath(pathObj, defaultObj);
return expandedPath ? findWithExpandedPath(expandedPath) : null;
Expand Down Expand Up @@ -59,7 +58,8 @@ function expandPath(pathObj, defaultObj) {
filePath = filePath.slice(parsed.root.length);
findUp = false;
basedir = parsed.root;
} else /* istanbul ignore next */ if (parsed.root) { // Expanded path has a drive letter on Windows.
} /* istanbul ignore next */ else if (parsed.root) {
// Expanded path has a drive letter on Windows.
filePath = filePath.slice(parsed.root.length);
basedir = path.resolve(parsed.root);
}
Expand All @@ -80,9 +80,9 @@ function expandPath(pathObj, defaultObj) {
}

function findWithExpandedPath(expanded) {
var found = expanded.findUp ?
findUpFile(expanded.basedir, expanded.path, expanded.extArr) :
findFile(expanded.basedir, expanded.path, expanded.extArr);
var found = expanded.findUp
? findUpFile(expanded.basedir, expanded.path, expanded.extArr)
: findFile(expanded.basedir, expanded.path, expanded.extArr);

if (!found) {
return null;
Expand Down Expand Up @@ -131,12 +131,12 @@ function createExtensionArray(exts) {

if (Array.isArray(exts)) {
exts = exts.filter(isString);
return (exts.length > 0) ? exts : [''];
return exts.length > 0 ? exts : [''];
}

if (isPlainObject(exts)) {
exts = Object.keys(exts);
return (exts.length > 0) ? exts : [''];
return exts.length > 0 ? exts : [''];
}

return [''];
Expand Down
3 changes: 1 addition & 2 deletions test/fixtures/fined/package.json
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
{
}
{}
Loading

0 comments on commit b4d3f5a

Please sign in to comment.