Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amanda v0.4.0 #35

Merged
merged 304 commits into from Mar 15, 2012
Merged

Amanda v0.4.0 #35

merged 304 commits into from Mar 15, 2012

Conversation

Baggz
Copy link
Owner

@Baggz Baggz commented Mar 14, 2012

Hi everyone!

I would like to introduce you the latest version of Amanda (v0.4.0).

First change (and probably the most important) is a change in the direction. Amanda is no longer just a validation library for JSON Schema. It's aiming to be an universal validation library, currently it supports only the JSON Schema Internet Draft, but I'm planning to add Orderly, Relax NG and others very soon.

Example

/**
 * Schema
 */
var schema = {
  type: 'object',
  properties: {
    name: {
      required: true,
      type: 'string',
      length: 7
    }
  }
};

/**
 * Data
 */
var data = {
  name: 'Kenneth'
};

// Initialize a JSON Schema validator
var jsonSchemaValidator = amanda('json');

// Validate the data against the schema
jsonSchemaValidator.validate(data, schema, function(error) {
  // Do something...
});

Compliant with the JSON Schema Internet Draft

Amanda is now more compliant with the JSON Schema Internet Draft. I have added new attributes.

Also the format attribute supports all formats defined by the JSON Schema Internet Draft plus some custom formats like alpha, alphanumeric, decimal, percentage and others.

Another notable change is that validators has been renamed to attributes. Instead of calling the addValidator method, please use the addAttribute method. This changes also applies to the Error object.

  • addValidatoraddAttribute
  • validatorattribute
  • validatorNameattributeName
  • validatorValueattributeValue
  • ...

Attributes API

The thing I'm the most excited about is enhanced attributes API. You already know you can add a custom attribute.

var myValidator = amanda('json');

/**
 * MyAttribute
 */
var myAttribute = function(property, propertyValue, attributeValue, propertyAttributes, callback) {
  // Do something...
};

myValidator.addAttribute('test', myAttribute);

An error can be reported by calling the addError method.

var myAttribute = function(property, propertyValue, attributeValue, propertyAttributes, callback) {

  if ( ... ) {
    this.addError('Lorem ipsum dolor error!');
  }

  return callback();

}

Attributes are more powerful with the new enhanced attributes API. They have an access to the internal API (via this keyword).

The same applies for internal properties.

  • An instance (this.instance)
  • A schema (this.schema)
  • An Error object (this.errors)
  • All the attributes (this.attributes)

Again, all these methods and properties are available under the this keyword.

Documentation

The documentation has been completely revamped. It could be found in the /docs/ folder. To be noted, the documentation is not complete yet.

Tests

All tests have been rewritten into Mocha in order to test the library in the browser.

Error Messages

More accurate error messages, that's it.

Build

Amanda was separated into multiple files. I hope you and the ‘make’ command get along well.

Conclusion

Although I was trying hard to not break the current API, in some cases it could happen. Please keep this in mind.

František Hába added 30 commits March 7, 2012 20:09
@ghost ghost assigned Baggz Mar 15, 2012
@Baggz Baggz merged commit 01d1e73 into master Mar 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant