Home Manual Reference Source Test Repository
public class | source

TraitUtil

Static Method Summary

Static Public Methods
public static

safeArray(value: *): Array

Provides safe array creation from a given input.

public static

Provides a utility method that determines the name of a method for ESTree / Babylon AST nodes.

public static

safeComputedOperands(node: object, parent: object): Array<*>

Provides a utility method that determines the operands of a method for ESTree / Babylon AST nodes.

public static

Provides a utility method that determines the operators of a method for ESTree / Babylon AST nodes.

public static

safeName(object: object, defaultName: string): string

Provides a utility method that defers to object.name if it exists or fallback to defaultName or anonymous.

public static

safeNameOrValue(object: object, defaultNameOrValue: string): string

Provides a utility method that defers to object.name if it exists then falls back to 'object.value' if it exists or falls back to defaultNameOrValue or anonymous.

public static

safeValue(object: object, defaultValue: string): string

Provides a utility method that defers to object.value if it exists or fallback to defaultValue or anonymous.

Static Public Methods

public static safeArray(value: *): Array source

Provides safe array creation from a given input.

Params:

NameTypeAttributeDescription
value *

A value to potentially convert into a safe array.

Return:

Array

public static safeComputedName(node: object, parent: object): string source

Provides a utility method that determines the name of a method for ESTree / Babylon AST nodes. For ESTree the parent node must be accessed for class methods. If the name is a computed value and not a string literal then astParse is invoked to determine the computed name and is output as <computed~${computed expression}>.

Note; ESTree has a parent node which defines the method name with a child FunctionExpression / FunctionDeclaration. Babylon AST only has ClassMethod with a child key providing the method name.

Params:

NameTypeAttributeDescription
node object

The current AST node.

parent object

The parent AST node.

Return:

string

public static safeComputedOperands(node: object, parent: object): Array<*> source

Provides a utility method that determines the operands of a method for ESTree / Babylon AST nodes. For ESTree the parent node must be accessed for class methods. If the name is a computed value and not a string literal then astParse is invoked to determine the computed operands.

Note; ESTree has a parent node which defines the method name with a child FunctionExpression / FunctionDeclaration. Babylon AST only has ClassMethod with a child key providing the method name.

Params:

NameTypeAttributeDescription
node object

The current AST node.

parent object

The parent AST node.

Return:

Array<*>

public static safeComputedOperators(node: object, parent: object): Array<*> source

Provides a utility method that determines the operators of a method for ESTree / Babylon AST nodes. For ESTree the parent node must be accessed for class methods. If the node is computed then astParse is invoked to determine the computed operators.

Note; ESTree has a parent node which defines the method name with a child FunctionExpression / FunctionDeclaration. Babylon AST only has ClassMethod with a child key providing the method name.

Params:

NameTypeAttributeDescription
node object

The current AST node.

parent object

The parent AST node.

Return:

Array<*>

public static safeName(object: object, defaultName: string): string source

Provides a utility method that defers to object.name if it exists or fallback to defaultName or anonymous.

Params:

NameTypeAttributeDescription
object object

The target object to provide safe name coverage.

defaultName string

A default name to fallback to if object.name is missing.

Return:

string

public static safeNameOrValue(object: object, defaultNameOrValue: string): string source

Provides a utility method that defers to object.name if it exists then falls back to 'object.value' if it exists or falls back to defaultNameOrValue or anonymous.

Params:

NameTypeAttributeDescription
object object

The target object to provide safe name / value coverage.

defaultNameOrValue string

A default name / value to fallback to if object.name or object.value is missing.

Return:

string

public static safeValue(object: object, defaultValue: string): string source

Provides a utility method that defers to object.value if it exists or fallback to defaultValue or anonymous.

Params:

NameTypeAttributeDescription
object object

The target object to provide safe name coverage.

defaultValue string

A default value to fallback to if object.value is missing.

Return:

string