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

saurscript

v1.2.0

Published

A dead simple functional transpiled language for JavaScript!

Downloads

2

Readme

SaurScript Banner Dead-simple functional JavaScript transpiler.

SaurScript looks like this:

String myName = "Computer"
fun sayHi(String name) > String {
  return concat("Hello ", name)
}
String greeting = sayHi(myName)
logger.log(greeting)

It compiles to JavaScript:

const myName = "Computer";
const greeting = (function(name = myName) {
  return "Hello " + name;
})();
console.log(greeting)

Features

  • Functional
  • Pure
  • Statically typed
  • Lazy
  • Easy to learn

Concept

A lot of functional programming languages use unfamiliar syntax:

myName = "Computer"

sayHi :: String -> String
sayHi name = "Hello " ++ name

greeting = sayHi myName
main = print greeting

This can make it hard to learn. SaurScript uses more familiar syntax, making it easier to learn.

Learn SaurScript

To learn how to use SaurScript we're going to create a thesaurus.

Imports

Usually you'll want to import either the common or browser library to start. These give you access to logger, document, storage, map, strConcat, filter, and other useful tools. You can also import other .saur files.

// The common lib:
@import 'common'
// The browser lib (this includes common, but is only for frontend dev. Don't use both):
@import 'browser'
// Another `.saur` file:
@import 'myOtherFile'

Variables

Variables in SaurScript are immutable and statically typed.

Int myVar = 5

This will compile to:

const myVar = 5;

You must specify a type to create the variable. Once you create the variable, you cannot change it.

Don't think of variables as boxes where you can take things in and out. Think of the variable name as a word in our thesaurus, and the value is the synonyms.

Let's create an entry for our thesaurus:

Dictionary<String:Array<String>> entries = ["Dinosaur": "Dino", "Raptor", "Big Lizard"]

Here we declare a new variable named entries. It's type is a Dictionary. The key of the dictionary is a String (a word), and the value is an Array of Strings (synonyms).

Functions

Functions are lazy. If we don't use the function, it won't show up in our JavaScript code.

fun myFunction(Int arg1, Float arg2) -> Bool {
  logger.log(arg1 + arg2)
  return true
}

Since we don't use this function, our JavaScript file is empty.

Let's add a function to our thesaurus to get the synonyms for any given word.

fun synonyms(String word) -> Array<String> {
  return entries[word]
}

Classes

Classes are an experimental feature of SaurScript. They mix the Functional and Object Oriented paradigms.

@class MyClass
  @property Int id = 0
  fun whoami() -> String {
    return "A Computer"
  }
@endclass
@new MyClass myInstance(5)
logger.log(myInstance.whoami())

This will compile to:

function MyClass(id = 0) {
  this.id = id;
};
MyClass.prototype = {
  whoami: function() {
    return "A Computer"
  }
}
const myInstance = new MyClass(5)
console.log(myInstance.whoami())

Now we can create a class for each entry in our thesaurus:

@class Entry
  @property String word = ""
  @property Array<String> synonyms = []
@endclass

And a class for the thesaurus itself:

@class Thesaurus
  @property String name = ""
  @property String publisher = ""
  @property Array<Any> entries = []
@endclass

And we can create a thesaurus!

@new Entry dino("Dino", ["Dinosaur", "Raptor", "T-Rex"]
@new Entry lizard("Lizard", ["Iguana", "Gecko", "Monitor"]
@new Entry paradigm("Paradigm", ["Functional", "Imperative", "Object Oriented"]
@new Thesaurus thesaurus("SaurScript Thesaurus", "SaurScript Language", [dino, lizard, paradigm])

If, Else If, and Else

if myCondition == "yes" {
  logger.log("Agreed")
} elif myCondition != "maybe" {
  logger.log("So you're telling me there's a chance")
} else {
  logger.log("Not at all")
}

Repeat

SaurScript doesn't have for or while loops. Instead, you can use recursion, or repeat.

repeat 3 {
  logger.log("Hi")
}

Output:

Hi
Hi
Hi

We can use recursion to print all of the synonyms in our thesaurus:

@class Thesaurus
  ...
  fun allSynonyms(Int index = 0, Array<String> soFar) {
    if entries[index] != null {
      allSynonyms(index + 1, arrConcat(soFar, entries[index])
    } else {
      logger.log(soFar)
    }
  }
@endclass

Exports

Sometimes you want to export something for use in another .saur file. You can add @export in front of a variable, class, function, etc. to make it available outside the file.

@export String myName = "Carson"

@export @class myClass
  @property String greeting = "Hello World"
@endclass

@export @new myClass greeter(strConcat("Hello ", myName))

@export fun sayHi(Any greeterClass) > String {
  return greeterClass.greeting
}

It can now be imported from another .saur file:

@import 'myFile'
// We can now access everything @exported from the other file:
logger.log(sayHi(greeter))