@technobuddha/library
Version:
A large library of useful functions
31 lines (30 loc) • 1.26 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.unquote = void 0;
var isString_1 = __importDefault(require("lodash/isString"));
var escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
var unescapeJS_1 = __importDefault(require("../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
*/
function unquote(input, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.quote, quote = _c === void 0 ? '"' : _c, _d = _b.escape, escape = _d === void 0 ? unescapeJS_1.default : _d;
if (input.startsWith(quote) && input.endsWith(quote)) {
input = input.slice(quote.length, input.length - quote.length);
if (isString_1.default(escape))
return input.replace(new RegExp(escapeRegExp_1.default(escape), 'gu'), quote);
return escape(input);
}
return input;
}
exports.unquote = unquote;
exports.default = unquote;