Action

Sort lines (ignore case and articles)

Posted by dchar, Last update about 4 years ago

Sort lines of a draft ignoring case and leading articles (a, an, the).

Steps

  • script

    // Sort ignoring article
    
    const rmArticle = (s) => {
      return s.replace(/^(?:(a|an|the) +)/g, "");
    }
      
    const cmp = (a,b) => {
      a = a.toLowerCase();
      b = b.toLowerCase();
        
      a = rmArticle(a);
      b = rmArticle(b);
        
      return a === b ? 0 : a < b ? -1 : 1;
    }
      
    let l = editor.getText().split('\n');
    l = l.filter(l => l.trim());
    l.sort(cmp);
    editor.setText(l.join('\n') + '\n');
      
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.