import { propertyExists , UniqueNameGenerator } from '@sap-cloud-sdk/util' ; import { ServiceMapping , VdmMapping } from './service-mapping' ; internal export class GlobalNameFormatter { private directoryNameGenerator = new UniqueNameGenerator ( '-' ) ; private npmPackageNameGenerator = new UniqueNameGenerator ( '-' ) ; private vdmMapping : VdmMapping ; constructor ( vdmMapping ) { this . vdmMapping = vdmMapping || { } ; this . directoryNameGenerator . addToUsedNames ( ... Object . entries ( this . vdmMapping ) . map ( ( [ , v ] ) => v . directoryName ) ) ; this . npmPackageNameGenerator . addToUsedNames ( ... Object . entries ( this . vdmMapping ) . map ( ( [ , v ] ) => v . npmPackageName ) ) ; } public uniqueDirectoryName ( directoryName , originalFileName ) { return ( this . directoryNameFromMapping ( originalFileName ) || this . transformAndCacheDirectoryName ( directoryName ) ) ; } public uniqueNpmPackageName ( npmPackageName , originalFileName ) { return ( this . npmPackageNameFromMapping ( originalFileName ) || this . transformAndCacheNpmPackageName ( npmPackageName ) ) ; } private transformAndCacheDirectoryName ( directoryName ) { return this . directoryNameGenerator . generateAndSaveUniqueName ( directoryName ) ; } private transformAndCacheNpmPackageName ( npmPackageName ) { return this . npmPackageNameGenerator . generateAndSaveUniqueName ( npmPackageName ) ; } private directoryNameFromMapping ( originalFileName ) { return this . fromMapping ( originalFileName , 'directoryName' ) ; } private npmPackageNameFromMapping ( originalFileName ) { return this . fromMapping ( originalFileName , 'npmPackageName' ) ; } private fromMapping ( originalFileName , key ) { return propertyExists ( this . vdmMapping , originalFileName , key ) ? this . vdmMapping [ originalFileName ] [ key ] : undefined ; } }