New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

enjoi

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enjoi - npm Package Compare versions

Comparing version 3.2.1 to 3.2.2

3

CHANGELOG.md

@@ -0,2 +1,5 @@

### v3.2.2
* Documentation fixes.
### v3.2.1

@@ -3,0 +6,0 @@

2

package.json
{
"name": "enjoi",
"version": "3.2.1",
"version": "3.2.2",
"license": "Apache 2.0",

@@ -5,0 +5,0 @@ "description": "Converts json-schema to Joi schema for validation.",

@@ -28,19 +28,20 @@ [![Build Status](https://travis-ci.org/tlivings/enjoi.png)](https://travis-ci.org/tlivings/enjoi) [![NPM version](https://badge.fury.io/js/enjoi.png)](http://badge.fury.io/js/enjoi)

```javascript
var Joi = require('joi');
var Enjoi = require('enjoi');
const Joi = require('joi');
const Enjoi = require('enjoi');
var schema = Enjoi({
'title': 'Example Schema',
'type': 'object',
'properties': {
'firstName': {
'type': 'string'
const schema = Enjoi({
type: 'object',
properties: {
firstName: {
description: 'First name.',
type: 'string'
},
'lastName': {
'type': 'string'
lastName: {
description: 'Last name.',
type: 'string'
},
'age': {
'description': 'Age in years',
'type': 'integer',
'minimum': 0
age: {
description: 'Age in years',
type: 'integer',
minimum: 1
}

@@ -66,11 +67,18 @@ },

Sub-schemas can be provided through the `subSchemas` option for `$ref` values to lookup against.
Example:
```javascript
var schema = Enjoi({
'title': 'Example Schema',
'type': 'object',
'properties': {
'A': {
'$ref': 'sub#/something'
const schema = Enjoi({
type: 'object',
properties: {
a: {
$ref: '#/b' // # is root schema
},
b: {
type: 'string'
},
c: {
$ref: '#sub/d' // #sub is 'sub' under subSchemas.
}

@@ -80,4 +88,4 @@ }

subSchemas: {
'sub': {
'something': {
sub: {
d: {
'type': 'string'

@@ -92,25 +100,32 @@ }

Custom types can be provided through the `types` option.
```javascript
var schema = Enjoi({
type: 'file'
const schema = Enjoi({
type: 'thing'
}, {
types: {
file: Enjoi({
type: 'object',
properties: {
file: {
type: 'string'
},
consumes: {
type: 'string',
pattern: /multipart\/form-data/
}
}
})
thing: Joi.any()
}
});
```
schema.validate({file: 'data', consumes: 'multipart/form-data'}, function (error, value) {
error && console.log(error);
### Refine Type
You can use the refine type function to help refine types based on `type` and `format`. This will allow transforming a type for lookup against the custom `types`.
```javascript
const schema = Enjoi({
type: 'string',
format: 'email'
}, {
types: {
email: Joi.string().email()
},
refineType(type, format) {
if (type === 'string' && format === 'email') {
return 'email';
}
}
});
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc