Skip to content

Commit 197bde3

Browse files
committed
function comparator supported
1 parent 1a62cfa commit 197bde3

8 files changed

+262
-201
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ typings/
5959

6060
# testing file
6161
sandbox.js
62+
.vscode/

API.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
## `array.continuous(comparator, limit)`
1111

1212
Specifies the allowed date format:
13-
- `comparator` - `string` that should check continuous or not.
13+
- `comparator` - `string` or `func` that should check continuous or not.
1414
- `limit` - `integer` or `ref` the value of `comparator` should be start. Default `0`
1515

1616
```js

README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ Joi extensions for extra array rules.
88
[![Build status](https://ci.appveyor.com/api/projects/status/6942dw1ikdg729y2/branch/master?svg=true)](https://ci.appveyor.com/project/buianhthang/joi-array-extensions/branch/master)
99
[![Dependency Status](https://dependencyci.com/github/buianhthang/joi-array-extensions/badge)](https://dependencyci.com/github/buianhthang/joi-array-extensions)
1010

11-
# Usage
11+
# API
12+
See the [API Reference](https://github.com/buianhthang/joi-array-extensions/blob/master/API.md).
1213

14+
# Usage
1315
Usage is a two steps process. First, a schema is constructed using the provided types and constraints:
1416

1517
```js
@@ -25,13 +27,10 @@ const schema = Joi.array().items({
2527
# Coverage
2628

2729
```
28-
9 tests complete
29-
Test duration: 59 ms
30-
Assertions count: 25 (verbosity: 2.78)
30+
7 tests complete
31+
Test duration: 56 ms
32+
Assertions count: 40 (verbosity: 5.71)
3133
No global variable leaks detected
3234
Coverage: 100.00%
3335
Linting results: No issues
3436
```
35-
36-
# API
37-
See the [API Reference](https://github.com/buianhthang/joi-array-extensions/blob/master/API.md).

appveyor.yml

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ version: 1.0.{build}-{branch}
22

33
build: off
44

5-
artifacts:
6-
- path: build\**\*.tar.gz
7-
name: joi-array-extensions
8-
95
environment:
106
matrix:
117
- nodejs_version: "8"

lib/index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ module.exports = [
1818
return `${params.comparator} must be an integer and started continuous from ${params.limit}`
1919
},
2020
params: Joi.object().keys({
21-
comparator: Joi.string().required(),
21+
comparator: Joi.alternatives(
22+
Joi.string().required(),
23+
Joi.func()
24+
),
2225
limit: Joi.alternatives()
2326
.try(Joi.number().integer(), Joi.func().ref())
2427
.default(0)
@@ -46,8 +49,16 @@ module.exports = [
4649
startFrom = limit
4750
}
4851

52+
let key
53+
if (typeof comparator === 'function') {
54+
key = 'function comparator'
55+
}
56+
if (typeof comparator === 'string') {
57+
key = comparator
58+
}
59+
4960
const localState = {
50-
key: comparator,
61+
key,
5162
path: state.path.concat(comparator),
5263
parent: state.parent,
5364
reference: state.reference

package-lock.json

+60-85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
},
4545
"devDependencies": {
4646
"eslint": "^4.7.2",
47-
"eslint-config-airbnb-base": "^12.0.0",
47+
"eslint-config-airbnb-base": "^12.0.1",
4848
"eslint-config-prettier": "^2.5.0",
4949
"eslint-plugin-import": "^2.7.0",
5050
"eslint-plugin-prettier": "^2.3.1",
5151
"husky": "^0.14.3",
52-
"joi": "^11.0.3",
52+
"joi": "^11.1.1",
5353
"lab": "^14.3.1",
5454
"lint-staged": "^4.2.1",
55-
"prettier": "^1.7.0"
55+
"prettier": "^1.7.2"
5656
}
5757
}

0 commit comments

Comments
 (0)