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

mongeasy

v1.0.1

Published

a lightweight wrapper and mongoose schema declaration language, for beginners and experts.

Downloads

8

Readme

Stable version released!

Mongeasy aims to streamline the management of models and schemas in your projects by utilizing a simple syntax. This is achieved by employing CSS (Carnage Schema Syntax), which is a flag-based declaration and modification language designed by Nikhil Swami also visit swamix.com . CSS is just a shortcut way of writing mongoose schemas, which is a superset of mongoose. It is not a new library, it is just a new way of writing mongoose schemas, which is more readable, clean and easy to maintain. It is not a replacement for mongoose, rather an extension. if you know how ls -la works in linux, you know this package half already!

Why Should I Use It?

  • easy to use, mongeasy!
  • light weight less than 100 kb.
  • lesser boilerplate and redeclarations.
  • 66% shorter code!
  • reverse compatibility, fallback to mongoose anytime, without breaking anything.

Install

npm i mongeasy
pnpm i mongeasy
yarn i mongeasy
bun i mongeasy

Example

import mongoose from 'mongoose';
import { models } from 'mongeasy';

let Models = models({
    Computer: [
        'name           |String |!|*|#|(3,16)', // ! = unique, * = required, # = index, (3,16) = minlength,maxlength
        'price          |Number |+U|+R|+I', // same as above, +U = unique, +R = required, +I = index
        'madeIn         |ObjectId|ref:CountryNames', // ref:CountryNames = reference to another model
        'dateOfPurchase |Date   |*', // Date = Date , * = required
        "color          |String |['red','blue','green']", // ['red','blue','green'] = enum
        'inStock        |Boolean|',
        'storageTemp    |Number |(-10,60)', // (0,) = min no upper limit
        'globalStockQty |Number |(0,)', // (0,) = min, no upper limit // (,100) = no lower limit
    ],
    Employee: [
        'name|String|!|*|#|(3,16)',
        'salary|Number|+R',
        'dateOfJoining|Date|*',
        'designation|String|*',
        'gender|String|["male","female"]',
        'isMarried|Boolean|*',
        'address|String|*',
        'phone|String|*',
    ],
});

console.log(Models);

// Connect to database , connection is same
mongoose.connect('mongodb://localhost:27017/test', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
});

// add a computer as usual
let c = new Models.Computer({
    name: 'Macbook Pro 2',
    price: 2000 + Math.random() * 1000,
    madeIn: 'India',
    dateOfPurchase: new Date(),
    color: 'red',
    inStock: true,
    storageTemp: 50,
    globalStockQty: 100,
});
c.save();

// exit
setTimeout(() => {
    mongoose.disconnect();
}, 100);

Format: <Name> | <Type> | <Modifiers>

Name:

  • the name of field - emojis also supported

Type :

all supported, as we directly pass to Core Library https://mongoosejs.com/docs/schematypes.html

  • [ Array, Boolean, BigInt, Buffer, Date, Decimal, Decimal128, DocumentArray, Map, Mixed, Number, ObjectId, String, Subdocument, UUID, Oid, Object, Bool, ObjectID ]

Modifiers:

The syntax consists of the following elements: Note: "/" means "either option" refer https://mongoosejs.com/docs/schematypes.html#indexes

  • +U / ! = unique
  • +R / * = required
  • +I / # = index
  • (0, 999) = min,max
  • ['adam', 'eve'] = enum

This CSS-based declaration paradigm aims to provide a simplified way of defining Mongoose schemas, making it easier to work with MongoDB data models.