Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface JshikiEvaluateOptions

Options for evaluating.

Hierarchy

Properties

Optional explicitAllow

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.

default

false

example
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

Optional operators

operators: OperatorOptions

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

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

Optional rules

rules: AccessRule[]

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

example
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

Optional scope

scope: Record<any, any>

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

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

Optional syntax

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

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

Generated using TypeDoc