UNPKG

diffusion

Version:

Diffusion JavaScript client

70 lines (69 loc) 2.32 kB
"use strict"; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.permissionsToString = exports.setToString = exports.quoteAndEscape = void 0; /** * Quote any necessary characters within a string * * @param str the string to escape * @return a quoted and escaped string */ function quoteAndEscape(str) { var e_1, _a; var escaped = ''; if (str.indexOf('\'') < 0 && str.indexOf('\\') < 0) { escaped += str; } else { try { for (var str_1 = __values(str), str_1_1 = str_1.next(); !str_1_1.done; str_1_1 = str_1.next()) { var c = str_1_1.value; if (c === '\'' || c === '\\') { escaped += '\\'; } escaped += c; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (str_1_1 && !str_1_1.done && (_a = str_1.return)) _a.call(str_1); } finally { if (e_1) throw e_1.error; } } } return "'" + escaped + "'"; } exports.quoteAndEscape = quoteAndEscape; /** * Convert an array of strings to a single formatted string * * @param stringSet an array of strings * @return a string containing each string in quotes, concatenated and * surrounded by brackets */ function setToString(stringSet) { return '[' + stringSet.map(quoteAndEscape).join(' ') + ']'; } exports.setToString = setToString; /** * Convert an array of permissions to a single formatted string * * @param permissions an array of permissions * @return a string containing the concatenated permissions, * surrounded by brackets */ function permissionsToString(permissions) { return '[' + permissions.join(' ') + ']'; } exports.permissionsToString = permissionsToString;