F# runtime library for Fable compiler that provides JavaScript/TypeScript implementations of F# core types and operations
pkg:dotnet/fable-library@1.1.x
npx @tessl/cli install tessl/dotnet-fable-library@1.1.0The Fable Library is the F# runtime library for the Fable compiler that provides JavaScript/TypeScript implementations of F# core types and operations. It enables F# code to compile to JavaScript while maintaining strong compatibility with .NET APIs, providing efficient implementations optimized for browser and Node.js environments.
The library contains over 500+ public functions organized into 12 major functional areas, covering everything from basic type operations to advanced asynchronous programming patterns.
In F# code, the library functions are available through standard F# modules:
open System
open System.Collections.Generic
open FSharp.CoreWhen consuming from JavaScript or TypeScript:
// Core utilities and types
import * as Util from "fable-library/Util.js";
import * as Types from "fable-library/Types.js";
import * as Option from "fable-library/Option.js";
// Numeric types
import * as Long from "fable-library/Long.js";
import * as Decimal from "fable-library/Decimal.js";
// Collections
import * as Seq from "fable-library/Seq.js";
import * as Array from "fable-library/Array.js";
// Async programming
import * as Async from "fable-library/Async.js";import * as Types from "fable-library/Types.js";
import * as Option from "fable-library/Option.js";
// Create F# option values
const someValue = Option.some(42);
const noneValue = null; // F# None becomes null in JS
// Create F# lists
const list = new Types.List(1, new Types.List(2, new Types.List(3, null)));
// Create F# records
class Person extends Types.Record {
constructor(name, age) {
super();
this.name = name;
this.age = age;
}
}import * as Seq from "fable-library/Seq.js";
// Create sequences
const numbers = Seq.range(1, 10);
const doubled = Seq.map(x => x * 2, numbers);
// Convert to array
const result = Seq.toArray(doubled);
// [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]// F# async workflow
async {
let! result = someAsyncOperation()
return result * 2
}// JavaScript consumption of F# async
import * as Async from "fable-library/Async.js";
const computation = Async.startAsPromise(asyncWorkflow);
computation.then(result => console.log(result));The library is built on a sophisticated type system that maps F# types to JavaScript equivalents:
Comprehensive numeric type support including:
Multiple collection implementations optimized for different use cases:
Complete async programming stack:
Foundation types, utilities, and interfaces that underpin the entire library.
import { IComparer, IEquatable, equals, compare } from "fable-library/Util.js";
// Equality and comparison operations
const isEqual = equals(obj1, obj2);
const comparison = compare(value1, value2);Comprehensive numeric type system with full arithmetic operations.
import * as Long from "fable-library/Long.js";
import * as Decimal from "fable-library/Decimal.js";
// 64-bit integer arithmetic
const bigNum = Long.fromString("9223372036854775807");
const doubled = Long.multiply(bigNum, Long.fromNumber(2));
// Decimal arithmetic
const precise = Decimal.fromString("123.456789");
const result = Decimal.multiply(precise, Decimal.fromNumber(2));Rich string manipulation capabilities with .NET String API compatibility.
import * as String from "fable-library/String.js";
import * as RegExp from "fable-library/RegExp.js";
// String manipulation
const result = String.replace("Hello World", "World", "Fable");
// "Hello Fable"
// Regular expressions
const matches = RegExp.matches("test123", "\\d+");
// ["123"]Complete date and time handling with timezone support.
import * as Date from "fable-library/Date.js";
import * as TimeSpan from "fable-library/TimeSpan.js";
// Date operations
const now = Date.now();
const tomorrow = Date.addDays(now, 1);
// Time spans
const duration = TimeSpan.fromHours(2.5);
const totalMinutes = TimeSpan.totalMinutes(duration); // 150Extensive collection operations with functional programming support.
import * as Seq from "fable-library/Seq.js";
import * as Array from "fable-library/Array.js";
// Sequence operations
const filtered = Seq.filter(x => x > 5, Seq.range(1, 10));
const mapped = Seq.map(x => x * x, filtered);
const result = Seq.toArray(mapped);
// Array operations with F# semantics
const arr = [1, 2, 3, 4, 5];
const folded = Array.fold((acc, x) => acc + x, 0, arr); // 15Observable pattern and event system implementation.
import * as Observable from "fable-library/Observable.js";
import * as Event from "fable-library/Event.js";
// Observable operations
const mapped = Observable.map(x => x * 2, source);
const filtered = Observable.filter(x => x > 10, mapped);
// Event handling
const event = new Event();
event.Add(value => console.log(value));
event.Trigger("Hello");Complete async programming infrastructure with cancellation support.
import * as Async from "fable-library/Async.js";
import { MailboxProcessor } from "fable-library/MailboxProcessor.js";
// Async operations
const computation = Async.sleep(1000);
const promise = Async.startAsPromise(computation);
// Actor model
const processor = MailboxProcessor.Start(async mailbox => {
while (true) {
const msg = await mailbox.Receive();
console.log(`Received: ${msg}`);
}
});
processor.Post("Hello Actor");Text encoding and binary data conversion utilities.
import * as Encoding from "fable-library/Encoding.js";
import * as BitConverter from "fable-library/BitConverter.js";
// Text encoding
const bytes = Encoding.toBytes("Hello World");
const text = Encoding.toString(bytes);
// Binary conversion
const intBytes = BitConverter.getBytesInt32(42);
const value = BitConverter.toInt32(intBytes, 0);Runtime type information and reflection capabilities.
import * as Reflection from "fable-library/Reflection.js";
// Type construction
const stringType = Reflection.string_type;
const listType = Reflection.list(Reflection.int32_type);
// Type information
const fullName = Reflection.fullName(listType);
const generics = Reflection.getGenerics(listType);Integration with external JavaScript libraries and type definitions.
// BigDecimal support via big.js
import { Big } from "fable-library/lib/big.js";
const decimal1 = new Big("123.456");
const decimal2 = new Big("789.012");
const result = decimal1.plus(decimal2); // "912.468"Unicode character classification and manipulation.
import * as Char from "fable-library/Char.js";
// Character classification
const isLetter = Char.isLetter("A"); // true
const isDigit = Char.isDigit("5"); // true
const category = Char.getUnicodeCategory("A"); // Letter category
// Case conversion
const upper = Char.toUpper("hello"); // "HELLO"Build configuration and module splitting setup for optimal JavaScript output.
{
"compilerOptions": {
"target": "ES2015",
"module": "ES2015",
"outDir": "../../build/fable-library",
"strict": true
}
}