expjs

A simple javascript tool to expand tokens in a string as per given rule

Showing:

Popularity

Downloads/wk

2

GitHub Stars

0

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

1

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

expjs

Simple utility to expand string token with given rules

Install

npm install expjs

Usage


// the global mapping rule file
var Expander = require('expjs');

var mappingRule = {
    'btn': 'fg-color-dark bg-color-light',
    'btn-reverse': 'fg-color-light bg-color-dark'
}
module.exports = new Expander(mappingRule);


// a component file:
var cm = require('../css-class-mapping-rule');

var Btn = React.createClass({
  render: function () {
    return (
       <button className={cm('btn-reverse other-class')}>My button</button>
    );
  }
});

The above reactjs code will yield component looks like

<button class='fg-color-light bg-color-dark other-class'>My buttn</button>

Input variants (supported since v0.0.5)

In the above example, you pass the str list in a string separated by white space cm('btn-reverse other-class'), expjs also allows you to pass in array or javascript arguments:

<button className={cm(['btn-reverse', otherClass])}>My button</button>
<button className={cm('btn-reverse', otherClass)}>My button</button>

This will be useful when you are using variables for class name as shown above.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial