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
Promise
await fs.readJson(filePath)
Reads and parses a JSON file.
Parameters:filePath(string): Path to the JSON file
Promise
Writing Files
await fs.writeText(filePath, content)
Writes a string to a file.
Parameters:filePath(string): Path to the filecontent(string): Content to write
Promise
await fs.writeJson(filePath, data)
Writes an object to a JSON file.
Parameters:filePath(string): Path to the filedata(object): Data to write
Promise
await fs.appendText(filePath, content)
Appends content to a file.
Parameters:filePath(string): Path to the filecontent(string): Content to append
Promise
Directory Operations
await fs.readDir(dirPath)
Lists all files and directories in a directory.
Parameters:dirPath(string): Path to the directory
Promise
await fs.createDir(dirPath)
Creates a directory.
Parameters:dirPath(string): Path to create
Promise
await fs.removeDir(dirPath)
Removes a directory.
Parameters:dirPath(string): Path to remove
Promise
File Operations
await fs.exists(path)
Checks if a file or directory exists.
Parameters:path(string): Path to check
Promise
await fs.removeFile(filePath)
Removes a file.
Parameters:filePath(string): Path to the file
Promise
await fs.copyFile(source, dest)
Copies a file.
Parameters:source(string): Source pathdest(string): Destination path
Promise
await fs.rename(oldPath, newPath)
Renames or moves a file.
Parameters:oldPath(string): Current pathnewPath(string): New path
Promise
await fs.stat(path)
Gets file or directory information.
Parameters:path(string): Path to inspect
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
object
json.stringify(value)
Converts a value to JSON string.
Parameters:value(any): Value to stringify
string
json.stringifyPretty(value)
Converts a value to formatted JSON string.
Parameters:value(any): Value to stringify
string (formatted with indentation)
json.validate(jsonString)
Validates a JSON string.
Parameters:jsonString(string): JSON to validate
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)
Channel
Channel Methods:
await ch.send(value): Send a valueawait ch.recv(): Receive a valuech.close(): Close the channel
Async Utilities
await sleep(ms)
Pauses execution for a duration.
Parameters:ms(number): Milliseconds to sleep
Promise
await parallel(tasks, options)
Executes tasks in parallel.
Parameters:tasks(function[]): Array of async functionsoptions(object): Optional configuration
Promise
await race(tasks)
Returns the result of the first completed task.
Parameters:tasks(function[]): Array of async functions
Promise
await timeout(task, ms)
Executes a task with a timeout.
Parameters:task(function): Async function to executems(number): Timeout in milliseconds
Promise
await retry(task, options)
Retries a task on failure.
Parameters:task(function): Async function to retryoptions(object):{ maxAttempts, delay, backoff }
Promise
await sequence(tasks)
Executes tasks sequentially.
Parameters:tasks(function[]): Array of async functions
Promise