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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@trarn/middleware

v1.0.5

Published

Quick middleware for AVNX, poorly named since there is also helpers.

Readme

Avernix Technologies Middleware Library

This library provides a set of utility functions to simplify and standardize common tasks in your Node.js/Express applications.

Installation

To install the package, use npm or yarn:

npm install @trarn/middleware

or

yarn add @trarn/middleware

Usage

CommonJS (CJS) Example

If your project uses CommonJS, you can import and use the utilities as follows:

const {
    coerceBoolean,
    sanitizeParams,
    getParamValue,
    response,
    paramBuilder,
} = require('@trarn/middleware');

ECMAScript Modules (ESM) Example

If your project uses ECMAScript Modules, you can import and use the utilities as follows:

import {
    coerceBoolean,
    sanitizeParams,
    getParamValue,
    response,
    paramBuilder,
} from '@trarn/middleware';

1. coerceBoolean

Coerces a value to a boolean. This function is useful for standardizing the conversion of various types (like strings and numbers) to boolean values.

Example

// CommonJS
const { coerceBoolean } = require('@trarn/middleware');

// or ECMAScript Modules
import { coerceBoolean } from '@trarn/middleware';

console.log(coerceBoolean(true)); // returns true
console.log(coerceBoolean('true')); // returns true
console.log(coerceBoolean('1')); // returns true
console.log(coerceBoolean('false')); // returns false
console.log(coerceBoolean(0)); // returns false
console.log(coerceBoolean({})); // returns true

2. sanitizeParams

Middleware to sanitize parameters in an Express request object. This middleware removes potentially unsafe characters from query parameters, URL parameters, headers, and body parameters.

Example

// CommonJS
const express = require('express');
const { sanitizeParams } = require('@trarn/middleware');

// or ECMAScript Modules
import express from 'express';
import { sanitizeParams } from '@trarn/middleware';

const app = express();

// Use the sanitizeParams middleware
app.use(sanitizeParams());

app.post('/example', (req, res) => {
    res.json(req.body); // The body will be sanitized
});

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});

3. getParamValue

Retrieves the value of a specified parameter from an Express request object. It searches through query parameters, route parameters, headers, body, and nested properties.

Example

// CommonJS
const express = require('express');
const { getParamValue } = require('@trarn/middleware');

// or ECMAScript Modules
import express from 'express';
import { getParamValue } from '@trarn/middleware';

const app = express();

app.post('/example', async (req, res) => {
    const value = await getParamValue(req, ['userId', 'custom-header']);
    res.send(`Parameter value: ${value}`);
});

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});

4. Response

Sends a JSON response with the specified status and data, or redirects to a specified URL. Ensures that the response object is valid before attempting to send the response or perform the redirect.

Example

// CommonJS
const { response } = require('@trarn/middleware');

// or ECMAScript Modules
import { response } from '@trarn/middleware';

// Assuming the following response object:
const res = {
  status: (code) => ({
    json: (body) => console.log(`Status: ${code}, Body: ${JSON.stringify(body)}`),
    redirect: (url) => console.log(`Redirecting to: ${url}`)
  })
};

// Sending a successful response
response(res, 200, { message: 'Success' });
// Output: Status: 200, Body: {"ok":true,"success":true,"message":"Success"}

// Sending an error response
response(res, 404, { error: 'Not Found' });
// Output: Status: 404, Body: {"ok":false,"success":false,"error":"Not Found"}

// Redirecting to a URL
response(res, 302, { url: 'http://example.com' }, true);
// Output: Redirecting to: http://example.com

5. paramBuilder

Builds a query string from an object of parameters. This function is useful for creating URL query strings from an object of key-value pairs.

Example

// CommonJS
const { paramBuilder } = require('@trarn/middleware');

// or ECMAScript Modules
import { paramBuilder } from '@trarn/middleware';

const params = { name: 'John Doe', age: 25 };
const queryString = paramBuilder(params);
console.log(queryString); // Output: 'name=John%20Doe&age=25'

License

This project is licensed under the MIT License - see the LICENSE file for details.

About Avernix Technologies

Avernix Technologies is a company focused on delivering high-quality software solutions and tools to enhance productivity and security in modern web applications. For more information, visit our website.