shadow-fns
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

shadow-fns

Build Status npm module Coverage Status Dependency Status

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

Click Me!

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    0
    • latest

Version History

Package Sidebar

Install

npm i shadow-fns

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

342 kB

Total Files

293

Last publish

Collaborators

  • jinghua000