incode
is a library for building code injectors.
Example
Code with injectable regions:
// inj:emit("User", "pck") // inj:end
Code injector:
; const s = ;
Result after injection:
// inj:assign({ schema: "User" }) // inj:emit("pck") { console; } // inj:end
Features
- Block-scoped variables
- Indentation autodection for injectable regions
- Automatic removal of existing code in injectable regions
Directives
begin
- begin local scopeend
- end regionassign(data: JSON)
- assign data to a local scopeObject.assign
merge(data: JSON)
- merge data to a local scope_.merge
emit(...args: Array<JSON>)
- emit code
API
;
createDirectiveMatcher
creates a RegExp
object that will be used as a directive matcher.
;
extractRegions
extracts InjectableRegions
from text
.
;
inject
invokes cb
function and injects its result into a text.