UNPKG

diffusion

Version:

Diffusion JavaScript client

36 lines (28 loc) 952 B
// Quote any necessary characters within a string function quoteAndEscape(str) { var escaped = '\'', i = 0; if (str.indexOf('\'') < 0 && str.indexOf('\\') < 0) { escaped += str; } else { for (; i < str.length; ++i) { var c = str[i]; if (c === '\'' || c === '\\') { escaped += '\\'; } escaped += c; } } escaped += '\''; return escaped; } // Convert an array of roles to a single formatted string function rolesToString(roles) { return '[' + roles.map(quoteAndEscape).join(' ') + ']'; } // Convert an array of permissions to a single formatted string function permissionsToString(permissions) { return '[' + permissions.join(' ') + ']'; } module.exports.permissionsToString = permissionsToString; module.exports.quoteAndEscape = quoteAndEscape; module.exports.rolesToString = rolesToString;