Skip to content

Instantly share code, notes, and snippets.

@thepalbi
Created July 3, 2021 23:00
Show Gist options
  • Select an option

  • Save thepalbi/794c90e52d6a50f9b908d66c436181fd to your computer and use it in GitHub Desktop.

Select an option

Save thepalbi/794c90e52d6a50f9b908d66c436181fd to your computer and use it in GitHub Desktop.
Python wrapper to compare with jsinspect
import subprocess
import tempfile
# npm install -g jsinspect
additional_arguments = [
"-I", # Ignore identifers
"-L", # Ignore literals
"-t", "20", # Compare nodes count
"-m", "2", # Minimum number of equal nodes to get a match
]
def compare(a, b):
with tempfile.NamedTemporaryFile() as file_a, tempfile.NamedTemporaryFile() as file_b:
file_a.write(bytes(a, "utf-8"))
file_a.flush()
file_b.write(bytes(b, "utf-8"))
file_b.flush()
args = ["jsinspect"] + additional_arguments + \
[file_a.name, file_b.name]
p_result = subprocess.run(
args, capture_output=False, check=False, stdout=subprocess.DEVNULL)
return p_result.returncode == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment