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

emery

v1.4.3

Published

Utilities to help polish the rough parts of TypeScript.

Downloads

11,992

Readme

Emery


💎 Polish for the rough parts of TypeScript.

TypeScript is great but there's parts that are still rough around the edges, especially for developers who are new to the language.

Purpose and intent

Emery is a small collection of utilities that improve DX without compromising static types.

Check for ambiguous types

Emery exposes "checks" for dealing with ambiguous types.

Checks are just predicates that can't be expressed as type guards, without enforcing opaque types.

import { checkAll, isNonNegative, isInteger } from 'emery';

/**
 * Along with some default check functions, we provide helpers
 * for managing combinations. The `checkAll` helper is a bit
 * like `pipe` for predicates.
 */
export const isNonNegativeInteger = checkAll(isNonNegative, isInteger);

Assert the validity of props

An assertion declares that a condition be true before executing subsequent code, ensuring that whatever condition is checked must be true for the remainder of the containing scope.

import { assert } from 'emery';

import { isNonNegativeInteger } from './path-to/check';

function getThingByIndex(index: number) {
  assert(isNonNegativeInteger(index));

  return things[index]; // 🎉 Safely use the `index` argument!
}

Smooth over loose types

Utility functions for smoothing over areas of TypeScript that are loosely typed.

Because of JavaScript's dynamic implementation the default TS behaviour is correct, but can be frustrating in certain situations.

import { typedKeys } from 'emery';

const obj = { foo: 1, bar: 2 };

const thing = Object.keys(obj).map(key => {
  return obj[key]; // 🚨 'string' can't be used to index...
});
const thing2 = typedKeys(obj).map(key => {
  return obj[key]; // 🎉 No more TypeScript issues!
});

Philosophy and motivation

Like all good things, Emery started with curiosity. At Thinkmill we have an internal Slack channel for TypeScript where a question was raised about how to offer consumers error messages that convey intent, not just cascading type failures.

While that's not currently possible, it became apparent that there was demand for a solution. We also discovered that many developers were carrying around miscellaneous utilities for working with TypeScript between projects.


License

Copyright (c) 2023 Thinkmill Labs Pty Ltd. Licensed under the MIT License.