3 var count = require('ccount');
5 module.exports = enclose;
9 /* Wrap `url` in angle brackets when needed, or when
11 * In links, images, and definitions, the URL part needs
12 * to be enclosed when it:
14 * - has a length of `0`;
15 * - contains white-space;
16 * - has more or less opening than closing parentheses.
18 function enclose(uri, always) {
19 if (always || uri.length === 0 || re.test(uri) || count(uri, '(') !== count(uri, ')')) {
20 return '<' + uri + '>';