Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Polymorphic curried map for functional style JS
Javascript provides a native map function for arrays. However, sometimes we need to apply the same function to all properties of an object. Sometimes we are not sure or do not care which type of data we receive as an input. Sometimes we don't even know if the data is in fact present. So we end up writing loops, type checks, etc. Poly-map solves this problem in a generic way works equally well with arrays and objects so you never have to write those annoying iterations again.
npm install poly-map
let map = require('poly-map');
let object = {
a: 100,
b: 200
};
let array = [100, 200];
function double(number) {
return number * 2;
}
// Basic map
let result = map(double, object);
// -> {a: 200, b: 400}
result = map(double, array);
// -> [200, 400]
// Maybe
result = map(double, undefined);
// -> undefined
// Primitives
result = map(double, 100);
// -> 200
// Promise support
let data = Promise.resolve([100, 200])
map(double, data).then(console.log)
// -> [200, 400]
// Promise support
data = [Promise.resolve(100), Promise.resolve(200)]
map(double, [data1, data2]).then(console.log)
// -> [200, 400]
// Pipeline-style usage
getDataAsPromise()
.then(map(double))
.then(console.log)
// Async function support
data = [100, 200]
map(x => fetch(`http://some.com/resource/${x}`, data)
.then(map(x => x.json()))
.then(console.log)
npm test
FAQs
Polymorphic curried map for functional style JS
The npm package poly-map receives a total of 451 weekly downloads. As such, poly-map popularity was classified as not popular.
We found that poly-map 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.