11export type FakerArg = string | number | boolean | { json : string } ;
22
3+ const DEFAULT_ARRAY_LENGTH = 3 ;
4+ const INDENT_SIZE = 2 ;
5+
36export interface FieldMapping {
47 mongoType : string ;
58 fakerMethod : string ;
@@ -254,7 +257,7 @@ export function generateScript(
254257
255258 const documentCode = generateDocumentCode (
256259 structure ,
257- 2 ,
260+ INDENT_SIZE ,
258261 options . arrayLengthMap || { }
259262 ) ;
260263
@@ -309,7 +312,7 @@ console.log(\`Successfully inserted \${documents.length} documents into ${escape
309312 */
310313function generateDocumentCode (
311314 structure : DocumentStructure ,
312- indent : number = 2 ,
315+ indent : number = INDENT_SIZE ,
313316 arrayLengthMap : ArrayLengthMap = { }
314317) : string {
315318 // For each field in structure:
@@ -318,7 +321,7 @@ function generateDocumentCode(
318321 // - If ArrayStructure: generate array
319322
320323 const fieldIndent = ' ' . repeat ( indent ) ;
321- const closingBraceIndent = ' ' . repeat ( indent - 2 ) ;
324+ const closingBraceIndent = ' ' . repeat ( indent - INDENT_SIZE ) ;
322325 const rootLevelFields : string [ ] = [ ] ;
323326
324327 for ( const [ fieldName , value ] of Object . entries ( structure ) ) {
@@ -354,7 +357,7 @@ function generateDocumentCode(
354357 : { } ;
355358 const arrayCode = generateArrayCode (
356359 value as ArrayStructure ,
357- indent + 2 ,
360+ indent + INDENT_SIZE ,
358361 fieldName ,
359362 arrayLengthMap ,
360363 nestedArrayLengthMap
@@ -368,7 +371,7 @@ function generateDocumentCode(
368371 : arrayLengthMap ;
369372 const nestedCode = generateDocumentCode (
370373 value as DocumentStructure ,
371- indent + 2 ,
374+ indent + INDENT_SIZE ,
372375 nestedArrayLengthMap
373376 ) ;
374377 rootLevelFields . push ( `${ fieldIndent } ${ fieldName } : ${ nestedCode } ` ) ;
@@ -388,7 +391,7 @@ function generateDocumentCode(
388391 */
389392function generateArrayCode (
390393 arrayStructure : ArrayStructure ,
391- indent : number = 2 ,
394+ indent : number = INDENT_SIZE ,
392395 fieldName : string = '' ,
393396 parentArrayLengthMap : ArrayLengthMap = { } ,
394397 nestedArrayLengthMap : ArrayLengthMap = { }
@@ -399,7 +402,7 @@ function generateArrayCode(
399402 const arrayLength =
400403 typeof parentArrayLengthMap [ fieldName ] === 'number'
401404 ? parentArrayLengthMap [ fieldName ]
402- : 3 ;
405+ : DEFAULT_ARRAY_LENGTH ;
403406
404407 if ( 'mongoType' in elementType ) {
405408 // Array of primitives
0 commit comments