Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-google-recaptcha-hook

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-google-recaptcha-hook - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

types/functions.d.ts

2

dist/react-google-recaptcha-hook.cjs.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var r=require("react");const s=()=>{var c;typeof window.grecaptcha=="undefined"&&((c=window.___grecaptcha_cfg)!=null||(window.___grecaptcha_cfg={fns:[]}),window.grecaptcha={ready:e=>{window.___grecaptcha_cfg.fns.push(e)}})},d=()=>new Promise(c=>{s(),window.grecaptcha.ready(()=>c(window.grecaptcha.enterprise||window.grecaptcha))}),l=(c,e)=>{const t=e!=null&&e.language?`&hl=${e.language}`:"",n=e!=null&&e.enterprise?"enterprise.js":"api.js";return`https://www.${e!=null&&e.recaptchaNet?"recaptcha.net":"google.com"}/recaptcha/${n}?render=${c}${t}`},w=(c,e)=>{const t=r.useCallback(()=>{if(document.getElementById(c))return;const a=document.createElement("script");a.async=!0,a.type="text/javascript",a.src=l(c,e),a.id=c,document.getElementsByTagName("head")[0].appendChild(a)},[]),n=r.useCallback(async a=>{var h;const g=await d();return(h=g.execute)==null?void 0:h.call(g,c,{action:a})},[]),u=r.useRef(!1);return r.useEffect(()=>{u.current||(u.current=!0,t())},[t]),{executeGoogleReCaptcha:n,load:t}};exports.generateGrecaptchaSrc=l;exports.getGrecaptcha=d;exports.initGrecaptcha=s;exports.useGoogleReCaptcha=w;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var t=require("react");const h=()=>{var c;typeof window.grecaptcha=="undefined"&&((c=window.___grecaptcha_cfg)!=null||(window.___grecaptcha_cfg={fns:[]}),window.grecaptcha={ready:e=>{window.___grecaptcha_cfg.fns.push(e)},enterprise:{ready:e=>{window.___grecaptcha_cfg.fns.push(e)}}})},s=c=>new Promise(e=>{h(),c?window.grecaptcha.enterprise.ready(()=>e(window.grecaptcha.enterprise)):window.grecaptcha.ready(()=>e(window.grecaptcha))}),l=(c,e)=>{const r=e!=null&&e.language?`&hl=${e.language}`:"",n=e!=null&&e.enterprise?"enterprise.js":"api.js";return`https://www.${e!=null&&e.recaptchaNet?"recaptcha.net":"google.com"}/recaptcha/${n}?render=${c}${r}`},w=(c,e)=>{const r=t.useCallback(()=>{if(document.getElementById(c))return;const a=document.createElement("script");a.async=!0,a.type="text/javascript",a.src=l(c,e),a.id=c,document.getElementsByTagName("head")[0].appendChild(a)},[]),n=t.useCallback(async a=>{var d;const g=await s(e==null?void 0:e.enterprise);return(d=g.execute)==null?void 0:d.call(g,c,{action:a})},[]),u=t.useRef(!1);return t.useEffect(()=>{u.current||(u.current=!0,r())},[r]),{executeGoogleReCaptcha:n,load:r}};exports.useGoogleReCaptcha=w;

@@ -11,2 +11,7 @@ import { useCallback, useRef, useEffect } from "react";

window.___grecaptcha_cfg.fns.push(callback);
},
enterprise: {
ready: (callback) => {
window.___grecaptcha_cfg.fns.push(callback);
}
}

@@ -16,5 +21,9 @@ };

};
const getGrecaptcha = () => new Promise((resolve) => {
const getGrecaptcha = (enterprise) => new Promise((resolve) => {
initGrecaptcha();
window.grecaptcha.ready(() => resolve(window.grecaptcha.enterprise || window.grecaptcha));
if (enterprise) {
window.grecaptcha.enterprise.ready(() => resolve(window.grecaptcha.enterprise));
} else {
window.grecaptcha.ready(() => resolve(window.grecaptcha));
}
});

@@ -40,3 +49,3 @@ const generateGrecaptchaSrc = (siteKey, options) => {

var _a;
const grecaptcha = await getGrecaptcha();
const grecaptcha = await getGrecaptcha(options == null ? void 0 : options.enterprise);
return (_a = grecaptcha.execute) == null ? void 0 : _a.call(grecaptcha, siteKey, { action });

@@ -53,2 +62,2 @@ }, []);

};
export { generateGrecaptchaSrc, getGrecaptcha, initGrecaptcha, useGoogleReCaptcha };
export { useGoogleReCaptcha };

@@ -20,3 +20,3 @@ {

"license": "MIT",
"version": "0.1.2",
"version": "0.1.3",
"files": [

@@ -23,0 +23,0 @@ "dist",

@@ -1,36 +0,3 @@

declare global {
interface Window {
grecaptcha: ReCaptcha & {
enterprise?: ReCaptcha;
};
___grecaptcha_cfg: {
fns: (() => void)[];
};
}
}
declare type ReCaptcha = {
execute?(siteKey: string, options: {
action: string;
}): PromiseLike<string>;
ready(callback: () => void): void;
};
/**
* @see https://developers.google.com/recaptcha/docs/loading#loading_recaptcha_asynchronously
**/
export declare const initGrecaptcha: () => void;
export declare const getGrecaptcha: () => Promise<ReCaptcha>;
export declare const generateGrecaptchaSrc: (siteKey: string, options?: {
language?: string;
enterprise?: boolean;
recaptchaNet?: boolean;
}) => string;
export declare const useGoogleReCaptcha: (siteKey: string, options?: {
language?: string;
enterprise?: boolean;
recaptchaNet?: boolean;
}) => {
executeGoogleReCaptcha: (action: string) => Promise<string | undefined>;
load: () => void;
};
export {};
import { useGoogleReCaptcha } from "./useGoogleRecaptcha";
export { useGoogleReCaptcha };
//# sourceMappingURL=index.d.ts.map

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc