UNPKG

@technobuddha/library

Version:
19 lines (18 loc) 635 B
import escapeRegExp from 'lodash/escapeRegExp'; import isFunction from 'lodash/isFunction'; import escapeJS from '../escapeJS'; import build from '../build'; /** * Surround text with quotes * * @param input The text to surround * @param __namedParameters see {@link Options} * @default quote double-quote (") * @deffaultValue escape {@link escapeJs} * @returns text surrounded by quotes */ export function quote(input, { quote: q = '"', escape = escapeJS } = {}) { input = isFunction(escape) ? escape(input) : input.replace(new RegExp(escapeRegExp(q), 'ug'), escape); return build(q, input, q); } export default quote;