https://github.com/locutusjs/locutus
Bringing stdlibs of other programming languages to JavaScript for educational purposes
https://github.com/locutusjs/locutus
javascript ports programming-language
Last synced: 2 days ago
JSON representation
Bringing stdlibs of other programming languages to JavaScript for educational purposes
- Host: GitHub
- URL: https://github.com/locutusjs/locutus
- Owner: locutusjs
- License: other
- Created: 2009-09-03T09:52:00.000Z (over 16 years ago)
- Default Branch: main
- Last Pushed: 2026-01-08T22:40:56.000Z (2 months ago)
- Last Synced: 2026-01-13T19:24:19.199Z (2 months ago)
- Topics: javascript, ports, programming-language
- Language: HTML
- Homepage: https://locutus.io
- Size: 92.2 MB
- Stars: 3,734
- Watchers: 198
- Forks: 1,102
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Locutus
[](https://github.com/locutusjs/locutus/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/locutus)
[](https://locutus.io/php/)
[](https://locutus.io/python/)
> All your standard libraries will be assimilated into our ~~JavaScript~~ TypeScript collective. Resistance is futile.
Locutus is ~500 TypeScript implementations of standard library functions from PHP, Go, Python, Ruby, C, and [more](https://locutus.io/). Each function is individually importable and tree-shakeable.
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.
## Scope
Locutus ports function behavior, not foreign runtime baggage. We reimplement standard-library semantics in TypeScript, but keep API boundaries JavaScript-native.
That means we do not recreate alien language data structures or object models in Locutus APIs (for example: Go slices/maps, Python tuples/bytes, Ruby symbols, C structs/pointers, Perl refs).
Historic exception: for PHP compatibility, plain JS objects may be treated as associative arrays when `locutus.objectsAsArrays` is enabled.
Example: a Go date-formatting port in Locutus should accept a JavaScript `Date` and return a `string`, not a custom Go `time.Time` object.
## Install
```bash
npm install locutus
```
Locutus uses pragmatic versioning: `patch` is the default even for function-level parity fixes; see
`CONTRIBUTING.md#versioning` for exact bump criteria.
## Use
```typescript
import { sprintf } from 'locutus/php/strings/sprintf'
const effectiveness = 'futile'
console.log(sprintf('Resistance is %s', effectiveness))
// Resistance is futile
```
```typescript
import { Contains } from 'locutus/golang/strings/Contains'
console.log(Contains('Locutus', 'cut'))
// true
```
## Bundle Size
For bundle-sensitive browser builds, prefer per-function deep imports over category index imports.
Good:
```typescript
import { sprintf } from 'locutus/php/strings/sprintf'
```
Avoid in browser bundles:
```typescript
import { sprintf } from 'locutus/php/strings/index'
```
Why:
- deep imports only pull the function you asked for and its real dependencies
- category index imports can force bundlers to traverse many unrelated exports in the same namespace
- this matters most in prebundled UMD/browser artifacts where downstream tree-shaking cannot recover later
If you are publishing your own browser bundle on top of Locutus, treat deep imports as the default.
## Browser Compatibility (Copy-Paste Snippets)
Code shown on function pages (`Module JS` / `Standalone JS`) targets:
- `baseline widely available with downstream`
Package runtime targets:
- Node: `engines.node >= 22`
- Published dist output (`dist/` CommonJS + `dist/esm` ESM): `ES2022`
If your application targets older browsers, treat Locutus snippets like normal application code:
1. transpile to your target (for example with TypeScript, Babel, SWC, or esbuild)
2. add required polyfills for missing APIs in your environment
3. validate with your own Browserslist target and browser test matrix
Locutus does not inject polyfills into copy-paste snippets by default.
## Development
Some guidelines and instructions can be found in [CONTRIBUTING.md](CONTRIBUTING.md)
Quick commands:
- `yarn check` - format + lint + test
- `yarn test:parity` - cross-language verification
- `yarn test` - full test suite
- `yarn lint` - Biome check
- `yarn fix:biome` - auto-fix
## License
MIT, except for `src/php/bc/` and `src/php/_helpers/_bc.js` which are LGPL-2.1 (derived from PHP's bcmath/Libbcmath). See [LICENSE](LICENSE) for details.