Skip to content

Commit

Permalink
[UPDATE] add anagram and alphagram validators.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Apr 25, 2015
1 parent 9a3f760 commit 278f418
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
27 changes: 27 additions & 0 deletions README.md
Expand Up @@ -271,6 +271,33 @@ validate( 'uppercase', 'Beep' );
__Note__: validates that a `value` is a `string`.


##### [anagram](https://github.com/validate-io/anagram)

Validates if a `value` is an anagram.

``` javascript
validate( 'anagram[dog]', 'god' );
// returns true

validate( 'anagram[beep]', 'hello' );
// returns false
```



##### [alphagram](https://github.com/validate-io/alphagram)

Validates if a `value` is an alphagram.

``` javascript
validate( 'alphagram', 'beep' );
// returns true

validate( 'alphagram', 'hello' );
// returns false
```

__Note__: the `function` returns `false` if provided a non-string value.


===
Expand Down
16 changes: 15 additions & 1 deletion lib/index.js
Expand Up @@ -112,7 +112,7 @@ validate.number_array_max = function( value, max ) {
}; // end METHOD number_array_max

/**
* METHOD: size( valid, size )
* METHOD: size( value, size )
* Validates if a value is a multidimensional array of specified dimensions.
*
* @param {*} value - value to be validated
Expand Down Expand Up @@ -148,6 +148,20 @@ validate.string = require( 'validate.io-string' );
validate.alphanumeric = require( 'validate.io-alphanumeric' );
validate.lowercase = require( 'validate.io-lowercase' );
validate.uppercase = require( 'validate.io-uppercase' );
validate.alphagram = require( 'validate.io-alphagram' );

/**
* METHOD: anagram( value, str )
* Validates if a value is an anagram of a specified string.
*
* @param {*} value - value to be validated
* @param {String} str - comparison string
* @returns {Boolean} boolean indicating if the value is an anagram
*/
var anagram = require( 'validate.io-anagram' );
validate.anagram = function( value, str ) {
return anagram( str, value );
}; // end METHOD anagram()


/**
Expand Down
49 changes: 49 additions & 0 deletions test/test.alphagram.js
@@ -0,0 +1,49 @@
/* global require, describe, it */
'use strict';

// MODULES //

var // Expectation library:
chai = require( 'chai' ),

// Module to be tested:
validate = require( './../lib' );


// VARIABLES //

var expect = chai.expect,
assert = chai.assert;


// TESTS //

describe( 'input-validation', function tests() {

describe( 'alphagram', function tests() {

it( 'should positively validate', function test() {
assert.ok( validate( 'alphagram', 'beep' ) );
});

it( 'should negatively validate', function test() {
var values = [
5,
[],
'hello',
true,
function(){},
null,
{},
NaN,
undefined
];

for ( var i = 0; i < values.length; i++ ) {
assert.notOk( validate( 'alphagram', values[i] ) );
}
});

});

});
49 changes: 49 additions & 0 deletions test/test.anagram.js
@@ -0,0 +1,49 @@
/* global require, describe, it */
'use strict';

// MODULES //

var // Expectation library:
chai = require( 'chai' ),

// Module to be tested:
validate = require( './../lib' );


// VARIABLES //

var expect = chai.expect,
assert = chai.assert;


// TESTS //

describe( 'input-validation', function tests() {

describe( 'anagram', function tests() {

it( 'should positively validate', function test() {
assert.ok( validate( 'anagram[dog]', 'god' ) );
});

it( 'should negatively validate', function test() {
var values = [
5,
[],
'hello',
true,
function(){},
null,
{},
NaN,
undefined
];

for ( var i = 0; i < values.length; i++ ) {
assert.notOk( validate( 'anagram[beep]', values[i] ) );
}
});

});

});

0 comments on commit 278f418

Please sign in to comment.