.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / find-up / index.js
1 'use strict';
2 const path = require('path');
3 const locatePath = require('locate-path');
4
5 module.exports = (filename, opts) => {
6         opts = opts || {};
7
8         const startDir = path.resolve(opts.cwd || '');
9         const root = path.parse(startDir).root;
10
11         const filenames = [].concat(filename);
12
13         return new Promise(resolve => {
14                 (function find(dir) {
15                         locatePath(filenames, {cwd: dir}).then(file => {
16                                 if (file) {
17                                         resolve(path.join(dir, file));
18                                 } else if (dir === root) {
19                                         resolve(null);
20                                 } else {
21                                         find(path.dirname(dir));
22                                 }
23                         });
24                 })(startDir);
25         });
26 };
27
28 module.exports.sync = (filename, opts) => {
29         opts = opts || {};
30
31         let dir = path.resolve(opts.cwd || '');
32         const root = path.parse(dir).root;
33
34         const filenames = [].concat(filename);
35
36         // eslint-disable-next-line no-constant-condition
37         while (true) {
38                 const file = locatePath.sync(filenames, {cwd: dir});
39
40                 if (file) {
41                         return path.join(dir, file);
42                 } else if (dir === root) {
43                         return null;
44                 }
45
46                 dir = path.dirname(dir);
47         }
48 };