Skip to content

Commit

Permalink
object.regex(). Closes #2260
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Jan 4, 2020
1 parent 4513ac4 commit bfb77ea
Show file tree
Hide file tree
Showing 6 changed files with 1,494 additions and 1,444 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js

node_js:
- "10"
- "12"
- "node"

Expand Down
14 changes: 14 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,16 @@ const schema = Joi.object().ref();

Possible validation errors: [`object.refType`](#objectreftype)

#### `object.regex()`

Requires the object to be a `RegExp` object.

```js
const schema = Joi.object().regex();
```

Possible validation errors: [`object.regex`](#objectregex)

#### `object.rename(from, to, [options])`

Renames a key to another name (deletes the renamed key) where:
Expand Down Expand Up @@ -3916,6 +3926,10 @@ Additional local context properties:

The object is not a [`Joi.ref()`](#refkey-options).

#### `object.regex`

The object is not a `RegExp` object.

#### `object.rename.multiple`

Another rename was already done to the same target property.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012-2019, Sideway Inc, and project contributors
Copyright (c) 2012-2020, Sideway Inc, and project contributors
Copyright (c) 2012-2014, Walmart.
All rights reserved.

Expand Down
16 changes: 16 additions & 0 deletions lib/types/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,21 @@ module.exports = Any.extend({
}
},

regex: {
method() {

return this.$_addRule('regex');
},
validate(value, helpers) {

if (value instanceof RegExp) {
return value;
}

return helpers.error('object.regex', { value });
}
},

rename: {
method(from, to, options = {}) {

Expand Down Expand Up @@ -522,6 +537,7 @@ module.exports = Any.extend({
'object.oxor': '{{#label}} contains a conflict between optional exclusive peers {{#peersWithLabels}}',
'object.pattern.match': '{{#label}} keys failed to match pattern requirements',
'object.refType': '{{#label}} must be a Joi reference',
'object.regex': '{{#label}} must be a RegExp object',
'object.rename.multiple': '{{#label}} cannot rename "{{#from}}" because multiple renames are disabled and another key was already renamed to "{{#to}}"',
'object.rename.override': '{{#label}} cannot rename "{{#from}}" because override is disabled and target "{{#to}}" exists',
'object.schema': '{{#label}} must be a Joi schema of {{#type}} type',
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
"repository": "git://github.com/hapijs/joi",
"main": "lib/index.js",
"browser": "dist/joi-browser.min.js",
"files": [
"lib/**/*",
"dist/*"
],
"keywords": [
"schema",
"validation"
],
"dependencies": {
"@hapi/address": "^3.2.2",
"@hapi/formula": "^1.2.0",
"@hapi/hoek": "^8.2.4",
"@hapi/hoek": "^9.0.0",
"@hapi/pinpoint": "^1.0.2",
"@hapi/topo": "^3.1.3"
},
"devDependencies": {
"@hapi/bourne": "1.x.x",
"@hapi/code": "7.x.x",
"@hapi/lab": "21.x.x",
"@hapi/code": "8.x.x",
"@hapi/lab": "22.x.x",
"@hapi/joi-legacy-test": "npm:@hapi/joi@15.x.x"
},
"scripts": {
"prepublishOnly": "cd browser && npm install && npm run build",
"test": "lab -t 100 -a @hapi/code -L",
"test-cov-html": "lab -r html -o coverage.html -a @hapi/code"
},
"files": [
"lib/**/*",
"dist/*"
],
"license": "BSD-3-Clause"
}
Loading

0 comments on commit bfb77ea

Please sign in to comment.