Sha256: 7e4e73ec8166c809e0ff49f2b34edc2a7cc8cf92a8cd83655117f0255918da44

Contents?: true

Size: 583 Bytes

Versions: 21

Compression:

Stored size: 583 Bytes

Contents

module Ruby2JS
  class Converter

    # (int 1)
    # (float 1.1)
    # (str "1"))

    handle :str do |value|
      put value.inspect
    end

    handle :int, :float do |value|
      put number_format(value)
    end

    handle :octal do |value|
      put '0' + number_format(value.to_s(8))
    end

    def number_format(number)
      return number.to_s unless es2021
      parts = number.to_s.split('.')
      parts[0] = parts[0].gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1_")
      parts[1] = parts[1].gsub(/(\d\d\d)(?=\d)/, "\\1_") if parts[1]
      parts.join('.')
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ruby2js-5.1.1 lib/ruby2js/converter/literal.rb
ruby2js-5.1.0 lib/ruby2js/converter/literal.rb
ruby2js-5.0.1 lib/ruby2js/converter/literal.rb
ruby2js-5.0.0 lib/ruby2js/converter/literal.rb
ruby2js-4.2.2 lib/ruby2js/converter/literal.rb
ruby2js-4.2.1 lib/ruby2js/converter/literal.rb
ruby2js-4.2.0 lib/ruby2js/converter/literal.rb
ruby2js-4.1.7 lib/ruby2js/converter/literal.rb
ruby2js-4.1.6 lib/ruby2js/converter/literal.rb
ruby2js-4.1.5 lib/ruby2js/converter/literal.rb
ruby2js-4.1.4 lib/ruby2js/converter/literal.rb
ruby2js-4.1.3 lib/ruby2js/converter/literal.rb
ruby2js-4.1.2 lib/ruby2js/converter/literal.rb
ruby2js-4.1.1 lib/ruby2js/converter/literal.rb
ruby2js-4.1.0 lib/ruby2js/converter/literal.rb
ruby2js-4.0.5 lib/ruby2js/converter/literal.rb
ruby2js-4.0.4 lib/ruby2js/converter/literal.rb
ruby2js-4.0.3 lib/ruby2js/converter/literal.rb
ruby2js-4.0.2 lib/ruby2js/converter/literal.rb
ruby2js-4.0.1 lib/ruby2js/converter/literal.rb