--[[*
 * Create a regular expression from the given regex source string.
 *
 * ```js
 * const picomatch = require('picomatch');
 * // picomatch.toRegex(source[, options]);
 *
 * const { output } = picomatch.parse('*.js');
 * console.log(picomatch.toRegex(output));
 * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
 * ```
 * @param {String} `source` Regular expression source string.
 * @param {Object} `options`
 * @return {RegExp}
 * @api public
 ]]


function picomatch.toRegex(source: string, options: Object?)
	local ok, result = pcall(function()
		local opts: Object = options or {}
		return RegExp(
			source,
			Boolean.toJSBoolean(opts.flags) and opts.flags or if Boolean.toJSBoolean(opts.nocase) then "i" else ""
		)
	end)
	if not ok then
		local err = result
		if options ~= nil and options.debug == true then
			error(err)
		end
		return RegExp("$^")
	end
	return result
end
