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.00
# Locutus
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: locutus
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install locutus`
10
11
## Core Imports
12
13
```javascript
14
const locutus = require('locutus');
15
```
16
17
For individual function imports:
18
19
```javascript
20
const strlen = require('locutus/php/strings/strlen');
21
const arrayMerge = require('locutus/php/array/array_merge');
22
const abs = require('locutus/php/math/abs');
23
```
24
25
## Basic Usage
26
27
```javascript
28
const locutus = require('locutus');
29
30
// PHP string functions
31
const length = locutus.php.strings.strlen('Hello World'); // 11
32
const substring = locutus.php.strings.substr('Hello World', 0, 5); // 'Hello'
33
34
// PHP array functions
35
const merged = locutus.php.array.array_merge([1, 2], [3, 4]); // [1, 2, 3, 4]
36
const count = locutus.php.array.count([1, 2, 3]); // 3
37
38
// PHP math functions
39
const absolute = locutus.php.math.abs(-5); // 5
40
const rounded = locutus.php.math.round(3.14159, 2); // 3.14
41
42
// Go string functions
43
const contains = locutus.golang.strings.Contains('Hello World', 'World'); // true
44
45
// Python string functions
46
const capitalized = locutus.python.string.capwords('hello world'); // 'Hello World'
47
48
// C math functions
49
const absFloat = locutus.c.math.abs(-3.14); // 3.14
50
```
51
52
## Architecture
53
54
Locutus is organized by source language, with each language module containing category-specific submodules:
55
56
- **Language Modules**: Top-level organization by source language (php, c, golang, python, ruby)
57
- **Category Modules**: Within each language, functions are grouped by category (strings, math, array, etc.)
58
- **Individual Functions**: Each function is implemented as a separate module with comprehensive documentation
59
- **Cross-Language Consistency**: Similar functions across languages follow consistent naming and behavior patterns
60
61
## Capabilities
62
63
### PHP Functions (321 functions)
64
65
The most comprehensive module with 20 categories covering arrays, strings, math, dates, networking, and more. Includes virtually all commonly used PHP standard library functions.
66
67
```javascript { .api }
68
// Top-level PHP module access
69
const php = locutus.php;
70
71
// Category access examples
72
php.strings.strlen(string) // String length
73
php.array.array_merge(...arrays) // Merge arrays
74
php.math.abs(number) // Absolute value
75
php.datetime.date(format, timestamp) // Format date
76
php.var.is_array(variable) // Check if array
77
```
78
79
[PHP Functions](./php.md)
80
81
### C Functions (3 functions)
82
83
Core C standard library functions focusing on math and standard I/O operations.
84
85
```javascript { .api }
86
// C module access
87
const c = locutus.c;
88
89
c.math.abs(number) // Absolute value
90
c.math.frexp(number) // Extract mantissa and exponent
91
c.stdio.sprintf(format, ...args) // Formatted string output
92
```
93
94
[C Functions](./c.md)
95
96
### Go Functions (4 functions)
97
98
Go standard library string functions for common string operations.
99
100
```javascript { .api }
101
// Go module access
102
const golang = locutus.golang;
103
104
golang.strings.Contains(s, substr) // Check substring existence
105
golang.strings.Count(s, substr) // Count substring occurrences
106
golang.strings.Index(s, substr) // Find first occurrence index
107
golang.strings.LastIndex(s, substr) // Find last occurrence index
108
```
109
110
[Go Functions](./golang.md)
111
112
### Python Functions (5 functions)
113
114
Python standard library string constants and functions.
115
116
```javascript { .api }
117
// Python module access
118
const python = locutus.python;
119
120
python.string.ascii_letters() // ASCII letters function
121
python.string.ascii_lowercase() // Lowercase ASCII letters function
122
python.string.ascii_uppercase() // Uppercase ASCII letters function
123
python.string.capwords(s) // Capitalize words
124
python.string.punctuation() // Punctuation characters function
125
```
126
127
[Python Functions](./python.md)
128
129
### Ruby Functions (1 function)
130
131
Ruby standard library math function.
132
133
```javascript { .api }
134
// Ruby module access
135
const ruby = locutus.ruby;
136
137
ruby.Math.acos(x) // Arc cosine function
138
```
139
140
[Ruby Functions](./ruby.md)
141
142
## Types
143
144
```javascript { .api }
145
// Locutus main module structure
146
interface Locutus {
147
php: PhpModule;
148
c: CModule;
149
golang: GolangModule;
150
python: PythonModule;
151
ruby: RubyModule;
152
}
153
154
// Language module interfaces
155
interface PhpModule {
156
array: PhpArrayModule;
157
strings: PhpStringsModule;
158
math: PhpMathModule;
159
datetime: PhpDateTimeModule;
160
// ... other PHP categories
161
}
162
163
interface CModule {
164
math: CMathModule;
165
stdio: CStdioModule;
166
}
167
168
interface GolangModule {
169
strings: GolangStringsModule;
170
}
171
172
interface PythonModule {
173
string: PythonStringModule;
174
}
175
176
interface RubyModule {
177
Math: RubyMathModule;
178
}
179
```