https://github.com/parsabordbar/mongoose-data-sanitizer
A sanitizer plugin that makes sure the mogoose data input is in UTF-8 format, and if its not, converts it into UTF-8
https://github.com/parsabordbar/mongoose-data-sanitizer
express js mongodb mongoose mongoose-plugin nodejs npm sanitizer ts
Last synced: 14 days ago
JSON representation
A sanitizer plugin that makes sure the mogoose data input is in UTF-8 format, and if its not, converts it into UTF-8
- Host: GitHub
- URL: https://github.com/parsabordbar/mongoose-data-sanitizer
- Owner: ParsaBordbar
- Created: 2025-09-05T07:21:20.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-09-05T10:22:52.000Z (about 1 month ago)
- Last Synced: 2025-09-06T04:09:01.759Z (about 1 month ago)
- Topics: express, js, mongodb, mongoose, mongoose-plugin, nodejs, npm, sanitizer, ts
- Language: TypeScript
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mongoose-data-sanitizer
[](https://www.npmjs.com/package/mongoose-data-sanitizer)
[](https://www.npmjs.com/package/mongoose-data-sanitizer)
[](https://github.com/ParsaBordbar/mongoose-data-sanitizer/issues)
[](https://github.com/ParsaBordbar/mongoose-data-sanitizer)A simple **Mongoose plugin** that automatically sanitizes your data before saving or updating.
It ensures your documents are normalized to **NFC** and removes invalid control characters that might cause issues with MongoDB or string handling.---
## 📦 Installation
```bash
npm install mongoose-data-sanitizer
```
## What It Does- Converts strings to NFC normalized form
- Removes invalid binary/control characters
- Works on:
save()
updateOne()
findOneAndUpdate()
updateMany()
- Supports nested objects and arrays
### Usage
```
import mongoose, { Schema, model } from "mongoose";
import { sanitizerPlugin } from "mongoose-data-sanitizer";// Define your schema
const userSchema = new Schema({
name: String,
bio: String,
tags: [String],
});// Attach the sanitizer plugin
userSchema.plugin(sanitizerPlugin);const User = model("User", userSchema);
async function run() {
await mongoose.connect("mongodb://localhost:27017/test");const user = new User({
name: "Jo\u0301hn", // combining accent
bio: "Some bad char \u0008 here",
tags: ["hel\u200Blo", "wo\u0000rld"],
});await user.save();
console.log(await User.findOne({ _id: user._id }));
await mongoose.disconnect();
}
```