jshiki
    Preparing search index...

    Interface JshikiEvaluateOptions

    Options for evaluating.

    interface JshikiEvaluateOptions {
        explicitAllow?: boolean;
        operators?: OperatorOptions;
        rules?: AccessRule[];
        scope?: Record<any, any>;
        syntax?: SyntaxOptions;
    }

    Hierarchy (View Summary)

    Index

    Properties

    explicitAllow?: boolean

    If true, only properties with a matching allow rule can be accessed by the expression. If false, all properties can be accessed unless they have a block rule. Defaults to false.

    false
    
    const options = {
    explicitAllow: true,
    rules: [{ allow: 'foo.bar' }]
    }
    const obj = {
    foo: { bar: 'baz' },
    baz: { qux: 'quux' },
    }
    let expr = jshiki.parse('foo.bar', options)
    expr(obj) // => 'baz'

    let expr = jshiki.parse('baz', options)
    expr(obj) // => undefined
    operators?: OperatorOptions

    Defines which operators are allowed. By default, all supported operators, except for typeof, in, and instanceof, are allowed.

    const options = {
    operators: {
    unary: { allow: ['!'] },
    binary: { allow: ['+', '-', '*', '/', '%'] },
    logical: { block: ['??'] },
    ternary: false,
    },
    }
    rules?: AccessRule[]

    Access rules to use when determining what properties can be accessed by the expression. The rules are evaluated in order.

    const options = {
    rules: [
    { allow: 'foo.bar' },
    { block: ['baz', 'qux'] },
    ]
    }
    const obj = {
    foo: { bar: 'baz' },
    baz: { qux: 'quux' },
    }
    let expr = jshiki.parse('foo.bar', options)
    expr(obj) // => 'baz'

    expr = jshiki.parse('baz.qux', options)
    expr(obj) // => undefined
    scope?: Record<any, any>

    The scope to use when evaluating the expression. The expression will be limited to accessing the properties of the scope.

    const options = {
    scope: {
    foo: 'bar',
    baz: {
    qux: 'quux',
    }
    }
    }
    jshiki.evaluate('foo', options) // => 'bar'
    jshiki.evaluate('baz.qux', options) // => 'quux'
    syntax?: SyntaxOptions

    Defines what syntax is allowed. By default, all supported syntax is allowed.

    const options = {
    syntax: {
    memberAccess: true,
    calls: false,
    taggedTemplates: false,
    templates: true,
    objects: true,
    arrays: false,
    regexes: false,
    },
    }