npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoose-schema-types

v1.2.6

Published

A collection of mongoose types

Downloads

15

Readme

npm node downloads

Mongoose Schema Types plugin

This mongoose types library is a port of the awesome graphql-scalars libraries:

Currency EmailAddress GUID HSL HSLA HexColorCode Hexadecimal IBAN Int32 IPv4 IPv6 ISBN MAC PhoneNumber Port PostalCode RGB RGBA Url UtcOffset

Installation

npm install --save mongoose-schema-types

or

yarn add mongoose-schema-types

Usage

import mongoose from 'mongoose';
import 'mongoose-schema-types';

const schema = new mongoose.Schema({
    currency: { type: mongoose.Schema.Types.Currency },
    email: { type: mongoose.Schema.Types.EmailAddress },
    guid: { type: mongoose.Schema.Types.GUID },
    hsl: { type: mongoose.Schema.Types.HSL },
    hsla: { type: mongoose.Schema.Types.HSLA },
    hexcolorcode: { type: mongoose.Schema.Types.HexColorCode },
    hexadecimal: { type: mongoose.Schema.Types.Hexadecimal },
    iban: { type: mongoose.Schema.Types.IBAN },
    int32: { type: mongoose.Schema.Types.Int32 },
    ipv4: { type: mongoose.Schema.Types.IPv4 },
    ipv6: { type: mongoose.Schema.Types.IPv6 },
    isbn: { type: mongoose.Schema.Types.ISBN },
    mac: { type: mongoose.Schema.Types.MAC },
    phonenumber: { type: mongoose.Schema.Types.PhoneNumber },
    port: { type: mongoose.Schema.Types.Port },
    postalcode: { type: mongoose.Schema.Types.PostalCode },
    rgb: { type: mongoose.Schema.Types.RGB },
    rgba: { type: mongoose.Schema.Types.RGBA },
    url: { type: mongoose.Schema.Types.Url },
    utcoffset: { type: mongoose.Schema.Types.UtcOffset }
  });

Why?

Many mongoose type plugins exist on npm, but most of them only handle one type. And some of them are not linked to any git repo.

The Types

Currency

A field whose value is a ISO-4217 currency (case insensitive).

UtcOffset

String that will have a value of format ±hh:mm. List of tz database time zones.

EmailAddress

A field whose value conforms to the standard internet email address format as specified in RFC822.

Url

A field whose value conforms to the standard URL format as specified in RFC3986, and it uses real JavaScript URL objects.

PhoneNumber

A field whose value conforms to the standard E.164 format as specified in E.164 specification. Basically this is +17895551234. The very powerful libphonenumber library is available to take that format, parse and display it in whatever display format you want. It can also be used to parse user input and get the E.164 format to pass into a schema.

PostalCode

We're going to start with a limited set as suggested here and here.

Which gives us the following countries:

  • US - United States
  • UK - United Kingdom
  • DE - Germany
  • CA - Canada
  • FR - France
  • IT - Italy
  • AU - Australia
  • NL - Netherlands
  • ES - Spain
  • DK - Denmark
  • SE - Sweden
  • BE - Belgium
  • IN - India

This is really a practical decision of weight (of the package) vs. completeness.

In the future we might expand this list and use the more comprehensive list found here.

GUID

A field whose value is a generic Globally Unique Identifier.

Hexadecimal

A field whose value is a hexadecimal.

Int32

A field whose value is a int32. See also wikipedia.

HexColorCode

A field whose value is a hex color code.

HSL

A field whose value is a CSS HSL color.

IPv4

A field whose value is a IPv4 address.

IPv6

A field whose value is a IPv6 address.

ISBN

A field whose value is a ISBN-10 or ISBN-13 number.

MAC

A field whose value is a IEEE 802 48-bit MAC address.

Port

A field whose value is a valid TCP port within the range of 0 to 65535.

RGB

A field whose value is a CSS RGB color.

RGBA

A field whose value is a CSS RGBA color.

IBAN

Includes IBAN specifications for the following countries:

  • AD - Andorra
  • AE - United Arab Emirates
  • AL - Albania
  • AO - Angola
  • AT - Austria
  • AZ - Azerbaijan
  • BA - Bosnia and Herzegovina
  • BE - Belgium
  • BF - Burkina Faso
  • BG - Bulgaria
  • BH - Bahrain
  • BI - Burundi
  • BJ - Benin
  • BR - Brazil
  • BY - Belarus
  • CH - Switzerland
  • CI - Côte d'Ivoire
  • CM - Cameroon
  • CR - Costa Rica
  • CV - Cabo Verde
  • CY - Cyprus
  • DE - Germany
  • DK - Denmark
  • DO - Dominican Republic
  • DZ - Algeria
  • EE - Estonia
  • ES - Spain
  • FI - Finland
  • FO - Faroe Islands
  • FR - France
  • GB - United Kingdom of Great Britain and Northern Ireland
  • GE - Georgia
  • GI - Gibraltar
  • GL - Greenland
  • GR - Greece
  • GT - Guatemala
  • HR - Croatia
  • HU - Hungary
  • IE - Ireland
  • IL - Israel
  • IQ - Iraq
  • IR - Iran (Islamic Republic of)
  • IS - Iceland
  • IT - Italy
  • JO - Jordan
  • KW - Kuwait
  • KZ - Kazakhstan
  • LB - Lebanon
  • LC - Saint Lucia
  • LI - Liechtenstein
  • LT - Lithuania
  • LU - Luxembourg
  • LV - Latvia
  • MC - Monaco
  • MD - Moldova, Republic of
  • ME - Montenegro
  • MG - Madagascar
  • MK - North Macedonia
  • ML - Mali
  • MR - Mauritania
  • MT - Malta
  • MU - Mauritius
  • MZ - Mozambique
  • NL - Netherlands
  • NO - Norway
  • PK - Pakistan
  • PL - Poland
  • PS - Palestine, State of
  • PT - Portugal
  • QA - Qatar
  • RO - Romania
  • RS - Serbia
  • SA - Saudi Arabia
  • SC - Seychelles
  • SE - Sweden
  • SI - Slovenia
  • SK - Slovakia
  • SM - San Marino
  • SN - Senegal
  • ST - Sao Tome and Principe
  • SV - El Salvador
  • TL - Timor-Leste
  • TN - Tunisia
  • TR - Turkey
  • UA - Ukraine
  • VA - Holy See
  • VG - Virgin Islands (British)
  • XK - Kosovo

License

Released under the MIT license.

Contributing

Issues and Pull Requests are always welcome.

Sponsor

Thanks

Thanks to the awesome graphql-scalars library for all the hard work done. All validators and associated documentation come from this lib.