Pargras
Pargras
is a minimalistic helper around function arguments for Node.js and the Browser. Pargras
has a fluent
interface and supports adding, removing and altering arguments before applying them to a function.
Getting started
Node.js
Install pargras
using npm.
npm install pargras --save
Then require it into any module.
const Pargras = require('pargras');
Browser
You can download the latest release from the repository
Use a script tag to directly add Pargras
to the global scope.
<script src="pargras.min.js"></script>
Usage
function specialMin()
{
const args = new Pargras(arguments);
var min = args.shift().pop().applyTo(Math.min);
}
specialMin(0, 2, 3, 4, 1);
Examples
Return the function arguments as an array.
function afunc()
{
const args = new Pargras(arguments);
return args.array();
}
afunc(0, 1, "two", true);
Return the number of arguments passed to a function.
function afunc()
{
const args = new Pargras(arguments);
return args.length();
}
afunc(0, 1, "two", true);
Alter an argument value.
function afunc()
{
const args = new Pargras(arguments);
args.get(1);
args.set(1, 'altered');
args.get(1);
return args.array().sort();
}
afunc("peach", "banana", "apple");
Alter arguments and apply them to another function.
function afunc()
{
const args = new Pargras(arguments);
args.shift().pop().unshift('one').push('four');
args.applyTo(console.log);
}
afunc(1, 2, 3, 4);
More examples
Please refer to the test spec for more examples.
Testing
We use
Steps to be taken
- Clone or download the repository.
- Change into the project directory.
- Use
npm install
to install all development dependencies. - Use
npm runt lint
to run static code analysis. - Use
npm test
to run the tests. - Use
npm run coverage
to track test coverage. - The output should display successful execution results and a code coverage map.
Build
- Clone or download the repository.
- Change into project directory.
- Use
npm run build
in project directory to build pargras.min.js
from pargras.js
.
Contribution
Please use Github issues for requests.
Pull requests are welcome.
Issues
We use GitHub issues to track bugs. Please ensure your bug description is clear and has sufficient instructions to be
able to reproduce the issue.
The absolute best way to report a bug is to submit a pull request including a new failing test which describes the bug.
When the bug is fixed, your pull request can then be merged.
The next best way to report a bug is to provide a reduced test case on jsFiddle or jsBin or produce exact code inline
in the issue which will reproduce the bug.
Support
Changelog
v1.1.0
- Update npm modules.
- Update and extend test environment.
- Add static code analysis tool JSHint.
- Add Karma test runner.
- Fix JSHint issues.
- Replace uglify-js by terser for minification.
- Update README.
v1.0.3
v1.0.2
v1.0.1
v1.0.0
License
Copyright (c) 2016-present, Belexos. Pargras
is licensed under the MIT License.