sp-js-provisioning
Version:
SharePoint provisioning with pure JavaScript
51 lines • 2.13 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import * as xmljs from 'xml-js';
export function replaceUrlTokens(string, config) {
var siteAbsoluteUrl = null;
var siteRelativeUrl = null;
if (config.spfxContext) {
siteAbsoluteUrl = config.spfxContext.pageContext.site.absoluteUrl;
siteRelativeUrl = config.spfxContext.pageContext.site.serverRelativeUrl;
}
else if (window.hasOwnProperty('_spPageContextInfo')) {
siteAbsoluteUrl = _spPageContextInfo.siteAbsoluteUrl;
siteRelativeUrl = _spPageContextInfo.siteServerRelativeUrl;
}
return string
.replace(/{site}/g, siteRelativeUrl)
.replace(/{sitecollection}/g, siteAbsoluteUrl)
.replace(/{wpgallery}/g, siteAbsoluteUrl + "/_catalogs/wp")
.replace(/{hosturl}/g, window.location.protocol + "//" + window.location.host + ":" + window.location.port)
.replace(/{themegallery}/g, siteAbsoluteUrl + "/_catalogs/theme/15");
}
export function makeUrlRelative(absUrl) {
return absUrl.replace(document.location.protocol + "//" + document.location.hostname, '');
}
export function base64EncodeString(string) {
var bytes = [];
for (var index = 0; index < string.length; ++index) {
bytes.push(string.charCodeAt(index), 0);
}
var b64encoded = window.btoa(String.fromCharCode.apply(null, bytes));
return b64encoded;
}
export function isNode() {
return typeof window === 'undefined';
}
export function addFieldAttributes(schemaXml, attributes) {
var fieldXmlJson = JSON.parse(xmljs.xml2json(schemaXml));
fieldXmlJson.elements[0].attributes = __assign(__assign({}, fieldXmlJson.elements[0].attributes), attributes);
schemaXml = xmljs.json2xml(fieldXmlJson);
return schemaXml;
}
//# sourceMappingURL=index.js.map