koa-qs-lru

Nested query string support for Koa using LRU cache.

Usage no npm install needed!

<script type="module">
  import koaQsLru from 'https://cdn.skypack.dev/koa-qs-lru';
</script>

README

Koa Query String LRU

NPM version build status Test coverage David deps npm download

By default, Koa uses the native querystring module which does not provide nesting support and caches parsed results in a plain object regardless of his size.

This pathes a Koa app with:

  • qs (a querystring parsing and stringifying library with some added security)
  • lru-cache (a cache object that deletes the least-recently-used items)

Installation

$ npm install --save koa-qs-lru

Usage

var koa = require('koa')
var qs = require('koa-qs-lru');

// qs & lru-cache default settings
var app = qs(koa());

// custom settings
var app = qs(koa(), {
  cache: {},     // lru-cache options
  parse: {},     // qs -> parse options
  stringify: {}  // qs -> stringify options
});

Check qs and lru-cache packages for API documentation.

Example

var koa = require('koa')
var qs = require('koa-qs-lru');

var app = qs(koa(), {
  cache: { max: 1000 },         // Keep last 1000 used query objects in cache
  parse: { parameterLimit: 1 }  // Parse only the first parameter
});

app.use(function *() {
  this.body = this.query;
});

app.listen(3000);

License

MIT