"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.asKeywords = exports.getUrnCsidShortId = exports.isUrnCsid = exports.isCsid = void 0;
const csidPattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89aAbB][0-9a-fA-F]{3}(-[0-9a-fA-F]{12})?$/;
const urnCsidPattern = /^urn:cspace:name\(\w+\)$/;
/**
 * Determines if a given string is a valid guid-style csid.
 * @param {string} string - The string
 * @returns {boolean} True if the string is a valid csid, false otherwise.
 */

const isCsid = string => string && csidPattern.test(string);
/**
 * Determines if a given string is a valid URN-style csid. A URN-style csid may be substituted
 * for a guid-style csid for certain uses.
 * @param {string} string - The string
 * @returns {boolean} True if the string is a valid URN-style csid, false otherwise.
 */


exports.isCsid = isCsid;

const isUrnCsid = string => urnCsidPattern.test(string);
/**
 * Returns the short ID of a URN-style csid.
 *
 * @param {string} urnCsid
 * @returns {string} The short ID.
 */


exports.isUrnCsid = isUrnCsid;

const getUrnCsidShortId = urnCsid => urnCsid.substring(16, urnCsid.length - 1);
/**
 * Creates a keyword search parameter that may be used to find the record with a given csid. A
 * search performed with the resulting keyword parameter will find the record, but may also find
 * false positives. The result set must be filtered by checking the actual csid of each item.
 * @param {string} string - The csid
 * @returns {string} The keyword search parameter.
 */


exports.getUrnCsidShortId = getUrnCsidShortId;

const asKeywords = csid => `"${csid.replace(/-/g, ' ')}"`;

exports.asKeywords = asKeywords;