cspace-refname
Version:
CollectionSpace refname utilities
79 lines (75 loc) • 7.06 kB
JavaScript
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["cspaceRefName"] = factory();
else
root["cspaceRefName"] = factory();
})(self, () => {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/index.js":
/*!**********************!*\
!*** ./src/index.js ***!
\**********************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ getCsid: () => (/* binding */ getCsid),\n/* harmony export */ getDisplayName: () => (/* binding */ getDisplayName),\n/* harmony export */ getItemShortID: () => (/* binding */ getItemShortID),\n/* harmony export */ getServicePath: () => (/* binding */ getServicePath),\n/* harmony export */ getVocabularyShortID: () => (/* binding */ getVocabularyShortID),\n/* harmony export */ removeDisplayName: () => (/* binding */ removeDisplayName),\n/* harmony export */ setDisplayName: () => (/* binding */ setDisplayName)\n/* harmony export */ });\n/**\n * Retrieves the display name from a given ref name.\n * @param {string} refName - The ref name\n * @returns {string} The display name, or null if the ref name does not contain a display name.\n */\nconst getDisplayName = refName => {\n if (!refName || refName.charAt(refName.length - 1) !== \"'\") {\n return null;\n }\n const start = refName.indexOf(\"'\");\n if (start < 0 || start === refName.length - 1) {\n return null;\n }\n return refName.substring(start + 1, refName.length - 1);\n};\n\n/**\n * Retrieves the service path from a given ref name.\n * @param {string} refName - The ref name\n * @returns {string} The service path, or null if the ref name does not contain a service path.\n */\nconst getServicePath = refName => {\n if (!refName) {\n return null;\n }\n const parts = refName.split(':', 4);\n return parts[3] || null;\n};\n\n/**\n * Retrieves the vocabulary short identifier from a given ref name.\n * @param {string} refName - The ref name\n * @returns {string} The short ID, or null if the ref name does not contain a vocabulary short ID.\n */\nconst getVocabularyShortID = refName => {\n if (!refName) {\n return null;\n }\n const parts = refName.split(':', 6);\n const itemPart = parts[5];\n if (itemPart === 'item') {\n const vocabNamePart = parts[4];\n if (vocabNamePart && vocabNamePart.indexOf('name(') === 0 && vocabNamePart.lastIndexOf(')') === vocabNamePart.length - 1) {\n return vocabNamePart.substring(5, vocabNamePart.length - 1);\n }\n }\n return null;\n};\n\n/**\n * Retrieves the vocabulary item short identifier from a given ref name.\n * @param {string} refName - The ref name\n * @returns {string} The short ID, or null if the ref name does not contain a vocabulary item\n * short ID.\n */\nconst getItemShortID = refName => {\n if (!refName) {\n return null;\n }\n const parts = refName.split(':', 7);\n const itemPart = parts[5];\n if (itemPart === 'item') {\n const itemNamePart = parts[6];\n if (itemNamePart && itemNamePart.indexOf('name(') === 0) {\n const index = itemNamePart.indexOf(')');\n if (index > -1) {\n return itemNamePart.substring(5, index);\n }\n }\n }\n return null;\n};\n\n/**\n * Retrieves the csid from a given ref name, if present.\n * @param {string} refName - The ref name\n * @returns {string} The csid, or null if the ref name does not contain a csid.\n */\nconst getCsid = refName => {\n if (!refName) {\n return null;\n }\n const parts = refName.split(':', 5);\n const idPart = parts[4];\n if (idPart && idPart.indexOf('id(') === 0) {\n const index = idPart.indexOf(')');\n if (index > -1) {\n return idPart.substring(3, index);\n }\n }\n return null;\n};\nconst removeDisplayName = refName => {\n if (!refName) {\n return refName;\n }\n const start = refName.indexOf(\"'\");\n if (start < 0) {\n return refName;\n }\n return refName.substring(0, start);\n};\nconst setDisplayName = (refName, displayName) => {\n if (!refName) {\n return refName;\n }\n const strippedRefName = removeDisplayName(refName);\n return `${strippedRefName}'${displayName}'`;\n};\n\n//# sourceURL=webpack://cspaceRefName/./src/index.js?");
/***/ })
/******/ });
/************************************************************************/
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__["./src/index.js"](0, __webpack_exports__, __webpack_require__);
/******/ __webpack_exports__ = __webpack_exports__["default"];
/******/
/******/ return __webpack_exports__;
/******/ })()
;
});