API Reference

Complete reference for the Pulse standard library.

File System (std/fs)

The fs module provides comprehensive file system operations.

Reading Files

import fs from 'std/fs'

await fs.readText(filePath)

Reads a file and returns its contents as a string.

Parameters:
  • filePath (string): Path to the file
Returns: Promise
await fs.readJson(filePath)

Reads and parses a JSON file.

Parameters:
  • filePath (string): Path to the JSON file
Returns: Promise

Writing Files

await fs.writeText(filePath, content)

Writes a string to a file.

Parameters:
  • filePath (string): Path to the file
  • content (string): Content to write
Returns: Promise
await fs.writeJson(filePath, data)

Writes an object to a JSON file.

Parameters:
  • filePath (string): Path to the file
  • data (object): Data to write
Returns: Promise
await fs.appendText(filePath, content)

Appends content to a file.

Parameters:
  • filePath (string): Path to the file
  • content (string): Content to append
Returns: Promise

Directory Operations

await fs.readDir(dirPath)

Lists all files and directories in a directory.

Parameters:
  • dirPath (string): Path to the directory
Returns: Promise
await fs.createDir(dirPath)

Creates a directory.

Parameters:
  • dirPath (string): Path to create
Returns: Promise
await fs.removeDir(dirPath)

Removes a directory.

Parameters:
  • dirPath (string): Path to remove
Returns: Promise

File Operations

await fs.exists(path)

Checks if a file or directory exists.

Parameters:
  • path (string): Path to check
Returns: Promise
await fs.removeFile(filePath)

Removes a file.

Parameters:
  • filePath (string): Path to the file
Returns: Promise
await fs.copyFile(source, dest)

Copies a file.

Parameters:
  • source (string): Source path
  • dest (string): Destination path
Returns: Promise
await fs.rename(oldPath, newPath)

Renames or moves a file.

Parameters:
  • oldPath (string): Current path
  • newPath (string): New path
Returns: Promise
await fs.stat(path)

Gets file or directory information.

Parameters:
  • path (string): Path to inspect
Returns: Promise<{isFile, isDirectory, size, created, modified}>

JSON (std/json)

Parse and stringify JSON data.

import json from 'std/json'

json.parse(jsonString)

Parses a JSON string.

Parameters:
  • jsonString (string): JSON string to parse
Returns: object
json.stringify(value)

Converts a value to JSON string.

Parameters:
  • value (any): Value to stringify
Returns: string
json.stringifyPretty(value)

Converts a value to formatted JSON string.

Parameters:
  • value (any): Value to stringify
Returns: string (formatted with indentation)
json.validate(jsonString)

Validates a JSON string.

Parameters:
  • jsonString (string): JSON to validate
Returns: boolean

Math (std/math)

Mathematical functions and constants.

Constants

import math from 'std/math'

math.PI
math.E
math.SQRT2

Basic Functions

math.abs(x)
math.min(a, b)
math.max(a, b)
math.floor(x)
math.ceil(x)
math.round(x)
math.pow(base, exponent)
math.sqrt(x)

Trigonometry

math.sin(x)
math.cos(x)
math.tan(x)
math.toRadians(degrees)
math.toDegrees(radians)

Utilities

math.random()
math.randomInt(min, max)
math.clamp(value, min, max)
math.lerp(start, end, t)

Async (std/async)

Advanced async utilities and concurrency primitives.

Channels

import { channel } from 'std/async'

const ch = channel(bufferSize)

Creates a new channel for concurrent communication.

Parameters:
  • bufferSize (number): Buffer size (0 for unbuffered)
Returns: Channel Channel Methods:
  • await ch.send(value): Send a value
  • await ch.recv(): Receive a value
  • ch.close(): Close the channel

Async Utilities

await sleep(ms)

Pauses execution for a duration.

Parameters:
  • ms (number): Milliseconds to sleep
Returns: Promise
await parallel(tasks, options)

Executes tasks in parallel.

Parameters:
  • tasks (function[]): Array of async functions
  • options (object): Optional configuration
Returns: Promise
await race(tasks)

Returns the result of the first completed task.

Parameters:
  • tasks (function[]): Array of async functions
Returns: Promise
await timeout(task, ms)

Executes a task with a timeout.

Parameters:
  • task (function): Async function to execute
  • ms (number): Timeout in milliseconds
Returns: Promise
await retry(task, options)

Retries a task on failure.

Parameters:
  • task (function): Async function to retry
  • options (object): { maxAttempts, delay, backoff }
Returns: Promise
await sequence(tasks)

Executes tasks sequentially.

Parameters:
  • tasks (function[]): Array of async functions
Returns: Promise