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

c.mddocs/

C Functions

C standard library functions ported to JavaScript. This module contains 3 core functions focusing on mathematical operations and formatted output.

Capabilities

Math Functions (2 functions)

Core mathematical functions from the C standard library.

/**
 * C math functions
 */
c.math.abs(mixed_number)  // Absolute value of a number
c.math.frexp(arg)         // Extract mantissa and exponent from floating-point value

Usage Examples:

const locutus = require('locutus');

// Absolute value
const result1 = locutus.c.math.abs(-42);     // 42
const result2 = locutus.c.math.abs(-3.14);   // 3.14
const result3 = locutus.c.math.abs(15);      // 15

// Extract mantissa and exponent
const frexpResult = locutus.c.math.frexp(8.0);
// Returns array: [0.5, 4] where 0.5 * 2^4 = 8.0

Standard I/O Functions (1 function)

Formatted string output function from C standard library.

/**
 * C standard I/O function
 */
c.stdio.sprintf(format, ...args)  // Create formatted string

Usage Examples:

const locutus = require('locutus');

// Format string with various types
const formatted = locutus.c.stdio.sprintf(
  'Hello %s, you have %d messages and %.2f%% completion',
  'John',
  5,
  87.5
);
// Result: 'Hello John, you have 5 messages and 87.50% completion'

// Integer formatting
const intFormatted = locutus.c.stdio.sprintf('%d %04d %x', 42, 42, 42);
// Result: '42 0042 2a'

// Float formatting  
const floatFormatted = locutus.c.stdio.sprintf('%.2f %.4f', 3.14159, 3.14159);
// Result: '3.14 3.1416'

Function Details

abs(mixed_number)

Returns the absolute value of a number.

/**
 * Return the absolute value of a number
 * @param {number} mixed_number - The numeric value to process
 * @returns {number} The absolute value
 */
c.math.abs(mixed_number)

Parameters:

  • mixed_number (number): The numeric value to get absolute value of

Returns:

  • (number): The absolute value of the input

frexp(arg)

Breaks a floating-point value into a normalized fraction and an integral power of 2.

/**
 * Extract mantissa and exponent from floating-point value
 * @param {number} arg - The floating-point value
 * @returns {Array} Array containing [mantissa, exponent]
 */
c.math.frexp(arg)

Parameters:

  • arg (number): The floating-point value to break down

Returns:

  • (Array): Two-element array [mantissa, exponent] where mantissa * 2^exponent = arg

sprintf(format, ...args)

Returns a formatted string according to the given format string.

/**
 * Return a formatted string
 * @param {string} format - The format string
 * @param {...any} args - Values to substitute into format string
 * @returns {string} The formatted string
 */
c.stdio.sprintf(format, ...args)

Parameters:

  • format (string): Format string with conversion specifications
  • ...args (any): Values to be formatted and inserted

Returns:

  • (string): The formatted string

Format Specifiers:

  • %d - Integer
  • %f - Float
  • %s - String
  • %x - Hexadecimal (lowercase)
  • %X - Hexadecimal (uppercase)
  • %.nf - Float with n decimal places
  • %0nd - Integer padded with zeros to n digits

Import Patterns

// Full module access
const locutus = require('locutus');
locutus.c.math.abs(-42);
locutus.c.stdio.sprintf('%d', 42);

// Category-specific import (not available for C module)
// Individual function import
const abs = require('locutus/c/math/abs');
const sprintf = require('locutus/c/stdio/sprintf');

abs(-42);              // 42
sprintf('%d', 42);     // '42'

docs

c.md

golang.md

index.md

php.md

python.md

ruby.md

tile.json