-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HCK-8008: remove trailing comma before last deactivated column (#77)
* HCK-8008: remove trailing comma before last deactivated column * Revert "HCK-8008: remove trailing comma before last deactivated column" This reverts commit 2f88656. * HCK-8008: remove trailing comma before last deactivated column
- Loading branch information
1 parent
628c118
commit a0632c6
Showing
2 changed files
with
56 additions
and
2 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
53 changes: 53 additions & 0 deletions
53
forward_engineering/utils/joinActivatedAndDeactivatedStatements.js
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,53 @@ | ||
/** | ||
* @param {{ | ||
* index: number; | ||
* numberOfStatements: number; | ||
* lastIndexOfActivatedStatement: number; | ||
* delimiter: string; | ||
* }} | ||
* @return {string} | ||
* */ | ||
const getDelimiter = ({ index, numberOfStatements, lastIndexOfActivatedStatement, delimiter }) => { | ||
const isLastStatement = index === numberOfStatements - 1; | ||
const isLastActivatedStatement = index === lastIndexOfActivatedStatement; | ||
|
||
if (isLastStatement) { | ||
return ''; | ||
} | ||
|
||
if (isLastActivatedStatement) { | ||
return ' --' + delimiter; | ||
} | ||
|
||
return delimiter; | ||
}; | ||
|
||
/** | ||
* @param {{ | ||
* statements?: string[]; | ||
* delimiter?: string; | ||
* indent?: string; | ||
* }} | ||
* @return {string} | ||
* */ | ||
const joinActivatedAndDeactivatedStatements = ({ statements = [], delimiter = ',', indent = '\n' }) => { | ||
const lastIndexOfActivatedStatement = statements.findLastIndex(statement => !statement.startsWith('--')); | ||
const numberOfStatements = statements.length; | ||
|
||
return statements | ||
.map((statement, index) => { | ||
const currentDelimiter = getDelimiter({ | ||
index, | ||
numberOfStatements, | ||
lastIndexOfActivatedStatement, | ||
delimiter, | ||
}); | ||
|
||
return statement + currentDelimiter; | ||
}) | ||
.join(indent); | ||
}; | ||
|
||
module.exports = { | ||
joinActivatedAndDeactivatedStatements, | ||
}; |