1.0.5 • Published 8 years ago
from-before v1.0.5
from-before
API
operand::fromBefore(pattern)
Returns the trimmed string.
Looks for a pattern in a string and, if the pattern is found, cuts off the string before the first occurrence of the pattern.
Designed for use with ::
function bind syntax, as the this
property should be the string to trim.
operand
String to trim.
pattern
String to look for and trim before.
Use Case
import {fromBefore} from 'from-before'
const filepath = '~/app/node_modules/foo/bar.js'
filepath::fromBefore('node_modules/')
// -> 'node_modules/foo/bar.js`
See Also
const text = 'goodbye cruel world'
text::fromBefore('cruel') // 'cruel world'
text::fromAfter('cruel') // ' world'
text::untilBefore('cruel') // 'goodbye '
text::untilAfter('cruel') // 'goodbye cruel'
Colophon
Made by Sebastiaan Deckers in Singapore 🇸🇬