# All files / composer/utils/draft-js-custom-plugins/prepopulated-autocomplete-hashtag prepopulatedHashtagStrategy.js

33.33% Statements 3/9
0% Branches 0/2
0% Functions 0/2
33.33% Lines 3/9

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    207x

    7x

    7x

     const HASHTAG_REGEX = /(\s|^)#[\w]*/g;

    const findWithRegex = (regex, contentBlock, callback) => {
      const text = contentBlock.getText();
      let matchArr;
      let start;

      while ((matchArr = regex.exec(text)) !== null) { // eslint-disable-line
        const isPaddedBySpace = matchArr[1].length > 0;
        start = matchArr.index + (isPaddedBySpace ? 1 : 0);
        callback(start, matchArr.index + matchArr[0].length);
      }
    };

    const prepopulatedHashtagStrategy = (contentBlock, callback) => {
      findWithRegex(HASHTAG_REGEX, contentBlock, callback);
    };

    export default prepopulatedHashtagStrategy;