@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
84 lines (83 loc) • 3.2 kB
JavaScript
/**
* CodeAnalizerComment: Updated 1 imports on 2024-09-21 23:07:24
* Update:: import { ITrimAfter } to '@mikezimm/fps-core-v7/lib/components/molecules/source-props/Lists/getVX/IGetInterfaceV2;'
*/
import { DidNotTrim } from './constants';
/***
* d888888b d8888b. d888888b .88b d88. .d8b. d88888b d888888b d88888b d8888b. db db
* `~~88~~' 88 `8D `88' 88'YbdP`88 d8' `8b 88' `~~88~~' 88' 88 `8D `8b d8'
* 88 88oobY' 88 88 88 88 88ooo88 88ooo 88 88ooooo 88oobY' `8bd8'
* 88 88`8b 88 88 88 88 88~~~88 88~~~ 88 88~~~~~ 88`8b .dPYb.
* 88 88 `88. .88. 88 88 88 88 88 88 88 88. 88 `88. .8P Y8.
* YP 88 YD Y888888P YP YP YP YP YP YP YP Y88888P 88 YD YP YP
*
*
*/
export function trimAfter(str, trimCommand) {
let parser = '';
let result = DidNotTrim;
if (!str)
return '';
// https://github.com/mikezimm/drilldown7/issues/424
if (trimCommand === 'TrimAfterLastDot')
return str.substring(str.lastIndexOf('.') + 1); // https://github.com/mikezimm/drilldown7/issues/424
if (trimCommand === 'TrimAfterLastHash')
return str.substring(str.lastIndexOf('#') + 1); // https://github.com/mikezimm/drilldown7/issues/425
if (trimCommand === 'TrimAfterHyphen'.toLowerCase()) {
parser = '-';
}
if (trimCommand === 'TrimAfterDash'.toLowerCase()) {
parser = '-';
}
else if (trimCommand === 'TrimAfterTilda'.toLowerCase()) {
parser = '~';
}
else if (trimCommand === 'TrimAfterColon'.toLowerCase()) {
parser = ':';
}
else if (trimCommand === 'TrimAfterPar'.toLowerCase()) {
parser = ')';
}
else if (trimCommand === 'TrimAfterDot'.toLowerCase()) {
parser = '.';
}
// https://github.com/mikezimm/drilldown7/issues/478
else if (trimCommand === 'TrimAfter2Pipe'.toLowerCase()) {
parser = '||';
}
else if (trimCommand === 'TrimAfterPipe'.toLowerCase()) {
parser = '|';
}
// https://github.com/mikezimm/drilldown7/issues/426
else if (trimCommand === 'TrimAfterGT'.toLowerCase()) {
parser = '>';
}
if (parser !== '') {
result = TrimAfterThis(str, parser);
}
return result;
}
export function TrimAfterColon(str) {
return TrimAfterThis(str, ':');
}
export function TrimAfterTilda(str) {
return TrimAfterThis(str, '~');
}
export function TrimAfterHyphen(str) {
return TrimAfterThis(str, '-');
}
export function TrimAfterThis(str, parser) {
if (typeof str !== 'string') {
return str;
}
let idx = str.indexOf(parser);
return idx > -1 ? str.substring(idx + 1).trim() : DidNotTrim;
}
// https://github.com/mikezimm/drilldown7/issues/381
export function GetStringAfterHash(str, noHashResult) {
if (!str)
return noHashResult;
const index = str.lastIndexOf('#');
return index !== -1 ? str.substring(index + 1) : noHashResult;
}
//# sourceMappingURL=trimAfter.js.map