lib/angular-rails-templates/compact_javascript_escape.rb
def escape_javascript(raw)
      if raw
        quote = raw.count(%{'}) >= raw.count(%{"}) ? %{"} : %{'}
        escaped = raw.gsub(/(\\|\r\n|[\n\r#{quote}])/u) {|match| JS_ESCAPE_MAP[match] }
        "#{quote}#{escaped}#{quote}"
      else
        '""'
      end
    end
def escape_javascript(raw)
      if raw
        quote = raw.count(%{'}) >= raw.count(%{"}) ? %{"} : %{'}
        escaped = raw.gsub(/(\\|\r\n|[\n\r#{quote}])/u) {|match| JS_ESCAPE_MAP[match] }
        "#{quote}#{escaped}#{quote}"
      else
        '""'
      end
    end
We want to deliver the shortist valid javascript escaped string
 Count the number of " vs '
 If more ', escape "
 If more ", escape '
 If equal, prefer to escape "