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

oprajs / opra / 14419802659

12 Apr 2025 12:55PM UTC coverage: 82.088% (+4.2%) from 77.908%
14419802659

push

github

web-flow
Merge pull request #27 from oprajs/dev

Dev

3458 of 4432 branches covered (78.02%)

Branch coverage included in aggregate %.

16 of 16 new or added lines in 10 files covered. (100.0%)

1793 existing lines in 129 files now uncovered.

29424 of 35625 relevant lines covered (82.59%)

183.2 hits per line

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

88.73
/packages/common/src/document/data-type/primitive-types/string.type.ts
1
import { toString, type Validator, vg } from 'valgen';
1✔
2
import { DATATYPE_METADATA, DECODER, ENCODER } from '../../constants.js';
1✔
3
import { SimpleType } from '../simple-type.js';
1✔
4

1✔
5
@SimpleType({
1✔
6
  name: 'string',
1✔
7
  description: 'A sequence of characters',
1✔
8
  nameMappings: {
1✔
9
    js: 'string',
1✔
10
    json: 'string',
1✔
11
  },
1✔
12
})
1✔
13
export class StringType {
1✔
14
  constructor(properties?: Partial<StringType>) {
1✔
15
    if (properties) Object.assign(this, properties);
130!
16
  }
130✔
17

1✔
18
  @SimpleType.Attribute({
1✔
19
    description: 'Regex pattern to be used for validation',
1✔
20
  })
1✔
21
  pattern?: string | RegExp;
1✔
22

1✔
23
  @SimpleType.Attribute({
1✔
24
    description: 'Name of the pattern',
1✔
25
  })
1✔
26
  patternName?: string;
1✔
27

1✔
28
  @SimpleType.Attribute({
1✔
29
    description: 'Minimum number of characters',
1✔
30
  })
1✔
31
  minLength?: number;
1✔
32

1✔
33
  @SimpleType.Attribute({
1✔
34
    description: 'Minimum number of characters',
1✔
35
  })
1✔
36
  maxLength?: number;
1✔
37

1✔
38
  protected [DECODER](properties: Partial<this>): Validator {
1✔
39
    const x: Validator[] = [];
1,343✔
40
    if (properties.pattern) {
1,343✔
41
      let formatName: string | undefined = properties.patternName;
1✔
42
      if (!formatName) {
1!
43
        const meta = Reflect.getMetadata(
×
UNCOV
44
          DATATYPE_METADATA,
×
UNCOV
45
          Object.getPrototypeOf(this).constructor,
×
UNCOV
46
        );
×
47
        formatName = meta.name;
×
UNCOV
48
      }
×
49
      x.push(vg.matches(properties.pattern, { formatName }));
1✔
50
    }
1✔
51
    if (properties.minLength) x.push(vg.lengthMin(properties.minLength));
1,343✔
52
    if (properties.maxLength) x.push(vg.lengthMax(properties.maxLength));
1,343✔
53
    return x.length > 0
1,343✔
54
      ? vg.pipe([toString, ...x], { returnIndex: 0 })
3✔
55
      : toString;
1,340✔
56
  }
1,343✔
57

1✔
58
  protected [ENCODER](properties: Partial<this>): Validator {
1✔
59
    return this[DECODER](properties);
463✔
60
  }
463✔
61
}
1✔
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