@andrewscwei/mongodb-odm
Advanced tools
Comparing version 0.39.0 to 0.40.0
@@ -424,1 +424,18 @@ import { CollectionAggregationOptions, CollectionInsertManyOptions, CollectionInsertOneOptions, CommonOptions, FilterQuery, FindOneAndReplaceOption, IndexOptions, ObjectID, ReplaceOneOptions, UpdateQuery } from 'mongodb'; | ||
}): GeoCoordinate; | ||
/** | ||
* Makes an ObjectID from a value. | ||
* | ||
* @param value - Value to make the ObjectID from. | ||
* | ||
* @returns If successful, a new ObjectID instance will be returned. If not, | ||
* `undefined` will be returned. | ||
*/ | ||
export declare function ObjectIDMake(value: any): ObjectID | undefined; | ||
/** | ||
* Checks if a value can be used to create a valid ObjectID. | ||
* | ||
* @param value - The value to check. | ||
* | ||
* @returns `true` or `false`. | ||
*/ | ||
export declare function valueIsValidObjectID(value: any): boolean; |
@@ -106,2 +106,41 @@ "use strict"; | ||
exports.GeoCoordinateMake = GeoCoordinateMake; | ||
/** | ||
* Makes an ObjectID from a value. | ||
* | ||
* @param value - Value to make the ObjectID from. | ||
* | ||
* @returns If successful, a new ObjectID instance will be returned. If not, | ||
* `undefined` will be returned. | ||
*/ | ||
function ObjectIDMake(value) { | ||
if (!valueIsValidObjectID(value)) | ||
return undefined; | ||
return new mongodb_1.ObjectID(value); | ||
} | ||
exports.ObjectIDMake = ObjectIDMake; | ||
/** | ||
* Checks if a value can be used to create a valid ObjectID. | ||
* | ||
* @param value - The value to check. | ||
* | ||
* @returns `true` or `false`. | ||
*/ | ||
function valueIsValidObjectID(value) { | ||
if (is_1.default.nullOrUndefined(value)) | ||
return false; | ||
if (!mongodb_1.ObjectID.isValid(value)) | ||
return false; | ||
if (is_1.default.directInstanceOf(value, mongodb_1.ObjectID)) | ||
return true; | ||
try { | ||
const objectId = new mongodb_1.ObjectID(value); | ||
if (objectId.toHexString() !== String(value)) | ||
return false; | ||
} | ||
catch (err) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
exports.valueIsValidObjectID = valueIsValidObjectID; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@andrewscwei/mongodb-odm", | ||
"version": "0.39.0", | ||
"version": "0.40.0", | ||
"description": "ODM for MongoDB", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
Sorry, the diff of this file is not supported yet
207607
3559