https://github.com/morganconrad/fobu
YA functional utilities for JavaScript Objects, mimicking ES6 Array methods.
https://github.com/morganconrad/fobu
filter foreach functional-programming javascript map object reduce
Last synced: about 1 year ago
JSON representation
YA functional utilities for JavaScript Objects, mimicking ES6 Array methods.
- Host: GitHub
- URL: https://github.com/morganconrad/fobu
- Owner: MorganConrad
- License: mit
- Created: 2018-11-26T23:40:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-28T20:15:58.000Z (about 6 years ago)
- Last Synced: 2025-01-11T14:45:39.841Z (about 1 year ago)
- Topics: filter, foreach, functional-programming, javascript, map, object, reduce
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](http://travis-ci.org/MorganConrad/fobu)
[](https://github.com/MorganConrad/fobu)
[](https://www.npmjs.org/package/fobu)
[](https://snyk.io/test/github/morganconrad/fobu)
[](https://coveralls.io/github/MorganConrad/fobu)
# fobu
Yet another set of utilities to do "functional programming" on JavaScript Objects.
You can find many other versions of these online, but I like mine better :-).
Basically, allows you to use the ES6 array methods like `map()` and `reduce()` on objects.
Maybe you will find this useful. I mainly put it on GitHub so I can easily cut and paste these into other code.
## API
All methods take the object as the first argument, and the user function (or "predicate") to be applied as the 2nd.
The method will loop over the key/value pairs in the object, as determined by `Object.keys(theObject)`.
The user function will usually be called with three arguments, much like the array versions.
- The value
- the key (for the corresponding array versions, this is the index)
- the entire object
For `reduce() and `reduceRight()`, the user function takes an additional `acc` first argument.
### every(object, predicate)
Tests if every key/value pair passes `predicate(value, key, object)`. Returns true or false, and will "short-circuit".
### find(object, predicate)
Finds the first key/value pair that passes `predicate(value, key, object)`.
- returns it as an array: [key, value]
### filter(object, predicate)
Creates a new object with (shallow) copies of all key/value pairs that pass `predicate(value, key, object)`.
### forEach(object, fn)
Calls fn(value, key, object) for every key/value pair.
### map(object, fn)
Returns a new result object, with result[key] = fn(object[key], key, object).
### reduce(object, fn, initialValue)
### reduceRight(object, fn, initialValue)
### some(object, predicate)
Tests if any key/value pair passes `predicate(value, key, object)`. Returns true or false, and will "short-circuit".