# Path: pytablewriter/_converter.py
# def strip_quote(text: str, value: str) -> str:
#     re_replace = re.compile(f"[\"']{value:s}[\"']", re.MULTILINE)
# 
#     return re_replace.sub(value, text)
# 
# Path: pytablewriter/_function.py
# def quote_datetime_formatter(value) -> str:
#     return f'"{value.strftime(dataproperty.DefaultValue.DATETIME_FORMAT):s}"'
# 
# Path: pytablewriter/sanitizer/_javascript.py
# def sanitize_js_var_name(var_name: str, replacement_text: str = "") -> str:
#     """
#     Make a valid JavaScript variable name from ``var_name``.
# 
#     To make a valid name:
# 
#     - Replace invalid characters for a JavaScript variable name within
#       the ``var_name`` with the ``replacement_text``
#     - Delete invalid chars for the beginning of the variable name
#     - Append underscore (``"_"``) at the tail of the name if sanitized name
#       is one of the JavaScript reserved names
# 
#     :JavaScriptstr filename: Name to sanitize.
#     :param str replacement_text: Replacement text.
#     :return: A replacement string.
#     :rtype: str
#     :raises ValueError: If ``var_name`` or ``replacement_text`` is invalid.
# 
#     :Example:
#         :ref:`example-sanitize-var-name`
# 
#     .. note::
#         Currently, not supported Unicode variable names.
# 
#     .. seealso::
#         :py:func:`.validate_js_var_name`
#     """
# 
#     return JavaScriptVarNameSanitizer(var_name).sanitize(replacement_text)
# 
# Path: pytablewriter/writer/text/_common.py
# def bool_to_str(value) -> str:
#     if value is True:
#         return "true"
#     if value is False:
#         return "false"
# 
#     return value
# 
# Path: pytablewriter/writer/text/sourcecode/_sourcecode.py
# class SourceCodeTableWriter(IndentationTextTableWriter):
#     """
#     Base class of table writer with a source code (variable definition) format.
# 
#     .. py:attribute:: is_datetime_instance_formatting
#         :type: bool
# 
#         Write |datetime| values in the table as definition of |datetime| class
#         instances coincide with specific language if this value is |True|.
#         Write as |str| if this value is |False|.
#     """
# 
#     @abc.abstractmethod
#     def get_variable_name(self, value: str) -> str:  # pragma: no cover
#         pass
# 
#     @property
#     def variable_name(self) -> str:
#         """
#         Return a valid variable name that converted from the |table_name|.
# 
#         :return: A variable name.
#         :rtype: str
#         """
# 
#         return self.get_variable_name(self.table_name)
# 
#     @property
#     def margin(self) -> int:
#         return self._margin
# 
#     @margin.setter
#     def margin(self, value: int) -> None:
#         # margin setting must be ignored
#         return
# 
#     def __init__(self, **kwargs) -> None:
#         super().__init__(**kwargs)
# 
#         self.indent_string = kwargs.get("indent_string", "    ")
#         self.column_delimiter = ", "
#         self._margin = 0
# 
#         self.char_left_side_row = "["
#         self.char_right_side_row = "],"
#         self.char_cross_point = ""
#         self.char_opening_row_cross_point = ""
#         self.char_closing_row_cross_point = ""
# 
#         self.is_padding = False
#         self.is_write_header_separator_row = False
#         self.is_write_opening_row = True
#         self.is_write_closing_row = True
# 
#         self.is_formatting_float = False
#         self.is_datetime_instance_formatting = True
# 
#         self._quoting_flags[typepy.Typecode.DATETIME] = False
#         self._is_require_table_name = True
# 
#         self._init_cross_point_maps()
# 
#     def _get_value_row_separator_items(self) -> List[str]:
#         return []
# 
#     def _write_opening_row(self) -> None:
#         self.dec_indent_level()
#         super()._write_opening_row()
#         self.inc_indent_level()
# 
#     def _write_closing_row(self) -> None:
#         self.dec_indent_level()
#         super()._write_closing_row()
#         self.inc_indent_level()


import io
from typing import List
from dataproperty import ColumnDataProperty, DataProperty, DefaultValue
from typepy import StrictLevel, Typecode
from ...._converter import strip_quote
from ...._function import quote_datetime_formatter
from ....sanitizer import sanitize_js_var_name
from .._common import bool_to_str
from ._sourcecode import SourceCodeTableWriter

    def __init__(self, **kwargs) -> None:
        super().__init__(**kwargs)

        self.variable_declaration = "const"
        self._dp_extractor.type_value_map = {
            # Typecode.NONE: "null",
            Typecode.INFINITY: "Infinity",
            Typecode.NAN: "NaN",
        }
        self._dp_extractor.update_strict_level_map({Typecode.BOOL: StrictLevel.MAX})
        self.register_trans_func(bool_to_str)

    def get_variable_name(self, value: str) -> str:
        return sanitize_js_var_name(value, "_").casefold()

    def _write_table(self, **kwargs) -> None:
        if self.is_datetime_instance_formatting:
            self._dp_extractor.datetime_formatter = js_datetime_formatter
        else:
            self._dp_extractor.datetime_formatter = quote_datetime_formatter

        org_stream = self.stream
        self.stream = io.StringIO()

        self.inc_indent_level()
        super()._write_table(**kwargs)
        self.dec_indent_level()
        js_matrix_var_def_text = self.stream.getvalue().rstrip("\n")
        js_matrix_var_def_text = strip_quote(js_matrix_var_def_text, "true")

# Path: pytablewriter/_converter.py
# def strip_quote(text: str, value: str) -> str:
#     re_replace = re.compile(f"[\"']{value:s}[\"']", re.MULTILINE)
# 
#     return re_replace.sub(value, text)
# 
# Path: pytablewriter/_function.py
# def quote_datetime_formatter(value) -> str:
#     return f'"{value.strftime(dataproperty.DefaultValue.DATETIME_FORMAT):s}"'
# 
# Path: pytablewriter/sanitizer/_javascript.py
# def sanitize_js_var_name(var_name: str, replacement_text: str = "") -> str:
#     """
#     Make a valid JavaScript variable name from ``var_name``.
# 
#     To make a valid name:
# 
#     - Replace invalid characters for a JavaScript variable name within
#       the ``var_name`` with the ``replacement_text``
#     - Delete invalid chars for the beginning of the variable name
#     - Append underscore (``"_"``) at the tail of the name if sanitized name
#       is one of the JavaScript reserved names
# 
#     :JavaScriptstr filename: Name to sanitize.
#     :param str replacement_text: Replacement text.
#     :return: A replacement string.
#     :rtype: str
#     :raises ValueError: If ``var_name`` or ``replacement_text`` is invalid.
# 
#     :Example:
#         :ref:`example-sanitize-var-name`
# 
#     .. note::
#         Currently, not supported Unicode variable names.
# 
#     .. seealso::
#         :py:func:`.validate_js_var_name`
#     """
# 
#     return JavaScriptVarNameSanitizer(var_name).sanitize(replacement_text)
# 
# Path: pytablewriter/writer/text/_common.py
# def bool_to_str(value) -> str:
#     if value is True:
#         return "true"
#     if value is False:
#         return "false"
# 
#     return value
# 
# Path: pytablewriter/writer/text/sourcecode/_sourcecode.py
# class SourceCodeTableWriter(IndentationTextTableWriter):
#     """
#     Base class of table writer with a source code (variable definition) format.
# 
#     .. py:attribute:: is_datetime_instance_formatting
#         :type: bool
# 
#         Write |datetime| values in the table as definition of |datetime| class
#         instances coincide with specific language if this value is |True|.
#         Write as |str| if this value is |False|.
#     """
# 
#     @abc.abstractmethod
#     def get_variable_name(self, value: str) -> str:  # pragma: no cover
#         pass
# 
#     @property
#     def variable_name(self) -> str:
#         """
#         Return a valid variable name that converted from the |table_name|.
# 
#         :return: A variable name.
#         :rtype: str
#         """
# 
#         return self.get_variable_name(self.table_name)
# 
#     @property
#     def margin(self) -> int:
#         return self._margin
# 
#     @margin.setter
#     def margin(self, value: int) -> None:
#         # margin setting must be ignored
#         return
# 
#     def __init__(self, **kwargs) -> None:
#         super().__init__(**kwargs)
# 
#         self.indent_string = kwargs.get("indent_string", "    ")
#         self.column_delimiter = ", "
#         self._margin = 0
# 
#         self.char_left_side_row = "["
#         self.char_right_side_row = "],"
#         self.char_cross_point = ""
#         self.char_opening_row_cross_point = ""
#         self.char_closing_row_cross_point = ""
# 
#         self.is_padding = False
#         self.is_write_header_separator_row = False
#         self.is_write_opening_row = True
#         self.is_write_closing_row = True
# 
#         self.is_formatting_float = False
#         self.is_datetime_instance_formatting = True
# 
#         self._quoting_flags[typepy.Typecode.DATETIME] = False
#         self._is_require_table_name = True
# 
#         self._init_cross_point_maps()
# 
#     def _get_value_row_separator_items(self) -> List[str]:
#         return []
# 
#     def _write_opening_row(self) -> None:
#         self.dec_indent_level()
#         super()._write_opening_row()
#         self.inc_indent_level()
# 
#     def _write_closing_row(self) -> None:
#         self.dec_indent_level()
#         super()._write_closing_row()
#         self.inc_indent_level()


# Path: pytablewriter/writer/text/sourcecode/_javascript.py
import io
from typing import List
from dataproperty import ColumnDataProperty, DataProperty, DefaultValue
from typepy import StrictLevel, Typecode
from ...._converter import strip_quote
from ...._function import quote_datetime_formatter
from ....sanitizer import sanitize_js_var_name
from .._common import bool_to_str
from ._sourcecode import SourceCodeTableWriter


    def __init__(self, **kwargs) -> None:
        super().__init__(**kwargs)

        self.variable_declaration = "const"
        self._dp_extractor.type_value_map = {
            # Typecode.NONE: "null",
            Typecode.INFINITY: "Infinity",
            Typecode.NAN: "NaN",
        }
        self._dp_extractor.update_strict_level_map({Typecode.BOOL: StrictLevel.MAX})
        self.register_trans_func(bool_to_str)

    def get_variable_name(self, value: str) -> str:
        return sanitize_js_var_name(value, "_").casefold()

    def _write_table(self, **kwargs) -> None:
        if self.is_datetime_instance_formatting:
            self._dp_extractor.datetime_formatter = js_datetime_formatter
        else:
            self._dp_extractor.datetime_formatter = quote_datetime_formatter

        org_stream = self.stream
        self.stream = io.StringIO()

        self.inc_indent_level()
        super()._write_table(**kwargs)
        self.dec_indent_level()
        js_matrix_var_def_text = self.stream.getvalue().rstrip("\n")
        js_matrix_var_def_text = strip_quote(js_matrix_var_def_text, "true")

        js_matrix_var_def_text = strip_quote(js_matrix_var_def_text, "false")