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

reason

v3.3.4

Published

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems

Downloads

5,541

Readme

Reason

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems.

Build Status CircleCI

Getting Started

Community

Contributing

Documentations

Go to https://github.com/reasonml/reasonml.github.io to contribute to the Reason documentation.

Codebase

See the src folder's README.

Installation for Programmatic Usage

If you're not using Reason programmatically, disregard this section and see the Getting Started guide above. This is for using Reason's refmt as a third-party library.

JavaScript API

We expose a refmt.js for you to use on the web. Again, for local development, please use the native refmt that comes with the installation here. It's an order of magnitude faster than the JS version. Don't use the JS version unless you know what you're doing. Let's keep our ecosystem fast please.

Aaaanyways, to install refmt.js: npm install reason.

Here's the API, with pseudo type annotations:

  • parseRE(code: string): astAndComments: parse Reason code
  • parseREI(code: string): astAndComments: parse Reason interface code
  • printRE(data: astAndComments): string: print Reason code
  • printREI(data: astAndComments): string: print Reason interface code
  • parseML(code), parseMLI(code), printML(data), printMLI(data): same as above, but for the OCaml syntax

The type string is self-descriptive. The type astAndComments returned by the parse* functions is an opaque data structure; you will only use it as input to the print* functions. For example:

const refmt = require('reason')

// convert the ocaml syntax to reason syntax
const ast = refmt.parseML('let f a = 1');
const result = refmt.printRE(ast);
console.log(result) // prints `let f = (a) => 1`

The parse* functions potentially throw an error of this shape:

{
  message: string,
  // location can be undefined
  location: {
    // all 1-indexed
    startLine: number, // inclusive
    startLineStartChar: number, // inclusive
    endLine: number, // inclusive
    endLineEndChar: number, // **exclusive**
  }
}

NOTE: refmt.js requires the node module fs, which of course isn't available on the web. If using webpack, to avoid the missing module error, put node: { fs: 'empty' } into webpack.config.js. See https://webpack.js.org/configuration/node/#other-node-core-libraries for more information.

refmt.js is minified for you through Closure Compiler, with an accompanying refmt.map. The size is 2.3MB but don't get fooled; it gzips down to just 345KB. This way, you can carry it around in your own blog and use it to create interactive refmt playground, without worrying about imposing bandwidth overhead to your readers. Again, keep our ecosystem fast and lean.

Native API

We're spoiled with more APIs on the native side. To use Reason from OPAM as a native library, you have these functions. So:

  • Reason_toolchain.RE.implementation_with_comments
  • Reason_toolchain.RE.interface_with_comments
  • Reason_toolchain.RE.print_interface_with_comments
  • Reason_toolchain.ML.implementation_with_comments
  • etc.

The ML parsing functions might throw Syntaxerr.Error error. The RE parsing functions might throw:

Example usage:

let ast_and_comments =
  Lexing.from_string "let f a => 1"
  |> Reason_toolchain.RE.implementation_with_comments

(* Convert Reason back to OCaml syntax. That'll show these Reason users! *)
let ocaml_syntax =
  Reason_toolchain.ML.print_implementation_with_comments
    Format.str_formatter
    ast_and_comments;
  Format.flush_str_formatter ()

License

See Reason license in LICENSE.txt.

Works that are forked from other projects are under their original licenses.

Credit

The general structure of refmt repo was copied from whitequark's m17n project, including parts of the README that instruct how to use this with the OPAM toolchain. Thank you OCaml!