• 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

95.74
/src/ArrayType.ts
1
import { MixedType } from './MixedType';
3✔
2
import { PlainObject, CheckResult, ErrorMessageType } from './types';
3
import { ArrayTypeLocale } from './locales';
4

5
export class ArrayType<DataType = any, E = ErrorMessageType> extends MixedType<
3✔
6
  any[],
7
  DataType,
8
  E,
9
  ArrayTypeLocale
10
> {
11
  constructor(errorMessage?: E | string) {
12
    super('array');
54✔
13
    super.pushRule({
54✔
14
      onValid: v => Array.isArray(v),
75✔
15
      errorMessage: errorMessage || this.locale.type
108✔
16
    });
17
  }
18

19
  rangeLength(
20
    minLength: number,
21
    maxLength: number,
22
    errorMessage: E | string = this.locale.rangeLength
3✔
23
  ) {
24
    super.pushRule({
3✔
25
      onValid: (value: string[]) => value.length >= minLength && value.length <= maxLength,
12✔
26
      errorMessage,
27
      params: { minLength, maxLength }
28
    });
29
    return this;
3✔
30
  }
31

32
  minLength(minLength: number, errorMessage: E | string = this.locale.minLength) {
6✔
33
    super.pushRule({
9✔
34
      onValid: value => value.length >= minLength,
18✔
35
      errorMessage,
36
      params: { minLength }
37
    });
38

39
    return this;
9✔
40
  }
41

42
  maxLength(maxLength: number, errorMessage: E | string = this.locale.maxLength) {
3✔
43
    super.pushRule({
3✔
44
      onValid: value => value.length <= maxLength,
6✔
45
      errorMessage,
46
      params: { maxLength }
47
    });
48
    return this;
3✔
49
  }
50

51
  unrepeatable(errorMessage: E | string = this.locale.unrepeatable) {
3✔
52
    super.pushRule({
6✔
53
      onValid: items => {
54
        const hash: PlainObject = {};
9✔
55
        for (const i in items) {
9✔
56
          if (hash[items[i]]) {
27✔
57
            return false;
6✔
58
          }
59
          hash[items[i]] = true;
21✔
60
        }
61
        return true;
3✔
62
      },
63
      errorMessage
64
    });
65

66
    return this;
6✔
67
  }
68

69
  of(type: MixedType<any, DataType, E>) {
70
    super.pushRule({
21✔
71
      onValid: (items, data, fieldName) => {
72
        const checkResults = items.map((value, index) => {
24✔
73
          const name = Array.isArray(fieldName)
66!
74
            ? [...fieldName, `[${index}]`]
75
            : [fieldName, `[${index}]`];
76

77
          return type.check(value, data, name as string[]);
66✔
78
        });
79
        const hasError = !!checkResults.find(item => item?.hasError);
39!
80

81
        return {
24✔
82
          hasError,
83
          array: checkResults
84
        } as CheckResult<string | E>;
85
      }
86
    });
87

88
    return this;
21✔
89
  }
90
}
91

92
export default function getArrayType<DataType = any, E = string>(errorMessage?: E) {
3✔
93
  return new ArrayType<DataType, E>(errorMessage);
54✔
94
}
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