ramda-loader
v0.5.2
Published
Indispensable RamdaJs Webpack loader for writing and debugging functional code
Downloads
12
Maintainers
Readme
Native functional programming in JavaScript with Ramda and Webpack
Write beautiful functional programming code in JavaScript without namespacing or importing functions by hand.
Enforces Ramda names for a clean and consistent code base. Features enhanced debbuging that gives you precise stack traces for point-free programming with Ramda.
Install
$ npm install --save-dev ramda-loader
Add the loader to your webpack.config.js
:
module.exports = {
// ...
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'ramda-loader',
query: {
debug: true, // Will wrap Ramda functions in error handles with file name, line number and char location
strict: true, // Will disallow variables that have the same name as Ramda functions
imports: true // Will add import statements for every Ramda function found
}
}
]
}
}
Description
ramda-loader
uses Abstract Syntax Tree (AST) parsing and analysing to instrument your code and produce new code.
This way you gain confidence that you can use Ramda functions anywhere and your code will continue to work exactly the same as before.
In order promote point-free programming,
ramda-loader
enforces that you don't redeclare the names used by Ramda.
This ensures you achieve a standardised codebase that anyone can understand just by looking at Ramda's documentation - less maintanance on your side and less documentation to write.
Example
Given this file:
var add10 = add(10)
var answer = pipe(
add10,
ifElse(
equals(42),
always('The answer to your Ramda import problems'),
subtract(10)
)
)
answer(32) // The answer to your Ramda import problems
it will automatically import all the Ramda functions found:
var R = __webpack_require__(1)
var add = R.add
var pipe = R.pipe
var ifElse = R.ifElse
var equals = R.equals
var always = R.always
var subtract = R.subtract
var __ = R.__
var add10 = add(10)
var answer = pipe(
add10,
ifElse(
equals(42),
always('The answer to your Ramda import problems'),
subtract(__, 10)
)
)
answer(32) // The answer to your Ramda import problems
and with the debug=true
this becomes:
var __ramdaDebugWrapper = __webpack_require__(1).fn;
var add = R.add
var pipe = R.pipe
var ifElse = R.ifElse
var equals = R.equals
var always = R.always
var subtract = R.subtract
var __ = R.__
var add10 = __ramdaDebugWrapper('../sample/src/index.js', 1, 15, 'add', add)(10);
var answer = __ramdaDebugWrapper('../sample/src/index.js', 3, 16, 'pipe', pipe)(add10, __ramdaDebugWrapper('../sample/src/index.js', 5, 3, 'ifElse', ifElse)(__ramdaDebugWrapper('../sample/src/index.js', 6, 5, 'equals', equals)(42), __ramdaDebugWrapper('../sample/src/index.js', 7, 5, 'always', always)('The answer to your Ramda import problems'), __ramdaDebugWrapper('../sample/src/index.js', 8, 5, 'subtract', subtract)(__, 10)));
module.exports = answer;
Build
Install the dependencies, via:
$ npm install
then you can run:
$ npm run build
which will build the loader in the /dist
folder.
Running The Test Suite
Install the dependencies (see Build)
Then you can run the tests by running (which also builds the loader):
$ npm test
Contributing:
Feel free to open issues to propose stuff and participate. Pull requests are also welcome.