Sha256: 490773041cec3b34bed630dd9833bbf0e2093fdda181fb48a8a72cb8af85bce4
Contents?: true
Size: 692 Bytes
Versions: 8
Compression:
Stored size: 692 Bytes
Contents
require 'v8' require 'json' module JsHelpers class JsMethodInvoker JS_SOURCE_PATH = Pathname(File.expand_path('../js_source/', __FILE__)) def initialize @ctx = V8::Context.new do |ctx| ctx.eval(JS_SOURCE_PATH.join('zxcvbn.js').read) end end def eval(string) @ctx.eval(string) end def eval_convert_object(string) serialized = eval("JSON.stringify(#{string})") JSON.parse(serialized) end end def method_invoker $method_invoker ||= JsMethodInvoker.new end def run_js(javascript) method_invoker.eval_convert_object(javascript) end def js_zxcvbn(password) run_js("zxcvbn('#{password}')") end end
Version data entries
8 entries across 8 versions & 2 rubygems