mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-11 02:32:54 +00:00

* Releases updated version of datahub-web client UI code * Fix typo in yarn lock * Change yarn lock to match yarn registry directories * Previous commit missed some paths * Even more changes to yarnlock missing in previous commit * Include codegen file for typings * Add files to get parity for datahub-web and current OS datahub-midtier * Add in typo fix from previous commit - change to proper license * Implement proper OS fix for person entity picture url * Workarounds for open source DH issues * Fixes institutional memory api and removes unopensourced tabs for datasets * Fixes search dataset deprecation and user search issue as a result of changes * Remove internal only options in the avatar menu
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
/**
|
|
* Cached RegExp object for a global search of /
|
|
* @type {RegExp}
|
|
*/
|
|
const encodedSlashRegExp = new RegExp(encodeURIComponent('/'), 'g');
|
|
/**
|
|
* Replaces any occurrence of / with the encoded equivalent
|
|
* @param {string} urn
|
|
* @return {string}
|
|
*/
|
|
export const encodeForwardSlash = (urn: string): string => urn.replace(/\//g, () => encodeURIComponent('/'));
|
|
|
|
/**
|
|
* Replaces encoded slashes with /
|
|
* @param {string} urn
|
|
* @return {string}
|
|
*/
|
|
export const decodeForwardSlash = (urn: string): string =>
|
|
urn.replace(encodedSlashRegExp, () => decodeURIComponent('/'));
|
|
|
|
/**
|
|
* Replaces occurrences of / with the encoded counterpart in a urn string
|
|
* @param {string} urn
|
|
* @return {string}
|
|
*/
|
|
export const encodeUrn = (urn: string): string => encodeForwardSlash(urn);
|
|
|
|
/**
|
|
* Replaces encoded occurrences of / with the string /
|
|
* @param {string} urn
|
|
* @return {string}
|
|
*/
|
|
export const decodeUrn = (urn: string): string => decodeForwardSlash(urn);
|
|
|
|
/**
|
|
* Stores the encoded URL for the asterisk/wildcard symbol since encodeURIComponent doesn't catch these
|
|
* as a reserved symbol
|
|
* @type {string}
|
|
*/
|
|
const encodedWildcard = '%2A';
|
|
|
|
/**
|
|
* Cached RegExp object for a global search of /
|
|
* @type {RegExp}
|
|
*/
|
|
const encodedWildcardRegExp = new RegExp(encodedWildcard, 'g');
|
|
|
|
/**
|
|
* Replaces any occurence of * with the encoded equivalent
|
|
* @param {string} urn
|
|
* @return {string}
|
|
*/
|
|
export const encodeWildcard = (urn: string): string => urn.replace(/\*/g, encodedWildcard);
|
|
|
|
/**
|
|
* Replaces encoded slashes with /
|
|
* @param {string} urn
|
|
* @return {string}
|
|
*/
|
|
export const decodeWildcard = (urn: string): string => urn.replace(encodedWildcardRegExp, decodeURIComponent('*'));
|
|
|
|
/**
|
|
* Will extract the entity type from a urn
|
|
* @param urn
|
|
*/
|
|
export const extractEntityType = (urn: string): string | undefined => urn.split(':')[2];
|