https://github.com/cinemataztic/mongoose-alphanumeric
Alphanumeric characters generator plugin for Mongoose
https://github.com/cinemataztic/mongoose-alphanumeric
alphanumeric mongoose plugin
Last synced: 4 months ago
JSON representation
Alphanumeric characters generator plugin for Mongoose
- Host: GitHub
- URL: https://github.com/cinemataztic/mongoose-alphanumeric
- Owner: cinemataztic
- Created: 2022-09-29T06:49:10.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-12T08:22:26.000Z (over 3 years ago)
- Last Synced: 2025-02-28T12:39:03.555Z (over 1 year ago)
- Topics: alphanumeric, mongoose, plugin
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mongoose-alphanumeric
Plugin for Mongoose that generates alphanumeric code from a set of specified characters and length. Inspired by [mongoose-sluggable](https://www.npmjs.com/package/mongoose-sluggable).
## Installation
```sh
npm install mongoose-alphanumeric
```
## Requirements
Plugin requires alphanumeric field path to be added to the model without the **required** property.
## Usage
```
const mongooseAlphanumeric = require('mongoose-alphanumeric');
const schema = new Schema({
alphanumeric: { type: String, index: true , unique: true}
});
schema.plugin(mongooseAlphanumeric)
const Model = mongoose.model('Model', schema);
```
**Options**
Add options as per your requirements for alphanumeric code generation
- `[options]` {Object}
- `[field]` {String} - Name of field for storing alphanumeric, field name must match the field name set on the model schema. Default value is **alphanumeric**
- `[unique]` {Boolean} - If unique is set to false then the same alphanumeric code can be used in other documents within the same collection. Default value is **true**
- `[length]` {Number} - Determines the length of the alphanumeric code to be generated. Default value is **4**
- `[chars]` {String} - Set of characters from where alphanumeric code can be generated. Default value is **0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ**
### Example
```
schema.plugin(mongooseAlphanumeric, {
field: 'alphanumeric',
unique: true,
length: 5,
chars: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
});
```