UNPKG

spws

Version:

SharePoint Web Services Wrapper

44 lines 1.81 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var getPrecedingPathFromUrl_1 = __importDefault(require("./getPrecedingPathFromUrl")); /** * Retrieves a static name from a given set of parameters. * * @param params - The parameters containing the DefaultViewUrl and Title. * @param params.DefaultViewUrl - The default view URL of the list. * @param params.Title - The title of the list. * @returns The static name derived from the DefaultViewUrl or Title. * @throws Will throw an error if both DefaultViewUrl and Title are not provided. */ var getListStaticName = function (params) { // Destructure params var DefaultViewUrl = params.DefaultViewUrl, Title = params.Title; // Validate URL if (!DefaultViewUrl) { // Validate Title if (!Title) throw new Error("DefaultViewUrl and Title is required"); // If no DefaultViewUrl, return Title as the StaticName return Title; } // Get URL as lowercase var url = DefaultViewUrl.toLowerCase(); // Check if URL contains '/lists/' if (url.includes("/lists/")) return DefaultViewUrl.split("/Lists/")[1].split("/")[0]; // Check if URL contains '/forms/' if (url.includes("/forms/")) return (0, getPrecedingPathFromUrl_1.default)({ url: DefaultViewUrl, beforePath: "Forms", }); // Default return name var array = DefaultViewUrl.split("/"); // Return the second to last part of the URL return array[array.length - 2]; }; exports.default = getListStaticName; //# sourceMappingURL=getListStaticName.js.map