Hysen Labs
Open-source project
functionalscript/functionalscript avatar
functionalscript

functionalscript

FunctionalScript is a safe purely functional subset of JavaScript

68 stars6 forksJavaScriptMIT
DEEP OPEN-SOURCE ANALYSIS

FunctionalScript is a safe subset of JavaScript

A purely functional programming language that is a strict subset of JavaScript, so its modules run as ordinary JS with no build step.

A disciplined subset of JavaScript

FunctionalScript is a safe, purely functional programming language and a strict subset of ECMAScript, which is the standard behind JavaScript. The README explains its lineage by naming the things that inspired it. JSON and JSON5 are subsets of JavaScript values, and JSON is also a subset of FunctionalScript values. asm.js, a precursor to WebAssembly, is a subset of JavaScript, and TypeScript is a superset of JavaScript. The specification describes the language the compiler accepts today, while features not yet implemented live in a separate todo document. The design rules are what make it safe. Any FunctionalScript module is already a valid JavaScript module, so no extra build step is needed to run it. Code must not have side effects, and there are no exceptions to that rule such as an unsafe escape hatch like the ones found in Rust or C#. A module may depend only on another FunctionalScript module. It also has no standard library; only a safe subset of the standard JavaScript API may be used without referencing other modules. The vision is explicit: rather than invent yet another language people must learn, the project removes what makes the most popular cross platform language unsafe, insecure, or less portable, keeping the good parts and discarding the rest. That restraint is the whole point.

Compiling and the fjs CLI

Because a FunctionalScript module is already valid JavaScript, nothing needs compiling just to run it. The compiler serves the other direction: it evaluates a module and emits the data it exports, resolving every import along the way. The output file extension chooses the format. Compiling to a .f.js file keeps it JavaScript, and the output preserves the object graph, so a value referenced more than once stays shared and is emitted as a const. Compiling to a .json file produces a tree instead, which means shared values are expanded and types JSON cannot express, such as bigint and undefined, are unavailable. The README shows a small example where a module imports another, builds an array with a shared string, and the JavaScript output factors that string into a const while the JSON output repeats it. The compiler currently accepts import statements, const declarations, and data expressions including objects, arrays, strings, numbers, bigint, booleans, null, and undefined; functions and computed expressions are not supported yet. The fjs CLI offers several commands: fjs test runs the test suite, fjs compile builds to JavaScript or JSON, fjs run executes a module as a Node program, fjs cas provides content addressable storage, fjs mcp runs an MCP server over standard input, and fjs ci generates the GitHub Actions workflow.

Uses and design vision

The README lists several places FunctionalScript code can be used. It can run safely inside any JavaScript or TypeScript application or library, since it is just a constrained form of the same language. It can act as JSON with expressions, a middle ground the project calls DJS that bridges JSON and JavaScript without a new domain specific language. It can serve as a query language. And it can work as a smart contract programming language in decentralized finance, where the lack of side effects is a strong safety property. The vision section restates the motivation: the aim is a safe, cross platform language that works in any JS platform with no build step. The author notes there are thousands of programming languages and explicitly does not want to add another one people must learn. Instead the approach is subtractive, taking the most popular and portable language and removing the parts that make it unsafe, insecure, or less portable. That framing explains the project's boundaries: it inherits JavaScript's reach and tooling while giving up the features that cause bugs and surprises. The result is a small, auditable surface that fits naturally into existing JS ecosystems rather than competing with them on features.

Editorial conclusion

FunctionalScript is distributed under the MIT license as a monorepo, and its modules run as ordinary JavaScript with no build step required.

DEEP OPEN-SOURCE ANALYSIS

Official sources

Community notes

Community notes