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

prose

v0.0.1

Published

Extendable literate programming

Downloads

106

Readme

Prose

Prose is an experimental take on Literate_programming inspired by Literate coffeescript. It attempts to focus embrace problem solving, without binding you to any specific programing language.


Prose uses markdown as a primary format for describing problems and solutions for the particular problem that program is trying to solve.

Actual solutions to the problem are embedded as code blocks, written in any programing language that can compile to javascript.

Embedding code

Prose treats any markdown code block as an embedded program. Code can be written in any language as long as it can compile to JS and of course JS :) Standard shebang trick can be used to identify language the code is written in.

In order to demonstrate prose we will use it to write itself (yeah we're that meta!!). Since primary input format is markdown, we use a full featured markdown parser library marked:

#!/usr/bin/env javascript
var marked = require("marked")

In order to transpile prose into program we will need to parse a given markdown input. Library provides convenient function for that

function transpile(input) {
  return marked.lexer(input).

Prose will recognizes code block above as a javascript. If shebang is not provided code block is treated as a previous one.

To assemble an executable we will only need to combine text from the code blocks

   filter(function(block) {
      return block.type === "code"
    }).map(function(block) {
      return block.text
    }).join("\n\n")
}

Prose is designed in an idiomatic Unix style, in a sense that it takes program input from the standard input and writes compiled program into standard output.

function compile(input, output) {

All the data from the standard input is aggregated before running through a transpiler since individual data chunks may not represent valid / parseable data.

 var source = "";
  input.on("data", function onChunck(chunck) {
    source = source.concat(chunck)
  });

Once all data from the input has being read, we attempt to tranpile it and write it to standard output.

 input.once("end", function onRead() {
    try {
      output.write(transpile(source))
    } catch (error) {
      exit(error)
    }
  })

If anything goes wrong during reading / writing or transpilation we exit a program.

 input.on("error", exit)
  output.on("error", exit)
}

Although we don't just exit, if we run into error we report it and exit with exit code 1. If there are no errors we still exit, but with exit code 0.

function exit(error) {
  if (error) {
    console.error(error)
    process.exit(1)
  } else {
    process.exit(0)
  }
}

Also main task is wrapped in a function that opens standard input and passes both input and output to the compiler to do the job.

function main() {
  if (process.argv.length < 3) {
    process.stdin.resume()
    process.stdin.setEncoding("utf8")
    compile(process.stdin, process.stdout)
  } else {
    Module._load(path.resolve(process.argv[2]), null, true);
  }
}

If code is executed as a program (in which case it will it's going to be a main module)

if (require.main === module)

Program performs it's primary task by executing main function.

  main()

Also we will be exporting main function such that it could be called from the other programs:

module.exports = main

That's all this program does so far. As you have noticed it does not yet recognizes non JS languages, but support for that is coming soon!