• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rsuite / schema-typed / 8632715695

10 Apr 2024 02:11PM UTC coverage: 94.836% (-0.8%) from 95.618%
8632715695

Pull #78

github

web-flow
Merge e7b94ea96 into 9ff16c346
Pull Request #78: feat: add support for `equalTo` and `proxy`

331 of 367 branches covered (90.19%)

Branch coverage included in aggregate %.

138 of 140 new or added lines in 9 files covered. (98.57%)

3 existing lines in 2 files now uncovered.

477 of 485 relevant lines covered (98.35%)

186.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.29
/src/utils/createValidatorAsync.ts
1
import { CheckResult, RuleType } from '../types';
2
import formatErrorMessage from './formatErrorMessage';
3✔
3

4
/**
5
 * Create a data asynchronous validator
6
 * @param data
7
 */
8
export function createValidatorAsync<V, D, E>(data?: D, name?: string | string[], label?: string) {
3✔
9
  function check(errorMessage?: E | string) {
10
    return (checkResult: CheckResult<E> | boolean): CheckResult<E> | null => {
180✔
11
      if (checkResult === false) {
180✔
12
        return { hasError: true, errorMessage };
63✔
13
      } else if (typeof checkResult === 'object' && (checkResult.hasError || checkResult.array)) {
117✔
14
        return checkResult;
3✔
15
      }
16
      return null;
114✔
17
    };
18
  }
19

20
  return (value: V, rules: RuleType<V, D, E>[]) => {
120✔
21
    const promises = rules.map(rule => {
222✔
22
      const { onValid, errorMessage, params } = rule;
180✔
23
      const errorMsg = typeof errorMessage === 'function' ? errorMessage() : errorMessage;
180✔
24

25
      return Promise.resolve(onValid(value, data, name)).then(
180✔
26
        check(
27
          formatErrorMessage<E>(errorMsg, {
28
            ...params,
29
            name: label || (Array.isArray(name) ? name.join('.') : name)
492!
30
          })
31
        )
32
      );
33
    });
34

35
    return Promise.all(promises).then(results =>
222✔
36
      results.find((item: CheckResult<E> | null) => item && item?.hasError)
222!
37
    );
38
  };
39
}
40

41
export default createValidatorAsync;
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc