-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add unique handlebar helper #3717
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,21 @@ Handlebars.registerHelper( | |
} | ||
); | ||
|
||
Handlebars.registerHelper( | ||
HandlebarHelpersEnum.UNIQUE, | ||
function (array, property) { | ||
if (!Array.isArray(array)) return ''; | ||
|
||
return array | ||
.map((item) => { | ||
if (item[property]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the object doesn't have that property we should handle it somehow |
||
return item[property]; | ||
} | ||
}) | ||
.filter((value, index, self) => self.indexOf(value) === index); | ||
Comment on lines
+58
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I am getting it right, we will return an array of only the property we filtered the distinct of. I feel we should return the whole object. what do you think? |
||
} | ||
); | ||
|
||
@Injectable() | ||
export class CompileTemplate { | ||
async execute(command: CompileTemplateCommand): Promise<string> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jainpawan21 wdyt of also making it work for unique values of an array of strings?