Skip to content

Commit

Permalink
Added additional utility methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTimTam committed Aug 16, 2024
1 parent 4148b03 commit 6e981fa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
11 changes: 11 additions & 0 deletions dist/classes/JTF.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ export default class JTF {
});
}

/**
* @param {Document} document The document to stringify.
* @returns {string} A stringified version of the document.
*/
stringify(document) {
if (!(document instanceof Document))
throw new Error('Provided object is not of type "Document".');

return document.stringify();
}

/**
* Validate the contents of a table's cell.
* @param {Object} cell The cell to validate.
Expand Down
19 changes: 19 additions & 0 deletions dist/classes/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ export default class Table {
this.document.source.data[this.index] = value;
}

/**
* Get the table's label.
*/
get label() {
return this.source.label;
}

/**
* Set the table's label.
*/
set label(value) {
if (!value || typeof value !== "string")
throw new SyntaxError(
'Each table in the document must have a "label" string value.'
);

this.source.label = value;
}

/**
* Convert a table into a 2D array.
* @returns {string} The table as a 2D array.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nottimtam/jtf",
"version": "1.1.10",
"version": "1.1.11",
"description": "Utilities for interacting with .jtf files.",
"main": "dist/index.js",
"type": "module",
Expand Down

0 comments on commit 6e981fa

Please sign in to comment.