Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including jslint-lite with all npm packages installed. Try it out:

var jslintLite = require("jslint-lite")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

jslint-lite v2016.12.1

this zero-dependency package will provide browser-compatible versions of jslint and csslint

jslint-lite

this zero-dependency package will provide browser-compatible versions of jslint and csslint

travis-ci.org build-status istanbul coverage

NPM

package-listing

cdn download

live demo

github.com test-server

documentation

api-doc

api-doc

todo

  • none

change since 8b03a6a4

  • npm publish 2016.12.1
  • update documentation
  • fix cdn link
  • none

this package requires

  • darwin or linux os

additional info

  • csslint code derived from https://github.com/CSSLint/csslint/blob/v0.10.0/release/csslint.js
  • jslint code derived from https://github.com/douglascrockford/JSLint/blob/394bf291bfa3881bb9827b9fc7b7d1112d83f313/jslint.js

build-status travis-ci.org build-status

build commit status

git-branch :masterbetaalpha
test-server-1 :github.com test-servergithub.com test-servergithub.com test-server
test-server-2 :heroku.com test-serverheroku.com test-serverheroku.com test-server
test-report :test-reporttest-reporttest-report
coverage :istanbul coverageistanbul coverageistanbul coverage
build-artifacts :build-artifactsbuild-artifactsbuild-artifacts

master branch

  • stable branch
  • HEAD should be tagged, npm-published package

beta branch

  • semi-stable branch
  • HEAD should be latest, npm-published package

alpha branch

  • unstable branch
  • HEAD is arbitrary
  • commit history may be rewritten

quickstart web example

screen-capture

to run this example, follow the instruction in the script below

/*
example.js

this script will will demo the browser-version of jslint and csslint

instruction
    1. save this script as example.js
    2. run the shell command:
        $ npm install jslint-lite && \
            export PORT=8081 && \
            node example.js
    3. play with the browser-demo on http://localhost:8081
*/

/* istanbul instrument in package jslint-lite */
/*jslint
    bitwise: true,
    browser: true,
    maxerr: 8,
    maxlen: 96,
    node: true,
    nomen: true,
    regexp: true,
    stupid: true
*/
(function () {
    'use strict';
    var local;



    // run shared js-env code - pre-init
    (function () {
        // init local
        local = {};
        // init modeJs
        local.modeJs = (function () {
            try {
                return typeof navigator.userAgent === 'string' &&
                    typeof document.querySelector('body') === 'object' &&
                    typeof XMLHttpRequest.prototype.open === 'function' &&
                    'browser';
            } catch (errorCaughtBrowser) {
                return module.exports &&
                    typeof process.versions.node === 'string' &&
                    typeof require('http').createServer === 'function' &&
                    'node';
            }
        }());
        // init global
        local.global = local.modeJs === 'browser'
            ? window
            : global;
        // init utility2_rollup
        local = local.global.utility2_rollup || (local.modeJs === 'browser'
            ? local.global.utility2_jslint
            : require('jslint-lite'));
        // export local
        local.global.local = local;
    }());
    switch (local.modeJs) {



    // run browser js-env code - post-init
    case 'browser':
        /* istanbul ignore next */
        local.testRun = function (event) {
            switch (event && event.currentTarget.id) {
            case 'testRunButton1':
                // show tests
                if (document.querySelector('#testReportDiv1').style.display === 'none') {
                    document.querySelector('#testReportDiv1').style.display = 'block';
                    document.querySelector('#testRunButton1').innerText = 'hide internal test';
                    local.modeTest = true;
                    local.testRunDefault(local);
                // hide tests
                } else {
                    document.querySelector('#testReportDiv1').style.display = 'none';
                    document.querySelector('#testRunButton1').innerText = 'run internal test';
                }
                break;
            default:
                // reset stdout
                document.querySelector('#outputTextarea2').value = '';
                // jslint #inputTextareaJslint1
                local.jslint.jslintAndPrint(
                    document.querySelector('#inputTextareaJslint1').value,
                    'inputTextareaJslint1.js'
                );
                document.querySelector('#outputPreJslint1').textContent =
                    local.jslint.errorText
                    .replace((/\u001b\[\d+m/g), '')
                    .trim();
                // csslint #inputTextareaCsslint1
                local.jslint.jslintAndPrint(
                    document.querySelector('#inputTextareaCsslint1').value,
                    'inputTextareaCsslint1.css'
                );
                document.querySelector('#outputPreCsslint1').textContent =
                    local.jslint.errorText
                    .replace((/\u001b\[\d+m/g), '')
                    .trim();
                // try to eval input-code
                try {
                    /*jslint evil: true*/
                    eval(document.querySelector('#inputTextareaJslint1').value);
                } catch (errorCaught) {
                    console.error(errorCaught.stack);
                }
                // scroll stdout to bottom
                document.querySelector('#outputTextarea2').scrollTop =
                    document.querySelector('#outputTextarea2').scrollHeight;
            }
        };
        // log stderr and stdout to #outputTextarea2
        ['error', 'log'].forEach(function (key) {
            console['_' + key] = console[key];
            console[key] = function () {
                console['_' + key].apply(console, arguments);
                document.querySelector('#outputTextarea2').value +=
                    Array.from(arguments).map(function (arg) {
                        return typeof arg === 'string'
                            ? arg
                            : JSON.stringify(arg, null, 4);
                    }).join(' ') + '\n';
            };
        });
        // init event-handling
        ['click', 'keyup'].forEach(function (event) {
            Array.from(document.querySelectorAll('.on' + event)).forEach(function (element) {
                element.addEventListener(event, local.testRun);
            });
        });
        // run tests
        local.testRun();
        break;



    /* istanbul ignore next */
    // run node js-env code - post-init
    case 'node':
        // export local
        module.exports = local;
        // require modules
        local.fs = require('fs');
        local.http = require('http');
        local.path = require('path');
        local.url = require('url');
        // init assets
        /* jslint-ignore-begin */
        local.templateIndexHtml = '\
<!doctype html>\n\
<html lang="en">\n\
<head>\n\
<meta charset="UTF-8">\n\
<meta name="viewport" content="width=device-width, initial-scale=1">\n\
<title>{{env.npm_package_name}} v{{env.npm_package_version}}</title>\n\
<style>\n\
/*csslint\n\
    box-sizing: false,\n\
    ids: false,\n\
    universal-selector: false\n\
*/\n\
* {\n\
    box-sizing: border-box;\n\
}\n\
body {\n\
    background: #fff;\n\
    font-family: Arial, Helvetica, sans-serif;\n\
    margin: 1rem;\n\
}\n\
body > * {\n\
    margin-bottom: 1rem;\n\
}\n\
#outputPreCsslint1,\n\
#outputPreJslint1 {\n\
    color: #d00;\n\
}\n\
textarea {\n\
    font-family: monospace;\n\
    height: 10rem;\n\
    width: 100%;\n\
}\n\
textarea[readonly] {\n\
    background: #ddd;\n\
}\n\
</style>\n\
</head>\n\
<body>\n\
<!-- utility2-comment\n\
    <div id="ajaxProgressDiv1" style="background: #d00; height: 2px; left: 0; margin: 0; padding: 0; position: fixed; top: 0; transition: background 0.5s, width 1.5s; width: 25%;"></div>\n\
utility2-comment -->\n\
    <h1>\n\
<!-- utility2-comment\n\
        <a\n\
            {{#if env.npm_package_homepage}}\n\
            href="{{env.npm_package_homepage}}"\n\
            {{/if env.npm_package_homepage}}\n\
            target="_blank"\n\
        >\n\
utility2-comment -->\n\
            {{env.npm_package_name}} v{{env.npm_package_version}}\n\
<!-- utility2-comment\n\
        </a>\n\
utility2-comment -->\n\
    </h1>\n\
    <h3>{{env.npm_package_description}}</h3>\n\
<!-- utility2-comment\n\
    <h4><a download href="assets.app.js">download standalone app</a></h4>\n\
    <button class="onclick" id="testRunButton1">run internal test</button><br>\n\
    <div id="testReportDiv1" style="display: none;"></div>\n\
utility2-comment -->\n\
\n\
    <div>edit or paste script below to\n\
        <a href="http://www.jslint.com" target="_blank">jslint</a>\n\
    </div>\n\
<textarea class="onkeyup" id="inputTextareaJslint1">\n\
/*jslint\n\
    browser: true,\n\
    es6: true\n\
*/\n\
const message = "hello";\n\
console.log(message);\n\
console.log(null);\n\
</textarea>\n\
    <pre id="outputPreJslint1"></pre>\n\
    <div>edit or paste script below to\n\
        <a \n\
            href="https://github.com/CSSLint/csslint/wiki/Command-line-interface#options" \n\
            target="_blank"\n\
        >csslint</a>\n\
    </div>\n\
<textarea class="onkeyup" id="inputTextareaCsslint1">\n\
/*csslint\n\
    box-sizing: false,\n\
*/\n\
body {\n\
    box-sizing: border-box;\n\
    margin: 0px;\n\
}\n\
</textarea>\n\
    <pre id="outputPreCsslint1"></pre>\n\
    <label>stderr and stdout</label>\n\
    <textarea id="outputTextarea2" readonly></textarea>\n\
<!-- utility2-comment\n\
    {{#if isRollup}}\n\
    <script src="assets.app.min.js"></script>\n\
    {{#unless isRollup}}\n\
utility2-comment -->\n\
    <script src="assets.utility2.rollup.js"></script>\n\
    <script src="jsonp.utility2._stateInit?callback=window.utility2._stateInit"></script>\n\
    <script src="assets.jslint-lite.js"></script>\n\
    <script src="assets.example.js"></script>\n\
    <script src="assets.test.js"></script>\n\
<!-- utility2-comment\n\
    {{/if isRollup}}\n\
utility2-comment -->\n\
</body>\n\
</html>\n\
';
        /* jslint-ignore-end */
        local['/'] = local.templateIndexHtml
            .replace((/\{\{env\.(\w+?)\}\}/g), function (match0, match1) {
                // jslint-hack
                String(match0);
                switch (match1) {
                case 'npm_package_description':
                    return 'example module';
                case 'npm_package_name':
                    return 'example';
                case 'npm_package_version':
                    return '0.0.1';
                }
            });
        if (local.global.utility2_rollup) {
            break;
        }
        try {
            local['/assets.example.js'] = local.fs.readFileSync(__filename, 'utf8');
        } catch (ignore) {
        }
        local['/assets.jslint-lite.js'] = '//' + local.fs.readFileSync(
            local.jslint.__dirname + '/lib.jslint.js',
            'utf8'
        );
        // run the cli
        if (module !== require.main) {
            break;
        }
        // start server
        console.log('server starting on port ' + process.env.PORT);
        local.http.createServer(function (request, response) {
            switch (local.url.parse(request.url).pathname) {
            case '/':
            case '/assets.example.js':
            case '/assets.jslint-lite.js':
            case '/assets.test.js':
                response.end(local[local.url.parse(request.url).pathname]);
                break;
            default:
                response.end();
            }
        }).listen(process.env.PORT);
        // if $npm_config_timeout_exit exists,
        // then exit this process after $npm_config_timeout_exit ms
        if (Number(process.env.npm_config_timeout_exit)) {
            setTimeout(process.exit, Number(process.env.npm_config_timeout_exit));
        }
        break;
    }
}());

output from electron

screen-capture

output from shell

screen-capture

package.json

{
    "package.json": true,
    "author": "kai zhu <kaizhu256@gmail.com>",
    "bin": { "jslint-lite": "lib.jslint.js" },
    "description": "{{packageJson.description}}",
    "devDependencies": {
        "electron-lite": "kaizhu256/node-electron-lite#alpha",
        "utility2": "kaizhu256/node-utility2#alpha"
    },
    "engines": { "node": ">=4.0" },
    "homepage": "https://github.com/kaizhu256/node-jslint-lite",
    "keywords": [
        "browser",
        "csslint",
        "eshint", "eslint",
        "jshint", "jslint",
        "lint",
        "web"
    ],
    "license": "MIT",
    "main": "lib.jslint",
    "name": "jslint-lite",
    "os": ["darwin", "linux"],
    "repository" : {
        "type" : "git",
        "url" : "https://github.com/kaizhu256/node-jslint-lite.git"
    },
    "scripts": {
        "build-ci": "utility2 shRun shReadmeBuild",
        "start": "\
export PORT=${PORT:-8080} && \
export npm_config_mode_auto_restart=1 && \
utility2 shRun shIstanbulCover test.js",
        "test": "export PORT=$(utility2 shServerPortRandom) && utility2 test test.js"
    },
    "version": "2016.12.1"
}

changelog of last 50 commits

screen-capture

internal build-script

  • build.sh
# build.sh

# this shell script will run the build for this package

shBuildCiTestPre() {(set -e
# this function will run the pre-test build
    # test example.js
    (export MODE_BUILD=testExampleJs &&
        shRunScreenCapture shReadmeTestJs example.js) || return $?
    # test published-package
    (export MODE_BUILD=npmTestPublished &&
        shRunScreenCapture shNpmTestPublished) || return $?
)}

shBuildCiTestPost() {(set -e
# this function will run the post-test build
    # if running legacy-node, then return
    [ "$(node --version)" \< "v7.0" ] && return || true
    export NODE_ENV=production
    # deploy app to gh-pages
    (export MODE_BUILD=deployGithub &&
        shDeployGithub) || return $?
    # deploy app to heroku
    (export MODE_BUILD=deployHeroku &&
        shDeployHeroku) || return $?
)}

shBuild() {(set -e
# this function will run the main build
    # init env
    . node_modules/.bin/utility2 && shInit
    # cleanup github-gh-pages dir
    # export BUILD_GITHUB_UPLOAD_PRE_SH="rm -fr build"
    # init github-gh-pages commit-limit
    export COMMIT_LIMIT=16
    # if branch is alpha, beta, or master, then run default build
    if [ "$CI_BRANCH" = alpha ] ||
        [ "$CI_BRANCH" = beta ] ||
        [ "$CI_BRANCH" = master ]
    then
        shBuildCiDefault
    fi
)}
shBuild
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free