Пример #1
0
    def custom(
        string: str = "",
        separator: str = "",
        replaceSeparator: Optional[str] = None
    ) -> str:
        """Convert string from snake case to custom separator.

        Parameters
        ----------
        string : str
            String to convert.
        separator : str
            Separator.
        replaceSeparator : Optional[str]
            If is not None peplace `replaceSeparator` with `_`

        Returns
        -------
        str
            String converted to separator.

        """
        string = snake.snake(string=string, replaceSeparator=replaceSeparator)
        string = string.replace('_', separator)

        return string
Пример #2
0
    def sentence(string: str = "",
                 listMode: bool = False,
                 capitalize: bool = False,
                 upper: bool = False,
                 replaceSeparator: Optional[str] = None) -> Union[str, list]:
        """Convert string to a list of strings or string,
         string separated by spaces.

        Parameters
        ----------
        string : str
            String to convert.
        listMode : bool
            If listMode is True return a list of strings.
        capitalize : bool
            If capitalize is True capitalize all strings.
        upper : bool
            If upper is True convert to uppercase all strings.
        replaceSeparator : Optional[str]
            If is not None peplace `replaceSeparator` with `_`

        Returns
        -------
        Union[str, list]
            String separated by space or list of strings.

        """
        listOrString = (snake.snake(
            string=string, replaceSeparator=replaceSeparator)).capitalize()
        listOrString = listOrString.replace('_', ' ')

        if capitalize is True:
            listOrString = listOrString.capitalize()
            listOrString = re.sub(
                ' ([a-zA-Z0-9])',
                lambda m: " {}".format(m.group(1).capitalize()), listOrString)

        if upper is True:
            listOrString = listOrString.upper()
            listOrString = re.sub(' ([a-zA-Z0-9])',
                                  lambda m: " {}".format(m.group(1).upper()),
                                  listOrString)

        if listMode is True:
            listOrString = listOrString.split(' ')

        return listOrString
Пример #3
0
    def camel(string: str = "", replaceSeparator: Optional[str] = None) -> str:
        """Convert string to camel case.

        Parameters
        ----------
        string : str
            String to convert.
        replaceSeparator : Optional[str]
            If is not None peplace `replaceSeparator` with `_`

        Returns
        -------
        str
            String converted to camel case.

        """
        string = snake.snake(string=string, replaceSeparator=replaceSeparator)
        string = re.sub('_([a-zA-Z0-9])', lambda m: m.group(1).upper(), string)
        return string
Пример #4
0
    def kebab(string: str = "", replaceSeparator: Optional[str] = None) -> str:
        """Convert string to kebab case.

        Parameters
        ----------
        string : str
            String to convert.
        replaceSeparator : Optional[str]
            If is not None peplace `replaceSeparator` with `_`

        Returns
        -------
        str
            String converted to kebab case.

        """
        string = snake.snake(string=string, replaceSeparator=replaceSeparator)
        string = string.replace('_', '-')
        return string
Пример #5
0
    def pascal(string: str = "",
               replaceSeparator: Optional[str] = None) -> str:
        """Convert string to pascal case.

        Parameters
        ----------
        string : str
            String to convert.
        replaceSeparator : Optional[str]
            If is not None peplace `replaceSeparator` with `_`

        Returns
        -------
        str
            String converted to pascal case.

        """
        string = snake.snake(string=string, replaceSeparator=replaceSeparator)
        string = camel.camel(string)
        string = "{}{}".format(string[0].upper(), string[1:])
        return string