Skip to content

Instantly share code, notes, and snippets.

@tanupoo
Last active March 24, 2022 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanupoo/d9b8d177b3e7f4597c2e35a09a59c10c to your computer and use it in GitHub Desktop.
Save tanupoo/d9b8d177b3e7f4597c2e35a09a59c10c to your computer and use it in GitHub Desktop.
mozilla hubsのソースコードからQuery Stringを抜き出す
import sys
import re
"""
find ./src -name '*.js' |\
xargs grep -nE '(qs.get|qsTruthy|qsGet)' |\
python findopts.py
"""
opts = {}
for line in sys.stdin:
line = line.strip()
r = re.match('([^:]+):(\d+):(.+qs[^"]+"([^"]+))".*', line)
if r:
if " from " not in line:
file_name = r.group(1).replace("./src/","")
line_no = r.group(2)
code = r.group(3)
k = r.group(4)
if re.search("(qs.get|qsGet)", line):
if "parseInt" in line:
t = "int"
else:
t = "str"
elif "qsTruthy" in line:
t = "bool"
opts[k] = f"{t} | {file_name} | {line_no} | {code}"
print("| name | type | file | line# | code |")
print("|------|------|------|-------|------|")
for k,v in sorted(opts.items()):
print(f"| {k} | {v} |")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment