Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
barely-functional
Advanced tools
*A Tiny functional programming library *
barely-functional is a tiny (2.1Kb without minification) library for doing functional programming. It includes curry
and compose
, and wraps several native es5 methods including .map()
.reduce()
and .filter()
and several es6
methods such as .every()
and .find()
. The library also contains several non native functions inspired (READ: stolen)
from ramdajs.
npm i barely-functional
const _ = require('barely-functional')
const sumOfEven = _.compose(_.sum, _.filter((e) => e % 2 === 0))
Barely functional is written in es6. It will run on node.js v4.0 and up. If you wish to use it in the browser you need to use babel and (webpack/browserify)
Yes it is, but it is also a lot bigger. If you a writing a small module, you might not want to include all of Ramda.
## API
Adds the specified value to the end of the supplied array.
_.append(5, [1, 2, 3, 4]);
// => [1, 2, 3, 4, 5]
Performs right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary.
const add1 = (n) => n + 1
const double = (n) => n * 2
const add1AndDouble = _.compose(double, add1)
add1AndDouble(5)
// => 12
Concatenates two arrays.
_.concat([1, 2, 3], [4, 5, 6]);
// => [1, 2, 3, 4, 5, 6];
Returns a curried equivalent of the provided function. The curried function has two unusual capabilities. First, its arguments needn't be provided one at a time. If f is a ternary function and g is R.curry(f), the following are equivalent:
const sum3 = _.curry((a, b, c) => a + b + c)
sum3(1)(2)(3)
// => 6
sum3(1)(2, 3)
// => 6
sum3(1, 2)(3)
// => 6
sum3(1, 2, 3)
// => 6
Returns a new list without the first n elements
_.drop(2, [1, 2, 3, 4])
// => [3, 4]
Returns a new list without the last n elements
_.dropLast(2, [1, 2, 3, 4])
// => [1, 2]
Returns true if every element in the list satisfies the predicate function.
_.every(n => n > 2, [2, 3, 4])
// => false
every(n => n > 2, [3, 4, 5])
// => true
Returns a new list containing only the elements in the list that satisfies the predicated function.
_.filter(n => n > 2, [1, 2, 3, 4])
// => [3, 4]
Returns the first element satisfying the predicate function. If no element can be found it returns undefined.
_.find(n => n === 2, [1, 2, 3,4])
// => 2
Returns the index of first element satisfying the predicate function. If no element can be found it returns -1.
_.findIndex(n => n === 2, [1, 2, 3,4])
// => 1
Returns true if the given object has a property with the specified name.
_.has('a', {a:2})
// => true
_.has('b', {a:2})
// => false
Returns the first element of a list
_.head([1, 2, 3])
// => 1
Returns true if the list includes the given element
_.includes('a', ['a', 'b', 'c'])
// => true
Returns the index of the specified element in the list. Returns -1 if the element is not in the list
_.indexOf(1, [0, 1, 2, 3])
// => 1
Returns all elements of the list except the last
_.init([1, 2, 3, 4]])
// => [1, 2, 3]
Returns a string by concatenating all elements of the list interlaced with the specified string.
_.join('|', ['a', 'b', 'c'])
// => "a|b|c"
### keys :: Object -> [String]
Returns a list of the given objects keys.
```js
_.keys({a: 1, b: 2, c: 3})
// => ["a", "b", "c"]
Returns the last element of the list.
_.last([1, 2, 3])
// => 3
Returns the length of a list / function / string.
_.length([1, 2, 3])
// => 3
Returns a new list, constructed by applying the supplied function to every element of the supplied list.
_.map(n => n + 1, [1, 2, 3])
// => [2, 3, 4]
Tests a regular expression agains a string and returns a list of matches.
_.match(/a./, 'falaffel')
// => ['al', 'af']
return s the nth element of a list.
_.nth(3, [1, 2, 3, 4, 5])
// => 4
Returns the specified property of the given object.
_.prop('msg', {msg: 'hello wold'})
// => 'hello world'
returns a list of values related to the specified properties.
_.props(['a', 'b', 'c'], {a:1 b: 2, c: 3})
// => [1, 2, 3]
returns a list of all integers between the two specified numbers. the last number is not included.
_.range(3, 7)
//=> [3, 4, 5, 6]
Returns a single item by iterating through the list, successively calling the iterator function and passing it an accumulator value and the current value from the array, and then passing the result to the next call. The iterator function receives two values: (acc, value). It may use R.reduced to shortcut the iteration.
_.reduce((a, b) => a + b, 10, [1, 2, 3])
//=> 16
Returns a single item by iterating through the list, successively calling the iterator function and passing it an accumulator value and the current value from the array, and then passing the result to the next call.
Similar to reduce, except moves through the input list from the right to the left.
The iterator function receives two values: (acc, value)
_.reduceRight((a, b) => a + b, 10, [1, 2, 3])
// => 16
returns a new string by replacing each substring or regex match with a replacement. When given a string as the first argument, only the first occurance of the substring will be replaced.
_.replace(/\d/g, 5, '1, 2, 3, 4')
// => '5, 5, 5, 5'
returns a new list with the same elements in reverse order.
_.reverse([1, 2, 3])
// => [3, 2, 1]
returns a new list containing only the elements from the first index(inclusive) to the last index(exclusive)
_.slice(1, 4, [1, 2, 3, 4, 5])
// => [2, 3, 4]
returns true if any of the elements in the list satisfies the predicate function.
_.some(n => n > 2, [0, 1, 2, 3])
// => true
_.some(n => n > 2, [0, 1, 2])
// => false
returns a sorted copy of the given list based on the sorting function.
_.sort((a, b) => a - b, [2, 3, 1, 4])
// => [1, 2, 3, 4]
returns a list of strings based on the given separator
_.split(/\d/, "I have 3 apples and 2 oranges")
//=> ["I have", "apples and ", "oranges"]
returns the sum of all numbers in the list
_.sum([1, 2, 3])
// => 6
returns a copy of the list without the first element
_.tail([1, 2, 3])
//=> [2, 3]
returns the first n elements of a list
_.take(2, [1, 2, 3, 4])
// => [1, 2]
returns the last n elements of a list
_.takeLast(2, [1, 2, 3, 4])
// => [3, 4]
returns if the RegExp matches the string
_.test(/\d/, 'I have 3 Apples')
// => true
_.test(/\d/, 'I have three Apples')
// => false
returns a new string where all letters are lower case
_.toLowerCase('I have a dream')
// => 'i have a dream'
returns a new string where all letters are upper case
_.toLowerCase('I have a dream')
// => 'I HAVE A DREAM'
returns a new string where all leading and trailing spaces has been removed
_.trim(' I have a dream ')
// => 'I have a dream'
returns a list of all values in the given Object
_.values({x: 1, y: 2, x: 3})
// => [1, 2, 3]
basic.js is just 1.1KB. It contains all the native es5/es6 functions as well as curry and compose.
const _ = require('barely-functional/basic')
FAQs
*A Tiny functional programming library *
We found that barely-functional demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.