OC Hash Builder

1.0.5 · active · verified Sun Apr 19

oc-hash-builder is a utility library within the OpenComponents (OC) ecosystem, designed to provide deterministic hashing capabilities. Its primary role is to generate consistent hashes for component-related data, configurations, and content, which is crucial for OpenComponents' internal mechanisms such as caching, component identification, and versioning. As of version 1.0.5, it represents a stable initial release. The library's release cadence is likely tied to the broader OpenComponents project, focusing on stability and integration rather than frequent, independent updates. A key differentiator is its purpose-built nature for the OpenComponents framework, ensuring compatibility and adherence to OC's specific requirements for managing and deploying micro-frontends. It ships with TypeScript types, facilitating its use in modern JavaScript and TypeScript projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `oc-hash-builder` to create deterministic hashes for objects and strings, which is critical for identifying and caching OpenComponents artifacts.

import { buildHash } from 'oc-hash-builder';

// Example 1: Hashing a simple object
const componentConfig = {
  name: 'my-component',
  version: '1.0.0',
  dependencies: ['lodash@4.17.21'],
  settings: {
    env: 'production'
  }
};
const configHash = buildHash(componentConfig);
console.log(`Hash for component config: ${configHash}`);

// Example 2: Hashing a string (e.g., component template content)
const templateContent = `<div>Hello, {{name}}!</div>`;
const contentHash = buildHash(templateContent);
console.log(`Hash for template content: ${contentHash}`);

// Example 3: Ensuring deterministic hashing
const sameConfigDifferentOrder = {
  settings: {
    env: 'production'
  },
  dependencies: ['lodash@4.17.21'],
  name: 'my-component',
  version: '1.0.0'
};
const orderIndependentHash = buildHash(sameConfigDifferentOrder);
console.log(`Hash for reordered config (should be same): ${orderIndependentHash}`);

// In a real OpenComponents context, this might be used internally or exposed
// via a plugin system for ensuring component integrity and cache keys.
// For instance, during component publishing or rendering lifecycle.

view raw JSON →