MCPcopy
hub / github.com/locutusjs/locutus

github.com/locutusjs/locutus @v3.0.36 sqlite

repository ↗ · DeepWiki ↗ · release v3.0.36 ↗
4,453 symbols 11,409 edges 1,812 files 106 documented · 2%
README

Locutus

CI npm version Verified: PHP 8.3 Verified: Python 3.12

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. 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

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

import { sprintf } from 'locutus/php/strings/sprintf'

const effectiveness = 'futile'
console.log(sprintf('Resistance is %s', effectiveness))
// Resistance is futile
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:

import { sprintf } from 'locutus/php/strings/sprintf'

Avoid in browser bundles:

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

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 for details.

Extension points exported contracts — how you extend this code

TestResult (Interface)
(no doc)
test/parity/index.ts
CountObj (Interface)
(no doc)
src/php/strings/str_replace.ts
Globby (Interface)
(no doc)
src/_util/vendor.d.ts
ParitySelectionInput (Interface)
(no doc)
scripts/select-parity-targets.ts
Finding (Interface)
(no doc)
scripts/check-ts-debt-policy.ts
UpstreamSurfaceScopeAuditOptions (Interface)
(no doc)
scripts/upstream-surface-scope-audit.ts
UpstreamSurfaceEnumerationOptions (Interface)
(no doc)
scripts/upstream-surface-enumeration.ts
PackageJsonShape (Interface)
(no doc)
scripts/check-engine-bump.ts

Core symbols most depended-on inside this repo

join
called by 81
src/perl/core/join.ts
_X
called by 64
src/php/strings/md5.ts
digitAt
called by 54
src/php/_helpers/_bc.ts
toPhpArrayObject
called by 46
src/php/_helpers/_phpTypes.ts
parseArguments
called by 42
test/parity/lib/languages/golang.ts
ymd
called by 32
src/php/datetime/strtotime.ts
runInDocker
called by 31
test/parity/lib/docker.ts
abs
called by 31
src/c/math/abs.ts

Shape

Function 4,248
Interface 98
Method 95
Class 12

Languages

TypeScript100%

Modules by API surface

src/_util/util.ts77 symbols
test/parity/lib/languages/golang.ts53 symbols
test/parity/lib/upstream-surface.ts45 symbols
src/python/_helpers/_operator.ts41 symbols
src/python/_helpers/_calendar.ts38 symbols
test/parity/lib/upstream-surface-canonical.ts36 symbols
src/python/difflib/ndiff.ts28 symbols
test/parity/lib/types.ts27 symbols
src/python/_helpers/_itertools.ts26 symbols
src/php/_helpers/_phpRuntimeState.ts26 symbols
src/php/_helpers/_phpTypes.ts23 symbols
scripts/select-parity-targets.ts21 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

@biomejs/biome2.4.6 · 1×
@types/node25.4.0 · 1×
@vitest/browser-playwright4.0.18 · 1×
cross-env10 · 1×
debug4.4.3 · 1×
hexo8.1.1 · 1×
hexo-cli4.3.2 · 1×
hexo-deployer-git4.0.0 · 1×
hexo-front-matter-excerpt0.2.0 · 1×
hexo-generator-alias1.0.0 · 1×
hexo-generator-archive2.0.0 · 1×
hexo-generator-category2.0.0 · 1×

Datastores touched

(mysql)Database · 1 repos
databasenameDatabase · 1 repos

For agents

$ claude mcp add locutus \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact