Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apply-or

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apply-or - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

changelog.md

17

index.js

@@ -18,12 +18,9 @@ 'use strict'

*
* @param {Function|*} fn
* @param {Function|*} func
* Function to be invoked.
*
* @param {Array} [args]
* @param {Array|*} [args]
* Arguments to apply to function.
*
* @param {*} def
* Default value to return if `fn` is not a function.
*
* @param {*} self
* @param {*} [self]
* `this` value.

@@ -35,6 +32,6 @@ *

function apply (fn, args, def, self) {
return (typeof fn === 'function')
? fn.apply(self, array(args))
: def
function apply (func, args, self) {
return (typeof func === 'function')
? func.apply(self, array(args))
: func
}
{
"name": "apply-or",
"version": "0.1.1",
"version": "0.2.0",
"description": "Invoke .apply if value is a function, otherwise, return default value.",
"main": "index.js",
"scripts": {
"dev": "nodemon -V -x 'npm run test' -e 'js json'",
"dev": "nodemon -x 'npm run test' -e 'js json'",
"standard": "standard",

@@ -9,0 +9,0 @@ "test": "node test.js test/**/*.js | tap-spec",

@@ -9,2 +9,6 @@ # apply-or

## Why?
`Function.prototype.bind` is normally sufficient; however, there are situations where it is useful to treat a value as a `Function` (invoke it) only if it is indeed a `Function`; otherwise, return it as-is. Calling `.apply` on a value that is not a function would cause an error.
## Example

@@ -14,13 +18,23 @@

function max () {
return Math.max.apply(null, this.val)
function divmax (divisor) {
return Math.max.apply(null, this.val) / divisor
}
var data = {
val: [3, 2, 1]
val: [9, 7, 15, 12]
}
apply(max, null, null, data)
apply(divmax, 5, data)
//=> divmax.apply({ val: [9, 7, 15, 12] }, [5])
//=> 15 / 5
//=> 3
## API
###### `apply(func, args, self)`
* `func` Function to be invoked.
* `args` Arguments to apply to function.
* `self` `this` value.
## License

@@ -27,0 +41,0 @@

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