Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

fn

v1.0.4arrow_drop_down
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
STATUS
Passing
DOWNLOADS
0
VISIBILITY
Public
PUBLISHED
A year ago
SIZE
7 KB
subject
Utilities for working with functions
1 contributor
Use fn in your project ?
Copied
npm i @bit/narwold.lib._utils.fn
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
revert changes
reload
toggle layout
maximize
extractArgs(function(a, b) {}); // returns ['a', 'b']
modifieddraft
let multiply3Subtract1ShowFriendly = pipe( n => n * 3, n => n - 1, n => `${n} is the result` console.log( multiply3Subtract1ShowFriendly(2)
modifieddraft
chevron_left
chevron_right

Utilities for working with functions

extractArgs (
fn:Function
) : Array<string>

Given any function, will attempt to return a list of argument names. IMPORTANT - This function will not properly deal with ES6 destructuring.

Example
extractArgs(function(a, b) { })
// returns ['a', 'b']
Argument
fn: Function
Returns
Array<string>

returns a list of argument names

pipe (
functions:...Function
) : Function

Given an argument list of functions, will output a new function. That function, when given any input, will be run through the list of functions given in the previous step, with the output of the previous function piped to the next.

Example
let multiply3Subtract1ShowFriendly = pipe(
	n => n * 3,
	n => n - 1,
	n => `${n} is the result`
)
console.log(multiply3Subtract1ShowFriendly(2)) // "5 is the result"
Argument
functions: ...Function
Returns
Function

constructed function that, when run, will run through all functions passed as arguments

Test Summary

Function Utilities #extractArgs() should extract arg names from a regular function

Pass

Function Utilities #extractArgs() should extract arg names from an arrow function

Pass

Function Utilities #extractArgs() should extract arg names from an arrow function without parens

Pass

Function Utilities #extractArgs() should extract arg names from a function with complex contents

Pass

Function Utilities #pipe() should pipe several functions together

Pass

Function Utilities #pipe() should ignore non-functions

Pass