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

typelint

v1.0.2

Published

ESlint rule for optional typing in JavaScript, based on JSDoc

Downloads

16

Readme

TypeLint

TypeLint is an ESlint rule for optional typing in JavaScript, based on JSDoc.

TypeLint provides optional typing for your code, not forcing you to write new definitions.

Demo

Features

Currently TypeLint supports JSON Schema for describing data shapes.

JSON Schema is advanced, popular and well documented format for describing JSON data.

For example if you use Swagger for your API, you already have JSON Schema definitions, that you can use.

Also you can bind Mongoose schemas using TypeLint adapters.

To bind your models to TypeLint, put the following settings block to the root of your .eslintrc:

  "settings": {
    "typelint" : {
      "modelsDir": "./swagger/models"
    }
  },

Models are expected as files, where each of them contains one definition.

Name of the file is a name of the model.

Supported formats:

  • JSON
  • YAML
  • JS files as common.js modules (export object is a schema)

Usage

npm i eslint && npm i typelint

Put typelint rule to your .eslintrc with needed priority (2 is recommended).

For example, your .eslintrc can look as following:

{
  "env": {
    "node": true,
    "es6": true
  },
  "rules": {
    "no-console": 0,
    "no-param-reassign": 2,
    "typelint": 2
  },
  "settings": {
    "typelint" : {
      "modelsDir": "./models/swagger"
    }
  }
}

Extend your JSDoc comments with TypeLint notations <typeName>:

/**
 * @param movieObject <movie>
 */
function getDirector(movieObject) {

Now TypeLint knows, that movieObject parameters has type of movie

Run

./node_modules/.bin/eslint --rulesdir ./node_modules/typelint/rules .

or enable ESLint tools in your IDE, e.g WebStorm:

What it is and what it is not

TypeLint is a helper, but not a full-fledged typed system for js.

If you want to make your code 100% typed, please use any of existing static typed languages, which can be transpiled to JavaScript (TypeScript, Flow etc)

The goal of TypeLint is to help developer avoid undefined errors, but optionally and staying all the speed and flexibility of JavaScript developement.

BTW TypeLint was written with help of TypeLint 😊️

All .eslinrc typelint settings options

  • lintNative - {Bolean} should TypeLint check native JS types, defined by ususal JSDoc notation. Default: false
  • modelsDir - {String} path to your models dir. Every file is a separate model
  • excludeModelDirs - {Array} array of paths, that models finder should ignore while loading models
  • adapters - {Array} array of adapters (functions in adapters dir) that would transform your models before comparing with real code cases.
  • useCache - {Boolean} caches all models (will work faster, but changes in models will not affect). Default: false

Planned features

  • Support JSDoc typedef
  • Support GraphQL schemas
  • Possibility to use /@var/ definitions everywhere
  • Handle passing typed variables (partially including)
  • Detect when variable was reassigned
  • Other types of models bindings

License

MIT.