0.0.4 • Published 7 years ago

kuali-mongoose-helpers v0.0.4

Weekly downloads
1
License
AGPL-3.0
Repository
github
Last release
7 years ago

kuali-mongoose-helpers

Generic functions that make dealing with kuali specific mongoose standards easier to maintain.

Installation

npm install kuali-mongoose-helpers

API

toTimestamp(date)

Returns the number, representative of the number of milliseconds since the Unix Epoch.

  • date {Date} - The date to convert
const { toTimestamp } = require('kuali-mongoose-helpers')

toTimestamp(new Date(10)) === 10
toTimestamp(new Date('2017-10-18T20:50:02.551Z')) === 1508359802551

renameKey(oldKey, newKey, object)

Moves one key from an object to a new key.

  • oldKey {String} - The key to move from
  • newKey {String} - The key to move to
  • object {Object} - The object to modify (it actually returns a new object. This function treats the object immutably)
const { renameKey } = require('kuali-mongoose-helpers')

renameKey('_id', 'id', { _id: 'foobar', name: 'hello' }) // -> { id: 'foobar', name: 'hello' }

sortStringToObject

Converts a comma delimited sort string into an object you can pass into mongoose.find().sort().

  • sortString {String} - The string to convert. Should be a comma delimited string of fields.
const { sortStringToObject } = require('kuali-mongoose-helpers')

sortStringToObject('name,-createdAt') // -> { name: 1, createdAt: -1 }
0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago