-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86a70cc
commit 033fc07
Showing
4 changed files
with
108 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats a ref array into a string representation. | ||
* If the first step is an entity, the separator is a colon, otherwise a dot. | ||
* | ||
* @param {Array} ref - The reference array to be formatted. | ||
* @param {Object} model - The model object containing definitions. | ||
* @returns {string} The formatted string representation of the reference. | ||
*/ | ||
function prettyPrintRef(ref, model = null) { | ||
return ref.reduce((acc, curr, j) => { | ||
if (j > 0) { | ||
if (j === 1 && model?.definitions[ref[0]]?.kind === 'entity') { | ||
acc += ':' | ||
} else { | ||
acc += '.' | ||
} | ||
} | ||
return acc + `${curr.id ? curr.id + '[…]' : curr}` | ||
}, '') | ||
} | ||
|
||
// export the function to be used in other modules | ||
module.exports = { | ||
prettyPrintRef, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters