Giter Club home page Giter Club logo

arrg's Introduction

arrg

An argument processor / type checker / code writer

The intent is to ultimately implement a declarative syntax for rules of a library or API.

This could be used dynamically to validate arguments passed to an API against a set of rules or to generate code that efficiently does this. This could effectively reduce all of the boilerplate argument processing code in a JS project as well as automatically generate documentation. It could also be viewed as a shim to add some amount of typing to JS.

An AMD module that slurped in rule text (which is really just JSON) and produced the efficient argument processing code could also be another step. In this way you could make what is effectively precompilers for JS which took a declarative syntax for code generation.

Currently a simple argument checking system check.js is the only piece somewhat fully implemented. It can take simple prose such as "I need an integer which is > 2 and < 5" and check all of these things. It's not a NLP, but that would be fun :)

A potential readme syntax guide for the processor follows:


/**                                                                                                                      
 *                                                                                                                       
 * process(rules, arguments)                                                                                             
 * Array of rules or just one rule. A rule is a simple string for a type check / conditional or a complex object         
 * TODO: function as a rule (generally bypasses the declarative system for unhandled cases)                              
 * type: regex of acceptable types /function|integer/.                                                                   
 *      There are special numeric types (integer, natural/positive, whole/positiveInclZero,                              
 *      negative, negativeInclZero, between#And#, between#IAnd#I)                                                        
 * required: true or false                                                                                               
 * default: a default value, checked against type                                                                        
 * alias: an alternative name {string} or array of alternative names [{string}]                                          
 * members: if type has object or array, this lists the members                                                          
 *      the value of a member "memberFoo": {} is treated as a rule                                                       
 *      if type has array, the value of the "members" can be an array of rules or a rule to all members                  
 * typeMemberMap: maps type to an object member { function: "afterFoo" }                                                 
 *      only valid when "members" exists                                                                                 
 * valMap: maps one value to another { "fast": 500 }                                                                     
 *      also can map an accepted type to a function that returns another accepted type                                   
 *      { "string": function(val) { return val.parseInt(); } }                                                           
 *                                                                                                                       
 *  @return {array|typePassed} the array of processed args                                                               
 *                                                                                                                       
 *                                                                                                                       
 * in the future doc should be pluggable with templates                                                                  
 * doc(rules)                                                                                                            
 *                                                                                                                       
 * configure(config)                                                                                                     
 * inlineErrors:                                                                                                         
 * logLevel:                                                                                                             
 */   

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.