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

marion

v0.1.6

Published

Find the right actor with TypeScript

Readme

Marion

Installation

npm install marion

Usage

import marion from 'marion'

interface Alpha { type: 'alpha', count: number }
interface Beta { type: 'beta', label: string }

const actors = {
  alpha: (input: Alpha) => {
    return input.count / 10
  },
  beta: (input: Beta) => {
    return input.label
  }
}

const alpha: Alpha = { type: 'alpha', count: 42 }
const alphaResult = marion(actors, alpha) // Inferred as number

type AlphaBeta = Alpha | Beta
const beta: AlphaBeta = { type: 'beta', label: 'Hello' }
const betaResult = marion(actors, beta) // Inferred as string

Problem

In JavaScript, it is common to have a set of functions that handle different inputs based on a discriminant property, with each function taking different inputs and returning different outputs:

let users = []

const actors = {
  create: (request) => users.push({
    id: users.length + 1, name: request.name
  }),
  read: () => users,
  delete: (request) => {
    users = users.filter(user => user.id !== request.id)
    return users.every(user => user.id !== request.id)
  }
}

function handleRequest(request) {
  const actor = actors[request.type]
  return actor(request)
}

const deleteResult = handleRequest({ type: 'delete', id: 42 })
// Result is boolean

In TypeScript, this pattern often leads to unsafe typing and the input/output being inferred as a union of all possible types:

let users: Array<{ id: number, name: string }> = []

const actors = {
  create: (request: { name: string }) => users.push({
    id: users.length + 1, name: request.name
  }),
  read: () => users,
  delete: (request: { id: number }) => {
    users = users.filter(user => user.id !== request.id)
    return users.every(user => user.id !== request.id)
  }
}

// Defining the input type can be complex, so unsafe patterns are often used
function handleRequest (request: { type: keyof typeof actors, [key: string]: any }) {
  const actor = actors[request.type] // Inferred as union of all handlers
  return actor(request) // Error: Argument of type
  // '{ [key: string]: any; type: "create" | "read" | "update" | "delete"; }'
  // is not assignable to parameter of type
  // '{ id: number; name: string; }'. ts(2345)
}

const deleteResult = handleRequest({ type: 'delete', id: 42 })
// Inferred as a union of all return types

Solution

marion correctly infers the input and output based on the input's type property:

const deleteResult = marion(actors, { type: 'delete', id: 42 })
// Correctly inferred as boolean

const createResult = marion(actors, { type: 'create', id: 42 })
// Correctly throws:
// Property 'name' is missing in type '{ type: "create"; id: number; }'
// but required in type '{ name: string; }'. ts(2345)

Marion Dougherty

marion is named after Marion Dougherty, a pioneering casting director who helped create many great films and acting careers. Many prominent filmmakers lobbied The Academy of Motion Picture Arts and Sciences to recognize her contributions during her lifetime with a special award, but they were refused. Casting director is the most prominent creative role in the film industry more often held by women than men. There is still no Oscar category for casting directors. A casting director finds the perfect actor for each role, and marion is dedicated to her legacy.