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

littless

v1.0.9

Published

[![Build Status](https://drone-github.pr00f.media/api/badges/DPr00f/littless/status.svg)](https://drone-github.pr00f.media/DPr00f/littless)

Downloads

3

Readme

Littless

Build Status

This project is a helper for serverless services that is achieved through the usage of adapters.

Inspired by express middlewares and the idea was to be able to reuse some of them.

Install

npm install littless -S

Install an adapter

npm install littless-adapter-netlify -S

or

npm install littless-adapter-vercel -S

Usage

Netlify example

Create a functions/test.js

const littless = require('littless').default;
const adapter = require('littless-adapter-netlify').default;
const cookieParser = require('cookie-parser');
const {json} = require('body-parser');
const app = littless();

app.useAdapter(adapter);

app.use(json({
  extended: true
}));
app.use(cookieParser());
app.useAfter((req, res) => {
  if (!res.shouldOutput()) {
    res.status(500)
      .send({
        error: true,
        message: 'No body was sent up until this point'
      })
  }
});

exports.handler = app.any(async (req, res, next) => {
  console.dir(req);
  res.send({
    path: req.path,
    cookies: req.cookies,
    query: req.query,
    body: req.body
  });

  req.on('data', (chunck) => {
    console.log(chunck);
  })

  next();
});

Vercel example

Create a api/test.js

const littless = require('littless').default;
const adapter = require('littless-adapter-vercel').default;
const cookieParser = require('cookie-parser');
const app = littless();

app.useAdapter(adapter);
app.use(cookieParser());
app.useAfter((req, res) => {
  if (!res.shouldOutput()) {
    res.status(500)
      .send({
        error: true,
        message: 'No body was sent up until this point'
      })
  }
});

module.exports = app.any(async (req, res, next) => {
  res.send({
    path: req.path,
    cookies: req.cookies,
    query: req.query,
    body: req.body
  });

  next();
});

Please note that vercel already parses the body so no need to use the body-parser

Specify the method to use

You can use the already made middlewares to filter the allowed methods

app.get(/* ... */)
app.post(/* ... */)
app.put(/* ... */)
app.delete(/* ... */)

Or you can use only or except to construct your own

app.only(['POST', 'GET'], (req, res, next) => {
  /* ... */
})
app.except(['DELETE'], (req, res, next) => {
  /* ... */
})

Using adapters

Adapters can be used with .useAdapter

Available adapters

For now the available parsers are for netlify and vercel but you can inspect the adapters code and create your own.

If you do create a new parser please reach out to me so I can include it in the official list.

App Available Methods

| Method | Arguments | Description | | --------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | | useAdapter | Adapter Class | (Required) Specify which adapter to be used to parse information from serverless service | | use | Function(req, res, nextMiddleware) | Append middleware | | useAfter | Function(req, res, nextMiddleware) | Append middleware to be used after the callback function | | useBefore | Function(req, res, nextMiddleware) | Preprend middleware | | post | Function(req, res, nextMiddleware) | Only allow POST and OPTIONS requests and calls back the first argument | | get | Function(req, res, nextMiddleware) | Only allow GET and OPTIONS requests and calls back the first argument | | delete | Function(req, res, nextMiddleware) | Only allow DELETE and OPTIONS requests and calls back the first argument | | put | Function(req, res, nextMiddleware) | Only allow PUT and OPTIONS requests and calls back the first argument | | any | Function(req, res, nextMiddleware) | Allows any requests and calls back the first argument | | only | Methods (Array), Function(req, res, nextMiddleware) | Allows user to specify methods to allow and calls back the second argument | | except | Methods (Array), Function(req, res, nextMiddleware) | Allows user to specify methods to block and calls back the second argument |

Request Api

| Method / Property | Type | Description | | ----------------- | --------------- | --------------------------------------------------------------------------- | | headers | Object | Request headers are accessible from this property | | query | Object | Query params are accessible from this property | | httpMethod | String | The method of the request | | path | String | The url path | | body | String / Object | Normally a string but can be parsed depending on the service or the adapter | | raw | Object | The original event sent by the service |

Response Api

| Method | Arguments | Description | | ------- | -------------------------- | -------------------------------------------------------------------------------- | | status | code:Number | Specify the response code | | set | key:String, value:String | Sets a header for the response i.e res.set('Content-Type', 'application/json') | | headers | key:String, value:String | Alias for set | | send | body:Any | Sets the response body |

Note: Possibly the response should have a way of setting a cookie but this can be achieved with the headers or creating a middleware for that which might be an option for the future.