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

spark-dac

v1.0.0

Published

Data as code library to interprete data with code functions or export code as data with value

Readme

SparkDAC

A TypeScript library that enables Data as Code functionality - allowing you to interpret data with code functions or export code as data with values.

Description

SparkDAC (Data as Code) provides a powerful way to bridge the gap between configuration data and executable code. You can:

  • Import JSON configuration data and execute it as code functions
  • Export class methods as structured data configurations
  • Use decorators to mark functions for data serialization
  • Maintain type safety throughout the process

Installation

npm install spark-dac

Or with Bun:

bun add spark-dac

Quick Start

1. Define a Class with Decorated Methods

import { declare } from 'spark-dac';

class MyService {
    @declare("greeting", ["message", "name"])
    greet(message: string, name: string): string {
        return `${message}, ${name}!`;
    }

    @declare("calculation", ["a", "b"])
    add(a: number, b: number): number {
        return a + b;
    }
}

2. Export Code as Data

import { exportCodeAsData, exportCodeAsFile } from 'spark-dac';

const values = new Map([
    ["greeting", [
        { name: "message", data: "Hello" },
        { name: "name", data: "World" }
    ]],
    ["calculation", [
        { name: "a", data: 5 },
        { name: "b", data: 3 }
    ]]
]);

// Export as data object
const data = exportCodeAsData(MyService, values);

// Or export directly to JSON file
exportCodeAsFile("./config.json", MyService, values);

3. Import and Execute Data as Code

import { importedDataAsCode, importedDataFileAsCode } from 'spark-dac';

// From JSON string
const jsonData = JSON.stringify(data);
importedDataAsCode(jsonData, MyService);

// From JSON file
importedDataFileAsCode("./config.json", MyService);

API Reference

Functions

exportCodeAsData<T>(clazz, values): ICodeData | undefined

Exports class methods as a structured data object.

  • clazz: Class constructor with decorated methods
  • values: Map of function names to their parameter values
  • Returns: Structured data object or undefined

exportCodeAsFile<T>(path, clazz, values, callback?): void

Exports class methods directly to a JSON file.

  • path: File path for the output JSON
  • clazz: Class constructor with decorated methods
  • values: Map of function names to their parameter values
  • callback: Optional callback function after file write

importedDataAsCode<T>(data, clazz): void

Imports and executes configuration from a JSON string.

  • data: JSON string with configuration data
  • clazz: Class constructor to apply the configuration to

importedDataFileAsCode<T>(path, clazz): void

Imports and executes configuration from a JSON file.

  • path: Path to the JSON configuration file
  • clazz: Class constructor to apply the configuration to

Decorator

@declare(name: string, params: string[])

Marks a method for data serialization and execution.

  • name: Unique identifier for the function
  • params: Array of parameter names the function expects

Interfaces

ICodeData

interface ICodeData {
    config: IConfigCode[]
}

IConfigCode

interface IConfigCode {
    name: string,
    params: IParams[]
}

IParams

interface IParams {
    name: string,
    type: string,
    value: any
}

IFunctionOutput

interface IFunctionOutput {
    name: string,
    data: any
}

Example JSON Structure

The exported data follows this structure:

{
    "config": [
        {
            "name": "greeting",
            "params": [
                {
                    "name": "message",
                    "type": "string",
                    "value": "Hello"
                },
                {
                    "name": "name", 
                    "type": "string",
                    "value": "World"
                }
            ]
        },
        {
            "name": "calculation",
            "params": [
                {
                    "name": "a",
                    "type": "number",
                    "value": 5
                },
                {
                    "name": "b",
                    "type": "number", 
                    "value": 3
                }
            ]
        }
    ]
}

Use Cases

  • Configuration Management: Store complex application configurations as executable code
  • Dynamic Function Execution: Execute functions based on external data sources
  • Serializable Workflows: Convert business logic into portable data formats
  • Testing: Generate test scenarios from data configurations

Requirements

  • TypeScript ^5.8.3
  • Node.js or Bun runtime

License

MIT

Author

IGSparkew