# This code is original from jsmin by Douglas Crockford, it was translated to # Python by Baruch Even. It was rewritten by Dave St.Germain for speed. # # The MIT License (MIT) # # Copyright (c) 2013 Dave St.Germain # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE.
def jsmin(js, **kwargs): """
returns a minified version of the javascript string """
klass = io.StringIO
ins = klass(js)
outs = klass()
JavascriptMinify(ins, outs, **kwargs).minify() return outs.getvalue()
class JavascriptMinify(object): """
Minify an input stream of javascript, writing
to an output stream """
def minify(self, instream=None, outstream=None): if instream and outstream:
self.ins, self.outs = instream, outstream
self.is_return = False
self.return_buf = ''
def write(char): # all of this is to support literal regular expressions. # sigh if char in'return':
self.return_buf += char
self.is_return = self.return_buf == 'return' else:
self.return_buf = ''
self.is_return = self.is_return and char < '!'
self.outs.write(char) if self.is_return:
self.return_buf = ''
def regex_literal(self, next1, next2): assert next1 == '/'# otherwise we should not be called!
self.return_buf = ''
read = self.ins.read
write = self.outs.write
in_char_class = False
write('/')
next = next2 while next and (next != '/'or in_char_class):
write(next) if next == '\\':
write(read(1)) # whatever is next is escaped elif next == '[':
write(read(1)) # character class cannot be empty
in_char_class = True elif next == ']':
in_char_class = False
next = read(1)
if previous_non_space and (
previous_non_space in self.newlineend_strings or previous_non_space > '~'): while 1: if next2 < '!':
next2 = read(1) ifnot next2: break else: if next2 in self.newlinestart_strings \ or next2 > '~'or next2 == '/':
do_newline = True break
return next2, do_newline
¤ Dauer der Verarbeitung: 0.25 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.