or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

c.mdgolang.mdindex.mdphp.mdpython.mdruby.md
tile.json

tessl/npm-locutus

JavaScript library that ports standard library functions from other programming languages (PHP, C, Go, Python, Ruby) to JavaScript

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/locutus@2.0.x

To install, run

npx @tessl/cli install tessl/npm-locutus@2.0.0

index.mddocs/

Locutus

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

Package Information

  • Package Name: locutus
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install locutus

Core Imports

const 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');

Basic Usage

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

Architecture

Locutus is organized by source language, with each language module containing category-specific submodules:

  • Language Modules: Top-level organization by source language (php, c, golang, python, ruby)
  • Category Modules: Within each language, functions are grouped by category (strings, math, array, etc.)
  • Individual Functions: Each function is implemented as a separate module with comprehensive documentation
  • Cross-Language Consistency: Similar functions across languages follow consistent naming and behavior patterns

Capabilities

PHP Functions (321 functions)

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 array

PHP Functions

C Functions (3 functions)

Core 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 output

C Functions

Go Functions (4 functions)

Go 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 index

Go Functions

Python Functions (5 functions)

Python 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 function

Python Functions

Ruby Functions (1 function)

Ruby standard library math function.

// Ruby module access
const ruby = locutus.ruby;

ruby.Math.acos(x)  // Arc cosine function

Ruby Functions

Types

// 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;
}