npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@workflow-stack/interpolation

v0.1.8

Published

JSONata-based interpolation utilities for @workflow-stack

Downloads

60

Readme

@workflow-stack/interpolation

JSONata-based interpolation utilities for @workflow-stack. Recursively interpolates string values in objects using powerful JSONata expressions.

Installation

npm install @workflow-stack/interpolation

Usage

import { interpolateObject, cookiesToHeader, buildQueryString } from '@workflow-stack/interpolation';

interpolateObject

Recursively interpolates all string values in an object using JSONata expressions wrapped in curly braces.

const context = {
  user: { id: 123, name: 'John' },
  env: { apiKey: 'secret-key' }
};

// Simple path expressions
await interpolateObject('{user.id}', context);
// => 123 (preserves number type)

// Nested object interpolation
await interpolateObject({
  url: 'https://api.example.com/users/{user.id}',
  headers: {
    'Authorization': 'Bearer {env.apiKey}'
  }
}, context);
// => { url: 'https://api.example.com/users/123', headers: { Authorization: 'Bearer secret-key' } }

Type Preservation

Single token expressions preserve the original type:

const context = {
  number: 42,
  boolean: true,
  array: [1, 2, 3],
  object: { key: 'value' }
};

await interpolateObject('{number}', context);   // => 42 (number)
await interpolateObject('{boolean}', context);  // => true (boolean)
await interpolateObject('{array}', context);    // => [1, 2, 3] (array)
await interpolateObject('{object}', context);   // => { key: 'value' } (object)

Mixed text with tokens returns a string:

await interpolateObject('https://{host}:{port}/api', { host: 'example.com', port: 8080 });
// => 'https://example.com:8080/api'

JSONata Features

Full JSONata expression support:

const context = {
  order: {
    items: [
      { price: 10, qty: 2 },
      { price: 20, qty: 1 }
    ]
  },
  users: [
    { name: 'alice', status: 'active' },
    { name: 'bob', status: 'inactive' }
  ]
};

// Aggregations
await interpolateObject('{$sum(order.items.(price * qty))}', context);
// => 40

// Filters
await interpolateObject('{users[status="active"].name}', context);
// => 'alice'

// Transformations
await interpolateObject('{users.name.$uppercase()}', context);
// => ['ALICE', 'BOB']

Complex Expressions with Nested Braces

Use {-expression-} syntax for expressions containing nested braces:

const context = {
  items: [
    { id: 1, name: 'Item 1' },
    { id: 2, name: 'Item 2' }
  ]
};

await interpolateObject('{-$map(items, function($x) { $x.id })-}', context);
// => [1, 2]

cookiesToHeader

Converts a cookies object to a Cookie header string:

cookiesToHeader({ session: 'abc123', user: 'john' });
// => 'session=abc123; user=john'

buildQueryString

Converts an object to a URL query string:

buildQueryString({ page: '1', limit: '10', sort: 'name' });
// => 'page=1&limit=10&sort=name'

API

interpolateObject(obj: any, context: InterpolationContext): Promise<any>

Recursively interpolates all string values in an object using JSONata expressions.

  • obj: The value to interpolate (string, object, array, or primitive)
  • context: The context object available for expression evaluation
  • returns: The interpolated value with preserved types

cookiesToHeader(cookies: Record<string, string>): string

Converts a cookies object to a Cookie header string.

buildQueryString(query: Record<string, string>): string

Converts a query object to a URL-encoded query string.

InterpolationContext

Type definition for the context object:

type InterpolationContext = Record<string, any>;

Error Handling

If a JSONata expression fails to evaluate, the original string is preserved:

await interpolateObject('{nonexistent.path}', {});
// => '{nonexistent.path}'

License

MIT