0.2.0 • Published 3 years ago

mongoose-title-case v0.2.0

Weekly downloads
97
License
MIT
Repository
github
Last release
3 years ago

mongoose-title-case

A mongoose.js plugin for titlizing ~& trimming~ schemas.

Installation

$ npm install mongoose-title-case --save
OR
$ yarn add mongoose-title-case

Usage

NOTE: Schema#trim is now a path option in mongoose. Use of mongoose-title-case's trim option is deprecated and will be removed in a future release. Mongoose plugin style.

var mongoose = require('mongoose'),
    Schema   = mongoose.Schema,
    titleize = require('mongoose-title-case'),

var userSchema = new Schema({
  name: {
    first: String,
    last:  String
  }
});

// Attach some mongoose hooks
userSchema.plugin(titleize, {
  paths: [ 'name.first', { path: 'name.last', trim: false } ], // Array of paths
  trim: true
});

module.exports = mongoose.model('User', userSchema);

And watch it work

var User   = require('path/to/model');

var document = new User({
  name: {
    first: ' bob ',
    last:  'ross '
  }
});

document.save().then(record => {
  console.log(record.name.first); // 'Bob'
  console.log(record.name.last); // 'Ross '
});

Options

Options used in mongoose-title-case

  • options.paths {String|{ path: String, surname: Boolean }} (Required) Array of paths to title case & trim
  • options.paths.*.surname {Boolean} Tells title-case to respect this field as a surname, meaning it will run it against a prefix dictionary.
  • options.trim {Boolean} Trim all paths. true by default DEPRECATED
  • options.surnamePrefixes {String} A dictionary of surname prefixes to replace the included dictionary.
0.2.0

3 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago