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

curry-named

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

curry-named - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

20

index.js
'use strict'
function curryNamed (keys, fn) {
return function helper (o) {
return function (o2) {
const obj = Object.assign({}, o, o2)
return includes(keys, Object.keys(obj)) ? fn(obj) : helper(obj)
return function helper (cache) {
return function (...objects) {
const incoming = Object.assign({}, ...objects)
const argsOverridden = includesSome(Object.keys(cache), Object.keys(incoming))
const error = `The following arguments were overidden: ${argsOverridden}`
if (argsOverridden.length > 0) throw Error(error)
const obj = Object.assign({}, cache, ...objects)
return includesEvery(keys, Object.keys(obj)) ? fn(obj) : helper(obj)
}
}
}({})
}
const includes = (mandatory, received) =>
const includesEvery = (mandatory, received) =>
mandatory.every(key =>
received.includes(key))
const includesSome = (mandatory, received) =>
mandatory.filter(key =>
received.includes(key))
module.exports = curryNamed
{
"name": "curry-named",
"version": "1.0.0",
"version": "1.1.0",
"description": "Curry for named arguments",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,3 +5,3 @@ # curry-named

## usage
## Usage

@@ -19,2 +19,11 @@ ```js

### Partial application works too
```js
cont { partial } = require('lodash/fp')
const partiallyApplied = partial(foo)([{ a: 1 }])
const actual = partiallyApplied({ b: 2 })({ c: 4 })
const expected = 7
```
## Inspiration

@@ -21,0 +30,0 @@

const test = require('tape')
const { partial } = require('lodash/fp')
const curry = require('./')
test('basic test', function (t) {
const foo = curry(
['a', 'b', 'c'],
({a, b, c}) => a + b + c)
const foo = curry(
['a', 'b', 'c'],
({a, b, c}) => a + b + c)
test('original function', t => {
const actual = foo({ a: 1, b: 2, c: 4})
const expected = 7
t.equal(actual, expected)
t.end()
})
// const actual = curry(foo, keys)({ a: 1 })({ a: 1, b: 2, c: 3}) TODO fail
const actual = foo({ a: 1 })({ b: 2, c: 3})
const expected = 6
test('currying', t => {
const actual = foo({ a: 1 })({ b: 2, c: 4})
const expected = 7
t.equal(actual, expected)
t.end()
})
test('partial application (simple)', t => {
const actual = foo({ a: 1 })({ b: 2 }, { c: 4 })
const expected = 7
t.equal(actual, expected)
t.end()
})
test('partial application (lodash)', t => {
const partiallyApplied = partial(foo)([{ a: 1 }])
const actual = partiallyApplied({ b: 2 })({ c: 4 })
const expected = 7
t.equal(actual, expected)
t.end()
})
test('argument overriding', t => {
try {
foo({ a: 1 })({ a: 1, b: 2, c: 4})
} catch (e) {
return t.end()
}
})
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