WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f246019

Browse files
committed
Update Callback type hint
- Specify the `customClass` parameter's expected format. - Add example usage for clarity.
1 parent f273cfe commit f246019

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ Allows you to add custom rules by giving a callback function and a custom class.
132132

133133
#### Arguments
134134

135-
- `callback` (required) - the callback function.
136-
- `customClass` (required) - the name of the class.
135+
- `callback` (required) - the callback function, that must return `true` if the value is valid.
136+
- `customClass` (required) - the name of the class, which must match the pattern `/^[a-zA-Z\d]+$/`.
137137

138138
### CaZipCode
139139

@@ -331,7 +331,9 @@ The following is an example for the extra IP assert:
331331

332332
```js
333333
const Validator = require('validator.js').Validator;
334-
const is = require('validator.js').Assert.extend(require('validator.js-asserts'));
334+
const is = require('validator.js').Assert.extend(
335+
require('validator.js-asserts')
336+
);
335337
const validator = new Validator();
336338

337339
// Validate IP `1.3.3.7`.

src/types/index.d.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,18 @@ export interface ValidatorJSAsserts {
6060
/** Valid Canadian ZIP code (postal code). */
6161
caZipCode(): AssertInstance;
6262

63-
/** Run a custom callback function, passing a custom class name. */
63+
/**
64+
* Run a custom callback function, passing a custom class name.
65+
* @param fn - Callback function that receives the value to validate, which should return `true` if valid.
66+
* @param customClass - Custom class name to use for the assert. Must match the pattern `/^[a-zA-Z\d]+$/`.
67+
* @example
68+
* ```js
69+
* is.callback(
70+
* (value) => typeof value === 'string' && value.length > 0,
71+
* 'NonEmptyString'
72+
* );
73+
* ```
74+
*/
6475
callback(fn: (value: unknown) => boolean, customClass: string): AssertInstance;
6576

6677
/** Valid Brazilian CPF number. @requires cpf */

0 commit comments

Comments
 (0)