Skip to content

Commit

Permalink
feat(core): adds replace filter (#3525)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeach committed Apr 14, 2017
1 parent a0e1700 commit 6e8281c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/scripts/modules/core/core.module.js
Expand Up @@ -19,6 +19,7 @@ import {WEBHOOK_STAGE_MODULE} from './pipeline/config/stages/webhook/webhookStag
import {UNMATCHED_STAGE_TYPE_STAGE} from './pipeline/config/stages/unmatchedStageTypeStage/unmatchedStageTypeStage';
import {SETTINGS} from 'core/config/settings';
import {INSIGHT_NGMODULE} from './insight/insight.module';
import {REPLACE_FILTER} from './filter/replace.filter';

require('../../../fonts/spinnaker/icons.css');

Expand Down Expand Up @@ -133,6 +134,7 @@ module.exports = angular
require('./pipeline/config/preconditions/types/clusterSize/clusterSize.precondition.type.module.js'),
require('./pipeline/config/preconditions/types/expression/expression.precondition.type.module.js'),
require('./presentation/presentation.module.js'),
REPLACE_FILTER,

require('./search/search.module.js'),
require('./securityGroup/securityGroup.module.js'),
Expand Down
18 changes: 18 additions & 0 deletions app/scripts/modules/core/filter/replace.filter.ts
@@ -0,0 +1,18 @@
import {module, isDefined, ILogService} from 'angular';

function replace($log: ILogService): Function {
return (str: string, regExStr: string, replaceValue: string) => {
if (!isDefined(regExStr)) {
$log.debug(`Did not supply regex string for 'replace' filter.`);
return str;
} else if (!isDefined(replaceValue)) {
$log.debug(`Did not supply replacement value for 'replace' filter.`);
return str;
} else {
return str.replace(new RegExp(regExStr, 'g'), replaceValue);
}
};
}

export const REPLACE_FILTER = 'spinnaker.core.replace.filter';
module(REPLACE_FILTER, []).filter('replace', replace);

0 comments on commit 6e8281c

Please sign in to comment.