https://github.com/iam-abdul/mongo-parser-visualizer
The mongoose-parser package provides a streamlined way to extract Mongoose models from JavaScript files containing model definitions. This is particularly useful for documentation generation, code analysis, or refactoring tasks.
https://github.com/iam-abdul/mongo-parser-visualizer
extract extract-mongodb-schema mongodb mongoose mongoose-parser mongoose-schema schema schema-parser visualization
Last synced: 3 months ago
JSON representation
The mongoose-parser package provides a streamlined way to extract Mongoose models from JavaScript files containing model definitions. This is particularly useful for documentation generation, code analysis, or refactoring tasks.
- Host: GitHub
- URL: https://github.com/iam-abdul/mongo-parser-visualizer
- Owner: iam-abdul
- Created: 2024-05-10T11:40:34.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-28T06:51:21.000Z (about 2 years ago)
- Last Synced: 2025-09-28T06:41:49.675Z (10 months ago)
- Topics: extract, extract-mongodb-schema, mongodb, mongoose, mongoose-parser, mongoose-schema, schema, schema-parser, visualization
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/mongoose-parser
- Size: 85.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readME.md
Awesome Lists containing this project
README
# mongoose-parser: Extract Mongoose Models from File Content
### Description
The `mongoose-parser` package provides a streamlined way to extract Mongoose models from JavaScript files containing model definitions. This is particularly useful for documentation generation, code analysis, or refactoring tasks.
### Installation
Install `mongoose-parser` using npm:
```
npm install mongoose-parser
```
### Usage
Import the extractModel function from the package and pass the file content as a string to extract information about the defined Mongoose models.
Here's an example showing how to use mongoose-parser in your code:
```
import extractModel from "mongoose-parser"
# file content as string
const fileContent = `import mongoose from "mongoose";
const Schema = mongoose.Schema;
let UserSchema = new Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
required: true,
},
date: {
type: Date,
default: Date.now,
},
});
const User = mongoose.model("User", UserSchema);
`
const models = extractModel(fileContent);
console.log(models)
// [
// {
// model: "User",
// jsSchemaName: "UserSchema",
// schema: {
// name: {
// type: "String",
// required: true,
// },
// email: {
// type: "String",
// required: true,
// unique: true,
// },
// password: {
// type: "String",
// required: true,
// },
// date: {
// type: "Date",
// default: "Date.now",
// },
// },
// nodeId: 3,
// },
// ]
```