xulbux 1.5.5__py3-none-any.whl → 1.5.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xulbux might be problematic. Click here for more details.

xulbux/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  """
2
- >>> import XulbuX as xx
2
+ >>> import xulbux as xx
3
3
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
4
4
  • CUSTOM TYPES:
5
5
  • rgba(int,int,int,float)
@@ -9,35 +9,45 @@
9
9
  • FILE OPERATIONS xx.File
10
10
  • JSON FILE OPERATIONS xx.Json
11
11
  • SYSTEM ACTIONS xx.System
12
- • MANAGE ENVIRONMENT VARS xx.EnvVars
13
- CMD LOG AND ACTIONS xx.Cmd
14
- • PRETTY PRINTING xx.FormatCodes
15
- COLOR OPERATIONS xx.Color
12
+ • MANAGE THE ENV PATH VAR xx.EnvPath
13
+ CONSOLE LOG AND ACTIONS xx.Console
14
+ EASY PRETTY PRINTING xx.FormatCodes
15
+ WORKING WITH COLORS xx.Color
16
16
  • DATA OPERATIONS xx.Data
17
- STR OPERATIONS xx.String
17
+ STRING OPERATIONS xx.String
18
18
  • CODE STRING OPERATIONS xx.Code
19
19
  • REGEX PATTERN TEMPLATES xx.Regex
20
20
  """
21
21
 
22
- __version__ = '1.5.5'
23
- __author__ = 'XulbuX'
24
- __email__ = 'xulbux.real@gmail.com'
25
- __license__ = 'MIT'
26
- __copyright__ = 'Copyright (c) 2024 XulbuX'
27
- __url__ = 'https://github.com/XulbuX-dev/Python/tree/main/Libraries/XulbuX'
28
- __description__ = 'A library which includes a lot of really helpful functions.'
22
+ __version__ = "1.5.8"
23
+ __author__ = "XulbuX"
24
+ __email__ = "xulbux.real@gmail.com"
25
+ __license__ = "MIT"
26
+ __copyright__ = "Copyright (c) 2024 XulbuX"
27
+ __url__ = "https://github.com/XulbuX-dev/Python/tree/main/Libraries/XulbuX"
28
+ __description__ = "A library which includes a lot of really helpful functions."
29
29
  __all__ = [
30
- '__help__', '_consts_', 'xx_cmd', 'xx_code', 'xx_color', 'xx_data', 'xx_env_vars', 'xx_file',
31
- 'xx_format_codes', 'xx_json', 'xx_path', 'xx_regex', 'xx_string', 'xx_system'
30
+ "_consts_",
31
+ "xx_console",
32
+ "xx_code",
33
+ "xx_color",
34
+ "xx_data",
35
+ "xx_env_path",
36
+ "xx_file",
37
+ "xx_format_codes",
38
+ "xx_json",
39
+ "xx_path",
40
+ "xx_regex",
41
+ "xx_string",
42
+ "xx_system",
32
43
  ]
33
44
 
34
- from .__help__ import help
35
45
  from ._consts_ import *
36
- from .xx_cmd import *
37
46
  from .xx_code import *
38
47
  from .xx_color import *
48
+ from .xx_console import *
39
49
  from .xx_data import *
40
- from .xx_env_vars import *
50
+ from .xx_env_path import *
41
51
  from .xx_file import *
42
52
  from .xx_format_codes import *
43
53
  from .xx_json import *
@@ -1,50 +1,32 @@
1
- try: from ._consts_ import DEFAULT
2
- except: from _consts_ import DEFAULT
3
- try: from .xx_format_codes import *
4
- except: from xx_format_codes import *
5
- try: from .xx_cmd import *
6
- except: from xx_cmd import *
1
+ from . import __version__
2
+ from ._consts_ import DEFAULT
3
+ from .xx_format_codes import FormatCodes
4
+ from .xx_console import Console
7
5
 
8
- import os as _os
9
6
 
10
-
11
-
12
-
13
- def get_version(file:str = '__init__.py', var:str = '__version__') -> str:
14
- try:
15
- from . import var
16
- return var
17
- except ImportError:
18
- init_path = _os.path.join(_os.path.dirname(__file__), file)
19
- if _os.path.isfile(init_path):
20
- with open(init_path, encoding='utf-8') as f:
21
- for line in f:
22
- if line.startswith(var): return line.split('=')[-1].strip().strip('\'"')
23
- return 'unknown'
24
-
25
- def help():
7
+ def help_command():
26
8
  """Show some info about the library, with a brief explanation of how to use it."""
27
9
  color = {
28
- 'lib': DEFAULT.color['ice'],
29
- 'import': DEFAULT.color['red'],
30
- 'class': DEFAULT.color['lavender'],
31
- 'types': DEFAULT.color['lightblue'],
32
- 'punctuators': DEFAULT.color['darkgray'],
10
+ "lib": DEFAULT.color["ice"],
11
+ "import": DEFAULT.color["red"],
12
+ "class": DEFAULT.color["lavender"],
13
+ "types": DEFAULT.color["lightblue"],
14
+ "punctuators": DEFAULT.color["darkgray"],
33
15
  }
34
16
  FormatCodes.print(
35
- rf''' [_|b|#7075FF] __ __
17
+ rf""" [_|b|#7075FF] __ __
36
18
  [b|#7075FF] _ __ __ __/ / / /_ __ ___ __
37
19
  [b|#7075FF] | |/ // / / / / / __ \/ / / | |/ /
38
- [b|#7075FF] > , </ /_/ / /_/ /_/ / /_/ /> , <
39
- [b|#7075FF]/_/|_|\____/\__/\____/\____//_/|_| [*|BG:{DEFAULT.color['gray']}|#000] v[b]{get_version()} [*]
20
+ [b|#7075FF] > , </ /_/ / /_/ /_/ / /_/ /> , <
21
+ [b|#7075FF]/_/|_|\____/\__/\____/\____//_/|_| [*|BG:{DEFAULT.color['gray']}|#000] v[b]{__version__} [*]
40
22
 
41
23
  [i|{DEFAULT.color['coral']}]A TON OF COOL FUNCTIONS, YOU NEED![*]
42
24
 
43
25
  [b|#75A2FF]Usage:[*]
44
26
  [{color['punctuators']}]# GENERAL LIBRARY[*]
45
- [{color['import']}]import [{color['lib']}]XulbuX [{color['import']}]as [{color['lib']}]xx[*]
27
+ [{color['import']}]import [{color['lib']}]xulbux [{color['import']}]as [{color['lib']}]xx[*]
46
28
  [{color['punctuators']}]# CUSTOM TYPES[*]
47
- [{color['import']}]from [{color['lib']}]XulbuX [{color['import']}]import [{color['lib']}]rgba[{color['punctuators']}], [{color['lib']}]hsla[{color['punctuators']}], [{color['lib']}]hexa[*]
29
+ [{color['import']}]from [{color['lib']}]xulbux [{color['import']}]import [{color['lib']}]rgba[{color['punctuators']}], [{color['lib']}]hsla[{color['punctuators']}], [{color['lib']}]hexa[*]
48
30
 
49
31
  [b|#75A2FF]Includes:[*]
50
32
  [dim](•) CUSTOM TYPES:
@@ -55,20 +37,16 @@ def help():
55
37
  [dim](•) FILE OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]File[*]
56
38
  [dim](•) JSON FILE OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Json[*]
57
39
  [dim](•) SYSTEM ACTIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]System[*]
58
- [dim](•) MANAGE ENVIRONMENT VARS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Env_vars[*]
59
- [dim](•) CMD LOG AND ACTIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Cmd[*]
60
- [dim](•) PRETTY PRINTING [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]FormatCodes[*]
61
- [dim](•) COLOR OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Color[*]
40
+ [dim](•) MANAGE THE ENV PATH VAR [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]EnvPath[*]
41
+ [dim](•) CONSOLE LOG AND ACTIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Console[*]
42
+ [dim](•) EASY PRETTY PRINTING [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]FormatCodes[*]
43
+ [dim](•) WORKING WITH COLORS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Color[*]
62
44
  [dim](•) DATA OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Data[*]
63
- [dim](•) STR OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]String[*]
45
+ [dim](•) STRING OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]String[*]
64
46
  [dim](•) CODE STRING OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Code[*]
65
47
  [dim](•) REGEX PATTERN TEMPLATES [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Regex[*]
66
48
  [_]
67
49
  [dim](Press any key to exit...)
68
- ''', DEFAULT.text_color)
69
- Cmd.pause_exit(pause=True)
70
-
71
-
72
-
73
- if __name__ == '__main__':
74
- help()
50
+ """
51
+ )
52
+ Console.pause_exit(pause=True)
xulbux/_consts_.py CHANGED
@@ -1,147 +1,144 @@
1
1
  class DEFAULT:
2
2
 
3
- text_color:str = '#95B5FF'
4
- color:dict[str,str] = {
5
- 'white': '#F1F2FF',
6
- 'lightgray': '#B6B7C0',
7
- 'gray': '#7B7C8D',
8
- 'darkgray': '#67686C',
9
- 'black': '#202125',
10
- 'red': '#FF606A',
11
- 'coral': '#FF7069',
12
- 'orange': '#FF876A',
13
- 'tangerine': '#FF9962',
14
- 'gold': '#FFAF60',
15
- 'yellow': '#FFD260',
16
- 'green': '#7EE787',
17
- 'teal': '#50EAAF',
18
- 'cyan': '#3EE6DE',
19
- 'ice': '#77EFEF',
20
- 'lightblue': '#60AAFF',
21
- 'blue': '#8085FF',
22
- 'lavender': '#9B7DFF',
23
- 'purple': '#AD68FF',
24
- 'magenta': '#C860FF',
25
- 'pink': '#EE60BB',
26
- 'rose': '#FF6090',
3
+ text_color: str = "#95B5FF"
4
+ color: dict[str, str] = {
5
+ "white": "#F1F2FF",
6
+ "lightgray": "#B6B7C0",
7
+ "gray": "#7B7C8D",
8
+ "darkgray": "#67686C",
9
+ "black": "#202125",
10
+ "red": "#FF606A",
11
+ "coral": "#FF7069",
12
+ "orange": "#FF876A",
13
+ "tangerine": "#FF9962",
14
+ "gold": "#FFAF60",
15
+ "yellow": "#FFD260",
16
+ "green": "#7EE787",
17
+ "teal": "#50EAAF",
18
+ "cyan": "#3EE6DE",
19
+ "ice": "#77EFEF",
20
+ "lightblue": "#60AAFF",
21
+ "blue": "#8085FF",
22
+ "lavender": "#9B7DFF",
23
+ "purple": "#AD68FF",
24
+ "magenta": "#C860FF",
25
+ "pink": "#EE60BB",
26
+ "rose": "#FF6090",
27
27
  }
28
28
 
29
29
 
30
-
31
-
32
30
  class CHARS:
33
31
 
34
32
  # CODE TO SIGNAL, ALL CHARACTERS ARE ALLOWED
35
- all = '<*allowed>'
33
+ all = "<*allowed>"
36
34
 
37
35
  # DIGIT SETS
38
- digits = '0123456789'
39
- float_digits = digits + '.'
40
- hex_digits = digits + '#abcdefABCDEF'
36
+ digits = "0123456789"
37
+ float_digits = digits + "."
38
+ hex_digits = digits + "#abcdefABCDEF"
41
39
 
42
40
  # LETTER CATEGORIES
43
- lowercase = 'abcdefghijklmnopqrstuvwxyz'
44
- lowercase_extended = lowercase + 'äëïöüÿàèìòùáéíóúýâêîôûãñõåæç'
45
- uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
46
- uppercase_extended = uppercase + 'ÄËÏÖÜÀÈÌÒÙÁÉÍÓÚÝÂÊÎÔÛÃÑÕÅÆÇß'
41
+ lowercase = "abcdefghijklmnopqrstuvwxyz"
42
+ lowercase_extended = lowercase + "äëïöüÿàèìòùáéíóúýâêîôûãñõåæç"
43
+ uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
44
+ uppercase_extended = uppercase + "ÄËÏÖÜÀÈÌÒÙÁÉÍÓÚÝÂÊÎÔÛÃÑÕÅÆÇß"
47
45
 
48
46
  # COMBINED LETTER SETS
49
- letters = lowercase + uppercase
50
- letters_extended = lowercase_extended + uppercase_extended
47
+ letters = lowercase + uppercase
48
+ letters_extended = lowercase_extended + uppercase_extended
51
49
 
52
50
  # ASCII sets
53
- special_ascii = ' !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
54
- special_ascii_extended = special_ascii + 'ø£Ø×ƒªº¿®¬½¼¡«»░▒▓│┤©╣║╗╝¢¥┐└┴┬├─┼╚╔╩╦╠═╬¤ðÐı┘┌█▄¦▀µþÞ¯´≡­±‗¾¶§÷¸°¨·¹³²■ '
55
- standard_ascii = special_ascii + digits + letters
56
- full_ascii = special_ascii_extended + digits + letters_extended
57
-
58
-
51
+ special_ascii = " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
52
+ special_ascii_extended = special_ascii + "ø£Ø×ƒªº¿®¬½¼¡«»░▒▓│┤©╣║╗╝¢¥┐└┴┬├─┼╚╔╩╦╠═╬¤ðÐı┘┌█▄¦▀µþÞ¯´≡­±‗¾¶§÷¸°¨·¹³²■ "
53
+ standard_ascii = special_ascii + digits + letters
54
+ full_ascii = special_ascii_extended + digits + letters_extended
59
55
 
60
56
 
61
57
  class ANSI:
62
58
 
63
59
  global CHAR, START, SEP, END
64
60
 
65
- CHAR = char = '\x1b'
66
- START = start = '['
67
- SEP = sep = ';'
68
- END = end = 'm'
61
+ CHAR = char = "\x1b"
62
+ START = start = "["
63
+ SEP = sep = ";"
64
+ END = end = "m"
65
+ modifier = {"lighten": "+l", "darken": "-d"}
69
66
 
70
- def seq(parts:int = 1) -> str:
67
+ def seq(parts: int = 1) -> str:
71
68
  """Generate an ANSI sequence with `parts` amount of placeholders."""
72
- return CHAR + START + SEP.join(['{}' for _ in range(parts)]) + END
69
+ return CHAR + START + SEP.join(["{}" for _ in range(parts)]) + END
73
70
 
74
- seq_color:str = CHAR + START + '38' + SEP + '2' + SEP + '{}' + SEP + '{}' + SEP + '{}' + END
75
- seq_bg_color:str = CHAR + START + '48' + SEP + '2' + SEP + '{}' + SEP + '{}' + SEP + '{}' + END
71
+ seq_color: str = CHAR + START + "38" + SEP + "2" + SEP + "{}" + SEP + "{}" + SEP + "{}" + END
72
+ seq_bg_color: str = CHAR + START + "48" + SEP + "2" + SEP + "{}" + SEP + "{}" + SEP + "{}" + END
76
73
 
77
- color_map:list[str] = [
74
+ color_map: list[str] = [
78
75
  ########### DEFAULT CONSOLE COLOR NAMES ############
79
- 'black',
80
- 'red',
81
- 'green',
82
- 'yellow',
83
- 'blue',
84
- 'magenta',
85
- 'cyan',
86
- 'white'
76
+ "black",
77
+ "red",
78
+ "green",
79
+ "yellow",
80
+ "blue",
81
+ "magenta",
82
+ "cyan",
83
+ "white",
87
84
  ]
88
85
 
89
- codes_map:dict[str|tuple[str], int] = {
86
+ codes_map: dict[str | tuple[str], int] = {
90
87
  ###################### RESETS ######################
91
- '_': 0,
92
- ('_bold','_b'): 22,
93
- ('_dim','_d'): 22,
94
- ('_italic','_i'): 23,
95
- ('_underline','_u'): 24,
96
- ('_double-underline','_du'): 24,
97
- ('_inverse','_invert','_in'): 27,
98
- ('_hidden','_hide','_h'): 28,
99
- ('_strikethrough','_s'): 29,
100
- ('_color','_c'): 39,
101
- ('_background','_bg'): 49,
88
+ "_": 0,
89
+ ("_bold", "_b"): 22,
90
+ ("_dim", "_d"): 22,
91
+ ("_italic", "_i"): 23,
92
+ ("_underline", "_u"): 24,
93
+ ("_double-underline", "_du"): 24,
94
+ ("_inverse", "_invert", "_in"): 27,
95
+ ("_hidden", "_hide", "_h"): 28,
96
+ ("_strikethrough", "_s"): 29,
97
+ ("_color", "_c"): 39,
98
+ ("_background", "_bg"): 49,
102
99
  ################### TEXT FORMATS ###################
103
- ('bold','b'): 1,
104
- ('dim','d'): 2,
105
- ('italic','i'): 3,
106
- ('underline','u'): 4,
107
- ('inverse','invert','in'): 7,
108
- ('hidden','hide','h'): 8,
109
- ('strikethrough','s'): 9,
110
- ('double-underline','du'): 21,
100
+ ("bold", "b"): 1,
101
+ ("dim", "d"): 2,
102
+ ("italic", "i"): 3,
103
+ ("underline", "u"): 4,
104
+ ("inverse", "invert", "in"): 7,
105
+ ("hidden", "hide", "h"): 8,
106
+ ("strikethrough", "s"): 9,
107
+ ("double-underline", "du"): 21,
111
108
  ############## DEFAULT CONSOLE COLORS ##############
112
- 'black': 30,
113
- 'red': 31,
114
- 'green': 32,
115
- 'yellow': 33,
116
- 'blue': 34,
117
- 'magenta': 35,
118
- 'cyan': 36,
119
- 'white': 37,
109
+ "black": 30,
110
+ "red": 31,
111
+ "green": 32,
112
+ "yellow": 33,
113
+ "blue": 34,
114
+ "magenta": 35,
115
+ "cyan": 36,
116
+ "white": 37,
120
117
  ########## BRIGHT DEFAULT CONSOLE COLORS ###########
121
- ('bright:black','br:black'): 90,
122
- ('bright:red','br:red'): 91,
123
- ('bright:green','br:green'): 92,
124
- ('bright:yellow','br:yellow'): 93,
125
- ('bright:blue','br:blue'): 94,
126
- ('bright:magenta','br:magenta'): 95,
127
- ('bright:cyan','br:cyan'): 96,
128
- ('bright:white','br:white'): 97,
118
+ ("bright:black", "br:black"): 90,
119
+ ("bright:red", "br:red"): 91,
120
+ ("bright:green", "br:green"): 92,
121
+ ("bright:yellow", "br:yellow"): 93,
122
+ ("bright:blue", "br:blue"): 94,
123
+ ("bright:magenta", "br:magenta"): 95,
124
+ ("bright:cyan", "br:cyan"): 96,
125
+ ("bright:white", "br:white"): 97,
129
126
  ######## DEFAULT CONSOLE BACKGROUND COLORS #########
130
- 'bg:black': 40,
131
- 'bg:red': 41,
132
- 'bg:green': 42,
133
- 'bg:yellow': 43,
134
- 'bg:blue': 44,
135
- 'bg:magenta': 45,
136
- 'bg:cyan': 46,
137
- 'bg:white': 47,
127
+ "bg:black": 40,
128
+ "bg:red": 41,
129
+ "bg:green": 42,
130
+ "bg:yellow": 43,
131
+ "bg:blue": 44,
132
+ "bg:magenta": 45,
133
+ "bg:cyan": 46,
134
+ "bg:white": 47,
138
135
  ##### BRIGHT DEFAULT CONSOLE BACKGROUND COLORS #####
139
- ('bg:bright:black','bg:br:black'): 100,
140
- ('bg:bright:red','bg:br:red'): 101,
141
- ('bg:bright:green','bg:br:green'): 102,
142
- ('bg:bright:yellow','bg:br:yellow'): 103,
143
- ('bg:bright:blue','bg:br:blue'): 104,
144
- ('bg:bright:magenta','bg:br:magenta'): 105,
145
- ('bg:bright:cyan','bg:br:cyan'): 106,
146
- ('bg:bright:white','bg:br:white'): 107,
136
+ ("bg:bright:black", "bg:br:black"): 100,
137
+ ("bg:bright:red", "bg:br:red"): 101,
138
+ ("bg:bright:green", "bg:br:green"): 102,
139
+ ("bg:bright:yellow", "bg:br:yellow"): 103,
140
+ ("bg:bright:blue", "bg:br:blue"): 104,
141
+ ("bg:bright:magenta", "bg:br:magenta"): 105,
142
+ ("bg:bright:cyan", "bg:br:cyan"): 106,
143
+ ("bg:bright:white", "bg:br:white"): 107,
147
144
  }
xulbux/xx_code.py CHANGED
@@ -1,28 +1,20 @@
1
- from .xx_string import *
2
- from .xx_regex import *
3
- from .xx_data import *
1
+ from .xx_string import String
2
+ from .xx_regex import Regex
3
+ from .xx_data import Data
4
4
 
5
5
  import regex as _rx
6
6
 
7
7
 
8
-
9
-
10
8
  class Code:
11
9
 
12
10
  @staticmethod
13
- def normalize_spaces(string:str, tab_spaces:int = 4) -> str:
14
- """Replaces all special space characters with normal spaces.<br>
15
- Also replaces tab characters with `tab_spaces` spaces."""
16
- return string.replace('\t', ' ' * tab_spaces).replace('\u2000', ' ').replace('\u2001', ' ').replace('\u2002', ' ').replace('\u2003', ' ').replace('\u2004', ' ').replace('\u2005', ' ').replace('\u2006', ' ').replace('\u2007', ' ').replace('\u2008', ' ').replace('\u2009', ' ').replace('\u200A', ' ')
17
-
18
- @staticmethod
19
- def add_indent(code:str, indent:int) -> str:
11
+ def add_indent(code: str, indent: int) -> str:
20
12
  """Adds `indent` spaces at the beginning of each line."""
21
- indented_lines = [' ' * indent + line for line in code.splitlines()]
22
- return '\n'.join(indented_lines)
13
+ indented_lines = [" " * indent + line for line in code.splitlines()]
14
+ return "\n".join(indented_lines)
23
15
 
24
16
  @staticmethod
25
- def get_tab_spaces(code:str) -> int:
17
+ def get_tab_spaces(code: str) -> int:
26
18
  """Will try to get the amount of spaces used for indentation."""
27
19
  code_lines = String.get_string_lines(code, remove_empty_lines=True)
28
20
  indents = [len(line) - len(line.lstrip()) for line in code_lines]
@@ -30,42 +22,50 @@ class Code:
30
22
  return min(non_zero_indents) if non_zero_indents else 0
31
23
 
32
24
  @staticmethod
33
- def change_tab_size(code:str, new_tab_size:int, remove_empty_lines:bool = False) -> str:
25
+ def change_tab_size(code: str, new_tab_size: int, remove_empty_lines: bool = False) -> str:
34
26
  """Replaces all tabs with `new_tab_size` spaces.<br>
35
- If `remove_empty_lines` is `True`, empty lines will be removed in the process."""
27
+ If `remove_empty_lines` is `True`, empty lines will be removed in the process.
28
+ """
36
29
  code_lines = String.get_string_lines(code, remove_empty_lines=True)
37
30
  lines = code_lines if remove_empty_lines else String.get_string_lines(code)
38
31
  tab_spaces = Code.get_tab_spaces(code)
39
32
  if (tab_spaces == new_tab_size) or tab_spaces == 0:
40
33
  if remove_empty_lines:
41
- return '\n'.join(code_lines)
34
+ return "\n".join(code_lines)
42
35
  return code
43
36
  result = []
44
37
  for line in lines:
45
38
  stripped = line.lstrip()
46
39
  indent_level = (len(line) - len(stripped)) // tab_spaces
47
- new_indent = ' ' * (indent_level * new_tab_size)
40
+ new_indent = " " * (indent_level * new_tab_size)
48
41
  result.append(new_indent + stripped)
49
- return '\n'.join(result)
42
+ return "\n".join(result)
50
43
 
51
44
  @staticmethod
52
- def get_func_calls(code:str) -> list:
45
+ def get_func_calls(code: str) -> list:
53
46
  """Will try to get all function calls and return them as a list."""
54
- funcs, nested_func_calls = _rx.findall(r'(?i)' + Regex.func_call(), code), []
47
+ funcs = _rx.findall(r"(?i)" + Regex.func_call(), code)
48
+ nested_func_calls = []
55
49
  for _, func_attrs in funcs:
56
- nested_calls = _rx.findall(r'(?i)' + Regex.func_call(), func_attrs)
50
+ nested_calls = _rx.findall(r"(?i)" + Regex.func_call(), func_attrs)
57
51
  if nested_calls:
58
52
  nested_func_calls.extend(nested_calls)
59
53
  return Data.remove_duplicates(funcs + nested_func_calls)
60
54
 
61
55
  @staticmethod
62
- def is_js(code:str, funcs:list = ['__', '$t', '$lang']) -> bool:
56
+ def is_js(code: str, funcs: list = ["__", "$t", "$lang"]) -> bool:
63
57
  """Will check if the code is likely to be JavaScript."""
64
- funcs = '|'.join(funcs)
65
- js_pattern = _rx.compile(Regex.outside_strings(r'''^(?:
58
+ funcs = "|".join(funcs)
59
+ js_pattern = _rx.compile(
60
+ Regex.outside_strings(
61
+ r"""^(?:
66
62
  (\$[\w_]+)\s* # JQUERY-STYLE VARIABLES
67
63
  |(\$[\w_]+\s*\() # JQUERY-STYLE FUNCTION CALLS
68
- |((''' + funcs + r')' + Regex.brackets('()') + r'''\s*) # PREDEFINED FUNCTION CALLS
64
+ |(("""
65
+ + funcs
66
+ + r")"
67
+ + Regex.brackets("()")
68
+ + r"""\s*) # PREDEFINED FUNCTION CALLS
69
69
  |(\bfunction\s*\() # FUNCTION DECLARATIONS
70
70
  |(\b(var|let|const)\s+[\w_]+\s*=) # VARIABLE DECLARATIONS
71
71
  |(\b(if|for|while|switch)\s*\() # CONTROL STRUCTURES
@@ -98,5 +98,8 @@ class Code:
98
98
  |(\bdelete\b) # DELETE OPERATOR
99
99
  |(\btypeof\b) # TYPEOF OPERATOR
100
100
  |(\bvoid\b) # VOID OPERATOR
101
- )[\s\S]*$'''), _rx.VERBOSE | _rx.IGNORECASE)
101
+ )[\s\S]*$"""
102
+ ),
103
+ _rx.VERBOSE | _rx.IGNORECASE,
104
+ )
102
105
  return bool(js_pattern.fullmatch(code))