
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
tdastscript
Advanced tools
utility to create tdast trees.
npm install tdastscript
import td from 'tdastscript';
const tdast = td('table', [
td('row', [
td('column', 'row0-column0'),
td('column', 'row0-column1'),
td('column', {
value: 'row0-column3',
badProperty: 'badProperty',
dataType: 'percentage',
data: { fieldA: 'valueA', fieldB: true },
label: 'Column 3',
}),
]),
td('row', [
'row1-cell0',
'row1-cell1',
'row1-cell2',
]),
]);
yields the following tree:
expect(tdast).toEqual({
type: 'table',
children: [
{
type: 'row',
index: 0,
children: [
{
type: 'column',
index: 0,
value: 'row0-column0',
},
{
type: 'column',
index: 1,
value: 'row0-column1',
},
{
type: 'column',
index: 2,
value: 'row0-column2',
},
],
},
{
type: 'row',
index: 1,
children: [
{
type: 'cell',
columnIndex: 0,
rowIndex: 1,
value: 'row1-cell0',
},
{
type: 'cell',
columnIndex: 1,
rowIndex: 1,
value: 'row1-cell1',
},
{
type: 'cell',
columnIndex: 2,
rowIndex: 1,
value: 'row1-cell2',
},
],
},
],
});
td(type[, props][, children|value])function td(
/** Node type */
arg1?: NodeType,
/** 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.
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.
expect(td('table', {
data: { badProperty: 'badProperty', fieldA: 'valueA' },
position: UnistPosition,
})).toEqual({
type: 'table',
data: { fieldA: 'valueA' },
position: UnistPosition,
});
expect(td('row', {
data: { badProperty: 'badProperty', fieldA: 'valueA' },
index: 5,
position: UnistPosition,
}), [
'cell1',
'cell2',
]).toEqual({
type: 'row',
data: { fieldA: 'valueA' },
index: 5,
position: UnistPosition,
children: [
{ type: 'cell', value: 'cell1' },
{ type: 'cell', value: 'cell2' },
],
});
/** tdastscript can return any valid tdast node. */
type Node = Cell | Column | Row | Table;
/** Node types of tdast nodes. */
type NodeType = 'cell' | 'column' | 'row' | 'table';
/** Child nodes can be actual nodes or string values representing Cell nodes */
type Children = Node[] | string[];
/** Node properties in object syntax */
type Properties = Record<string, any>;
/** Alias for loosely-typed value */
type Value = any;
FAQs
utility to create tdast trees
The npm package tdastscript receives a total of 21 weekly downloads. As such, tdastscript popularity was classified as not popular.
We found that tdastscript demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.