@Left, @Right, @LeftBack, @RightBack, @Middle equivalents in JavaScript

Simple equivalents to these Lotus Notes formulas
JavaScript

@Left

function strLeft(sourceStr, keyStr){
	return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : sourceStr.split(keyStr)[0];
}

@Right

function strRight(sourceStr, keyStr){
	idx = sourceStr.indexOf(keyStr);
	return (idx == -1 | keyStr=='') ? '' : sourceStr.substr(idx+ keyStr.length);
}

@RightBack

function rightBack(sourceStr, keyStr){
	arr = sourceStr.split(keyStr);
	return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : arr.pop()
}

@LeftBack

function leftBack(sourceStr, keyStr){
	arr = sourceStr.split(keyStr)
	arr.pop();
	return (keyStr==null | keyStr=='') ? '' : arr.join(keyStr)
}

@Middle

function middle(sourceStr, keyStrLeft, keyStrRight){ 
	return strLeft(strRight(sourceStr,keyStrLeft), keyStrRight);
}

Written by Frank Joseph Brefere III

Posted by fbrefere001 on Friday March 27, 2009