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

@azyr/hexagon

v0.4.0

Published

Hexagon is a JavaScript library aimed to make it easier in JS to follow a Hexagonal Architecture, independently from whichever framework you decide to use.

Readme

Hexagon

Hexagon is a JavaScript library aimed to make it easier in JS to follow a Hexagonal Architecture, independently from whichever framework you decide to use.

It allows to define infrastructure-independent use cases with pure javascript that get their primary and secondary ports at different points in time and gets executed on demand with the ports that have been previously passed

Install

Install Hexagon using yarn:

yarn add @azyr/hexagon

Or npm:

npm install @azyr/hexagon

Examples

hexagon is used to create a UseCase scenario, passing the implementation of the use case as a JS function that receives an object as a single input containing all the ports used in the use case:

import hexagon from '@azyr/hexagon';

function showSum({
  num1, // primary port (first summand)
  num2, // primaty port (second summand)
  show, // secondary port (render the result)
}) {
  show(num1 + num2);
}

const showSumUseCase = hexagon(showSum);

With execute, a UseCase can be executed passing all the ports:

const showSumUseCase = hexagon(showSum);

showSumUseCase.execute({ num1: 1, num2: 2, show: res => console.log(res) }); // 3

With usePorts, a new UseCase is returned with those ports bound

const showSumUseCase = hexagon(showSum);

const logSumUseCase = showSumUseCase.usePorts({ show: res => console.log(res) });

logSumUseCase.execute({ num1: 2, num2: 3 }); // 5
logSumUseCase.execute({ num1: 1, num2: 2 }); // 3

Any amount of ports can be bound with usePorts, even all of them:

const showSumUseCase = hexagon(sum);

const log3UseCase = showSumUseCase.usePorts({
  num1: 1,
  num2: 2,
  show: res => console.log(res),
});

log3UseCase.execute(); // 3

Multiple UseCases can be build based on a UseCase with some ports already bound:

const showSumUseCase = hexagon(sum);

const logSumUseCase = showSumUseCase.usePorts({
  show: res => console.log(res),
});

const warnSumUseCase = showSumUseCase.usePorts({
  show: res => console.warn(`Warning: ${res}`),
});

logSumUseCase.execute({ num1: 2, num2: 3 }); // 5
warnSumUseCase.execute({ num1: 2, num2: 3 }); // Warning: 5

Asynchronicity

The UseCase can be implemented with an async function (or a function that returns a promise), allowing the infrastructure to await the UseCase execution (or .then the execution)

const asyncUseCase = hexagon(asyncFunction);

await asyncUseCase.execute();

// or without async/await:

asyncUseCase.execute().then(() => {});

Use Case References

If the same UseCase is called twice with the same ports with the same values, the reference to the returned UseCase is the same:

const useCase1 = useCase.usePorts({ a: 1, b: 2 });
const useCase2 = useCase.usePorts({ a: 1, b: 2 });

useCase1 === useCase2 // true

If the ports are different or their value changes, the reference will be different:

const useCase1 = useCase.usePorts({ a: 1, b: 2 });
const useCase2 = useCase.usePorts({ a: 1, c: 3 });

useCase1 === useCase2 // false

If the returned UseCase is called with the same ports, the reference won't change either:

const useCaseWithPortsBound = useCase.usePorts({ a: 1, b: 2 });
const useCase2 = useCaseWithPortsBound.usePorts({ a: 1 });

useCase1 === useCase2 // true