$ show guillaumepotier/Parsley.js
Parsley.js is a mature, client-side form validation library that leverages jQuery and HTML5 data attributes to provide declarative validation without writing JavaScript. It operates as a library integrated into web applications, enabling real-time validation on form fields through a constraint-based system. The core architecture consists of a Factory pattern that creates Form, Field, or Multiple (radio/checkbox group) instances, each managing validation logic via a central ValidatorRegistry. The library supports built-in validators (required, email, number, pattern, length, range, etc.), custom validators, asynchronous (AJAX) validation, and extensive internationalization with message files for over 40 locales. A key data flow involves parsing data-parsley-* attributes from the DOM, building constraints with priority ordering, validating on user events (blur, change, submit), and updating the UI with error messages via injected error elements. External dependencies include jQuery (>=1.8) and, optionally, an ES5 shim for legacy browser support. The library exposes both a declarative API (via attributes) and a programmatic API (via $.fn.parsley()), and uses a pub/sub event system for extensibility. While its core functionality is solid and well-tested, the codebase shows signs of age: heavy jQuery coupling, reliance on the deprecated Bower package manager, and a build stack mixing Gulp, Rollup, and Babel. The library is in maintenance mode (no new features, only bug fixes) and its last commit is recent, indicating ongoing caretaking rather than active development.
The LLM identified 2 files worth highlighting for reuse:
Demonstrates the Parsley custom validator plugin pattern by implementing a Luhn algorithm (credit card number) validator. It defines a validator with a priority, requirement type ('string'), and error message, and registers it via `window.Parsley.addValidator`. This file is self-contained, requires no internal Parsley imports beyond the global namespace, and can be extracted as a reference or base for adding custom validators to any Parsley instance.
Illustrates how to create a Parsley plugin that binds custom behaviors to validation events. It listens to Parsley lifecycle events (like 'field:success', 'field:error') and can be used to integrate third-party UI or analytics. The file follows the recommended plugin pattern by extending `ParsleyExtend` and using the instance's event system, making it a reusable template for adding cross-cutting concerns to Parsley forms.