Skip to content

Commit

Permalink
fix(formatter): add throw error with instruction if missing params
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Mar 10, 2018
1 parent 5d4587d commit cbb01d9
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Column, Formatter } from './../models/index';
/** Takes an hyperlink URI prefix (passed in column definition "params.uriPrefix") and adds the cell value. The structure will be "<a href="uriPrefix">value</a>" */
export const hyperlinkUriPrefixFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) => {
let uriPrefix = (columnDef && columnDef.params && columnDef.params.uriPrefix) ? columnDef.params.uriPrefix : '';
if (!uriPrefix) {
throw new Error(`HyperlinkUriPrefix Formatter require a "uriPrefix" that can be passed through params. e.g.:: formatter: Formatters.hyperlinkUriPrefix, params: { uriPrefix: '/users/' }`);
}
if (value && uriPrefix && typeof uriPrefix === 'string' && !uriPrefix.includes('<script>')) {
uriPrefix += value;
return '<a href="' + uriPrefix + '">' + value + '</a>';
Expand Down

0 comments on commit cbb01d9

Please sign in to comment.