Giter Site home page Giter Site logo

ka-challenge-analyzer's Introduction

Code Challenge Analyzer

An API for testing JavaScript code for the presence of specific constructs.

##Usage

Dependencies:

  • Esprima parser 2.7.2
  • jQuery 1.12.1
  • normalize.css 3.0.3

To install dependencies, run:

npm install

##Example To view an example implementation, open the analyzer.html file in your browser.
The example implementation in analyzerExample.js has a whitelist that contains a 'while' loop and an 'if' statement, a blacklist that contains a 'variable' declaration, and also looks for an 'if' statement nested inside of a 'for' loop.

##API

This API's current release allows testing for the presence of 'if' statements, 'while' loops, 'for' loops, and variable declarations. It also allows for testing for the presence of one-level-deep nesting of these constructs.

To access the API, initialize a new tester object:

var tester = new Tester();

####Whitelist

The whitelist contains constructs that must be present in the code being analyzed. To add a construct to the whitelist, call:

tester.required(construct string);

Available construct strings: 'if', 'while', 'for', 'variable'.

To analyze code using the whitelist:

tester.findRequired(input string);

.findRequired eturns an error string if the constructs in the whitelist are not found, eg. "The program MUST use an 'if statement'.". Returns null if whitelist constructs are present.

####Blacklist

The blacklist contains constructs that must not be present in the code being analyzed. To add a construct to the blacklist, call:

tester.banned(construct string)

Available construct strings: 'if', 'while', 'for', 'variable'

To analyze code using the blacklist:

tester.findBanned(input string);

.findBanned returns an error string if the constructs in the blacklist are present, eg. "The program MUST NOT use an 'if statement'.". Returns null if blacklist constructs are not present.

####Nested constructs

To specify constructs that should be nested, call:

tester.nested(outer construct, inner construct)

Available constructs: 'if', 'while', 'for', 'variable'

To analyze code for nested constructs, call:

tester.findNested(input string);

.findNested returns an error string if the nesting is not present, eg. "There should be a 'while loop' and inside of it there should be an 'if statement'". Returns null if nested construct is found.

ka-challenge-analyzer's People

Contributors

delphinefoo avatar

Watchers

James Cloos avatar  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.