Skip to content

Instantly share code, notes, and snippets.

@TravisMullen
Created September 16, 2021 00:06
Show Gist options
  • Save TravisMullen/3a358e084e6461b482df148c4d879273 to your computer and use it in GitHub Desktop.
Save TravisMullen/3a358e084e6461b482df148c4d879273 to your computer and use it in GitHub Desktop.
Helper for Mermaid Diagrams
// classDiagram
// [classA][Arrow][ClassB]:LabelText
// classA <|-- classB
// classC *-- classD
// classE o-- classF
// classG <-- classH
// classI -- classJ
// classK <.. classL
// classM <|.. classN
// classO .. classP
// Type Description
const relationshipTypes = Object.assign({},
...Object.entries({
'<|--': 'Inheritance',
'*--': 'Composition',
'o--': 'Aggregation',
'-->': 'Association',
'--': 'Link Solid',
'..>': 'Dependency',
'..|>': 'Realization',
'..': 'Link Dashed'
})
.map(([ type, desc ]) => ({
[ desc.toLowerCase().replace(' ', '-') ] : type
}))
)
console.log(relationshipTypes)
const defineRelationship = (classNameA, classNameB, relationshipLabel = 'requires', relationship = 'dependency') => {
return `${classNameA} ${relationshipTypes[relationship]} ${classNameB}: ${relationshipLabel}`
}
console.log(defineRelationship('Entity Service','Search Service'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment