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

closer

v0.2.3

Published

Clojure parser and core library in JavaScript, compatible with the Mozilla Parser API.

Downloads

7

Readme

Closer.js

Build Status NPM version Dependency Status devDependency Status

Closer.js is a parser for the Clojure programming language written in JavaScript, compatible with the Mozilla Parser API. It also provides much of the Clojure core library as a separate module (thanks in large part to swannodette/mori). All of this is heavily tested, with > 90% code coverage (the untested 10% is mostly unused code from the Jison parser generator).

It was created to be used on CodeCombat, a site that teaches users how to code by playing a game (there's multiplayer too!). CodeCombat is open-source, backed by YCombinator, participating in Google Summer of Code 2014, and is generally awesome all around. Go check it out!

This project could be useful for a variety of things like browser-based Clojure code editing, linting, syntax highlighting, auto-completion, and running sandboxed Clojure code in a browser.

Key Features

defmacro is not supported at the moment, as I haven't quite figured it out yet. Ideas and pull requests on how to go about it are always welcome!

Installation & Usage

Get it via NPM: npm install closer.

Closer works on Node.js and all modern browsers (via browserify). It has been tested on Node 0.10.24, Chromium 34, and Firefox 28.

closer.parse(src, options={})

  • src is a String containing the input Clojure code

  • options can contain the following:

    • loc (default true): if true, AST nodes will have line and column-based location information attached to them

    • range (default false): if true, AST nodes will have range-based location information attached to them, similar to Esprima

    • loose (default false): if true, Closer will try to handle common syntax errors and will always return a valid AST, even if empty, similar to Acorn's loose mode

    • coreIdentifier (default 'closerCore'): if the core library is being used, it must be in scope at the point of execution with this name. The parser qualifies calls to core functions with this. For example:

    // parse
    var closer = require('closer');
    var ast = closer.parse('(+ 1 2)', { coreIdentifier: 'core' });
    // execute
    var core = closer.core; // the name of this variable must match coreIdentifier
    var escodegen = require('escodegen');
    eval(escodegen.generate(ast)); // === 3
    // escodegen generates JS from AST (https://github.com/Constellation/escodegen)

    If being used in a browser, this parameter will usually not need to be used.

    • assertionsIdentifier (default 'closerAssertions'): if user-defined functions are to be executed, the assertions module must be in scope at the point of execution with this name. For example:
    // parse
    var closer = require('closer');
    var opts = { assertionsIdentifier: 'assertions' };
    var ast1 = closer.parse('(#(do %) 42)', opts);
    var ast2 = closer.parse('(#(do %) 42 57)', opts);
    var ast3 = closer.parse('(#(+ % %2) 42 "str")', opts);
    // execute
    var assertions = closer.assertions; // the name of this variable must match assertionsIdentifier
    var escodegen = require('escodegen');
    eval(escodegen.generate(ast1)); // === 42
    eval(escodegen.generate(ast2)); // ArityError: expected 1..1 args, got 2
    eval(escodegen.generate(ast3)); // ArgTypeError: str is not a number

    If being used in a browser, this parameter will usually not need to be used.

closer.core

All implemented clojure.core functions are in this object. A list of what's available can be found here.

Ensure it is in scope (with the same name as that passed in the parser's coreIdentifier option) if you want to execute JS code generated from your AST using escodegen, for instance.

closer.assertions

This is a small module emulating Clojure's arity and type checks. You will never need to use this directly; only ensure it is in scope (with the same name as that passed in the parser's assertionsIdentifier option), if you want to execute JS code generated from your AST using escodegen, for instance.

Demo

Check out the demo page. Extensive examples of usage can be found in the core and functional tests.

Contributing

New contributors can look at issue #10 to dive in easily and quickly!

Closer's primary dependencies are the Jison parser generator and Mori. All new features and functions should have corresponding tests. Issues and pull requests are welcome. So are ideas, pointers, and code on how to implement defmacro in JavaScript.

Setup / workflow instructions:

  • Fork and clone this repository
  • Run these commands from project root:
    • npm install
    • sudo npm install -g grunt-cli jison
  • Run grunt test to make sure everything's working
  • Make your changes, running grunt test to test them
  • You can run ./repl to get a basic Clojure REPL: it will display the parser output and execute it as JavaScript
  • Once all tests pass, commit and push your changes, and send a pull request! Congratulations!

License

Licensed under the MIT License.

Contributors