Socket
Book a DemoInstallSign in
Socket

sf-formula

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sf-formula

Formula evaluation engine

1.22.0
latest
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

SF Formula

A powerful formula evaluation engine for TypeScript/JavaScript applications.

Installation

npm install sf-formula

Import Options

This library provides multiple import paths to avoid dependency conflicts, especially with CodeMirror:

Default Import (Compiled)

import { formulaEval } from 'sf-formula';

Core Functionality Only (Raw TypeScript)

// For projects that want to avoid CodeMirror dependencies
import { formulaEval } from 'sf-formula/core';

Raw TypeScript Source

// Direct access to TypeScript source files
import { formulaEval } from 'sf-formula/src';

Individual Modules

// Import specific functionality
import { defaultFunctions } from 'sf-formula/functions';
import { parser } from 'sf-formula/parser';

CodeMirror Integration

If you're using CodeMirror in your project and experiencing conflicts, use the /core import:

import { formulaEval } from 'sf-formula/core';
import { EditorView } from '@codemirror/view'; // Your own CodeMirror version

// This avoids duplicate CodeMirror instances
const result = formulaEval('2 + 2');

For CodeMirror language support (syntax highlighting, autocompletion), install peer dependencies:

npm install @codemirror/language @codemirror/autocomplete @lezer/common @lezer/highlight @lezer/lr

Then use:

import { languagePack } from 'sf-formula';
import { EditorView } from '@codemirror/view';

const view = new EditorView({
  extensions: [languagePack()],
  // ... other config
});

Usage

import { formulaEval } from 'sf-formula/core';

// Simple evaluation
const result = formulaEval('2 + 2'); // 4

// With variables
const context = { x: 10, y: 5 };
const result2 = formulaEval('x + y', context); // 15

// With nested objects
const context2 = { user: { age: 25 } };
const result3 = formulaEval('user.age > 18', context2); // true

// With functions
const result4 = formulaEval('IF(x > 0, "positive", "negative")', { x: 5 }); // "positive"

Peer Dependencies

If you need CodeMirror integration, install these peer dependencies:

  • @codemirror/language
  • @codemirror/autocomplete
  • @lezer/common
  • @lezer/highlight
  • @lezer/lr

License

MIT

Keywords

formula

FAQs

Package last updated on 19 Jun 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.