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

rsuite / schema-typed / 8657282119

12 Apr 2024 05:09AM UTC coverage: 95.227%. Remained the same
8657282119

Pull #80

github

web-flow
Merge 1ad0891ec into 9b4a8f368
Pull Request #80: refactor: replace `lodash.set` with `set-value`

332 of 369 branches covered (89.97%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

466 of 469 relevant lines covered (99.36%)

198.7 hits per line

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

96.97
/src/utils/createValidatorAsync.ts
1
import { CheckResult, RuleType } from '../types';
2
import formatErrorMessage, { joinName } 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 => {
234✔
11
      if (checkResult === false) {
234✔
12
        return { hasError: true, errorMessage };
93✔
13
      } else if (typeof checkResult === 'object' && (checkResult.hasError || checkResult.array)) {
141✔
14
        return checkResult;
3✔
15
      }
16
      return null;
138✔
17
    };
18
  }
19

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

25
      return Promise.resolve(onValid(value, data, name)).then(
234✔
26
        check(
27
          formatErrorMessage<E>(errorMsg, {
28
            ...params,
29
            name: label || joinName(name)
444✔
30
          })
31
        )
32
      );
33
    });
34

35
    return Promise.all(promises).then(results =>
264✔
36
      results.find((item: CheckResult<E> | null) => item && item?.hasError)
264!
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

© 2026 Coveralls, Inc