CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-dustjs-helpers

Context helpers that extend the core Dust.js templating system with conditional logic, mathematical operations, and iteration utilities.

Overview
Eval results
Files

utility-helpers.mddocs/

Utility Helpers

Utility and debug helpers that provide debugging capabilities and utility operations for template development and maintenance.

Capabilities

Context Debug Helper

Helper for debugging template contexts by outputting context information in various formats.

/**
 * Context dump helper - outputs context data for debugging
 * @param key - "full" for complete context stack, otherwise current context (optional)
 * @param to - "console" to log to console, otherwise outputs to template (optional)
 */
{@contextDump key="full|current" to="console|template"/}

Usage Examples:

// Dump current context to template
{@contextDump/}
<!-- Outputs JSON representation of current context -->

// Dump full context stack to template
{@contextDump key="full"/}
<!-- Outputs complete context stack as JSON -->

// Log current context to console
{@contextDump to="console"/}
<!-- Logs to console, no template output -->

// Log full context stack to console
{@contextDump key="full" to="console"/}
<!-- Logs complete stack to console -->

// Debug specific template section
<h2>User Profile</h2>
{#user}
  <p>Name: {name}</p>
  <p>Email: {email}</p>

  <!-- Debug the current user context -->
  {@contextDump to="console"/}
{/user}

// Debug in development environment
{@select key="{env}"}
  {@eq value="development"}
    <details>
      <summary>Debug Context</summary>
      <pre>{@contextDump/}</pre>
    </details>
  {/eq}
{/select}

Output Format:

The context dump is JSON-formatted with special handling for functions:

  • Functions are converted to strings with formatting cleanup
  • Output is escaped for safe HTML rendering when output to template
  • Console output uses raw JSON format

Context Types:

  • Current context: Shows only the current context head (default)
  • Full context: Shows the entire context stack including parent contexts

Deprecated Reference Helper

Legacy helper for resolving dust references (deprecated, use native dust resolution instead).

/**
 * Tap helper - resolves dust references (DEPRECATED)
 * @param input - Value or reference to resolve
 * @deprecated Use native Dust context resolution instead
 * @removal_version 1.8
 */
{@tap}{reference_to_resolve}{/tap}

Migration Examples:

// OLD (deprecated, will be removed in v1.8)
{@tap}{user.profile.name}{/tap}

// NEW (use native Dust resolution)
{user.profile.name}

// OLD (deprecated)
{@tap}{#items}{name}{/items}{/tap}

// NEW (native Dust iteration)
{#items}{name}{/items}

// OLD (deprecated with complex references)
{@tap}{user.settings[0].value}{/tap}

// NEW (native resolution)
{user.settings[0].value}

Deprecation Warning:

The @tap helper generates deprecation warnings when used:

  • Warning message: "Deprecation warning: tap is deprecated and will be removed in a future version of dustjs-helpers"
  • Links to migration documentation: https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#tap
  • Scheduled removal in version 1.8
  • Warnings are cached per helper name to prevent spam in logs
  • Uses internal _deprecated() function that tracks already shown warnings

Advanced Debugging Patterns

Conditional Debug Output

// Debug only in development mode
{@eq key="{debug}" value="true"}
  <div class="debug-panel">
    <h3>Template Debug Info</h3>
    <h4>Current Context:</h4>
    <pre>{@contextDump/}</pre>

    <h4>Full Stack:</h4>
    <pre>{@contextDump key="full"/}</pre>
  </div>
{/eq}

// Debug specific data sections
{#products}
  <div class="product">
    <h3>{name}</h3>

    {@contextDump key="current" to="console"/}

    {@select key="{debug}"}
      {@eq value="verbose"}
        <small>Debug: {name} | Price: {price} | Stock: {stock}</small>
      {/eq}
    {/select}
  </div>
{/products}

Performance and Error Debugging

// Log context size for performance monitoring
{@size key="{data}"}
  {@contextDump to="console"/}
  <!-- Log context when data size exceeds threshold -->
  {@gt value="1000"}
    {@contextDump key="full" to="console"/}
  {/gt}
{/@size}

// Debug missing data
{@contextDump key="current" to="console"/}
{@select key="{user}"}
  {@none}
    <!-- Log context when user is missing -->
    {@contextDump key="full" to="console"/}
    <p>User data not available</p>
  {/none}
{/select}

Security Considerations:

  • Never use @contextDump with template output in production
  • Context may contain sensitive data that should not be exposed to users
  • Always use to="console" parameter for production debugging
  • Consider environment-based conditional rendering for debug helpers

Best Practices:

  • Use @contextDump primarily during development and testing
  • Combine with conditional helpers to control when debugging occurs
  • Log to console rather than template output to avoid exposing data
  • Remove or conditionally disable debug helpers in production builds

Install with Tessl CLI

npx tessl i tessl/npm-dustjs-helpers

docs

conditional-logic.md

index.md

iteration-control.md

math-operations.md

utility-helpers.md

tile.json