Lesson 3 of 8 · 2 min
Extract facts without a model
import re
bundle = '''const API="https://api.example.com/v2";fetch(API+"/users/me",{method:"GET"});
axios.post("/v2/orders",body);const k="EXAMPLE_PUBLIC_ID";import x from "lodash";'''
def facts(code):
return {
"urls": sorted(set(re.findall(r"https?://[\w.\-]+(?:/[\w\-./]*)?", code))),
"paths": sorted(set(re.findall(r"[\"'](/[a-z0-9_\-]+(?:/[a-z0-9_\-{}:]+)+)[\"']", code))),
"calls": sorted(set(re.findall(r"\b(fetch|axios\.\w+|XMLHttpRequest)\b", code))),
"imports": sorted(set(re.findall(r"from [\"']([\w@/\-]+)[\"']", code))),
}
for key, found in facts(bundle).items():
print(key, found)
