@thxmike/mongoose-url-type

A url field-type for Mongoose schemas. This is a fork of https://github.com/konsumer/mongoose-type-url

Usage no npm install needed!

<script type="module">
  import thxmikeMongooseUrlType from 'https://cdn.skypack.dev/@thxmike/mongoose-url-type';
</script>

README

mongoose-type-url

A url field-type for Mongoose schemas

npm

Greenkeeper badge Build Status Code Climate

usage

This will validate a url, correctly:

var mongoose = require('mongoose');
require('mongoose-type-url');

var UserSchema = new mongoose.Schema({
    url: {
        work: mongoose.SchemaTypes.Url,
        profile: mongoose.SchemaTypes.Url
    }
});

You can also use the stuff in String type:

var UserSchema = new mongoose.Schema({
    url: {
        work: {type: mongoose.SchemaTypes.Url, required: true},
        profile: {type: mongoose.SchemaTypes.Url, required: true},
    }
});

You can also use it as an array:

var UserSchema = new mongoose.Schema({
    urls: [{type: mongoose.SchemaTypes.Url}]
});