1.1.7 • Published 7 months ago

mongoose-id-utils v1.1.7

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

About

Functions to resolve comomn problens with ObjectId

Install

npm install --save mongoose-id-utils

Usage

const { isObjectId, extractIdString, extractIdObjectId } = require('mongoose-id-utils')

Example

API

isObjectId

const { isObjectId } = require('mongoose-id-utils')

const id = '5e4e2f3b8a4f4c001e0e4c2d'

console.log(isObjectId(id))

// Output: true

extractIdString

const { extractIdString } = require('mongoose-id-utils')

const idString = '5e4e2f3b8a4f4c001e0e4c2d'
const idInDocument = {
  _id: '5e4e2f3b8a4f4c001e0e4c2d'
}

console.log(extractIdString(id))

// Output: 5e4e2f3b8a4f4c001e0e4c2d

console.log(extractIdString(idInDocument))

// Output: 5e4e2f3b8a4f4c001e0e4c2d

extractIdObjectId

const { extractIdObjectId } = require('mongoose-id-utils')

const idString = '5e4e2f3b8a4f4c001e0e4c2d'
const idInDocument = {
  _id: '5e4e2f3b8a4f4c001e0e4c2d'
}

console.log(extractIdObjectId(id))

// Output: ObjectId('5e4e2f3b8a4f4c001e0e4c2d')

console.log(extractIdObjectId(idInDocument))

// Output: ObjectId('5e4e2f3b8a4f4c001e0e4c2d')

Contributing

Please consult CONTRIBUTING for guidelines on contributing to this project.

Author

mongoose-id-utils © Marcos Porto, Released under the Apache-2.0 License.

1.1.7

7 months ago

1.1.6

8 months ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago