UNPKG

@technobuddha/library

Version:
23 lines (22 loc) 790 B
import isString from 'lodash/isString'; import escapeRegExp from 'lodash/escapeRegExp'; import unescapeJS from '../unescapeJS'; /** * Remove surrounding quotes from text * * @param input The text to surrounded by quotes * @param __namedParameters see {@link Options} * @default quote double-quote (") * @default escape unescapeJS * @returns the unescaped text with quotes removed */ export function unquote(input, { quote = '"', escape = unescapeJS } = {}) { if (input.startsWith(quote) && input.endsWith(quote)) { input = input.slice(quote.length, input.length - quote.length); if (isString(escape)) return input.replace(new RegExp(escapeRegExp(escape), 'gu'), quote); return escape(input); } return input; } export default unquote;