structured.js is a Javascript library that provides a simple interface for checking the structure of Javascript code, backed by the abstract syntax tree generated by Esprima. Structured.js works in-browser or as a standalone npm module. It is used particularly for checking beginner code to provide useful feedback as part of Khan Academy's CS curriculum.
A structure is valid Javascript code that contains blanks ( _ characters) and stand-ins ($str) that match values. The structure is sensitive to nesting and ordering. The matcher only requires that code contain the structure -- extra code has no effect.
Structures can contain any Javascript -- control structures (for, while, if, else, try, etc), function calls, variable declarations, parameters, numbers, strings, arrays, objects, and even operators are all fair game. Use _ characters to indicate what can be filled by anything. Use variables starting with $ to indicate what static values should be the same (i.e. $foo to indicate some number, string, or name). You can also check out the pretty display of structures.
Try it out!
QUnit test code generated here.