Skip to content

Commit

Permalink
feat(odd): added even and odd methods, closes #66
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Apr 6, 2016
1 parent c3fe749 commit 57a7a20
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 15 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ for advice and examples.

* **API**
* [check.email](#checkemail)
* [check.odd and check.even](#checkodd-and-checkeven)
* [check.port](#checkport)
* [check.systemPort](#checksystemport)
* [check.userPort](#checkuserport)
Expand Down Expand Up @@ -137,6 +138,16 @@ check.email('me@foo.bar') // true
check.email('me.foo.bar') // false
```

#### check.odd and check.even

Check if a number odd or even

```js
check.odd(2) // false
check.odd(3) // true
check.even(2) // true
```

#### check.port

Returns true if passed argument is positive number less or equal to largest
Expand Down
34 changes: 27 additions & 7 deletions dist/check-more-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,24 @@ return /******/ (function(modules) { // webpackBootstrap
x.indexOf(prefix) === 0
}

/**
Checks if given number is even
@method even
*/
function even (n) {
return n % 2 === 0
}

/**
Checks if given number is odd
@method odd
*/
function odd (n) {
return n % 2 === 1
}

/**
Checks if the given item is the given {arrya, string}
Expand Down Expand Up @@ -656,17 +674,19 @@ return /******/ (function(modules) { // webpackBootstrap
}

module.exports = {
found: found,
startsWith: startsWith,
allSame: allSame,
contains: contains,
type: curry2(type),
even: even,
found: found,
hexRgb: hexRgb,
index: index,
odd: odd,
oneOf: curry2(oneOf, true),
raises: raises,
sameLength: sameLength,
allSame: allSame,
unit: unit,
hexRgb: hexRgb,
raises: raises
startsWith: startsWith,
type: curry2(type),
unit: unit
}


Expand Down
2 changes: 1 addition & 1 deletion dist/check-more-types.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ check.email('me@foo.bar') // true
check.email('me.foo.bar') // false
```

### check.odd and check.even

Check if a number odd or even

```js
check.odd(2) // false
check.odd(3) // true
check.even(2) // true
```

### check.port

Returns true if passed argument is positive number less or equal to largest
Expand Down
28 changes: 28 additions & 0 deletions src/mid-level-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

/* global describe, it */
describe('check-more-types mid-level predicates', function () {
const la = require('lazy-ass')
const mid = require('./mid-level')
const check = require('..')

it('is an object', function () {
la(check.object(mid))
})

it('check/even', function () {
la(mid.even(2), '2 is even')
la(mid.even(4), '4 is even')
la(mid.even(0), '0 is even')
la(!mid.even(1), '1 is not even')
la(!mid.even(11), '11 is not even')
})

it('check/odd', function () {
la(!mid.odd(2), '2 is not odd')
la(!mid.odd(4), '4 is not odd')
la(!mid.odd(0), '0 is not odd')
la(mid.odd(1), '1 is odd')
la(mid.odd(11), '11 is odd')
})
})
Loading

0 comments on commit 57a7a20

Please sign in to comment.