All your standard libraries will be assimilated into our
JavaScriptTypeScript collective. Resistance is futile.
Locutus is 626 TypeScript implementations of standard library functions from 18 programming languages: C, Go, Python, Ruby, PHP, Perl, Lua, R, Julia, Elixir, Clojure, AWK, Tcl, PowerShell, Rust, Swift, Kotlin, and Haskell. 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 utility framework for TypeScript. If you need a broad utility toolkit, lodash is often the better fit.
JavaScript’s standard library improves every year, so for production apps it is worth checking whether your target environments already support what you need out of the box.
Locutus still offers practical value where native APIs differ or parity with other languages matters, and it is easy to import a single function. Function page notes help you judge maturity before adopting.
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.