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

Haixing-Hu / js-common-decorator / 214d62ca-32aa-44ba-af6c-f0078b9541b4

29 Oct 2024 06:30PM UTC coverage: 82.353% (-0.7%) from 83.06%
214d62ca-32aa-44ba-af6c-f0078b9541b4

push

circleci

Haixing-Hu
build: upgrade dependencies and rebuild the library

473 of 581 branches covered (81.41%)

Branch coverage included in aggregate %.

633 of 762 relevant lines covered (83.07%)

174.02 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
//
3
//    Copyright (c) 2022 - 2023.
4
//    Haixing Hu, Qubit Co. Ltd.
5
//
6
//    All rights reserved.
7
//
8
////////////////////////////////////////////////////////////////////////////////
9
import Json from '@haixing_hu/json';
10
import Page from '../../model/page';
11
import assignImpl from './assign-impl';
12
import isValidPageSource from './is-valid-page-source';
13

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

67
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