Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 38 lines (31 sloc) 0.985 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
# Description:
# URL encoding and decoding
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot url encode|decode <query> - URL encode or decode <string>
# hubot url form encode|decode <query> - URL form-data encode or decode <string>
#
# Author:
# jimeh

module.exports = (robot) ->
  robot.respond /URL encode( me)? (.*)/i, (msg) ->
    msg.send encodeURIComponent(msg.match[2])

  robot.respond /URL decode( me)? (.*)/i, (msg) ->
    msg.send decodeURIComponent(msg.match[2])

  robot.respond /URL form encode( me)? (.*)/i, (msg) ->
    msg.send urlFormEncode(msg.match[2])

  robot.respond /URL form decode( me)? (.*)/i, (msg) ->
    msg.send urlFormDecode(msg.match[2])

# url form-data encoding helpers (partially ripped from jshashes npm package)
urlFormEncode = (str) ->
  escape(str)
    .replace(new RegExp('\\+','g'),'%2B')
    .replace(new RegExp('%20','g'),'+')

urlFormDecode = (str) ->
  unescape(str.replace(new RegExp('\\+','g'), ' '))
Something went wrong with that request. Please try again.