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

Haixing-Hu / js-common-decorator / 19554512-8fec-4ca3-b10e-185456332dd1

17 Oct 2024 03:09AM UTC coverage: 82.486% (-1.9%) from 84.405%
19554512-8fec-4ca3-b10e-185456332dd1

push

circleci

Haixing-Hu
build: specifies files of deployment

441 of 549 branches covered (80.33%)

Branch coverage included in aggregate %.

614 of 730 relevant lines covered (84.11%)

156.93 hits per line

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

83.33
/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 { requirePrototypeMethod } from '../utils';
10

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

50
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

© 2026 Coveralls, Inc