🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@json-eval-rs/bundler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@json-eval-rs/bundler

JSON Eval RS for bundlers (Webpack, Vite, Next.js, etc.) with ergonomic API

latest
Source
npmnpm
Version
0.0.30
Version published
Maintainers
1
Created
Source

@json-eval-rs/bundler

JSON Eval RS for modern bundlers (Webpack, Vite, Rollup, Next.js, etc.) with ergonomic API.

Installation

yarn install @json-eval-rs/bundler
# or
yarn add @json-eval-rs/bundler

Usage

import { JSONEval } from '@json-eval-rs/bundler';

const evaluator = new JSONEval({
  schema: {
    type: 'object',
    properties: {
      name: {
        type: 'string',
        rules: {
          required: { value: true, message: 'Name is required' },
          minLength: { value: 3, message: 'Min 3 characters' }
        }
      },
      email: {
        type: 'string',
        rules: {
          required: { value: true, message: 'Email is required' },
          email: { value: true, message: 'Invalid email' }
        }
      }
    }
  }
});

// Initialize (loads WASM)
await evaluator.init();

// Validate data
const result = await evaluator.validate({
  data: { name: 'Jo', email: 'invalid' }
});

if (result.has_error) {
  console.log('Validation errors:', result.errors);
  // [{ path: 'name', rule_type: 'minLength', message: 'Min 3 characters' }, ...]
}

// Evaluate schema with data
const evaluated = await evaluator.evaluate({
  data: { name: 'John', email: 'john@example.com' }
});

// Get schema values
const values = await evaluator.getSchemaValue();

// Clean up when done
evaluator.free();

API

new JSONEval(options)

Create a new evaluator instance.

Options:

  • schema (required) - JSON schema object
  • context (optional) - Context data object
  • data (optional) - Initial data object

await evaluator.init()

Initialize the WASM module. Must be called before other methods.

await evaluator.validate({ data, context? })

Validate data against schema rules.

Returns: { has_error: boolean, errors: ValidationError[] }

await evaluator.evaluate({ data, context? })

Evaluate schema with data and return evaluated schema.

await evaluator.evaluateDependents({ changedPaths, data, context?, nested? })

Re-evaluate fields that depend on changed paths.

await evaluator.getEvaluatedSchema({ skipLayout? })

Get the evaluated schema with optional layout resolution.

await evaluator.getSchemaValue()

Get all schema values (evaluations ending with .value).

await evaluator.reloadSchema({ schema, context?, data? })

Reload schema with new data.

await evaluator.cacheStats()

Get cache statistics: { hits, misses, entries }.

await evaluator.clearCache()

Clear the evaluation cache.

await evaluator.cacheLen()

Get number of cached entries.

evaluator.free()

Free WASM resources. Always call when done.

version()

Get library version string.

Example: Next.js

'use client';

import { JSONEval } from '@json-eval-rs/bundler';
import { useEffect, useState } from 'react';

export default function MyForm() {
  const [evaluator, setEvaluator] = useState(null);

  useEffect(() => {
    // Dynamically import (client-side only)
    import('@json-eval-rs/bundler').then(({ JSONEval }) => {
      const instance = new JSONEval({ schema });
      setEvaluator(instance);
    });

    return () => {
      if (evaluator) evaluator.free();
    };
  }, []);

  // ... use evaluator
}

License

MIT

Keywords

json

FAQs

Package last updated on 12 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts