Skip to content

Commit

Permalink
Added helper for stripper a family of punctuations
Browse files Browse the repository at this point in the history
  • Loading branch information
wi-ski committed Feb 6, 2017
1 parent ef3a468 commit 41328c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils/defaultFilterOptions.js
@@ -1,4 +1,5 @@
import stripDiacritics from './stripDiacritics';
import stripPunctuation from './stripPunctuation';

function filterOptions (options, filterValue, excludeOptions, props) {
if (props.ignoreAccents) {
Expand All @@ -17,6 +18,10 @@ function filterOptions (options, filterValue, excludeOptions, props) {
if (!filterValue) return true;
var valueTest = String(option[props.valueKey]);
var labelTest = String(option[props.labelKey]);
if (props.ignorePunctuation) {
if (props.matchProp !== 'label') valueTest = stripPunctuation(valueTest);
if (props.matchProp !== 'value') labelTest = stripPunctuation(labelTest);
}
if (props.ignoreAccents) {
if (props.matchProp !== 'label') valueTest = stripDiacritics(valueTest);
if (props.matchProp !== 'value') labelTest = stripDiacritics(labelTest);
Expand Down
6 changes: 6 additions & 0 deletions src/utils/stripPunctuation.js
@@ -0,0 +1,6 @@
'use strict';
const puncuation = /[.,\/'#!%\^&\*;:{}=\-_`~()]/g;
const empty = '';
module.exports = function stripPunctuation(str) {
return str.replace(puncuation, empty);
};

0 comments on commit 41328c7

Please sign in to comment.