npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

captcha-imh-component

v1.0.2

Published

A reusable React captcha-imh-component with customizable API calls, styling, and error handling.

Readme

captcha-imh-component

Un composant React réutilisable pour l'intégration de CAPTCHA dans vos applications web.

Installation

npm install captcha-imh-component

Utilisation de base

import React, { useState } from 'react';
import Captcha from 'captcha-imh-component';

function App() {
  const [captchaValue, setCaptchaValue] = useState('');
  const [reset, setReset] = useState(false);

  const handleCaptchaChange = (value) => {
    setCaptchaValue(value);
  };

  const handleReset = () => {
    setReset(!reset);
  };

  return (
    <div>
      <Captcha 
        onChange={handleCaptchaChange}
        reset={reset}
      />
      <button onClick={handleReset}>Reset CAPTCHA</button>
      <p>Valeur saisie: {captchaValue}</p>
    </div>
  );
}

export default App;

Props

| Prop | Type | Défaut | Description | |------|------|--------|-------------| | reset | boolean | false | Force le rechargement du CAPTCHA | | onChange | function | - | Callback appelé quand la valeur d'entrée change | | onCaptchaTextChange | function | - | Callback appelé quand le texte CAPTCHA change | | style | object | {} | Styles pour l'icône de rafraîchissement | | error | object | - | Objet d'erreur à afficher | | apiEndpoint | string | '/api/generate-captcha' | URL de l'API CAPTCHA | | httpMethod | string | 'GET' | Méthode HTTP pour l'API | | placeholder | string | 'Entrer CAPTCHA' | Placeholder du champ de saisie | | makeApiCall | function | - | Fonction personnalisée pour les appels API | | sessionStorageKey | string | 'sessionId' | Clé de stockage pour l'ID de session | | captchaStorageKey | string | 'captcha' | Clé de stockage pour le texte CAPTCHA | | inputStyle | object | {} | Styles personnalisés pour le champ de saisie | | containerStyle | object | {} | Styles personnalisés pour le conteneur | | imageStyle | object | {} | Styles personnalisés pour l'image CAPTCHA | | ErrorComponent | component | - | Composant personnalisé pour l'affichage des erreurs |

Exemples avancés

Avec fonction API personnalisée

import Captcha from 'captcha-imh-component';

const customApiCall = async (method, url, data, headers) => {
  // Votre logique d'appel API personnalisée
  const response = await fetch(url, {
    method,
    headers: {
      ...headers,
      'Authorization': 'Bearer your-token'
    },
    body: data ? JSON.stringify(data) : undefined
  });
  return response.json();
};

function App() {
  return (
    <Captcha 
      makeApiCall={customApiCall}
      apiEndpoint="https://your-api.com/captcha"
    />
  );
}

Avec composants personnalisés

import Captcha from 'captcha-imh-component';

const CustomError = ({ error, message }) => (
  <div className="custom-error-display">
    {error?.data?.detail && <span>{message}</span>}
  </div>
);

function App() {
  return (
    <Captcha 
      errorComponent={CustomError}
    />
  );
}

Avec styles personnalisés

import Captcha from 'captcha-imh-component';

function App() {
  const customStyles = {
    container: {
      backgroundColor: '#f5f5f5',
      padding: '20px',
      borderRadius: '8px'
    },
    input: {
      fontSize: '16px',
      fontFamily: 'Arial, sans-serif',
      border: '2px solid #007bff'
    },
    image: {
      border: '1px solid #ddd',
      borderRadius: '4px'
    }
  };

  return (
    <Captcha 
      containerStyle={customStyles.container}
      inputStyle={customStyles.input}
      imageStyle={customStyles.image}
    />
  );
}

Format de réponse API attendu

Le composant attend une réponse API dans l'un des formats suivants :

Pour CAPTCHA image :

{
  "data": {
    "image": "base64-encoded-image-string",
    "sessionId": "session-identifier"
  }
}

Pour CAPTCHA texte :

{
  "data": {
    "captchaText": "text-captcha-content",
    "sessionId": "session-identifier"
  }
}

Personnalisation CSS

Le composant utilise les classes CSS suivantes que vous pouvez personnaliser :

  • .captcha-container - Conteneur principal
  • .captcha-image-container - Conteneur de l'image
  • .captcha-image - Image CAPTCHA
  • .captcha-input-container - Conteneur du champ de saisie
  • .captcha-input - Champ de saisie
  • .captcha-error - Affichage des erreurs

Dépendances

  • React >= 16.8.0
  • react-dom >= 16.8.0

Licence

ISC

Contribution

Les contributions sont les bienvenues ! N'hésitez pas à ouvrir une issue ou soumettre une pull request.