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

hin.js

v1.0.24

Published

### Target Feature Set - *Strong* typings using vanilla JS - Granular, additive *inheritance*, avoiding the fragile base class problem - Easy, flexible, granular *dependency injection* - *Precise refactoring* within IDEs

Downloads

416

Readme

hin.js

Target Feature Set

  • Strong typings using vanilla JS
  • Granular, additive inheritance, avoiding the fragile base class problem
  • Easy, flexible, granular dependency injection
  • Precise refactoring within IDEs

The most wonderful feature of hin.js is the dependency injection.

Composable classes, singletons become easy to structure and easy to swap. That is in part thanks to inheritance that is far more granular than traditional: in hin.js each class property has its own inheritance.

It really shines when you need to take a prototype to production quality software seamlessly.


Docs are active work-in-progress!


Contents

Stateful vs Stateless Hinjs

Grouping

Injection

Public dependencies

Private dependencies

Singletons

Mocking dependencies


A small example to give you a sense of how small the interface surface is and how easy hin.js is

import {hinj, group} from 'hin.js'

const Database = group({
  connectionUrl: hinj(process.env.CONNECTION_URL),
  sql: hinj(
      /* setting lazy, default value */ 
      T => {
        const url = Database.connectUrl(T)
        // if using postgres library
        return postgres(url)
  }),
})

const Server = group({
  $handleIndex: hinj()
      .async(await (T, {req, res}) => {
        const i = Index(T) // creating a new instance of Index
                           // and setting this instnace of Server as the parent
        await Index.$load(i)
  
        const list = Index.list(i)
        const html = list.length ? 
            `<ul>${list.map(r => `<li>${r}</li>`)}</ul>` 
            : '<b>Nothing found!</b>'
        res.end(html)
      })
})

const Index = group({
  list: hinj(),
  $load: hinj()
      .async(await T => {
        const sql = Database.sql(T) // dependency injection at work
        const list = await sql`SELECT path FROM files`
        Index.list(T, list.map(r => r.path))
      })
})

// Initializing
const db = Database()
const server = Server(db) // Database becomes the parent of Server
                          // Now all hinj functions in Server have access to `db`
                          // through dependency injection

// Running
Server.$handleIndex(server, {/* req, res from Express.js */})

Hinges (stylized hin.js) is the result of a lineage of work:

  • Layer-compose: the grandmother of the lineage, which tried to do too much
  • Filo: that got it almost right
  • Hinges: is the stripped down version of Filo that gives granular control while giving better coding ergonomics.

hin.js is a stable set of procedures, commands and library interface. It satisfies the target feature set already, the interface does not need to change.

There might be a few ergonomic improvements introduced on the way to 2.0.0 (which will take a long time). Those would be inconsequential and backwards compatible.

The additional functionality (because who doesn't like to have it their way?) will come as plugins.