locutusjs/locutus
Composer 安装命令:
composer require locutusjs/locutus
包简介
Locutus other languages' standard libraries to JavaScript for fun and educational purposes
README 文档
README
All your standard libraries will be assimilated into our
JavaScriptTypeScript 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/esmESM):ES2022
If your application targets older browsers, treat Locutus snippets like normal application code:
- transpile to your target (for example with TypeScript, Babel, SWC, or esbuild)
- add required polyfills for missing APIs in your environment
- 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 + testyarn test:parity- cross-language verificationyarn test- full test suiteyarn lint- Biome checkyarn 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.
locutusjs/locutus 适用场景与选型建议
locutusjs/locutus 是一款 基于 TypeScript 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 3.77k, 最近一次更新时间为 2026 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「javascript」 「JS」 「ruby」 「python」 「polyfill」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 locutusjs/locutus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 locutusjs/locutus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 locutusjs/locutus 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
Manipulate arrays similar to Ruby.
Ruby range syntax parser for PHP.
A PHP client library for easily accessing Ruby on Rails-based REST services.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3773
- 点击次数: 42
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-07