Package Exports Overview
FractaLedger now provides a modern package exports system that gives users more precise control over how they import and use the library. This feature is part of Node.js's newer module resolution algorithm and offers several benefits:
- Granular Access Control: Explicitly define which parts of your package are accessible to users
- Multiple Entry Points: Allow users to import specific functionality without loading the entire package
- Dual Format Support: Support both CommonJS and ES Modules in the same package
- TypeScript Integration: Provide type definitions for better IDE support and type checking
With package exports, users can import only the specific functionality they need, which can lead to smaller bundle sizes and better performance in their applications.
CommonJS (Node.js)
// Import the entire package
const fractaledger = require('fractaledger');
// Import specific modules
const { BlockchainConnector } = require('fractaledger/blockchain');
const { initializeWalletManager } = require('fractaledger/wallet');
const { SPVTransceiver } = require('fractaledger/transceivers');
const { startApiServer } = require('fractaledger/api');
ES Modules (Modern JavaScript)
// Import the entire package
import fractaledger from 'fractaledger';
// Import specific modules
import { BlockchainConnector } from 'fractaledger/blockchain';
import { initializeWalletManager } from 'fractaledger/wallet';
import { SPVTransceiver } from 'fractaledger/transceivers';
import { startApiServer } from 'fractaledger/api';