All your standard libraries will be assimilated into our
JavaScriptTypeScript collective. Resistance is futile.
Locutus is 544 TypeScript implementations of standard library functions from 15 programming languages: C, Go, Python, Ruby, PHP, Perl, Lua, R, Julia, Elixir, Clojure, AWK, Tcl, PowerShell, and Rust. The project has been running since 2008 and has had 137 contributors.
Most of these started as rainy Sunday afternoon puzzles. Some are genuinely useful. Some are just fun to write. All of them are a way to learn how different languages solve the same problems, by reimplementing their standard library functions in TypeScript.
You can install individual functions via npm and tree-shake everything else away:
import { sprintf } from 'locutus/php/strings/sprintf' |
What we are not
Locutus is not a drop-in standard library for TypeScript. If you need a well-rounded utility library, lodash is the better choice.
That said, there are useful things here, and Locutus makes it easy to pull in just a single function. The notes on each function page should help you judge its maturity.
What we port
Individual functions from standard libraries. We port behavior, not baggage: function semantics in TypeScript, with JavaScript-native values at the API boundary.
That means we stay away from language constructs, global runtime environments, foreign data structures, and extending built-in natives. A Go date-formatting port here should take a JavaScript Date and return a string, not a custom Go time.Time.
Historic exception: for PHP compatibility, plain JS objects may be treated as associative arrays when locutus.objectsAsArrays is enabled.
A community effort
Not unlike Wikipedia, Locutus is an ongoing community effort. Our philosophy follows The McDonald’s Theory. Many of our functions are first iterations that could be improved. We hope they inspire you to come up with something better.
Contributing
We use GitHub for collaboration. There are a few guidelines in our CONTRIBUTING.md. It would be helpful to glance over them before submitting your work.
Licensing
Locutus is MIT licensed. Use it however you like, including in commercial projects, as long as the license travels with it.