Advertisement
mateon1

Minifier

Mar 29th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Minify a function...
  2.  
  3. FUNCTION.toString()
  4.     .replace(/\/\/.*?\n/g, "")  // "//" comments
  5.     .replace(/\/\*.*?\*\//, "") // "/**/" comments
  6.     .replace(/\s+/g, " ")       // Replace multiple spaces with one space
  7.     .replace(/([^\w])\s/g, "$1")    // Remove spaces after non-alphanumeric characters (;.,[]{}()<>=-+ etc.)
  8.     .replace(/\s([^\w])/g, "$1")    // Remove spaces before non-alphanum chars
  9.     .replace(/console\.log\(.*?\)([;}])/g, "$1") // Remove console.log()
  10.     .replace(/;+/g, ";")        // Remove multiple semicolons
  11.     .replace(/{;/g, "{")        // Remove semicolons after a {
  12.     .replace(/;}/g, "}");       // remove semicolons before a }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement