MCPcopy Index your code
hub / github.com/clips/pattern / minify

Function minify

pattern/graph/__init__.py:1108–1126  ·  view source on GitHub ↗

Returns a compressed Javascript string with comments and whitespace removed.

(js)

Source from the content-addressed store, hash-verified

1106#--- HTML CANVAS GRAPH RENDERER --------------------------------------------------------------------
1107
1108def minify(js):
1109 """ Returns a compressed Javascript string with comments and whitespace removed.
1110 """
1111 import re
1112 W = (
1113 "\(\[\{\,\;\=\-\+\*\/",
1114 "\)\]\}\,\;\=\-\+\*\/"
1115 )
1116 for a, b in (
1117 (re.compile(r"\/\*.*?\*\/", re.S), ""), # multi-line comments /**/
1118 (re.compile(r"\/\/.*"), ""), # singe line comments //
1119 (re.compile(r";\n"), "; "), # statements (correctly) terminated with ;
1120 (re.compile(r"[ \t]+"), " "), # spacing and indentation
1121 (re.compile(r"[ \t]([\(\[\{\,\;\=\-\+\*\/])"), "\\1"),
1122 (re.compile(r"([\)\]\}\,\;\=\-\+\*\/])[ \t]"), "\\1"),
1123 (re.compile(r"\s+\n"), "\n"),
1124 (re.compile(r"\n+"), "\n")):
1125 js = a.sub(b, js)
1126 return js.strip()
1127
1128DEFAULT, INLINE = "default", "inline"
1129HTML, CANVAS, STYLE, SCRIPT, DATA = "html", "canvas", "style", "script", "data"

Callers 1

exportMethod · 0.85

Calls 1

stripMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…