
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
F.js is a collection of helper methods used for functional and reactive programming in JavaScript. It provides methods for transforming, filtering, reducing and other operations which work on arrays, HTMLCollections, ES6 generators (and almost all other indexables) and streams of events.
With bower
bower install f.js --save-dev
And include the main script file into your project:
<script src="bower_components/f.js/dist/F.min.js"></script>
With NPM
npm install f-js --save-dev
And require the f-js
module into your files:
var Fjs = require("f-js"),
F = Fjs.F,
P = Fjs.P;
Manually downloading the zip file
curl https://codeload.github.com/colin-dumitru/F.js/zip/v0.4.5 -o F.js.zip
unzip F.js.zip
And include the main script file into your project:
<script src="F.js-0.4.5/dist/F.min.js"></script>
F.js works with regular Arrays (RUN)
var people = [
{ name: "John", age: 31},
{ name: "Colin", age: 25},
{ name: "Dave", age: 13},
{ name: "Vic", age: 52}
];
var result = F(people)
.filter(function(person) {
return person.age < 50;
})
.property("name")
.drop(1)
.zip(["first", "second"])
.toArray();
document.write(JSON.stringify(result));
HTML collections (RUN)
var links = document.getElementsByTagName("a"),
titles = document.getElementsByTagName("h5");
var result = F(links)
.property("href")
.dropWhile(function(val) {
return val.indexOf("http") == -1;
})
.zip(
F(titles)
.property("innerText")
)
.toMap();
document.write(JSON.stringify(result));
And even ES6 generators (RUN)
function *gen() {
for (var i = 0; i < 10; i++) {
yield i;
}
}
var result = F(gen())
.fold((l, r) => l + r);
document.write(result);
So at it's core, F.js is just another functional library. But the real power comes when you combine reactive programming with streams.
Streams are nothing more than promises which can resolve multiple times. You can either push or consume values from a stream, all done asynchronously. This enabled you to write more modular async code, by passing values through streams and not callbacks.
This next examples takes a search query from an input element and displays a list of images which match the given query, all done using streams.
Stream example (RUN)
var input = $("#search_query"),
keyStream = F.eventStream(input, "keydown"),
wordStream = F.stream(),
imageStream = F.stream();
F(keyStream)
.property("keyCode")
.accumulateUntil(P.equalTo(13)) /* Enter */
.map(function() {
return input.val();
})
.feedStream(wordStream)
.pullStream(keyStream);
F(wordStream)
.each(text =>
$.ajax({
url: url + text,
dataType: 'jsonp',
jsonp: 'jsonFlickrApi',
jsonpCallback: 'jsonFlickrApi'
})
.then(imageStream.push.bind(imageStream)))
.pullStream(wordStream);
F(imageStream)
.each(reset)
.property("photos", "photo")
.each(images =>
F(images)
.map(render)
.foreach(display))
.pullStream(imageStream);
Got you interested? Visit our wiki pages for more examples and information.
FAQs
Dead simple library for functional and reactive programming
The npm package f-js receives a total of 21 weekly downloads. As such, f-js popularity was classified as not popular.
We found that f-js 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.