@yagni-js/yagni
Version:
Yet another functional library
124 lines (74 loc) • 2.03 kB
Markdown
Yet another **pure functional** frontend library.
**Pure functional** in this context means functional code style - library code is
linted using [eslint-plugin-fp][eslint-plugin-fp] and
[][eslint-plugin-better]. Javascript code is purely
functional with just two exceptions:
- `tap()` function, used for controllable side effects,
- `mutate()` function, used for controllable mutations.
Using `npm`:
```shell
$ npm install --save-dev @yagni-js/yagni
```
Using `yarn`:
```shell
$ yarn add -D @yagni-js/yagni
```
Source code is written using [ES6 modules][es6-modules], built using
[][rollup] and distributed in two formats - as CommonJS module and as
ES6 module.
CommonJS usage:
```javascript
const _ = require('@yagni-js/yagni');
```
ES6 module usage:
```javascript
import * as _ from '@yagni-js/yagni';
// or
import { pipe, transform, map } from '@yagni-js/yagni';
```
Not yet available, please check sources.
Here is a function to convert an array of objects to http request query string:
```javascript
import * as _ from '@yagni-js/yagni';
const toQuery = _.pipe([
_.map(
_.pipe([
_.transformArr([
_.pick('key'),
_.pipe([
_.pick('value'),
encodeURIComponent
])
]),
_.join('=')
])
),
_.join('&'),
_.concat('?')
]);
```
Having input as:
```javascript
const params = [
{key: 'name', value: 'John Smith'},
{key: 'age', value: 35},
{key: 'country', value: 'UK'}
];
```
the result will be the following:
```javascript
const query = toQuery(params);
// query === '?name=John%20Smith&age=35&country=UK'
```
[][unlicense]
[]: https://github.com/jfmengels/eslint-plugin-fp
[]: https://github.com/idmitriev/eslint-plugin-better
[]: https://hacks.mozilla.org/2015/08/es6-in-depth-modules/
[]: https://rollupjs.org/
[]: http://unlicense.org/