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

@ts-common/fun.ts

v0.0.13

Published

Pure functional subset of JavaScripts/TypeScript.

Downloads

36

Readme

fun.ts

Build Status npm version

Purely functional subset of JavaScripts/TypeScript.

There are a lot of pure functional languages that can be compiled to JavaScript. Usually, the biggest problem with these libraries is interoperability. For example, if you have a big project written on JavaScript, it's very challenging to rewrite parts of this project step-by-step using another language. https://github.com/jashkenas/coffeescript/wiki/List-of-languages-that-compile-to-JS#static-typing.

The project is not another functional language that can be compiled into JavaScript. The project tries to define a subset of JavaScript that can be formally verified.

The subset can be used as a safe script or as a target platform for other programming languages.

Roadmap

Potential Targets and Applications

  • Markdown safe script that can be run in a browser (for example http://madoko.org/reference.html),
  • query languages,
  • distributed systems, like ALIQ, machine learning, AI,
  • as a target platform for other functional languages.
  • the subset can be recognized by browser and compiled into more optimal code (similar to asm.js).

Wish List

  • All data is immutable.

  • Pure functions, without side-effects.

  • Strong structural typing.

  • Type inference.

  • Compatibility with JavaScript and TypeScript.

    • write/read .d.ts files.
    • the subset should be valid JavaScript or TypeScript. So no need for additional transpilers, we only need a validator.
  • The language validator should be written on JavaScript/TypeScript so it can run in a browser.

  • no implicit type conversions. For example ?: should only accept bool type.

  • Type system should allow to describe monads. Example on pseudo-TypeScript

    type MonadStrategy = {
        type Monad<T>; // this line can't be compiled in TypeScript.
        readonly just: <T>(v: T) => Monad<T>
        readonly join: <T>(m: Monad<Monad<T>>) => Monad<T>
    }
    
    // Or
    type MonadStrategy = {
        type Monad { type T }; // this line can't be compiled in TypeScript.
        readonly just: <T>(v: T) => Monad { T }
        readonly join: <T>(m: Monad { T: Monad { T } }) => Monad { T }
    }
  • Type system should be able to reflect JSON-Schema.

Typing

Typing requires a languages extension. Several safe options are

  • embed typing in comments.
  • embed typing in a separate file.
  • typing is based on special run-time definitions, similar to Json-Schema. For example const MyType = { type: 'string', ... }.

Possible typing languages are

  • TypeScript,
  • JS docs,
  • JSON-Schema,
  • Some kind of Haskell type notations?

Proposed Typing

  • JavaScript. Starts with //: or /*:

    const myFunc
        //: (_: number) => string
        = v => v.toString()
    const myFunc /*: (_: number) => string */ = v => v.toString()

    Simplified types (incompatable with TypeScript).

    const myFunc
        //: number => string
        = v = v.toString()
    //type MyType = ...
    /*type MyType = {
    
    }*/
  • TypeScript

    const myFunc
        : (_: number) => string
        = v => v.toString()

Notes

Use hasOwnProperty() to check if we can read such properties as constructor. Incorrect code:

const m = x.constructor
// or
const { constructor } = x

Correct code:

const m = Object.prototype.hasOwnProperty.call(x, 'constructor') ? x.constructor : undefined

References

  • https://en.wikipedia.org/wiki/Hindley–Milner_type_system
  • https://en.wikipedia.org/wiki/Type_class
  • https://en.wikipedia.org/wiki/Structural_type_system
  • https://webkit.org/blog/6240/ecmascript-6-proper-tail-calls-in-webkit/
  • http://dippl.org/chapters/02-webppl.html
  • https://github.com/gcanti/fp-ts
  • https://github.com/jonaskello/tslint-immutable

Languages

ECMAScript Proposals

  • https://github.com/tc39/proposal-pattern-matching
  • https://github.com/tc39/proposal-pipeline-operator
  • https://github.com/tc39/proposal-partial-application
  • https://github.com/tc39/proposal-decorators