UNPKG

sp-js-provisioning

Version:
113 lines 4.5 kB
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."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; /** * Describes the Token Helper */ var TokenHelper = /** @class */ (function () { /** * Creates a new instance of the TokenHelper class */ function TokenHelper(context, config) { this.context = context; this.config = config; this.tokenRegex = /{[a-z]*:[ A-z|ÅÆØåæø]*}/g; } TokenHelper.prototype.replaceTokens = function (string) { var e_1, _a; var m; while ((m = this.tokenRegex.exec(string)) !== null) { if (m.index === this.tokenRegex.lastIndex) { this.tokenRegex.lastIndex++; } try { for (var m_1 = (e_1 = void 0, __values(m)), m_1_1 = m_1.next(); !m_1_1.done; m_1_1 = m_1.next()) { var match = m_1_1.value; var _b = __read(match.replace(/[{}]/g, '').split(':'), 2), tokenKey = _b[0], tokenValue = _b[1]; switch (tokenKey) { case 'listid': { if (this.context.lists[tokenValue]) { string = string.replace(match, this.context.lists[tokenValue]); } } break; case 'listviewid': { if (this.context.listViews[tokenValue]) { string = string.replace(match, this.context.listViews[tokenValue]); } } break; case 'webid': { if (this.context.web.Id) { string = string.replace(match, this.context.web.Id); } } break; case 'siteid': { if (this.context.web.Id) { string = string.replace(match, this.context.web.Id); } } break; case 'sitecollectionid': { if (this.context.web.Id) { string = string.replace(match, this.context.web.Id); } } break; case 'parameter': { if (this.config.parameters) { var parameterValue = this.config.parameters[tokenValue]; if (parameterValue) { string = string.replace(match, parameterValue); } } } break; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (m_1_1 && !m_1_1.done && (_a = m_1.return)) _a.call(m_1); } finally { if (e_1) throw e_1.error; } } } return string; }; return TokenHelper; }()); export { TokenHelper }; //# sourceMappingURL=tokenhelper.js.map