Code Monkey home page Code Monkey logo

ratify's Introduction

About Ratify

Ratify is a collection of utilities to perform validation checks and parsing. The main intention of usage for this is in web-applications in order to check form inputs for correctness and automatically parse them into their proper representations or return meaningful errors.

How To

Ratify has a load of TEST-* functions, each accompanied by a predicate equivalent. The TEST-* functions will signal errors of type RATIFICATION-ERROR if the test fails, whereas the predicates will simply return NIL. Both will return the passed argument unmodified on success. Some of the tests have an equivalent PARSE-* function in order to turn the string into a more useful representation.

The main interaction with Ratify is not supposed to be directly with the TEST-* and PARSE-* functions however, but rather through the TEST and PARSE wrapper functions. Both also have a macro shorthand to perform many tests and parsings at once, PERFORM-COMBINED-TESTS and WITH-PARSED-FORMS. These macros will perform as many tests as possible and only signal an error right after all tests have been made. This error is of type COMBINED-ERROR, which contains all the errors that occurred during the testing.

(ratify:perform-combined-tests
  (:integer "45")
  (:date "2014-08-01")
  (:ratio "566/21"))

(ratify:perform-combined-tests
  (:integer "4.5" "e")
  (:date "2014-08-01" "2014" "2014-55-99")
  (:ratio "566/21" "5.6/21"))
; Evaluation aborted on #<RATIFY-TESTING:COMBINED-ERROR {10074E51D3}>.

Or to perform parsing:

(let ((int "45")
      (url "http://foo.bar/baz.jp?what=ever#hashtag")
      (uri "things-are://sometimes:[email protected]/damn?protocols=i'm#telling+you!")
      (dt "2014-08-01T21:23:01"))
  (ratify:with-parsed-forms ((:integer int) (:url url) (:uri uri) (:datetime dt))
    (list int url uri dt)))

If an error occurs, the ERRORS function gives access to the list of errors that the COMBINED-ERROR contains. For a complete list of testing and parsing functions, please see the symbol index. The syntax grammar used to describe the valid values in the docstrings of each test is regex with the addition of <brackets> to refer to other tests, sometimes accompanied with a second line that describes limits of the values.

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.