[][src]Function minifier::js::minify_and_replace_keywords

pub fn minify_and_replace_keywords<'a>(
    source: &'a str,
    keywords_to_replace: &'a [(Keyword, &str)]
) -> Tokens<'a>

Minifies a given JS source code and to replace keywords.

Example

extern crate minifier;
use minifier::js::{Keyword, minify_and_replace_keywords};

fn main() {
    let js = r#"
        function replaceByNull(data, func) {
            for (var i = 0; i < data.length; ++i) {
                if func(data[i]) {
                    data[i] = null;
                }
            }
        }
    }"#.into();
    let js_minified = minify_and_replace_keywords(js, &[(Keyword::Null, "N")]);
    println!("{}", js_minified.to_string());
}

The previous code will have all its null keywords replaced with N. In such cases, don't forget to include the definition of N in the returned minified javascript:

var N = null;