shadow-fns v1.0.1
shadow-fns
Introduction
A javascript function library.
This library referenced ramda and lodash, especially ramda.
Chasing for more simplify and singleness function.
...Okay, just for my own preference.
Features
- Pure Function
- Functional
- Currying
- Pointfree
- No Context
- Close To Native
- More semantic
f.pipe(f.length, f.gt(5))
// => Means check the supplied parameter's length whether longer than 5.
f.tryCatch(JSON.parse, f.always({}))
// => Means try parse the supplied parameter, when throw an error will return `{}`.
f.pipe(f.map(f.prop('age')), f.sum)
// => Means get every `age` property from the list to an array, then sum it.
All functions read from left-to-right with humanized semantics.
Usage
Browser
<script src="./dist/shadow-fns.umd.min.js"></script>
You can also import from CDN
https://cdn.jsdelivr.net/npm/shadow-fns/dist/shadow-fns.umd.js
https://cdn.jsdelivr.net/npm/shadow-fns/dist/shadow-fns.umd.min.js
then
<script>
f.identity(10) // => 10
</script>
Node
npm i -D shadow-fns
or
yarn add --dev shadow-fns
then in cjs
const f = require('shadow-fns')
or in es
import { * as f } from 'shadow-fns'
then
const users = [
{ name: 'dog', age: 5 },
{ name: 'cat', age: 7 },
{ name: 'human', age: 12 }
]
const sumAge = f.pipe(
f.map(f.prop('age')),
f.sum
)
sumAge(users) // => 24
or just import the required functions
import { pipe, add, multiply } from 'shadow-fns'
const calc = pipe(add(2), multiply(2))
calc(3) // => 10
And if you are using es module, you can import source code directly,
which can show the comments and jump to the source in some IDE, will do much help to develop.
import { * as f } from 'shadow-fns/src'
Documentation
You can check the Full API documentation.
And I propose you to read the Usage Instruction, it will be helpful.
And if you'd like to contribute, see the Contributing Guide.
And Changelog is here.
Try
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago