Js2Py
Js2Py copied to clipboard
Add partial support for ES6 Arrow function
This seems to work with all my tests, but does not follow spec. Has the properties of a function rather than an Arrow function.
The code I want to run looks something like this:
import js2py
context = js2py.EvalJs()
def String_prototype_includes(searchString, position = 0):
this.cok()
S = this.to_string().value
searchStr = searchString.to_string().value
pos = position.to_int()
if S[pos:pos+len(S)].find(searchStr.lower()) != -1:
return this.Js(True)
return this.Js(False)
context.String.prototype.includes = String_prototype_includes
context.execute(r'''
const words = 'dead|beef'.split('|');
var sentence = ' This is a test'
let containsWord = words.some(word => sentence.toLowerCase().includes(word));
''')