Options
All
  • Public
  • Public/Protected
  • All
Menu

Project jshiki

Type aliases

AccessPath

AccessPath: string | AccessPathArray

A path to a property. Can be a string of format foo.bar.baz or an array of format ['foo', 'bar', Symbol('baz')]. '*' can be used as a wildcard. '**' can be used as a wildcard for properties at any depth.

AccessRule

AllowAccessRule

AllowAccessRule: object

Type declaration

  • allow: AccessPath

    The path to the property to which access should be allowed.

BinaryOperatorOptions

BinaryOperatorOptions: object | object

Defines which binary operators are allowed. Must provide an allow list or a block list, but not both. Valid options are +, -, *, **, /, %, <, >, <=, >=, ==, !=, ===, !==, |, &, <<, >>, >>>, in, instanceof.

example
// allows only binary operators '/', '%', '+', and '-'
{ allow: ['/', '%', '+', '-'] }
// allows any binary operator except '*', '**', and '&'
{ block: ['*', '**', '&'] }

BlockAccessRule

BlockAccessRule: object

Type declaration

  • block: AccessPath

    The path to the property to which access should be blocked.

JshikiAsyncExpression

JshikiAsyncExpression: function

Type declaration

    • (scope?: Record<any, any>): Promise<any>
    • A compiled, executable async expression.

      const expression = jshiki.parseAsync('await foo.bar()')
      await expression({
        foo: { bar: async () => 'baz' },
      }) // => 'baz'
      

      Parameters

      • Optional scope: Record<any, any>

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

      Returns Promise<any>

JshikiExpression

JshikiExpression: function

Type declaration

    • (scope?: Record<any, any>): any
    • A compiled, executable expression.

      const expression = jshiki.parse('foo.bar')
      expression({
        foo: { bar: 'baz' },
      }) // => 'baz'
      

      Parameters

      • Optional scope: Record<any, any>

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

      Returns any

LogicalOperatorOptions

LogicalOperatorOptions: object | object

Defines which logical operators are allowed. Must provide either an allow list or a block list, but not both. Valid options are ||, &&, ??.

example
// allows only logical operators '||' and '&&'
{ allow: ['||', '&&'] }
// allows any logical operator except '??'
{ block: ['??'] }

UnaryOperatorOptions

UnaryOperatorOptions: object | object

Defines which unary operators are allowed. Must provide an allow list or a block list, but not both. Valid options are -, +, !, ~, typeof.

example
// allows only unary operators '!' and '+'
{ unary: { allow: ['!', '+'] } }
// allows any unary operator except '-' and '~'
{ unary: { block: ['-', '~'] } }

Properties

default

default: object

Type declaration

  • evaluate: function
      • Evaluates an expression.

        example
        let result = jshiki.evaluate('1 + 2')
        // result => 3
        result = jshiki.evaluate('a + 2', { scope: { a: 5 } })
        // result => 7
        

        Parameters

        Returns any

        The result of the expression.

  • parse: function
      • Parses an expression into an executable function.

        example
        const expression = jshiki.parse('(a || 1) + 2')
        let result = expression()
        // result => 3
        result = expression({ a: 5 })
        // result => 7
        

        Parameters

        Returns JshikiExpression

        The parsed expression.

Functions

evaluate

  • Evaluates an expression.

    example
    let result = jshiki.evaluate('1 + 2')
    // result => 3
    result = jshiki.evaluate('a + 2', { scope: { a: 5 } })
    // result => 7
    

    Parameters

    Returns any

    The result of the expression.

evaluateAsync

  • Evaluates an expression asynchronously.

    example
    let result = await jshiki.evaluateAsync('1 + 2')
    // result => 3
    result = await jshiki.evaluateAsync(
      'await a() + 2', { scope: { a: async () => 5 } }
    )
    // result => 7
    

    Parameters

    Returns Promise<any>

    The result of the expression.

parse

  • Parses an expression into an executable function.

    example
    const expression = jshiki.parse('(a || 1) + 2')
    let result = expression()
    // result => 3
    result = expression({ a: 5 })
    // result => 7
    

    Parameters

    Returns JshikiExpression

    The parsed expression.

parseAsync

  • Parses an expression into an executable async function.

    example
    const expression = jshiki.parseAsync('(await a?.() || 1) + 2')
    let result = expression()
    // result => 3
    result = expression({ a: async () => 5 })
    // result => 7
    

    Parameters

    Returns JshikiAsyncExpression

    The parsed expression.

Generated using TypeDoc