plural-forms-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

plural-forms-parser

Why?

This library can parse Plural Forms header without violation of unsafe-eval rule from Content Security Policy

How?

It is using Shunting yard algorithm instead of eval() or new Function()

Example

const { parse } = require('plural-froms-parser');
const expression = 'n > 1 ? 2 : 3';
const rpnExpression = parse(expression);
//  {
//    postfix: [ 'n', 1, '>', 2, 3, '?:' ],
//    evaluate: [Function: evaluate]
//  }
rpnExpression.evaluate(1) // 2
rpnExpression.evaluate(2) // 3

References

Package Sidebar

Install

npm i plural-forms-parser

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

12.2 kB

Total Files

11

Last publish

Collaborators

  • stryzhevskyi