4.8.1. Type Hint: JavaScript Code

You can specify type hints to a writer via type_hint_list.

Sample Code:
Using type hint to change data type to write JavaScript code
from datetime import datetime
import pytablewriter as ptw

writer = ptw.JavaScriptTableWriter()
writer.header_list = ["header_a", "header_b", "header_c"]
writer.value_matrix = [
    [-1.1, "2017-01-02 03:04:05", datetime(2017, 1, 2, 3, 4, 5)],
    [0.12, "2017-02-03 04:05:06", datetime(2017, 2, 3, 4, 5, 6)],
]

print("// without type hints:  column data types detected automatically by default")
writer.table_name = "without type hint"
writer.write_table()

print("// with type hints: Integer, DateTime, String")
writer.table_name = "with type hint"
writer.type_hint_list = [ptw.Integer, ptw.DateTime, ptw.String]
writer.write_table()
Output:
JavaScript variable declaration code with/without type hints
// without type hints:  column data types detected automatically by default
const without_type_hint = [
    ["header_a", "header_b", "header_c"],
    [-1.1, "2017-01-02 03:04:05", new Date("2017-01-02T03:04:05")],
    [0.12, "2017-02-03 04:05:06", new Date("2017-02-03T04:05:06")]
];

// with type hints: Integer, DateTime, String
const with_type_hint = [
    ["header_a", "header_b", "header_c"],
    [-1, new Date("2017-01-02T03:04:05"), "2017-01-02 03:04:05"],
    [0, new Date("2017-02-03T04:05:06"), "2017-02-03 04:05:06"]
];