sp-js-provisioning
Version:
SharePoint provisioning with pure JavaScript
76 lines • 2.96 kB
JavaScript
/**
* 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 m;
while ((m = this.tokenRegex.exec(string)) !== null) {
if (m.index === this.tokenRegex.lastIndex) {
this.tokenRegex.lastIndex++;
}
for (var _i = 0, m_1 = m; _i < m_1.length; _i++) {
var match = m_1[_i];
var _a = match.replace(/[{}]/g, '').split(':'), tokenKey = _a[0], tokenValue = _a[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;
}
}
}
return string;
};
return TokenHelper;
}());
export { TokenHelper };
//# sourceMappingURL=tokenhelper.js.map