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

Haixing-Hu / js-common-decorator / 1970a515-3d5d-49ef-bafd-31c9a52cf4e9

10 Nov 2024 05:00PM UTC coverage: 80.83% (-1.5%) from 82.353%
1970a515-3d5d-49ef-bafd-31c9a52cf4e9

push

circleci

Haixing-Hu
feat: make @Normalizable support normalization of enum class field

481 of 608 branches covered (79.11%)

Branch coverage included in aggregate %.

90 of 116 new or added lines in 19 files covered. (77.59%)

20 existing lines in 4 files now uncovered.

649 of 790 relevant lines covered (82.15%)

227.51 hits per line

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

66.67
/src/enum-normalizer.js
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
//    Copyright (c) 2022 - 2024.
4
//    Haixing Hu, Qubit Co. Ltd.
5
//
6
//    All rights reserved.
7
//
8
////////////////////////////////////////////////////////////////////////////////
9
import isEnumClass from './impl/utils/is-enum-class';
10

11
/**
12
 * The normalizer used to normalize the value of an enumeration.
13
 *
14
 * @param {function} EnumClass
15
 *     The constructor function  of an enumeration class.
16
 * @return {function(string): EnumClass}
17
 *     The normalizer function for the specified enumeration class.
18
 */
19
function enumNormalizer(EnumClass) {
20
  return (value) => {
2✔
21
    if (!isEnumClass(EnumClass)) {
2!
NEW
22
      throw new TypeError('The argument must be the constructor function of an '
×
23
        + 'enumeration class decorated by `@Enum`.');
24
    }
25
    return EnumClass.of(value);
2✔
26
  };
27
}
28

29
export default enumNormalizer;
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