CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-locutus

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

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

php.mddocs/

PHP Functions

Comprehensive PHP standard library functions ported to JavaScript. This module contains 321 functions across 20 categories, covering virtually all commonly used PHP functionality.

Capabilities

Array Functions (73 functions)

Array manipulation and processing functions for creating, modifying, and analyzing arrays.

/**
 * Array manipulation functions
 */
php.array.array_change_key_case(array, case)        // Change key case
php.array.array_chunk(input, size, preserve_keys)   // Split into chunks
php.array.array_column(array, column_key, index_key) // Extract column
php.array.array_combine(keys, values)               // Combine arrays
php.array.array_count_values(array)                 // Count values
php.array.array_diff(array1, array2, ...)           // Array difference
php.array.array_diff_assoc(array1, array2, ...)     // Diff with keys
php.array.array_fill(start_index, num, value)       // Fill with value
php.array.array_filter(array, callback, flag)       // Filter elements
php.array.array_flip(array)                         // Flip keys/values
php.array.array_intersect(array1, array2, ...)      // Array intersection
php.array.array_keys(array, search_value, strict)   // Get all keys
php.array.array_map(callback, array1, ...)          // Map callback
php.array.array_merge(array1, array2, ...)          // Merge arrays
php.array.array_pad(array, size, value)             // Pad to length
php.array.array_pop(array)                          // Remove last element
php.array.array_push(array, element1, ...)          // Add elements to end
php.array.array_reverse(array, preserve_keys)       // Reverse array
php.array.array_search(needle, haystack, strict)    // Search for value
php.array.array_slice(array, offset, length, preserve_keys) // Extract slice
php.array.array_sum(array)                          // Sum values
php.array.array_unique(array, sort_flags)           // Remove duplicates
php.array.array_values(array)                       // Get all values
php.array.count(mixed_var, mode)                    // Count elements
php.array.in_array(needle, haystack, strict)        // Check value exists
php.array.range(start, end, step)                   // Create range
php.array.sort(array, sort_flags)                   // Sort array

Usage Examples:

const locutus = require('locutus');

// Array merging
const merged = locutus.php.array.array_merge([1, 2], [3, 4]); // [1, 2, 3, 4]

// Array filtering
const numbers = [1, 2, 3, 4, 5];
const even = locutus.php.array.array_filter(numbers, (n) => n % 2 === 0); // [2, 4]

// Array chunking
const chunked = locutus.php.array.array_chunk([1, 2, 3, 4, 5, 6], 2); // [[1, 2], [3, 4], [5, 6]]

String Functions (91 functions)

Comprehensive string manipulation and processing functions.

/**
 * String manipulation functions
 */
php.strings.addslashes(str)                          // Add slashes
php.strings.chr(ascii)                               // ASCII to char
php.strings.explode(delimiter, string, limit)        // Split string
php.strings.html_entity_decode(string, quote_style, charset) // Decode HTML
php.strings.htmlentities(string, quote_style, charset, double_encode) // Encode HTML
php.strings.htmlspecialchars(string, quote_style, charset, double_encode) // Encode special chars
php.strings.implode(glue, pieces)                    // Join array
php.strings.ltrim(str, charlist)                     // Left trim
php.strings.md5(str)                                 // MD5 hash
php.strings.nl2br(str, is_xhtml)                     // Newlines to BR
php.strings.ord(string)                              // Char to ASCII
php.strings.rtrim(str, charlist)                     // Right trim
php.strings.sha1(str)                                // SHA1 hash
php.strings.sprintf(format, ...args)                 // Format string
php.strings.str_pad(input, pad_length, pad_string, pad_type) // Pad string
php.strings.str_repeat(input, multiplier)            // Repeat string
php.strings.str_replace(search, replace, subject, count) // Replace text
php.strings.strlen(string)                           // String length
php.strings.strpos(haystack, needle, offset)         // Find position
php.strings.strtolower(str)                         // To lowercase
php.strings.strtoupper(str)                         // To uppercase
php.strings.substr(str, start, length)               // Substring
php.strings.trim(str, charlist)                      // Trim whitespace
php.strings.ucfirst(str)                            // Uppercase first
php.strings.ucwords(str, delimiters)                 // Uppercase words

Usage Examples:

const locutus = require('locutus');

// String manipulation
const length = locutus.php.strings.strlen('Hello World'); // 11
const upper = locutus.php.strings.strtoupper('hello'); // 'HELLO'
const padded = locutus.php.strings.str_pad('test', 10, '0', 'STR_PAD_LEFT'); // '000000test'

// String formatting
const formatted = locutus.php.strings.sprintf('Hello %s, you are %d years old', 'John', 25);
// 'Hello John, you are 25 years old'

Math Functions (46 functions)

Mathematical operations and functions.

/**
 * Mathematical functions
 */
php.math.abs(mixed_number)        // Absolute value
php.math.acos(arg)               // Arc cosine
php.math.asin(arg)               // Arc sine
php.math.atan(arg)               // Arc tangent
php.math.atan2(y, x)             // Arc tangent of y/x
php.math.ceil(value)             // Round up
php.math.cos(arg)                // Cosine
php.math.deg2rad(number)         // Degrees to radians
php.math.exp(arg)                // e^x
php.math.floor(value)            // Round down
php.math.log(arg, base)          // Logarithm
php.math.max(...values)          // Maximum value
php.math.min(...values)          // Minimum value
php.math.pow(base, exp)          // Power
php.math.rand(min, max)          // Random number
php.math.round(val, precision, mode) // Round number
php.math.sin(arg)                // Sine
php.math.sqrt(arg)               // Square root
php.math.tan(arg)                // Tangent

DateTime Functions (15 functions)

Date and time manipulation functions.

/**
 * Date and time functions
 */
php.datetime.date(format, timestamp)              // Format date
php.datetime.getdate(timestamp)                   // Get date info
php.datetime.gmdate(format, timestamp)            // GMT date
php.datetime.mktime(hour, minute, second, month, day, year) // Make timestamp
php.datetime.strftime(format, timestamp)          // Format with locale
php.datetime.strtotime(time, now)                 // Parse datetime
php.datetime.time()                               // Current timestamp

Variable Functions (30 functions)

Variable type checking and manipulation functions.

/**
 * Variable functions
 */
php.var.is_array(variable)        // Check if array
php.var.is_bool(variable)         // Check if boolean
php.var.is_float(variable)        // Check if float
php.var.is_int(variable)          // Check if integer
php.var.is_null(variable)         // Check if null
php.var.is_numeric(variable)      // Check if numeric
php.var.is_object(variable)       // Check if object
php.var.is_string(variable)       // Check if string
php.var.isset(variable)           // Check if set
php.var.empty(variable)           // Check if empty
php.var.gettype(variable)         // Get variable type
php.var.serialize(variable)       // Serialize variable
php.var.unserialize(str)          // Unserialize string

Other PHP Categories

BC Math Functions (7 functions)

php.bc.bcadd(left_operand, right_operand, scale)    // Add
php.bc.bccomp(left_operand, right_operand, scale)   // Compare
php.bc.bcdiv(left_operand, right_operand, scale)    // Divide
php.bc.bcmul(left_operand, right_operand, scale)    // Multiply
php.bc.bcround(number, precision)                   // Round
php.bc.bcscale(scale)                               // Set scale
php.bc.bcsub(left_operand, right_operand, scale)    // Subtract

Character Type Functions (11 functions)

php.ctype.ctype_alnum(text)       // Alphanumeric check
php.ctype.ctype_alpha(text)       // Alphabetic check
php.ctype.ctype_digit(text)       // Digit check
php.ctype.ctype_lower(text)       // Lowercase check
php.ctype.ctype_upper(text)       // Uppercase check

Filesystem Functions (6 functions)

php.filesystem.basename(path, suffix)    // Get basename
php.filesystem.dirname(path)             // Get directory name
php.filesystem.file_exists(filename)     // Check file exists
php.filesystem.pathinfo(path, options)   // Get path info

JSON Functions (3 functions)

php.json.json_decode(json_string, assoc, depth, options) // Decode JSON
php.json.json_encode(value, options, depth)              // Encode JSON
php.json.json_last_error()                               // Get last error

Network Functions (6 functions)

php.network.ip2long(ip_address)          // IP to long
php.network.long2ip(proper_address)      // Long to IP
php.network.inet_ntop(in_addr)           // Binary to presentation
php.network.inet_pton(ip_address)        // Presentation to binary

URL Functions (8 functions)

php.url.base64_encode(data)              // Base64 encode
php.url.base64_decode(data)              // Base64 decode
php.url.parse_url(str, component)        // Parse URL
php.url.urlencode(str)                   // URL encode
php.url.urldecode(str)                   // URL decode
php.url.rawurlencode(str)                // Raw URL encode
php.url.rawurldecode(str)                // Raw URL decode

Execution Functions (1 function)

php.exec.escapeshellarg(arg)              // Escape shell arguments

Function Handling Functions (5 functions)

php.funchand.call_user_func(cb, ...parameters)           // Call user function
php.funchand.call_user_func_array(cb, parameters)        // Call function with array
php.funchand.create_function(args, code)                 // Create anonymous function
php.funchand.function_exists(funcName)                   // Check if function exists
php.funchand.get_defined_functions()                     // Get defined functions

Internationalization Functions (2 functions)

php.i18n.i18n_loc_get_default()          // Get default locale
php.i18n.i18n_loc_set_default(name)      // Set default locale

Information Functions (6 functions)

php.info.assert_options(what, value)     // Assert configuration options
php.info.getenv(varname)                 // Get environment variable
php.info.ini_get(varname)                // Get configuration option
php.info.ini_set(varname, newvalue)      // Set configuration option
php.info.set_time_limit(seconds)         // Set execution time limit
php.info.version_compare(v1, v2, operator) // Compare version strings

Miscellaneous Functions (2 functions)

php.misc.pack(format, ...args)           // Pack data into binary string
php.misc.uniqid(prefix, moreEntropy)     // Generate unique identifier

Net Gopher Functions (1 function)

php['net-gopher'].gopher_parsedir(dirent) // Parse gopher directory entry

Regular Expression Functions (4 functions)

php.pcre.preg_match(regex, str)          // Perform regex match
php.pcre.preg_quote(str, delimiter)      // Quote regex characters
php.pcre.preg_replace(pattern, replacement, string) // Regex search and replace
php.pcre.sql_regcase(str)                // Case-insensitive regex

Xdiff Functions (2 functions)

php.xdiff.xdiff_string_diff(oldData, newData, contextLines, minimal) // Create diff
php.xdiff.xdiff_string_patch(originalStr, patch, flags, errorObj)     // Apply patch

XML Functions (2 functions)

php.xml.utf8_decode(strData)             // Decode UTF-8 strings
php.xml.utf8_encode(argString)           // Encode strings to UTF-8

Usage Patterns

Function Import Patterns

// Full module import
const locutus = require('locutus');
locutus.php.strings.strlen('test');

// Category import
const phpStrings = require('locutus/php/strings');
phpStrings.strlen('test');

// Individual function import
const strlen = require('locutus/php/strings/strlen');
strlen('test');

Common Use Cases

const locutus = require('locutus');

// Data processing pipeline
const processUsers = (users) => {
  return users
    .map(user => ({
      ...user,
      name: locutus.php.strings.trim(user.name),
      email: locutus.php.strings.strtolower(user.email)
    }))
    .filter(user => locutus.php.var.is_string(user.name) && user.name.length > 0);
};

// Date formatting
const formatDate = (timestamp) => {
  return locutus.php.datetime.date('Y-m-d H:i:s', timestamp);
};

// Array manipulation
const mergeAndSort = (...arrays) => {
  const merged = locutus.php.array.array_merge(...arrays);
  locutus.php.array.sort(merged);
  return merged;
};

docs

c.md

golang.md

index.md

php.md

python.md

ruby.md

tile.json