1 | export interface Scope {
|
2 | [key: string]: Scope | any;
|
3 | }
|
4 | export interface IGetOptions {
|
5 | /**
|
6 | * When set to a truthy value, we throw a `ReferenceError` for invalid varNames.
|
7 | * Invalid varNames are the ones that do not exist in the scope.
|
8 | * In that case the value for the varNames will be assumed an empty string.
|
9 | * By default we throw a `ReferenceError` to be compatible with how JavaScript
|
10 | * threats such invalid reference.
|
11 | * If a value does not exist in the scope, two things can happen:
|
12 | * - if `propsExist` is truthy, the value will be assumed empty string
|
13 | * - if `propsExist` is falsy, a `ReferenceError` will be thrown
|
14 | */
|
15 | readonly propsExist?: boolean;
|
16 | /**
|
17 | * Drilling a nested object to get the value assinged with a path is a relatively expensive
|
18 | * computation. Therefore you can set a value of how deep you are expecting a template to go and
|
19 | * if the nesting is deeper than that, the computation stops with an error.
|
20 | * This prevents a malicious or erronous template with deep nesting to block the JavaScript event
|
21 | * loop. The default is 10.
|
22 | */
|
23 | readonly depth?: number;
|
24 | }
|
25 | /**
|
26 | * A useful utility function that is used internally to lookup a variable name as a path to a
|
27 | * property in an object. It can also be used in your custom resolver functions if needed.
|
28 | *
|
29 | * This is similar to [Lodash's `_.get()`](https://lodash.com/docs/#get)
|
30 | *
|
31 | * It has a few differences with plain JavaScript syntax:
|
32 | * - No support for keys that include `[` or `]`.
|
33 | * - No support for keys that include `'` or `"` or `.`.
|
34 | * @see https://github.com/userpixel/micromustache/wiki/Known-issues
|
35 | * If it cannot find a value in the specified path, it may return undefined or throw an error
|
36 | * depending on the value of the `propsExist` param.
|
37 | * @param scope an object to resolve value from
|
38 | * @param varNameOrPropNames the variable name string or an array of property names (as returned by
|
39 | * `toPath()`)
|
40 | * @throws `SyntaxError` if the varName string cannot be parsed
|
41 | * @throws `ReferenceError` if the scope does not contain the requested key and the `propsExist` is
|
42 | * set to a truthy value
|
43 | * @returns the value or undefined. If path or scope are undefined or scope is null the result is
|
44 | * always undefined.
|
45 | */
|
46 | export declare function get(scope: Scope, varNameOrPropNames: string | string[], options?: IGetOptions): any;
|