npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

idealist

v0.1.0-alpha

Published

Functional HTTP micro-framework

Downloads

4

Readme

Idealist

Functional HTTP micro-framework.

Usage

//Import dependencies.
const App = require('idealist');
const R = require('ramda');

//Import some Free Moands we'd like to use.
const FreeState = require('freeky/state');

//Some lenses to work with the Response structure.
const headers = R.lensProp('headers');
const body = R.lensProp('body');
const status = R.lensProp('status');

//Create an empty App.
const app = App.empty()

//We can just map over the monad and use the "headers" lens to modify the response headers
.use(R.map(R.over(headers, R.assoc('X-Powered-By', 'Monads'))))

//We can install our own interpreter, which must return a StateFuture.
.install(FreeState, m => App.StateFuture(state => {
  const x = m.run(state);
  return App.Future.of({_0: x[0], _1: x[1]});
}))

//And now we can use it!
.use(next => FreeState.get.chain(state => {
  console.log('The request URL is', state.req.url);
  console.log('The database config is', state.config.db);
  return next; //chain the "next" monad
}))

//We can plain ignore the input Monad and return our own. This is like not calling "next"
.use(_ => App.Free.of({status: 200, body: 'wut?', headers: {}}))

//Set the status and body by using lenses
.use(R.map(R.pipe(
  R.set(status, 200),
  R.set(body, 'Secret sauce!')
)));

//The returned app instance is also "middleware".
//Note that we must first "concat" to join the interpreters of both apps.
const actualApp = App.empty().concat(app).use(app);

//All we're doing is chaining over Free Monads, so we could write our middleware like:
const middleware = next => Monad.do(function*(){
  const {req} = yield FreeState.get;
  console.log('Request to ', req.url, 'started at ', Date.now())
  const res = yield next;
  console.log('Request finished at', Date.now())
  return res;
}, Free.of);

//Middleware are pure compsable functions which compose in reverse, so we could:
actualApp.use(pipe(middleware, middleware, middleware));

//Mounts an app on the specified port. The third argument will appear on the
//request state as "config".
App.mount(actualApp, 3000, {
  db: 'mydb://username:password@localhost:1337/db'
});