New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ffn

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ffn

Turns arrays and values into Filtering Functions.

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8K
decreased by-4.51%
Maintainers
1
Weekly downloads
 
Created
Source

ffn

Turns arrays and values into Filtering Functions.

Many projects use callbacks to filter values. Sometimes this filtering involves complex conditions that need a function. Other times one just wants to test if the value equals another, or if the value appears in an array of acceptable values. Instead of making your project’s end-users write filters like x => x === 'value' or x => ['ok', 'also ok'].includes(x), let them provide the value or the array directly, and ffn will turn it into a filtering function.

Installation

Requires Node.js 6.0.0 or above.

npm i ffn

API

The module exports a single function.

Parameters

  1. f (any): A Function, an Array, or some other value.
  2. Object argument:
    • Optional: blacklist (bool): Set to true if ffn is being used to create a blacklist. This will make falsey values test true when f is undefined. Defaults to false.

Return Values

  • If f is a Function: returns f
  • If f is omitted or otherwise undefined: returns a function that tests whether its argument is truthy (unless blacklist is true)
  • If f is an Array: returns a function that tests whether its argument is included in f
  • Otherwise: returns a function that tests whether its argument is strictly equal to f

Example

const ffn = require('ffn')

const arr = [1, 2, 3, 4, 5]

// ffn returns functions as-is
arr.find(ffn(x => x % 2 === 0)) // 2

// ffn creates a function which checks for inclusion in the array
arr.find(ffn([4, 5])) // 4

// ffn creates a function which checks for equality with the value
arr.find(ffn(3)) // 3

For more projects like this, check out the xfn family of modules.

Keywords

FAQs

Package last updated on 14 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc