UNPKG

@botonic/plugin-contentful

Version:

## What Does This Plugin Do?

25 lines 707 B
import escapeStringRegexp from 'escape-string-regexp'; export function ltrim(str, chars) { while (str.length && chars.includes(str[0])) { str = str.slice(1); } return str; } export function rtrim(str, chars) { while (str.length && chars.includes(str[str.length - 1])) { str = str.slice(0, str.length - 1); } return str; } export function trim(str, chars) { str = rtrim(str, chars); return ltrim(str, chars); } /** * String.replaceAll only available in esnext */ export function replaceAll(haystack, oldStr, newStr) { oldStr = escapeStringRegexp(oldStr); return haystack.replace(new RegExp(oldStr, 'g'), newStr); } //# sourceMappingURL=strings.js.map