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

ckeditor / ckeditor5-package-generator / #765

pending completion
#765

travis-ci

117 of 117 branches covered (100.0%)

Branch coverage included in aggregate %.

416 of 416 relevant lines covered (100.0%)

8.97 hits per line

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

100.0
/packages/ckeditor5-package-generator/lib/utils/get-package-name-formats.js
1
/**
2
 * @license Copyright (c) 2020-2025, CKSource Holding sp. z o.o. All rights reserved.
3
 * For licensing, see LICENSE.md.
4
 */
5

6
const PARTS_REGEXP = /[0-9]+|[A-Za-z][a-z]*/g;
7

8
/**
1✔
9
 * This function returns an object with two properties: "package" and "plugin". Values of those properties
10
 * are object that contain the names formatted in different formats. If "pluginName" was not provided,
11
 * values for "plugin" will be the same as the "package" ones.
12
 *
13
 * @param {String} packageName
14
 * @param {String|undefined} pluginName
15
 * @returns {FormattedNames}
16
 */
17
export default function getPackageNameFormats( packageName, pluginName ) {
18
        return {
19
                package: format( packageName ),
1✔
20
                plugin: format( pluginName || packageName )
10✔
21
        };
22
}
16✔
23

24
/**
25
 * @param {String} name
26
 * @returns {FormattedName}
27
 */
28
function format( name ) {
29
        // Removing the scope and prefix in case of the package name.
30
        const raw = name.split( 'ckeditor5-' ).pop();
31

32
        // Separating the name into its components.
20✔
33
        const parts = raw.match( PARTS_REGEXP )
34
                // Unifying letter size in case of the plugin name.
35
                .map( part => part.toLowerCase() );
20✔
36

37
        return {
47✔
38
                raw,
39
                fullName: name,
20✔
40
                spacedOut: toSpacedOut( parts ),
41
                camelCase: toCamelCase( parts ),
42
                pascalCase: toPascalCase( parts ),
43
                lowerCaseMerged: parts.join( '' )
44
        };
45
}
46

47
/**
48
 * @param {Array<String>} parts
49
 * @returns {String}
50
 */
51
function toPascalCase( parts ) {
52
        return parts.map( uppercaseFirstChar ).join( '' );
53
}
40✔
54

55
/**
56
 * @param {Array<String>} parts
57
 * @returns {String}
58
 */
59
function toCamelCase( parts ) {
60
        const pascalCase = toPascalCase( parts );
61

20✔
62
        return pascalCase.charAt( 0 ).toLowerCase() + pascalCase.slice( 1 );
63
}
20✔
64

65
/**
66
 * @param {Array<String>} parts
67
 * @returns {String}
68
 */
69
function toSpacedOut( parts ) {
70
        return uppercaseFirstChar( parts.join( ' ' ) );
71
}
20✔
72

73
/**
74
 * @param {String} string
75
 * @returns {String}
76
 */
77
function uppercaseFirstChar( string ) {
78
        return string.charAt( 0 ).toUpperCase() + string.slice( 1 );
79
}
114✔
80

81
/**
82
 * @typedef {Object} FormattedNames
83
 *
84
 * @property {FormattedName} package
85
 *
86
 * @property {FormattedName} plugin
87
 */
88

89
/**
90
 * @typedef {Object} FormattedName
91
 *
92
 * @property {String} raw super-feature-name
93
 *
94
 * @property {String} full @scope/ckeditor5-super-feature-name
95
 *
96
 * @property {String} spacedOut Super feature name
97
 *
98
 * @property {String} camelCase superFeatureName
99
 *
100
 * @property {String} pascalCase SuperFeatureName
101
 *
102
 * @property {String} lowerCaseMerged superfeaturename
103
 */
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