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

Haixing-Hu / js-common-decorator / 416011cd-471d-4350-a9d5-aafb569cdeb0

22 Oct 2024 11:32AM UTC coverage: 83.06% (+0.1%) from 82.915%
416011cd-471d-4350-a9d5-aafb569cdeb0

push

circleci

Haixing-Hu
refactor: refactor createPage()

469 of 577 branches covered (81.28%)

Branch coverage included in aggregate %.

23 of 24 new or added lines in 4 files covered. (95.83%)

5 existing lines in 1 file now uncovered.

644 of 763 relevant lines covered (84.4%)

172.09 hits per line

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

88.89
/src/impl/model/create-page-impl.js
1
////////////////////////////////////////////////////////////////////////////////
2
import Json from '@haixing_hu/json';
3
import DefaultOptions from '../../default-options';
4
//
5
//    Copyright (c) 2022 - 2023.
6
//    Haixing Hu, Qubit Co. Ltd.
7
//
8
//    All rights reserved.
9
//
10
////////////////////////////////////////////////////////////////////////////////
11
import Page from '../../model/page';
12
import assignImpl from './assign-impl';
13
import isValidPageSource from './is-valid-page-source';
14

15
/**
16
 * Creates a Page object from the specified data.
17
 *
18
 * @param {function} Class
19
 *     The constructor of the class of the page content.
20
 * @param {object} page
21
 *     The data of the page.
22
 * @param {object} options
23
 *     the additional options for the creation. If this argument is
24
 *     `undefined` or `null`, the default options will be used. The default
25
 *     options can be retrieved by calling `DefaultOptions.get('assign')`.
26
 *     Available options are:
27
 *     - `normalize: boolean`, indicates whether to normalize this object
28
 *       after the assignment. The default value is `true`.
29
 *     - `convertNaming: boolean`, indicates whether to convert the naming
30
 *       style of the target object. The default value is `false`.
31
 *     - `sourceNamingStyle: NamingStyle`, the naming style of the source
32
 *       object. The default value is {@link LOWER_UNDERSCORE}.
33
 *     - `targetNamingStyle: NamingStyle`, the naming style of the target
34
 *       object. The default value is {@link LOWER_CAMEL}.
35
 *     - `targetTypes: object`, the additional information about types of
36
 *       fields of classes. The keys of this object are the path of the fields
37
 *       or sub-fields of the target object, the values are the type of the
38
 *       fields, represented as the constructor function of the type.
39
 *       The default value is `{}`.
40
 *     - `targetElementTypes: object`, the additional information about types of
41
 *       elements of fields of classes. The keys of this object are the path of
42
 *       the fields or sub-fields of the target object, the values are the type
43
 *       of the elements, represented as the constructor function of the type.
44
 *       The default value is `{}`.
45
 * @returns {Page}
46
 *     The created `Page` object.
47
 * @see Page
48
 * @author Haixing Hu
49
 * @private
50
 */
51
function createPageImpl(Class, page, options) {
52
  if (page === undefined || page === null) {
12✔
53
    return null;
2✔
54
  } else if (isValidPageSource(page, options)) {
10✔
55
    const result = new Page();
6✔
56
    const opt = { ...options };
6✔
57
    if (opt.targetElementTypes) {
6!
NEW
58
      opt.targetElementTypes['Page.content'] = Class;
×
59
    } else {
60
      opt.targetElementTypes = { 'Page.content': Class };
6✔
61
    }
62
    return assignImpl(Page, result, page, opt);
6✔
63
  } else {
64
    throw new TypeError(`Invalid page format: ${Json.stringify(page)}`);
4✔
65
  }
66
}
67

68
export default createPageImpl;
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