module JsRegex::Target

Constants

ES2009
ES2015
ES2018
SUPPORTED

Public Class Methods

cast(arg) click to toggle source
# File lib/js_regex/target.rb, line 8
def self.cast(arg)
  return ES2009 if arg.nil?

  normalized_arg = arg.to_s.upcase.sub(/^(ECMASCRIPT|ES|JAVASCRIPT|JS)? ?/, 'ES')
  return normalized_arg if SUPPORTED.include?(normalized_arg)

  raise ArgumentError.new(
    "Unknown target: #{arg.inspect}. Try one of #{SUPPORTED}."
  ).extend(JsRegex::Error)
end