You can check out the Perchance FAQ which talks about a question about open source Perchance and more, but here's an explanation:
Will there be an open-source Perchance library for programmers? Ideally, yes. The only reason there isn't one already is because Perchance was built in a very "MVP" manner. (Talking to the programmers here,) I've altered the prototypes of inbuilt objects (Array, String, etc.), inadvisably hacked together
Proxy
s andwith
statements to construct fake scopes and execution chains, simulated operator overloading by playing withvalueOf
and well-knownSymbols
, usedeval
unreservedly, and, in general, summoned every other JavaScript demon needed in order to get the Perchance DSL's syntax to work nicely (all code inside square brackets is executed as plain JavaScript, for those who missed that). So currently Perchance isn't in a state where it's easy to pull out the engine, throw it into an NPM module and call it a day (until this proposal becomes a reality, that is). If you're okay with the aforementioned mess, then you can pretty much just grab the.js
files that are used in the iframe, include them in your project and use them the same way they're used in the iframe html (you just pass createPerchanceTree your a string of perchance code and it returns the "root" of the tree, which you can then use to call the sublists).
— Perchance FAQ