.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / globjoin / index.js
1 'use strict';
2
3 var Path = require('path');
4 var slice = Array.prototype.slice;
5
6 function join(/* globs */) {
7         var args;
8
9         args = slice.call(arguments, 0);
10         return args.reduce(function (result, globs) {
11                 return _apply(result, function (path) {
12                         return _apply(globs, function (glob) {
13                                 return _join(path, glob);
14                         });
15                 });
16         }, '');
17 }
18
19 function _apply(values, fn) {
20         if (Array.isArray(values)) {
21                 return values.reduce(function (result, value) {
22                         return result.concat(fn(value));
23                 }, []);
24         }
25         return fn(values);
26 }
27
28 function _join(path, glob) {
29         var negative, positive;
30
31         if (glob[0] === '!') {
32                 positive = glob.substr(1);
33                 if (path[0] === '!') {
34                         negative = '';
35                 } else {
36                         negative = '!';
37                 }
38                 return negative + Path.join(path, positive);
39         }
40         return Path.join(path, glob);
41 }
42
43 module.exports = join;