@feugene/mu
Version:
Helpful TS utilities without dependencies
15 lines (12 loc) • 340 B
text/typescript
import toString from '~/to/toString'
/**
* Checks if string starts with the given target string
*
* @param {string} str
* @param {string} target
* @returns {boolean}
*/
export default function startsWith(str: string, target: string): boolean {
target = toString(target)
return toString(str).slice(0, target.length) === target
}