File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 3939
4040 }
4141
42- const ObjectId = ( rnd = r16 => Math . floor ( r16 ) . toString ( 16 ) ) =>
43- rnd ( Date . now ( ) / 1000 ) + ' ' . repeat ( 16 ) . replace ( / ./ g, ( ) => rnd ( Math . random ( ) * 16 ) ) ;
42+ const ObjectId = ( id ) => {
43+ // Define the rnd function
44+ const rnd = ( r16 ) => Math . floor ( r16 ) . toString ( 16 ) ;
45+
46+ if ( id === undefined ) {
47+ // If id is undefined, generate a new ObjectId
48+ return rnd ( Date . now ( ) / 1000 ) + '0' . repeat ( 16 ) . replace ( / ./ g, ( ) => rnd ( Math . random ( ) * 16 ) ) ;
49+ } else {
50+ // Check if the provided id is a valid ObjectId
51+ const validIdRegex = / ^ [ 0 - 9 a - f A - F ] { 24 } $ / ;
52+ if ( ! validIdRegex . test ( id ) ) {
53+ throw new Error ( 'Invalid ObjectId' ) ;
54+ }
55+ return id ; // Return the valid ObjectId as a string
56+ }
57+ } ;
4458
4559 function checkValue ( value ) {
4660 if ( / { { \s * ( [ \w \W ] + ) \s * } } / g. test ( value ) )
You can’t perform that action at this time.
0 commit comments