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

just-types

v2.0.0-alpha.3

Published

A collection of handy Typescript types.

Downloads

4,543

Readme

Just types

A collection of handy Typescript types.

Version Tests Status MIT

Contents

Installation

Install using npm

npm install -D just-types

Or using yarn

yarn add --dev just-types

Types Reference

Testing Your Types with just-types

just-types allows you to test your own types using Is, Equal and other testing utils. These utils are used internally to test just-types types. For Example, here is the source file of the Split type:

import {Equal, Is} from '../test'

export type Split<
  Text extends string,
  Separator extends string
> = Text extends `${infer First}${Separator}${infer Rest}` ? [First, ...Split<Rest, Separator>] : [Text]

type Tests = [
  Is<Equal<Split<'foo', '-'>, ['foo']>>,
  Is<Equal<Split<'foo-bar-baz', '-'>, ['foo', 'bar', 'baz']>>,
  Is<Equal<Split<'foo--', '-'>, ['foo', '', '']>>
]

As you see, we define the type, then we declare a Tests type (can be named anything) and assign a list of assertions types to it. These types are evaluated in realtime by Typescript, so we have instant feedback if something is wrong.

List of assertions

import {Is, Equal, Not, Extends, StartsWith} from 'just-types/test'

Is<Equal<A, B>> // asserts that types `A` and `B` are the same.
Is<Not<Equal<A, B>>> // asserts that types `A` and `B` are different.
Is<StartsWith<A, B>> // where `A` and `B` extend `string`: asserts that all elements of `A` start with with an element of `B`.
Is<Extends<A, B>> // asserts that type `A` extends type `B`

Contributing

You can contribute to this library in many ways, including:

  • Reporting bugs: Simply open an issue and describe the bug. Please include a code snippet to reproduce the bug, it really helps to solve the problem quickly.

  • Suggesting new types: If you have a common use case that you think worth having its own custom type, open an issue and we will discuss it. Do you already have an implementation for it? great, make a pull request and I will review it.

Those are just examples, any issue or pull request is welcome :)

Changelog

2.0.0-alpha.2 (April 13th 2023)

  • Add types:
    • In common module: Normalize
    • In object module: PartialKeys, PartialValues, RequiredKeys and RequiredValues

2.0.0-alpha.1 (April 11th 2023)

  • Full rewrite of the library.
  • Rewrite some types to use less recursion and be more efficient.
  • Separate types into modules: tuple, string, object, ...
  • Generate docs directly from source code.
  • Drop Parcel and use tsc instead.
  • Rename some types for better naming convention FilterOut => tuple.Exclude, FilterProps => object.ExtractValues, FilterPropsOut => object.ExcludeValues, ...

1.6.0 (Sptember 24th 2022)

  • Add FilterOut, FilterProps, FilterOutProps and Merge.
  • Add assertion type Extends.
  • Improve Tail to support string types.
  • Fix Filter to correctly handle union types.

1.5.0 (September 2nd 2022)

  • Export testing types: Is, Not, Equal, StartsWith

1.4.2 (March 21th 2022)

  • Add repository and homepage to package.json (forgot to add them on 1.4.1 :P).

1.4.1 (March 21th 2022)

1.4.0 (January 29th 2022)

1.3.1 (January 9th 2022)

  • Export missing types

1.3.0 (January 9th 2022)

1.2.0 (January 2nd 2022)

1.1.0 (December 01, 2021)

1.0.0 (November 22, 2021)

The first release containing the 7 types: