/** Either node properties, children nodes or value */
arg2?:Properties|Children|Value,
/** children nodes or value */
arg3?:Children|Value,,
):Node;
Returns a tdast Node (i.e. Cell, Column, Row, Table) with associated properties, children or value based on how it is called.
tdastscript conveniently assigns row/column indices on Row, Column, Cell nodes, based on how it is composed.
tdastscript can be used in a composable way, as shown in the opening example. See the following examples below for details on usage and behaviors.
Examples
Use without optional arguments to create simple nodes.
expect(td('table')).toEqual({
type:'table',
children:[],
});
expect(td('row')).toEqual({
type:'row',
children:[],
});
expect(td('cell')).toEqual({
type:'cell',
value:undefined,
});
expect(td('column')).toEqual({
type:'column',
value:undefined,
});
For Literal nodes, such as Cell and Column, if the second argument is skipped and only the third argument is provided as singleton values, create literal nodes:
expect(td('cell','cell1')).toEqual({
type:'cell',
value:'cell1',
});
expect(td('column','column1')).toEqual({
type:'column',
value:'column1',
});
For Parent nodes, such as Table and Row, if the second argument is skipped and only the the third argument is provided as child nodes, create parent nodes:
expect(td('table',[
{ type:'row', children:[]},
{ type:'row', children:[]},
])).toEqual({
type:'table',
children:[
{ type:'row', children:[]},
{ type:'row', children:[]},
],
});
expect(td('row',[
{ type:'cell', value:'cell1'},
'cell2',// accepts value literal shorthand to create Cell nodes
])).toEqual({
type:'row',
children:[
{ type:'cell', value:'cell1'},
{ type:'cell', value:'cell2'},
],
});
If the second argument is not skipped, attach the properties to the specified nodes. Note that tdastscript will only attach properties specified by the node's interface. Refer to the formal type definitions for details.