Javascript implementation of the pattern-matching algorithm used in i3s classic.