spws
Version:
SharePoint Web Services Wrapper
53 lines • 2.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Parses the Encoded Absolute URL to return an object with useful links
* @param {string} encodedAbsUrl The Item EncodedAbsUrl string
* @returns {object} Returns an object contains the ListName, ListUrl, DispFormUrl, EditFormUrl and NewFormUrl
* @example
* // Parse the Encoded Abs URL
* parseEncodedAbsUrl("http://contoso/sites/test/Lists/Announcements/4_.000");
*
* // Returns
* {
* ID: "1",
* ListName: "Announcements",
* ListUrl: "http://contoso/sites/test/Lists/Announcements",
* NewFormUrl: "http://contoso/sites/test/Lists/Announcements/NewForm.aspx",
* EditFormUrl: "http://contoso/sites/test/Lists/Announcements/EditForm.aspx?ID=4",
* DispFormUrl: "http://contoso/sites/test/Lists/Announcements/DispForm.aspx?ID=4"
* }
*
*/
var parseEncodedAbsUrl = function (encodedAbsUrl) {
// Define url object
var data = {
ID: "",
ListUrl: "",
ListName: "",
NewFormUrl: "",
EditFormUrl: "",
DispFormUrl: "",
};
// Validate type
if (typeof encodedAbsUrl !== "string")
throw new Error("Unable to parse the encoded absolute URL. Expect a string but received ".concat(typeof encodedAbsUrl));
// Validate empty string
if (!encodedAbsUrl.startsWith("http"))
throw new Error("The Encoded Absolute URL was not received as it is missing the protocol (http...)");
// Create a path array
var path = encodedAbsUrl.split("/");
// Get the ID and remove the last index from array
var ID = path.pop() || "";
// Get the ID from the path array
data.ID = ID.split("_")[0];
data.ListName = path[path.length - 1];
data.ListUrl = path.join("/");
data.NewFormUrl = "".concat(data.ListUrl, "/NewForm.aspx");
data.EditFormUrl = "".concat(data.ListUrl, "/EditForm.aspx?ID=").concat(data.ID);
data.DispFormUrl = "".concat(data.ListUrl, "/DispForm.aspx?ID=").concat(data.ID);
// Return data
return data;
};
exports.default = parseEncodedAbsUrl;
//# sourceMappingURL=parseEncodedAbsUrl.js.map