2018-02-14 16:00:32 -08:00
|
|
|
/**
|
|
|
|
|
* Matches a string that is prefixed by [platform and suffixed by ]
|
|
|
|
|
* Captures the match in the sole capture group
|
|
|
|
|
* @type {RegExp}
|
|
|
|
|
*/
|
2018-02-14 18:16:52 -08:00
|
|
|
const platformRegex = /\[platform=([^\]]+)]/;
|
2018-02-14 16:00:32 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks that a string represents a dataset platform
|
|
|
|
|
* @param {string} candidate
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
const isDatasetPlatform = (candidate: string): boolean => platformRegex.test(candidate);
|
|
|
|
|
|
|
|
|
|
/**
|
2018-02-21 11:06:21 -08:00
|
|
|
* Checks that a string represents a dataset segment
|
2018-02-14 16:00:32 -08:00
|
|
|
* @param {string} candidate
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
2018-02-21 11:06:21 -08:00
|
|
|
const isDatasetSegment = (candidate: string): boolean =>
|
2018-02-14 16:00:32 -08:00
|
|
|
!isDatasetPlatform(candidate) && ['.', '/'].includes(candidate.slice(-1));
|
|
|
|
|
|
2018-03-08 10:21:01 -08:00
|
|
|
/**
|
|
|
|
|
* Checks that a string is not a dataset platform or segment
|
|
|
|
|
* @param {string} candidate
|
|
|
|
|
* @return {boolean}
|
|
|
|
|
*/
|
|
|
|
|
const isDatasetIdentifier = (candidate: string): boolean =>
|
|
|
|
|
!!candidate && !isDatasetPlatform(candidate) && !isDatasetSegment(candidate); // not a platform and does not meet segment rules
|
|
|
|
|
|
2018-02-14 18:16:52 -08:00
|
|
|
/**
|
|
|
|
|
* Takes an encoded platform string and strips out the coding metadata
|
|
|
|
|
* @param {string} candidateString
|
|
|
|
|
* @returns {(string | void)}
|
|
|
|
|
*/
|
|
|
|
|
const getPlatformFromString = (candidateString: string): string | void => {
|
|
|
|
|
const resultArray: Array<string> | null = platformRegex.exec(candidateString);
|
|
|
|
|
|
|
|
|
|
if (resultArray) {
|
|
|
|
|
const [, platform] = resultArray;
|
|
|
|
|
return platform;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-31 20:51:14 -07:00
|
|
|
export { platformRegex, isDatasetPlatform, isDatasetSegment, getPlatformFromString, isDatasetIdentifier };
|