Js revealing module pattern

From Intense-Visions/harness-engineering · View interactive version

Js revealing module pattern is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Define all logic privately and selectively reveal only the public API

How to use this skill

Skill file

JS Revealing Module Pattern

Define all logic privately and selectively reveal only the public API

When to Use

Instructions

  1. Define all functions and variables in a private closure scope.
  2. At the end of the module, return an object that maps public names to private implementations.
  3. Internal functions can call each other freely — only the return object is public.
const counterModule = (() => {
  let _count = 0;

  function increment() {
    _count++;
  }
  function decrement() {
    _count--;
  }
  function getCount() {
    return _count;
  }
  function reset() {
    _count = 0;
  }

  // Reveal only the public API
  return { increment, decrement, getCount };
  // Note: reset() is private — not revealed
})();

counterModule.increment();
counterModule.increment();
console.log(counterModule.getCount()); // 2

Details

The Revealing Module is a refinement of the Module pattern. The key insight: all code (including private functions) is defined in the same flat scope, which makes it easy to see the full implementation. The final return statement is the sole arbiter of what is public.

Trade-offs:

When NOT to use:

Source

https://patterns.dev/javascript/revealing-module-pattern

Process

  1. Read the instructions and examples in this document.
  2. Apply the patterns to your implementation, adapting to your specific context.
  3. Verify your implementation against the details and edge cases listed above.

Harness Integration

Success Criteria

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.