A JavaScript implementation of MCard, a data model for persistently storing content with cryptographic hashing and timestamping.
MCard JS provides a cross-environment implementation that works in both Node.js and browser environments. The library offers functionality for:
- Creating and managing content cards with cryptographic hashing
- Storing structured data with timestamps
- Searching and retrieving cards by various criteria
- Synchronizing data with persistence providers
- Redux middleware for persisting application state
- MCard: Core data structure that wraps content with hash, timestamp, and metadata
- CardCollection: Manages multiple MCards, providing search and retrieval capabilities
- GTime: Handles global timestamping with region-aware formatting
- mcardPersistenceMiddleware: Redux middleware for persisting actions and state snapshots
- SafeBuffer: Cross-environment Buffer implementation for Node.js and browsers
- Content Type Detection: Automated detection and handling of various content types
- Cryptographic Utilities: Hash generation and validation
MCard JS is designed to work in both Node.js and browser environments through:
- Buffer polyfills for browser compatibility
- Environment detection for optimal feature usage
- TextEncoder/TextDecoder polyfills
- Enhanced middleware implementation following the Redux pattern (store => next => action)
- Support for both named and default exports for compatibility
- Graceful handling when storage service is unavailable
- Better test coverage (93.75% statements, 100% functions)
- Cross-environment support for Buffer/Uint8Array content handling
- Improved content access and conversion
- Robust test suite for both Node.js and browser environments
npm install @benkoo/mcardimport { MCard, CardCollection } from '@benkoo/mcard';
// Create a card with content
const card = new MCard('Hello, World!');
// Create a collection and add the card
const collection = new CardCollection();
collection.add(card);
// Retrieve by hash
const retrievedCard = collection.get(card.hash);
// Search by content
const searchResults = collection.search_by_string('Hello');import { createStore, applyMiddleware } from 'redux';
import { mcardPersistenceMiddleware } from '@benkoo/mcard';
import McardStorageService from './mcardStorageService';
import rootReducer from './reducers';
const store = createStore(
rootReducer,
applyMiddleware(
mcardPersistenceMiddleware(McardStorageService)
)
);Run the test suite with:
npm testnpm run buildMIT