panzerdp / voca

The ultimate JavaScript string library
https://vocajs.pages.dev
MIT License
3.61k stars 136 forks source link

keepAfter, keepBefore, keepBetween, keepChars #62

Open okabak123 opened 1 year ago

okabak123 commented 1 year ago

Hi, this is a feature suggestion to this awesome library.

The suggested functions are as follows:

*optional arguments

These are inspired by a program called EasyMorph. And for more info I'll link to their documentation.

keepAfter

This function returns characters after the first occurrence of after_string in text, if found. If after_string is not found within text and "empty" value is returned.

keepAfter('a/b/c/d', 'b') //Returns '/c/d'

More info

keepBefore

This function returns characters before the first occurrence of before_string in text, if found. If before_string is not found within text and "empty" value is returned.

keepBefore('5pm', 'pm') //Returns '5'

More info

keepBetween

This function returns the characters between the first occurrence of keep_start and the first occurrence of keep_end in text.

keepBetween('Mary Joe Smith', 'Mary ', ' Smith') //Returns 'Joe'

More info

keepChars

This function keeps only the characters given in keep_string and removes the others from text.

keepChars('a1b2c3', 'abc') //Returns 'abc'

More info