Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Created March 26, 2010 15:40
Show Gist options
  • Save ecounysis/345022 to your computer and use it in GitHub Desktop.
Save ecounysis/345022 to your computer and use it in GitHub Desktop.
#light
open System.Text.RegularExpressions
let minify js =
let replace (m:string) (r:string) (s:string) = Regex.Replace(s, m, r)
js
|> replace "\n\f" " "
|> replace "\n" " "
|> replace "\s{2,}" " "
|> replace "\{ " "{"
|> replace "\ }" "}"
|> replace "\) " ")"
|> replace " \(" "("
|> replace " = " "="
|> replace " \+ " "+"
|> replace " - " "-"
|> replace " \* " "*"
|> replace " / " "/"
|> replace ", " ","
open System.IO
let openFile (file:string) =
let sw = new StreamReader(file)
let it = sw.ReadToEnd()
sw.Close()
it
let writeFile (file:string) (the_string:string) =
let sw = new StreamWriter(file)
sw.Write(the_string)
sw.Close()
()
[]
let main args =
openFile args.[0]
|> minify
|> writeFile args.[1]
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment