File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -71,15 +71,21 @@ module.exports = {
7171 forceArray : function ( value ) {
7272 return this . isArray ( value ) ? value : [ value ]
7373 } ,
74+
75+ /**
76+ * @typedef {string } HexString
77+ * @description A hex string of 24 characters
78+ */
7479
7580 /**
7681 * Casts to ObjectId
77- * @param {string|ObjectId } str - string = hex string
78- * @return {ObjectId }
82+ * @param {HexString|ObjectId } [value] - empty string = new ObjectId('')
7983 */
80- id : function ( str ) {
81- if ( str == null ) return new ObjectId ( )
82- return typeof str === 'string' ? ObjectId . createFromHexString ( str ) : str
84+ id : function ( value ) {
85+ if ( value === undefined ) return new ObjectId ( )
86+ else if ( typeof value === 'string' ) return ObjectId . createFromHexString ( value )
87+ else if ( value instanceof ObjectId ) return value
88+ else throw new Error ( `Monastery: invalid value "${ value } " passed to id(value?: HexString|ObjectId).` )
8389 } ,
8490
8591 inArray : ( array , key , value ) => {
You can’t perform that action at this time.
0 commit comments