.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-stringify / lib / util / enclose-uri.js
1 'use strict';
2
3 var count = require('ccount');
4
5 module.exports = enclose;
6
7 var re = /\s/;
8
9 /* Wrap `url` in angle brackets when needed, or when
10  * forced.
11  * In links, images, and definitions, the URL part needs
12  * to be enclosed when it:
13  *
14  * - has a length of `0`;
15  * - contains white-space;
16  * - has more or less opening than closing parentheses.
17  */
18 function enclose(uri, always) {
19   if (always || uri.length === 0 || re.test(uri) || count(uri, '(') !== count(uri, ')')) {
20     return '<' + uri + '>';
21   }
22
23   return uri;
24 }