Skip to content

Pluralization as collection detection

Alexandre Courpron edited this page Dec 26, 2016 · 5 revisions

Please note that using pluralization to detect collections has several drawbacks :

  • slower
  • false negatives / positives
  • limited internationalization

If you still want or need to use pluralization, you may use one of the following external library:

npm install inflection; // english
npm install pluralize; // english
npm install pluralize-fr; // french
npm install pluralize-es; // spanish

Example with inflection:

import inflection from 'inflection';

const treem = new Treem({
  detect: {
    collection: node => {
      return {
        check: node === inflection.pluralize(node),
        name: node
      }
    }
  }
});
``
Clone this wiki locally