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

fn-pasta

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fn-pasta - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

38

fn-pasta.js

@@ -6,3 +6,3 @@ // pasta.js

function comp (args) {
if (!Array.isArray(args)) args = p.arrify(arguments)
if (!Array.isArray(args)) args = p.slice(arguments)
return function (input) {

@@ -16,8 +16,7 @@ return args.reduceRight(function (last, cur) {

function partial (fn) {
var args = p.arrify(arguments)
args.shift() // remove the function
var args = p.slice(arguments, 1)
return function () {
var innerArgs = p.arrify(arguments)
var innerArgs = p.slice(arguments)
return fn.apply(this, args.map(function (arg) {
if (arg == null) return innerArgs.shift()
if (typeof arg === 'undefined') return innerArgs.shift()
return arg

@@ -29,4 +28,15 @@ }).concat(innerArgs)

function curry (fn, times) {
var args = []
, self = this
if (!(times >= 2)) times = 2
return function currying (arg) {
args.push(arg)
if (args.length === times) return fn.apply(self, args)
return currying
}
}
var numOfArgs =
{ '1': function (fn) { return function (arg) { return fn(arg) } }
{ '1': function (fn) { return function (a) { return fn(a) } }
, '2': function (fn) { return function (a, b) { return fn(a, b) } }

@@ -39,3 +49,3 @@ , '3': function (fn) { return function (a, b, c) { return fn(a, b, c) } }

return function () {
return fn.apply(null, p.arrify(arguments).slice(0, num))
return fn.apply(null, p.slice(arguments).slice(0, num))
}

@@ -52,3 +62,3 @@ }

if (typeof def !== 'undefined') val = def(cas)
else if (typeof obj._default !== 'undefined') val = obj._default
else if (typeof obj._default === 'string') val = obj[obj._default]
else val = obj['default']

@@ -88,2 +98,4 @@ }

, '': function (a) { return a }
// Default
, '_default': ''
}

@@ -95,2 +107,10 @@

function all (fn) {
fn = args(2)(fn)
return function () {
var args = p.slice(arguments)
return args.reduce(fn)
}
}
function get (key) {

@@ -110,2 +130,4 @@ return function (obj) {

, partial: partial
, curry: curry
, all: all
}

@@ -112,0 +134,0 @@

{ "name": "fn-pasta"
, "version": "0.0.3"
, "version": "0.0.4"
, "author": "Nick Niemeir <nick.niemeir@gmail.com> (http://nrn.io)"

@@ -4,0 +4,0 @@ , "main": "fn-pasta.js"

@@ -14,7 +14,14 @@ Functional Pasta

partial(fn, [args, ...])
partial(fn[, args, ...])
------------------------
Return fn with arguments applied. Blank spots are held for nulls.
Return fn with arguments applied. Passing undefined will leave a hole
that will be filled with arguments from the second fn call before
the rest are appended to the arguments list.
curry(fn[, times])
------------------
Return a function that takes a single argument *times* number of times,
and then calls fn in the context it was called in. *times* defaults/min is 2.
limit(num)

@@ -47,1 +54,7 @@ ----------

all(fn)
-------
Return a function that reduces all of it's arguments over fn. fn gets passed
two arguments at a time.

@@ -8,22 +8,25 @@ var p = require('../fn-pasta')()

, asdf: 42
, _default: 'blah'
, default: 'blah'
}
, strDef =
{ foo: 'bar'
, asdf: 42
, _default: 'asdf'
}
, caseObj = p.casify(obj)
, strDefCas = p.casify(strDef)
, otherCase = p.casify(obj, function () {return 'doh'})
, add = p.op('+')
, sum = p.all(p.op('+'))
function add (a, b) {
return a + b
}
t.plan(15)
t.equal(p.d('asdf'), 'asdf', 'Ident function')
t.equal(caseObj('foo'), 'bar', 'Existing case')
t.equal(caseObj('weeeeee'), 'blah', 'Non-extant case')
t.equal(otherCase('notThere'), 'doh', 'Non-extant explicit default')
t.equal(strDefCas('n/a'), 42, 'Default property')
t.equal(caseObj('weeeeee'), 'blah', 'Default value')
t.equal(otherCase('notThere'), 'doh', 'Default function')
t.equal(p.one(add)('a', 'b'), 'aundefined', 'One uses only the first arg')
t.equal(p.args(4)(function (a, b, c, d, e) { return e })(1, 2, 3, 4, 5, 6)
, undefined
t.equal(p.args(4)(sum)(1, 2, 3, 4, 5, 6)
, 10
, 'Arg limit using default/limit fn')

@@ -45,4 +48,9 @@

t.equal(p.partial(add, null, 'b')('c'), 'cb','Partial application')
t.equal(p.partial(add, undefined, 'b')('c'), 'cb','Partial application')
t.equal(p.curry(add)(1)(1), 2, 'Curry default')
t.equal(p.curry(sum, 5)(1)(2)(3)(4)(5), 15, 'Curry 5 times')
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