Skip to content

Commit

Permalink
[UPDATE] lib, tests, examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Feb 20, 2015
1 parent 7273a68 commit 876876b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 19 deletions.
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
string-array
String Array
===
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependencies][dependencies-image]][dependencies-url]

Expand All @@ -17,18 +17,36 @@ For use in the browser, use [browserify](https://github.com/substack/node-browse
## Usage

``` javascript
var foo = require( 'validate.io-string-array' );
var isStringArray = require( 'validate.io-string-array' );
```

#### foo( value )
#### isStringArray( value )

What does this function do?
Validates if a `value` is a `string array`.

``` javascript
var arr = ['a','b','c'];

var bool = isStringArray( value );
// returns true
```

__Note__: the method will return `false` for an empty `array`.


## Examples

``` javascript
var foo = require( 'validate.io-string-array' );
var isStringArray = require( 'validate.io-string-array' );

console.log( isStringArray( ['beep','','foo'] ) );
// returns true

console.log( isStringArray( [] ) );
// returns false

console.log( isStringArray( [1,2,3] ) );
// returns false
```

To run the example code from the top-level application directory,
Expand Down
11 changes: 10 additions & 1 deletion examples/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
'use strict';

var module = require( './../lib' );
var isStringArray = require( './../lib' );

console.log( isStringArray( ['beep','','foo'] ) );
// returns true

console.log( isStringArray( [] ) );
// returns false

console.log( isStringArray( [1,2,3] ) );
// returns false
33 changes: 25 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,37 @@

// MODULES //

// var module_alias = require( 'module_name' );
var isArray = require( 'validate.io-array' ),
isString = require( 'validate.io-string' );


// FUNCTIONS //
// IS STRING ARRAY //

/**
* FUNCTION: foo()
* {{ foo description }}.
* FUNCTION: isStringArray( value )
* Validates if a value is a string array.
*
* @param {*} value - value to be validated
* @returns {Boolean} boolean indicating if a value is a string array
*/
function foo() {

} // end FUNCTION foo()
function isStringArray( value ) {
var len;
if ( !isArray( value ) ) {
return false;
}
len = value.length;
if ( !len ) {
return false;
}
for ( var i = 0; i < len; i++ ) {
if ( !isString( value[i] ) ) {
return false;
}
}
return true;
} // end FUNCTION isStringArray()


// EXPORTS //

module.exports = foo;
module.exports = isStringArray;
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@
"validate.io",
"validate",
"validation",
"validator"
"validator",
"valid",
"string",
"array",
"stringarray",
"is",
"isstringarray"
],
"bugs": {
"url": "https://github.com/validate-io/string-array/issues"
},
"dependencies": {},
"dependencies": {
"validate.io-array": "^1.0.3",
"validate.io-string": "^1.0.2"
},
"devDependencies": {
"chai": "1.x.x",
"mocha": "1.x.x",
Expand Down
37 changes: 34 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var // Expectation library:
chai = require( 'chai' ),

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


// VARIABLES //
Expand All @@ -21,9 +21,40 @@ var expect = chai.expect,
describe( 'validate.io-string-array', function tests() {

it( 'should export a function', function test() {
expect( lib ).to.be.a( 'function' );
expect( isStringArray ).to.be.a( 'function' );
});

it( 'should do something' );
it( 'should positively validate', function test() {
var bool;

bool = isStringArray( ['a','b','c'] );
assert.ok( bool );

bool = isStringArray( [new String('a') ] );
assert.ok( bool );
});

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

for ( var i = 0; i < values.length; i++ ) {
assert.notOk( badValue( values[i] ) );
}
function badValue( value ) {
return isStringArray( value );
}
});

});

0 comments on commit 876876b

Please sign in to comment.