
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
codemirror-lang-dentaku
Advanced tools
Dentaku is a parser and evaluator of formulas for Ruby. This package is language support of this formula language for CodeMirror.
npm install --save codemirror codemirror-lang-dentaku
import { EditorView } from "codemirror";
import { dentaku } from "codemirror-lang-dentaku";
new EditorView({
extensions: [dentaku()],
});
case
statements)This package doesn't offer support for everything that Dentaku offers, see the list of missing features below.
The main export, dentaku
, comes packaged with linting and autocompletion that you can configure:
dentaku({ completionOptions, linterOptions });
completionOptions
)export interface DentakuLanguageCompletionOptions {
/**
* CodeMirror `Completion` objects for known variables.
*
* @example
* ["a", "b"].map(name => ({ label: name, type: "variable" }))
*/
variableEntries?: Array<Completion>;
/**
* CodeMirror `Completion` objects for custom functions.
*
* @example
* ["fnA", "fnB"].map(name => ({ label: name, type: "function" }))
*/
customFunctionEntries?: Array<Completion>;
/**
* Converter of built-in Dentaku functions into `Completion` objects.
* Allows you to add additional information to completions like descriptions.
*/
makeEntryForBuiltInFunctions?: (
name: (typeof builtInFunctions)[number]
) => Completion | null | false;
/**
* Converter of built-in Dentaku operators into `Completion` objects.
* Allows you to add additional information to completions like descriptions.
*/
makeEntryForBuiltInOperators?: (
name: (typeof builtInOperators)[number]
) => Completion | null | false;
}
linterOptions
)The linterOptions
object is of type DentakuLinterOptions & { codeMirrorConfig?: Parameters<typeof linter>[1] }
(see linter
).
This means that, apart from allowing fields from DentakuLinterOptions
described below, the linterOptions
also allows an optional codeMirrorConfig
field that lets you specify options for the CodeMirror linter function (linter(lintSource, options)
).
The customFunctions
property is an object with the custom functions names as keys and Arity
object as values (see Custom Functions below).
export interface DentakuLinterOptions {
/** List of variable names to not treat as undefined. */
knownVariables?: Array<string>;
/** Custom functions. */
customFunctions?: Record<string, Arity>;
/** Custom error messages. */
messages?: ErrorMessages;
}
/** Message codes that can be overridden with custom messages. */
export interface ErrorMessages {
/** Generic "invalid syntax" message when no better message can be inferred. */
invalidSyntax: string;
/** Missing a closing bracket in a list of function arguments. */
closingBracketMissing: string;
/** Expected a comma before this function argument. */
expectedCommaBefore: string;
/** Expected an operator before this expression. */
expectedOperatorBefore: string;
/** The function name needs parentheses to be called. */
callParenthesesMissing: string;
/** This variable is not defined. */
undefinedVariable: string;
/** Expected exactly that many parameters, found this many. */
expectedExactArgumentCount: (
actualCount: number,
expectedCount: number
) => string;
/** Expected at most that many parameters, found this many. */
expectedMaximumArgumentCount: (
actualCount: number,
maxCount: number
) => string;
/** Expected at least that many parameters, found this many. */
expectedMinimumArgumentCount: (
actualCount: number,
minCount: number
) => string;
/** Expected between that and that many parameters, found this many. */
expectedArgumentCountRange: (
actualCount: number,
minCount: number,
maxCount: number
) => string;
}
The configuration of custom functions allows defining the minimum and maximum number of arguments that can be passed to each function. When a function supports an unknown number of maximum arguments, Infinity
should be provided. If an empty object ({}
) is provided as value, by default, the minimum will be 0
and the maximum Infinity
. When a is provided, both minArgs
and maxArgs
are required.
/** Arity config for built-in and custom functions */
export type Arity = {
/** @default 0 */
minArgs?: number;
/** @default Infinity */
maxArgs?: number;
};
// Example of custom functions configuration
const customFunctions: Record<string, Arity> = {
fnWithOneArg: {
minArgs: 1,
maxArgs: 1,
},
fnWithTwoOrMoreArgs: {
minArgs: 2,
maxArgs: Infinity,
},
fnWithDefaultConfig: {},
};
These features aren't on our roadmap because we don't use them currently, but contributions are highly welcome!
0xFF
)a AND b
), functions are supported though (e.g, and(a, b)
)case
statementsFAQs
CodeMirror support for the Dentaku formula language
We found that codemirror-lang-dentaku demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.