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

readable-types

v4.0.3

Published

Utils for typescript language

Downloads

35

Readme

With Readable-Types, you can create TypeScript types that are easy to read and understand. The library provides a set of intuitive and expressive utilities for defining complex types, reducing the need for manual type checking and making your code more reliable.

Whether you're building a small project or a large enterprise application, Readable Types can help you save time and reduce errors by providing a more readable and maintainable way to define your types.

In addition to making type creation more manageable, Readable Types also includes a suite of testing utilities to help ensure that your types are correct and reliable. With support for both unit and integration testing, you can rest assured that your types are functioning as expected.

Get started with Readable Types today and take the first step toward a more readable, reliable, and maintainable codebase!

Installation

To add the library to your project just need to run:

npm

npm install readable-types

yarn

yarn add readable-types

Usage

Our library provides a comprehensive set of TypeScript utility functions that are ready to use out of the box. Simply import the library into your project or file, and its all!.

Here's a quick example of how you might use Readable-Types in your project:

import { IsString, IsNumber, Modify } from 'readable-types';

type A = { a: string, b: number }

type isNumber = IsNumber<A['b']>;
//   ^? true
type isString = IsString<A['b']>;
//   ^? false

type B = Modify<A, { a: number, c: object }>
//   ^? { a: number, b: number, c: object }

Testing with Readable-Types

In order to verify that your types are functioning as expected, it's essential to implement testing. Readable-Types provides a suite of utilities to aid in this process. You can write your tests in several different ways based on your preferences and requirements.

Here's how to do it:

1. Basic Syntax

The simplest way to create tests is by using the testType function inside a describeType block:

describeType('MyType', () => {
  testType('Should behave as expected', () => {
    type MyType = /* Your type here... */;
    type ExpectedType = /* Expected result here... */;
    // More types...

    assertType<MyType>().equals<ExpectedType>(),
    // More assertions...
  });
});

2. Using Array

describeType('MyType', () => {
  testType('Should behave as expected', [
    assertType<MyType>().equals<ExpectedType>(),
    assertType<MyType>().not.equals<UnexpectedType>(),
    // More assertions...
  ]);
});

3. Using Object

describeType('MyType', () => {
  testType('Should behave as expected', {
    test1: assertType<MyType>().equals<ExpectedType>(),
    test2: assertType<MyType>().equals<ExpectedType>(),
    'MyType should equal ExpectedType': assertType<MyType>().equals<ExpectedType>(),
    'really any text': assertType<MyType>().equals<ExpectedType>(),
    // More labeled assertions...
  });
});

Execute Test

To test with our library, we use the TypeScript compiler reading the AST. For "run" the test you need to ejecute:

rtft

Additionally, we recommend adding this command to your Husky pre-commit hook to ensure that any changes to these files are caught before they are committed to the repository.

These are the basic ways to create type tests with Readable-Types. Remember, testing your types is crucial to maintain robust and bug-free TypeScript code. Happy testing!

Compatibility

Readable-Types is compatible with TypeScript versions 4.2 and above.

Roadmap

We're always working to improve and expand Readable-Types. Here's a sneak peek at what's coming up in future versions:

  • More type utilities for common use cases
  • Enhanced testing capabilities

License

MIT

Authors

Feedback

We're always looking to improve our library, and your feedback is essential to that process. If you have any suggestions, comments, or bug reports, please feel free to open an issue on our GitHub repository. We appreciate your input and thank you for helping us make Readable Types even better!