JavaScript library that ports standard library functions from other programming languages (PHP, C, Go, Python, Ruby) to JavaScript
npx @tessl/cli install tessl/npm-locutus@2.0.0Locutus is a JavaScript library that ports standard library functions from multiple programming languages (PHP, C, Go, Python, Ruby) to JavaScript for fun and educational purposes. It provides 334 cross-language utility functions that allow developers to use familiar functions from other ecosystems within JavaScript applications.
npm install locutusconst locutus = require('locutus');For individual function imports:
const strlen = require('locutus/php/strings/strlen');
const arrayMerge = require('locutus/php/array/array_merge');
const abs = require('locutus/php/math/abs');const locutus = require('locutus');
// PHP string functions
const length = locutus.php.strings.strlen('Hello World'); // 11
const substring = locutus.php.strings.substr('Hello World', 0, 5); // 'Hello'
// PHP array functions
const merged = locutus.php.array.array_merge([1, 2], [3, 4]); // [1, 2, 3, 4]
const count = locutus.php.array.count([1, 2, 3]); // 3
// PHP math functions
const absolute = locutus.php.math.abs(-5); // 5
const rounded = locutus.php.math.round(3.14159, 2); // 3.14
// Go string functions
const contains = locutus.golang.strings.Contains('Hello World', 'World'); // true
// Python string functions
const capitalized = locutus.python.string.capwords('hello world'); // 'Hello World'
// C math functions
const absFloat = locutus.c.math.abs(-3.14); // 3.14Locutus is organized by source language, with each language module containing category-specific submodules:
The most comprehensive module with 20 categories covering arrays, strings, math, dates, networking, and more. Includes virtually all commonly used PHP standard library functions.
// Top-level PHP module access
const php = locutus.php;
// Category access examples
php.strings.strlen(string) // String length
php.array.array_merge(...arrays) // Merge arrays
php.math.abs(number) // Absolute value
php.datetime.date(format, timestamp) // Format date
php.var.is_array(variable) // Check if arrayCore C standard library functions focusing on math and standard I/O operations.
// C module access
const c = locutus.c;
c.math.abs(number) // Absolute value
c.math.frexp(number) // Extract mantissa and exponent
c.stdio.sprintf(format, ...args) // Formatted string outputGo standard library string functions for common string operations.
// Go module access
const golang = locutus.golang;
golang.strings.Contains(s, substr) // Check substring existence
golang.strings.Count(s, substr) // Count substring occurrences
golang.strings.Index(s, substr) // Find first occurrence index
golang.strings.LastIndex(s, substr) // Find last occurrence indexPython standard library string constants and functions.
// Python module access
const python = locutus.python;
python.string.ascii_letters() // ASCII letters function
python.string.ascii_lowercase() // Lowercase ASCII letters function
python.string.ascii_uppercase() // Uppercase ASCII letters function
python.string.capwords(s) // Capitalize words
python.string.punctuation() // Punctuation characters functionRuby standard library math function.
// Ruby module access
const ruby = locutus.ruby;
ruby.Math.acos(x) // Arc cosine function// Locutus main module structure
interface Locutus {
php: PhpModule;
c: CModule;
golang: GolangModule;
python: PythonModule;
ruby: RubyModule;
}
// Language module interfaces
interface PhpModule {
array: PhpArrayModule;
strings: PhpStringsModule;
math: PhpMathModule;
datetime: PhpDateTimeModule;
// ... other PHP categories
}
interface CModule {
math: CMathModule;
stdio: CStdioModule;
}
interface GolangModule {
strings: GolangStringsModule;
}
interface PythonModule {
string: PythonStringModule;
}
interface RubyModule {
Math: RubyMathModule;
}