Giter Site home page Giter Site logo

jsmin's Introduction

JSMin

This repository contains the Windows application jsmin.exe and the jsmin function. If you just want to use the jsmin command, just download jsmin.exe or compile yourself.

Compilation example

For Windows, please add the extension .exe

gcc jsmin.c lib/jsmin.c -o jsmin

Command

This command erases extra whitespace and comments in the javascript code, making it one line and reducing the file size.

Before

var sample = 100
log(sample)

// sample function
function log(num) {
  if (num > 50) {
    console.log("examples of use")
  } else num += 20
}

After

var sample=100;log(sample);function log(num){if(num>50){console.log("examples of use")}else num+=20}

Usage

jsmin example.js

When a file name is specified in the command line argument of jsmin, a file such as example.min.js is created in the same directory, and the compression result is output to this file.

jsmin input.js -o output.js

You can also specify the destination file with the -o (--output) option. You can also write jsmin -o output.js input.js.

jsmin example.js -w

In addition, the -w (--overwerite) option will overwrite the original file without creating a new file.You can also write jsmin -w example.js.

jsmin -h

Use the -h (--help) option to see how to use jsmin

Usage: jsmin <file> [options...]

Options:
  -o, --output <file>  write to <file> instead of writing in '...min.js'
  -w, --overwrite      overwrite the file
  -h, --help           get help for commands
  -v, --version        show jsmin version

Jsmin function

#include "lib/jsmin.h"

char *jsmin(char *code)

Parameters:

code - Original javascript code

Returns:

Minified javascript code

Example

Directory
 ├ example.c
 └ lib
    ├ jsmin.h
    └ jsmin.hc
// example.c

#include <stdio.h>
#include "lib/jsmin.h"

int main() {

    FILE *fp = fopen("example.js", "r+");
    
    // Get the contents of example.js
    int i = 0;
    char code[100000];
    while((code[i] = fgetc(fp)) != EOF) i++;
    code[i] = '\0';

    char *result = jsmin(code); // <-- Minify the code here

    // Overwrite the file
    fputs(result, fp);
    fclose(fp);

    return 0;
}

Compile

gcc example.c lib/jsmin.c -o jsmin

This console application minifies example.js by overwriting it.

jsmin's People

Contributors

cromite avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.