File: target.rb

package info (click to toggle)
ruby-js-regex 3.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 164 kB
  • sloc: ruby: 1,002; makefile: 3
file content (19 lines) | stat: -rw-r--r-- 454 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class JsRegex
  module Target
    ES2009 = 'ES2009'
    ES2015 = 'ES2015'
    ES2018 = 'ES2018'
    SUPPORTED = [ES2009, ES2015, ES2018].freeze

    def self.cast(arg)
      return ES2009 if arg.nil?

      normalized_arg = arg.to_s.upcase
      return normalized_arg if SUPPORTED.include?(normalized_arg)

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