This document covers the core standard library modules that provide fundamental functionality for OwnLang programs. These modules implement essential capabilities such as string manipulation, mathematical operations, file I/O, functional programming constructs, and type utilities. For information about the module loading mechanism and interface design, see Module Architecture. For specialized modules like HTTP clients and graphics, see Network and HTTP Modules and Graphics and UI Modules.
The standard library consists of several core modules that are commonly imported together to provide a comprehensive foundation for OwnLang applications. Each module implements the standard Module
interface and provides both constants and functions through the constants()
and functions()
methods.
Sources: examples/network/twitch_tools.own2 examples/versions/whatsnew_1.5.0.own1
std
ModuleThe std
module provides core string manipulation and utility functions essential for most OwnLang programs. It serves as the foundational module for basic operations.
Function | Purpose | Example Usage |
---|---|---|
getBytes() | Convert string to byte array | getBytes("Hello") |
stringFromBytes() | Convert byte array to string | stringFromBytes([119, 111, 114, 108, 100]) |
stripMargin() | Remove margin from multi-line strings | `text.stripMargin(" |
contains() | Check if string contains substring | contains(haystack, needle) |
indexOf() | Find substring position | indexOf(string, substring) |
substring() | Extract substring | substring(text, start, end) |
replace() | Replace text occurrences | replace(text, old, new) |
split() | Split string into array | split(text, delimiter) |
toLowerCase() | Convert to lowercase | toLowerCase(text) |
urlencode() | URL encode string | urlencode(url) |
The std
module implements advanced string processing capabilities including encoding support and margin handling for formatted text blocks.
Sources: examples/versions/whatsnew_1.5.0.own4-8 examples/versions/whatsnew_1.5.0.own10-18 examples/network/twitch_tools.own104 examples/network/twitch_tools.own160-164 examples/network/twitch_tools.own181
math
ModuleThe math
module provides mathematical functions and constants required for numerical computations.
The module supports common mathematical operations including rounding, ceiling functions, random number generation, and provides standard mathematical constants.
Sources: examples/network/twitch_tools.own67 examples/network/twitch_tools.own92 examples/network/twitch_tools.own127
functional
ModuleThe functional
module implements stream processing and higher-order functions for functional programming patterns in OwnLang.
Operation | Purpose | Example |
---|---|---|
stream() | Create stream from data | stream(range(1, 10)) |
filter() | Filter elements | .filter(def(x) = x % 2 == 0) |
joining() | Join elements to string | .joining(", ") |
reduce() | Reduce to single value | .reduce(accumulator, initial) |
forEach() | Execute for each element | .forEach(action) |
The joining()
function supports customizable separators and optional prefix/suffix formatting.
Sources: examples/versions/whatsnew_1.5.0.own22-27 examples/network/twitch_tools.own2
types
ModuleThe types
module provides type checking and conversion utilities for runtime type validation and coercion.
The module enables dynamic type checking and provides utilities for working with OwnLang's flexible type system, supporting operations on arrays, objects, and primitive types.
Sources: examples/network/twitch_tools.own2
json
ModuleThe json
module handles JSON serialization and deserialization with support for formatted output.
Function | Purpose | Usage |
---|---|---|
jsonencode() | Serialize to JSON | jsonencode(data) |
jsonencode() | Pretty-print JSON | jsonencode(data, 2) |
jsondecode() | Parse JSON | jsondecode(jsonString) |
The module supports both compact and pretty-printed JSON output with configurable indentation levels.
Sources: examples/versions/whatsnew_1.5.0.own78-81 examples/network/twitch_tools.own72 examples/network/twitch_tools.own107 examples/network/twitch_tools.own148
date
ModuleThe date
module provides comprehensive date and time manipulation capabilities with timezone support.
Function | Purpose | Example |
---|---|---|
parseDate() | Parse date string | parseDate(str, format) |
formatDate() | Format date object | formatDate(date, format) |
newFormat() | Create date format | newFormat("yyyy-MM-dd") |
newDate() | Create date object | newDate(timestamp) |
toTimestamp() | Convert to timestamp | toTimestamp(date) |
The module supports ISO 8601 date formats and custom formatting patterns with timezone handling.
Sources: examples/network/twitch_tools.own51 examples/network/twitch_tools.own80 examples/network/twitch_tools.own139 examples/network/twitch_tools.own151 examples/network/twitch_tools.own182-183
gzip
ModuleThe gzip
module provides data compression and decompression using the GZIP algorithm.
Function | Purpose | Usage |
---|---|---|
gzipBytes() | Compress byte array | gzipBytes(byteArray) |
ungzipBytes() | Decompress byte array | ungzipBytes(compressedBytes) |
The module works with byte arrays and integrates with the std
module's getBytes()
and stringFromBytes()
functions for text compression workflows.
Sources: examples/versions/whatsnew_1.5.0.own84-91
java
ModuleThe java
module enables Java interoperability by providing access to Java classes and objects from OwnLang code.
Function | Purpose | Example |
---|---|---|
newClass() | Create Java class reference | newClass("java.util.Random") |
The module enables instantiation of Java objects and calling their methods directly from OwnLang code, bridging the gap between OwnLang and the Java ecosystem.
Sources: examples/versions/whatsnew_1.5.0.own95-97
Standard library modules are typically imported together using the use
statement to provide a comprehensive foundation for application development.
The modules work together seamlessly, with std
providing the foundation, functional
enabling stream processing, and specialized modules like json
and date
handling specific data formats and operations.
Sources: examples/network/twitch_tools.own2 examples/versions/whatsnew_1.5.0.own1
Refresh this wiki