title: How to limit the words input in Quill Js?
body: <p>I'm following the example of codepen <a href="https://codepen.io/quill/pen/wWOdXZ?editors=1010" rel="nofollow">building a word counter modul</a> in addition of counting, <strong>I need to limit the input to 30 words, so the user can't write any more</strong>. I don't know where to implement what I need. I think I can use something like splice( begin, end).</p>
  
  <p>These two are doing the count words stuff:</p>
  
  <pre><code>calculate() {
     let text = this.quill.getText();
     if (this.options.unit === 'word') {
       text = text.trim();
       return text.length &gt; 0 ? text.split(/\s+/).length : 0
     } else {
      return text.length;
     }
   }
  
   update() {
     var length = this.calculate();
     var label = this.options.unit;
     if (length !== 1) {
       label += 's';
     } 
   this.container.innerHTML = length + ' ' + label;
   }
  </code></pre>
  
  <p>I don't know if I have to add a new method or modify one of this two. Something like: </p>
  
  <pre><code>limitWords() {
    let text = this.quill.getText();
    if (text.length &gt; 30) {
       text = text.splice(0, 30);
    }
    return text.length;
  }
  </code></pre>
  
  <p>This obviously fails, any guidance would be very appreciated!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to @maioman I got a more close approach of what I need, by doing the following I can "limit" the words to 30.</p>
  
  <p><strong>The problem</strong> </p>
  
  <p>If I keep typing the previews words disappear and than I get a undefined in the input field: </p>
  
  <pre><code>update() {
  var length = this.calculate();
  if (length &gt; 30) { 
    this.restrict();
  }
  var label = this.options.unit;
  if (length !== 1) {
    label += 's';
  }
   this.container.innerHTML = length + ' ' + label;
  }
  
  restrict() {
    let text = this.quill.getText();
    text = text.replace(/\s+.+/);
    this.quill.setText(text);
    this.update()
   } 
  </code></pre>
  
  <p><strong>What I tried:</strong></p>
  
  <pre><code>let text = this.quill.getText().slice(0, 30); 
  </code></pre>
  
  <p>This doesn't throws an undefined but it does not work. </p>