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

piff

v0.8.7

Published

A language that compiles down to PHP.

Downloads

67

Readme

piff

A language that compiles down to PHP.

Warning: piff is a work in progress. Its syntax might change until version 1.0

Why?

PHP has warts; It's also the foundation of many Legacy Systems (including one I have to maintain). This tool is my attempt to maintain my sanity in this light.

It has had a good number of language features bolted on over the years (Closures, OO, Traits, Namespaces, etc...) but, because of its syntax, it's hard to appreciate them.

For example, when defining a closure you must explicitly declare all variables is uses, even if it's obvious from the code what the programmer had in mind.

I'm aware that there are tools for compiling JavaScript to PHP, but I didn't want to make promises about the conceptual model that are not true. PHP is not just an Uglier JavaScript.

Why the idiotic name?

If you sound out PHP, it kinda sounds like Piff. In the same way that piff kinda feels like PHP.

Features / Opinions

  1. Semicolons are optional
  2. Use clauses are automatically inferred
  3. Functions can be composed using a special pipe syntax
  4. Defining classes is less verbose
  5. Defining arrays is less verbose
  6. Formatting should be part of the language (like in go)
  7. ...

A Quick Piff Example

// Calling Overriden methods with parent
class A {
  say(m) {
    print(m)
  }
}

class B extends A {
  say(m) {
    parent(m + '!')
  }
}

// @a expands to $this->a
class A {
  prefix = 'Hello: '
  say(m) { print(@prefix + m) }
}

// @@field expands to self::$field, @@m() expands to self::m()
class B {
  static prefix = 'Hello: '
  static say(m) { print(@@prefix + m) }
}

// named functions
fn add(a, b) { return a + b }

// Anonymous functions (with expression as block)
mult = fn (a, b) a * b

// Automatically figures out "use" clause
ticks = []
tick = fn() { ticks[] = mktime() }

// function composition alternate syntax
a() |> b(_) |> c(_) // is the same as: c(b(a()))

Installation

npm install -g piff

Usage

Command line usage is available using piff-cli

Programmatic usage can be performed like so:

const piff = require('piff')
let php = piff.transpile("fn add(a, b) { return a + b }\n echo(add(1,2))")
console.log(php) // <?php echo("hello" . "\n")?>

console.log(piff.format("fn add(a,b){return a+b}")
// outputs a nicely formatted version of the piff code

Command line usage