/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import chalk from '@casual-simulation/chalk' ; import type { CompareKeys } from '../pretty-format' ; import type { DiffOptions , DiffOptionsNormalized } from './types' ; export const noColor = ( string ) : string => string ; const DIFF_CONTEXT_DEFAULT = 5 ; const OPTIONS_DEFAULT = { aAnnotation : 'Expected' , aColor : chalk . green , aIndicator : '-' , bAnnotation : 'Received' , bColor : chalk . red , bIndicator : '+' , changeColor : chalk . inverse , changeLineTrailingSpaceColor : noColor , commonColor : chalk . dim , commonIndicator : ' ' , commonLineTrailingSpaceColor : noColor , compareKeys : undefined , contextLines : DIFF_CONTEXT_DEFAULT , emptyFirstOrLastLinePlaceholder : '' , expand : true , includeChangeCounts : false , omitAnnotationLines : false , patchColor : chalk . yellow , } ; const getCompareKeys = ( compareKeys ? ) : CompareKeys => compareKeys && typeof compareKeys === 'function' ? compareKeys : OPTIONS_DEFAULT . compareKeys ; const getContextLines = ( contextLines ? ) : number => typeof contextLines === 'number' && Number . isSafeInteger ( contextLines ) && contextLines >= 0 ? contextLines : DIFF_CONTEXT_DEFAULT ; export const normalizeDiffOptions = ( options = { } ) : DiffOptionsNormalized => ( { ... OPTIONS_DEFAULT , ... options , compareKeys : getCompareKeys ( options . compareKeys ) , contextLines : getContextLines ( options . contextLines ) , } ) ;