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

Haixing-Hu / js-common-decorator / 4a8f9cc9-54f8-4621-9cf9-09b62718bff8

26 Nov 2024 07:01AM UTC coverage: 80.514% (-0.3%) from 80.83%
4a8f9cc9-54f8-4621-9cf9-09b62718bff8

push

circleci

Haixing-Hu
feat: add Page.emptyPage() method

480 of 609 branches covered (78.82%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

2 existing lines in 1 file now uncovered.

648 of 792 relevant lines covered (81.82%)

226.94 hits per line

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

72.22
/src/impl/model/create-impl.js
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
//    Copyright (c) 2022 - 2023.
4
//    Haixing Hu, Qubit Co. Ltd.
5
//
6
//    All rights reserved.
7
//
8
////////////////////////////////////////////////////////////////////////////////
9
import assignImpl from './assign-impl';
10
import hasPrototypeFunction from '../utils/has-prototype-function';
11

12
/**
13
 * Creates an instance of a model class.
14
 *
15
 * @param {function} Class
16
 *     The constructor of a model class.
17
 * @param {object} obj
18
 *     The data object, usually obtained from a JSON object.
19
 * @param {object} options
20
 *     the additional options for the creation. If this argument is
21
 *     `undefined` or `null`, the default options will be used. The default
22
 *     options can be retrieved by calling `DefaultOptions.get('assign')`.
23
 *     Available options are:
24
 *     - `normalize: boolean`, indicates whether to normalize this object
25
 *       after the assignment. The default value is `true`.
26
 *     - `convertNaming: boolean`, indicates whether to convert the naming
27
 *       style of the target object. The default value is `false`.
28
 *     - `sourceNamingStyle: NamingStyle`, the naming style of the source
29
 *       object. The default value is {@link LOWER_UNDERSCORE}.
30
 *     - `targetNamingStyle: NamingStyle`, the naming style of the target
31
 *       object. The default value is {@link LOWER_CAMEL}.
32
 * @returns {Class | null}
33
 *     If the `obj` is `undefined` or `null`, returns `null`; otherwise, returns
34
 *     a new instance of the model class whose fields are initialized with the
35
 *     data in the `obj`.
36
 * @see DefaultOptions.get('assign')
37
 * @author Haixing Hu
38
 * @private
39
 */
40
function createImpl(Class, obj, options) {
41
  if (obj === undefined || obj === null) {
39✔
42
    return null;
6✔
43
  } else if (typeof obj !== 'object') {
33!
44
    throw new TypeError(`The first argument of ${Class.name}.create() must be an object.`);
×
45
  } else if (hasPrototypeFunction(Class, 'assign')) {
33!
46
    const result = new Class();
33✔
47
    result.assign(obj, options);
33✔
48
    return result;
32✔
49
  } else {
UNCOV
50
    const result = new Class();
×
UNCOV
51
    return assignImpl(Class, result, obj, options);
×
52
  }
53
}
54

55
export default createImpl;
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