<commit_before>module ImportJS
  class Importer
    def import
      variable_name = VIM.evaluate("expand('<cword>')")
      path_to_file = find_path_to_file(variable_name)
      if path_to_file
        require_statement = "var #{variable_name} = require('#{path_to_file}');"
        VIM::Buffer.current.append(0, require_statement)
      else
        VIM.message("No file found for #{variable_name}")
      end
    end

    private

    def camelcase_to_snakecase(string)
      # Grabbed from
      # http://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby
      string.gsub(/::/, '/')
            .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
            .gsub(/([a-z\d])([A-Z])/, '\1_\2')
            .tr('-', '_')
            .downcase
    end

    def find_path_to_file(variable_name)<commit_msg>Don't import empty strings<commit_after>module ImportJS
  class Importer
    def import
      variable_name = VIM.evaluate("expand('<cword>')")
      if variable_name.empty?
        VIM.message('No variable to import. Place your cursor on a variable, then try again')
        return
      end

      path_to_file = find_path_to_file(variable_name)
      if path_to_file
        require_statement = "var #{variable_name} = require('#{path_to_file}');"
        VIM::Buffer.current.append(0, require_statement)
      else
        VIM.message("No file found for #{variable_name}")
      end
    end

    private

    def camelcase_to_snakecase(string)
      # Grabbed from
      # http://stackoverflow.com/questions/1509915/converting-camel-case-to-underscore-case-in-ruby
      string.gsub(/::/, '/')
            .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
            .gsub(/([a-z\d])([A-Z])/, '\1_\2')
            .tr('-', '_')
            .downcase
    end

    def find_path_to_file(variable_name)
{'fraction_non_alphanumeric': 0.15249588590235874, 'fraction_numerical': 0.013165112452002194, 'mean_word_length': 2.448015122873346, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2853982', 'n_tokens_mistral': 639, 'n_tokens_neox': 621, 'n_words': 103}