Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haltcase/stunsail
Super opinionated collection of utility functions.
https://github.com/haltcase/stunsail
collection functions hacktoberfest library modular tools utility
Last synced: 20 days ago
JSON representation
Super opinionated collection of utility functions.
- Host: GitHub
- URL: https://github.com/haltcase/stunsail
- Owner: haltcase
- License: mit
- Created: 2017-01-31T09:08:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-12-06T07:00:01.000Z (about 4 years ago)
- Last Synced: 2024-12-23T00:42:47.234Z (29 days ago)
- Topics: collection, functions, hacktoberfest, library, modular, tools, utility
- Language: JavaScript
- Homepage: https://stunsail.netlify.com/
- Size: 555 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license
Awesome Lists containing this project
README
# stunsail · [![Version](https://flat.badgen.net/npm/v/stunsail)](https://www.npmjs.com/package/stunsail) [![License](https://flat.badgen.net/npm/license/stunsail)](https://www.npmjs.com/package/stunsail) [![Travis CI](https://flat.badgen.net/travis/citycide/stunsail)](https://travis-ci.org/citycide/stunsail) [![JavaScript Standard Style](https://flat.badgen.net/badge/code%20style/standard/green)](https://standardjs.com)
> Super opinionated, functional utility collection.
## installation
```sh
# using yarn:
yarn add stunsail# or npm:
npm i stunsail
```## usage
```js
import S from 'stunsail'// commonjs / ES5
const S = require('stunsail')
```A module version is also available if you use ES modules:
```js
import S from 'stunsail/es'
```You can also selectively `import` just what you need, which is especially
recommended if you use the [babel plugin](#babel-plugin) as this is much
more efficient.```js
import { defaults, kebabCase, matches, toArray } from 'stunsail'const { defaults, kebabCase, matches, toArray } = require('stunsail')
```## api
See the [documentation here](https://stunsail.netlify.com/docs/api)
for a more complete reference.### overview
```js
import {
clamp,
map,
filter,
first,
matches,
pipe,
toNumber
} from 'stunsail'const number = pipe(
'36',
num => toNumber(num), // -> 36
num => clamp(num, 10, 30), // -> 30
num => console.log(num) // -> 'number = 30'
)const found = pipe(
map([1, 2, 3, 4, 5], num => ({ value: num * 2 })),
// -> [{ value: 2 }, { value: 4 }, ... ]
objects => filter(objects, obj => matches(obj, { value: 6 })),
// -> [{ value: 6 }]
objects => first(objects),
// -> { value: 6 }
obj => console.log(obj.value)
// -> 6
)
```### with `param.macro`
stunsail is really fun to use alongside [`param.macro`][macro] — a Babel
plugin that lets you partially apply functions at compile time. You can make
the [above example](#overview) look like this:```js
import { _, it } from 'param.macro'
import {
clamp,
map,
filter,
first,
matches,
pipe,
toNumber
} from 'stunsail'const number = pipe(
'36',
toNumber(_),
clamp(_, 10, 30),
console.log(`number = ${_}`)
)const found = pipe(
map([1, 2, 3, 4, 5], { value: it * 2 }),
filter(_, matches(_, { value: 6 })),
first(_),
console.log(_.value)
)
```This combo allows you to use stunsail like you would lodash/fp or Ramda,
but without the runtime performance hit that comes with an auto-curried
library.## babel plugin
stunsail ships with a babel plugin included. It can be used like so:
### babel v7
`.babelrc.js` →
```js
module.exports = {
presets: [],
plugins: ['module:stunsail/babel']
}
```### babel v6
`.babelrc` →
```json
{
"presets": [],
"plugins": ["stunsail/babel"]
}
```This will allow you to write simpler `import`s but output
and still benefit from more efficient alternatives, ie:```js
import { partition } from 'stunsail'// commonjs / ES5
const { partition } = require('stunsail')
```... will be compiled to:
```js
import partition from 'stunsail/partition'// commonjs / ES5
const partition = require('stunsail/partition')
````import` statements can optionally be compiled to equivalent `require`
calls to avoid adding a module transformer separately.### configuration
Optionally configure the plugin by using an Array of
`[pluginName, optionsObject]`:```js
module.exports = {
presets: [],
plugins: [
['module:stunsail/babel', {
useRequire: false,
useModules: true
}]
]
}
```| property | type | default | description |
| :----------: | :-------: | :-----: | ----------- |
| `useRequire` | `Boolean` | `false` | Whether to convert `import` statements to `require`s. Has no effect on `require` calls. |
| `useModules` | `Boolean` | `false` | Redirect `stunsail` imports to `stunsail/es`. Ignored if `useRequire` is set to `true`. |## see also
* [`param.macro`][macro] – Babel plugin for compile-time partial application
and lambda parameters
* [`tryad`][tryad] – Monadic mashup of Maybe & Either (Option/Result) for
more functional null & error handling## contributing
Search the [issues](https://github.com/citycide/stunsail) if you come
across any trouble, open a new one if it hasn't been posted, or, if you're
able, open a [pull request](https://help.github.com/articles/about-pull-requests/).
Contributions of any kind are welcome in this project.## license
MIT © [Bo Lingen / citycide](https://github.com/citycide)
[macro]: https://github.com/citycide/param.macro
[tryad]: https://github.com/citycide/tryad