1.0.1 • Published 4 years ago

discord-embed-validator v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

discord-embed-validator

joi schema for validating Discord Embed Objects.

The official documentation for the Embed Object can be found here, and its limits here.

Install

npm install discord-embed-validator

Usage examples

Valid Embed

const validator = require('discord-embed-validator')

const embed = {
  title: 'This is my valid embed!',
  fields: [
    {
      name: 'It has a field',
      value: 'And the field has a value!'
    }
  ]
}

validator.validate(embed)
// { value: { title: 'This is my valid embed!', fields: [ [Object] ] } }

Invalid Embed

const validator = require('discord-embed-validator')

const invalidEmbed = {
  title: 'This one is invalid',
  fields: [
    {
      'title': 'Because this field uses "title" instead of "name", and is missing its value!'
    }
  ]
}

validator.validate(invalidEmbed)
/*
{
  value: { title: 'This one is invalid', fields: [ [Object] ] },
  error: [Error [ValidationError]: "fields[0].name" is required] {
    _original: { title: 'This one is invalid', fields: [Array] },
    details: [ [Object] ]
  }
}
*/