1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.featurePath = exports.group = exports.capitalize = exports.underscore = exports.classify = exports.camelize = exports.dasherize = exports.decamelize = void 0;
|
4 | /**
|
5 | * @license
|
6 | * Copyright Google Inc. All Rights Reserved.
|
7 | *
|
8 | * Use of this source code is governed by an MIT-style license that can be
|
9 | * found in the LICENSE file at https://angular.io/license
|
10 | */
|
11 | const STRING_DASHERIZE_REGEXP = /[ _.]/g;
|
12 | const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g;
|
13 | const STRING_CAMELIZE_REGEXP = /(-|_|\.|\s)+(.)?/g;
|
14 | const STRING_UNDERSCORE_REGEXP_1 = /([a-z\d])([A-Z]+)/g;
|
15 | const STRING_UNDERSCORE_REGEXP_2 = /-|\s+/g;
|
16 | /**
|
17 | * Converts a camelized string into all lower case separated by underscores.
|
18 | *
|
19 | ```javascript
|
20 | decamelize('innerHTML'); // 'inner_html'
|
21 | decamelize('action_name'); // 'action_name'
|
22 | decamelize('css-class-name'); // 'css-class-name'
|
23 | decamelize('my favorite items'); // 'my favorite items'
|
24 | ```
|
25 |
|
26 | @method decamelize
|
27 | @param {String} str The string to decamelize.
|
28 | @return {String} the decamelized string.
|
29 | */
|
30 | function decamelize(str) {
|
31 | return str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase();
|
32 | }
|
33 | exports.decamelize = decamelize;
|
34 | /**
|
35 | Replaces underscores, spaces, periods, or camelCase with dashes.
|
36 |
|
37 | ```javascript
|
38 | dasherize('innerHTML'); // 'inner-html'
|
39 | dasherize('action_name'); // 'action-name'
|
40 | dasherize('css-class-name'); // 'css-class-name'
|
41 | dasherize('my favorite items'); // 'my-favorite-items'
|
42 | dasherize('nrwl.io'); // 'nrwl-io'
|
43 | ```
|
44 |
|
45 | @method dasherize
|
46 | @param {String} str The string to dasherize.
|
47 | @return {String} the dasherized string.
|
48 | */
|
49 | function dasherize(str) {
|
50 | return decamelize(str || '').replace(STRING_DASHERIZE_REGEXP, '-');
|
51 | }
|
52 | exports.dasherize = dasherize;
|
53 | /**
|
54 | Returns the lowerCamelCase form of a string.
|
55 |
|
56 | ```javascript
|
57 | camelize('innerHTML'); // 'innerHTML'
|
58 | camelize('action_name'); // 'actionName'
|
59 | camelize('css-class-name'); // 'cssClassName'
|
60 | camelize('my favorite items'); // 'myFavoriteItems'
|
61 | camelize('My Favorite Items'); // 'myFavoriteItems'
|
62 | ```
|
63 |
|
64 | @method camelize
|
65 | @param {String} str The string to camelize.
|
66 | @return {String} the camelized string.
|
67 | */
|
68 | function camelize(str) {
|
69 | return str
|
70 | .replace(STRING_CAMELIZE_REGEXP, (_match, _separator, chr) => {
|
71 | return chr ? chr.toUpperCase() : '';
|
72 | })
|
73 | .replace(/^([A-Z])/, (match) => match.toLowerCase());
|
74 | }
|
75 | exports.camelize = camelize;
|
76 | /**
|
77 | Returns the UpperCamelCase form of a string.
|
78 |
|
79 | ```javascript
|
80 | 'innerHTML'.classify(); // 'InnerHTML'
|
81 | 'action_name'.classify(); // 'ActionName'
|
82 | 'css-class-name'.classify(); // 'CssClassName'
|
83 | 'my favorite items'.classify(); // 'MyFavoriteItems'
|
84 | ```
|
85 |
|
86 | @method classify
|
87 | @param {String} str the string to classify
|
88 | @return {String} the classified string
|
89 | */
|
90 | function classify(str) {
|
91 | return str
|
92 | .split('.')
|
93 | .map((part) => capitalize(camelize(part)))
|
94 | .join('.');
|
95 | }
|
96 | exports.classify = classify;
|
97 | /**
|
98 | More general than decamelize. Returns the lower\_case\_and\_underscored
|
99 | form of a string.
|
100 |
|
101 | ```javascript
|
102 | 'innerHTML'.underscore(); // 'inner_html'
|
103 | 'action_name'.underscore(); // 'action_name'
|
104 | 'css-class-name'.underscore(); // 'css_class_name'
|
105 | 'my favorite items'.underscore(); // 'my_favorite_items'
|
106 | ```
|
107 |
|
108 | @method underscore
|
109 | @param {String} str The string to underscore.
|
110 | @return {String} the underscored string.
|
111 | */
|
112 | function underscore(str) {
|
113 | return str
|
114 | .replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2')
|
115 | .replace(STRING_UNDERSCORE_REGEXP_2, '_')
|
116 | .toLowerCase();
|
117 | }
|
118 | exports.underscore = underscore;
|
119 | /**
|
120 | Returns the Capitalized form of a string
|
121 |
|
122 | ```javascript
|
123 | 'innerHTML'.capitalize() // 'InnerHTML'
|
124 | 'action_name'.capitalize() // 'Action_name'
|
125 | 'css-class-name'.capitalize() // 'Css-class-name'
|
126 | 'my favorite items'.capitalize() // 'My favorite items'
|
127 | ```
|
128 |
|
129 | @method capitalize
|
130 | @param {String} str The string to capitalize.
|
131 | @return {String} The capitalized string.
|
132 | */
|
133 | function capitalize(str) {
|
134 | return str.charAt(0).toUpperCase() + str.slice(1);
|
135 | }
|
136 | exports.capitalize = capitalize;
|
137 | function group(name, group) {
|
138 | return group ? `${group}/${name}` : name;
|
139 | }
|
140 | exports.group = group;
|
141 | function featurePath(group, flat, path, name) {
|
142 | if (group && !flat) {
|
143 | return `../../${path}/${name}/`;
|
144 | }
|
145 | return group ? `../${path}/` : './';
|
146 | }
|
147 | exports.featurePath = featurePath;
|
148 | //# sourceMappingURL=strings.js.map |
\ | No newline at end of file |