Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3593502
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:35:09+00:00 2026-05-18T19:35:09+00:00

I am just starting up a new web application and I want to implement

  • 0

I am just starting up a new web application and I want to implement some form of contract’esque style validation in my JavaScript. I did some quick googling, and came across JsContact but the syntax isn’t quite what I had in mind. Is anyone aware of other libraries?

I am thinking I want the syntax to be something like

String.prototype.padLeft = function(c, width) {
  Verify.value(c).isRequired().isNotNull().isChar();
  Verify.value(width).isRequired().isNotNull().isNumber().greaterThan(0);

  ...

  Verify.value(result).isNotNull();

  return result;
};

Although it won’t take long to put together my own library that has the syntax/methods I want, if someone else has already done the work and it is close enough, it will save me some time. Thanks in advance.

UPDATE

I won’t have time to work on this until this afternoon, so I will give it a few more hours to see if anyone has any recommendations. If not, I will post whatever I create up somewhere as an answer below for other people to reference if they desire.

I have also given a little more thought to the API that would make sense, and I am currently thinking something like (contrived examples):

 function searchUser(firstName, middleInit, lastName) {
   Verify.value(firstName).isString().matching(/\w+/);       // Must have value
   Verify.value(middleInit).whenNotNull().isChar();          // May be null, but not undefined
   Verify.value(lastName).isString().withMinimumLengthOf(2); // Must have value

   ...
 }

 function syncTime(serverTime, now) {
   Verify.value(serverTime).isDate();         // Must have value.
   Verify.value(now).whenDefined().isDate();  // May be undefined, but not null.

 }

My current thought is that tolerating NULL or UNDEFINED values is atypical (at least for me?), as such, rather than explicitly specifying that a value .isNotNull() you would actually disable the rule for .whenDefined() or .whenNotNull() as shown above. I may make .whenNotNull() not error on UNDEFINED, but I see NULL vs. UNDEFINED as an important distinction; we’ll see… all other methods will be pretty typical… thoughts? comments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:35:09+00:00Added an answer on May 18, 2026 at 7:35 pm

    Given that no one has recommended any existing libraries, or that I am crazy for thinking this is a good idea I went ahead and threw together a basic library. The code isn’t fancy, but it does what I want, and it is reasonably fast to run (approx 40 chained checks per ms in IE).

    I settled on a final syntax like:

    function syncTime(serverTime, now) {
      Verify.value(serverTime).always().isDate();   // Cannot be undefined or null.
      Verify.value(now).whenDefined().isDate();     // Cannot be null, but must be date when defined.
    
      //Code
    }
    
    function searchForUser(firstName, middleInit, lastName) {
      Verify.value(firstName).always().isString().withMinimumLengthOf(2);  // Cannot be undefined or null.
      Verify.value(lastName).always().isString().withMinimumLengthOf(2);   // Cannot be undefined or null.
      Verify.value(middleInit).whenNotNull().isChar().between('A', 'Z');   // Cannot be undefined, but must be single char string when not null.
    
      //Code
    }
    

    I opted for an explicit ‘Must Have Value’ via the .always() check, personally I found it nicer to read; but I could see some going another way.

    Given that the source is more than I want to post in this answer, please head to this CodePlex Wiki Page if you are interested in the source. I guess it turned in to more of a fluent assertion library; but it does what I need.

    Update

    I updated the source on the linked CodePlex page above. Specifically, I restructed the Verify class to make use of a ‘value context’ rather than always building new Verifier objects; improved IE’s performance greatly (never was an issue with FireFox or Chrome)… now handles about 100 chained checks per ms in IE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When starting out with a new application, would you rather just use an existing
I am starting a new project trying to create a web application for an
I'm just starting a new project and I am getting some really weird stuff
I'm just working on a web application with sencha touch. I need to implement
I'm very new to Catalyst and just starting building up a web app to
I'm starting up a new web application. It's going to be hosted on a
I just need some guidance. I'm fairly new to MVC3 and to web development
I'm just starting up a new ATL/WTL project and I was wondering if the
I'm new to the Entities Framework, and am just starting to play around with
I am just in a process of starting a new task, wherein in i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.