1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.featurePath = exports.group = exports.pluralize = 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 | var STRING_DASHERIZE_REGEXP = /[ _]/g;
|
12 | var STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g;
|
13 | var STRING_CAMELIZE_REGEXP = /(-|_|\.|\s)+(.)?/g;
|
14 | var STRING_UNDERSCORE_REGEXP_1 = /([a-z\d])([A-Z]+)/g;
|
15 | var 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 | function decamelize(str) {
|
27 | return str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase();
|
28 | }
|
29 | exports.decamelize = decamelize;
|
30 | /**
|
31 | Replaces underscores, spaces, or camelCase with dashes.
|
32 |
|
33 | ```javascript
|
34 | dasherize('innerHTML'); // 'inner-html'
|
35 | dasherize('action_name'); // 'action-name'
|
36 | dasherize('css-class-name'); // 'css-class-name'
|
37 | dasherize('my favorite items'); // 'my-favorite-items'
|
38 | ```
|
39 | */
|
40 | function dasherize(str) {
|
41 | return decamelize(str || '').replace(STRING_DASHERIZE_REGEXP, '-');
|
42 | }
|
43 | exports.dasherize = dasherize;
|
44 | /**
|
45 | Returns the lowerCamelCase form of a string.
|
46 |
|
47 | ```javascript
|
48 | camelize('innerHTML'); // 'innerHTML'
|
49 | camelize('action_name'); // 'actionName'
|
50 | camelize('css-class-name'); // 'cssClassName'
|
51 | camelize('my favorite items'); // 'myFavoriteItems'
|
52 | camelize('My Favorite Items'); // 'myFavoriteItems'
|
53 | ```
|
54 | */
|
55 | function camelize(str) {
|
56 | return str
|
57 | .replace(STRING_CAMELIZE_REGEXP, function (_match, _separator, chr) {
|
58 | return chr ? chr.toUpperCase() : '';
|
59 | })
|
60 | .replace(/^([A-Z])/, function (match) { return match.toLowerCase(); });
|
61 | }
|
62 | exports.camelize = camelize;
|
63 | /**
|
64 | Returns the UpperCamelCase form of a string.
|
65 |
|
66 | ```javascript
|
67 | 'innerHTML'.classify(); // 'InnerHTML'
|
68 | 'action_name'.classify(); // 'ActionName'
|
69 | 'css-class-name'.classify(); // 'CssClassName'
|
70 | 'my favorite items'.classify(); // 'MyFavoriteItems'
|
71 | ```
|
72 | */
|
73 | function classify(str) {
|
74 | return str
|
75 | .split('.')
|
76 | .map(function (part) { return capitalize(camelize(part)); })
|
77 | .join('.');
|
78 | }
|
79 | exports.classify = classify;
|
80 | /**
|
81 | More general than decamelize. Returns the lower\_case\_and\_underscored
|
82 | form of a string.
|
83 |
|
84 | ```javascript
|
85 | 'innerHTML'.underscore(); // 'inner_html'
|
86 | 'action_name'.underscore(); // 'action_name'
|
87 | 'css-class-name'.underscore(); // 'css_class_name'
|
88 | 'my favorite items'.underscore(); // 'my_favorite_items'
|
89 | ```
|
90 | */
|
91 | function underscore(str) {
|
92 | return str
|
93 | .replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2')
|
94 | .replace(STRING_UNDERSCORE_REGEXP_2, '_')
|
95 | .toLowerCase();
|
96 | }
|
97 | exports.underscore = underscore;
|
98 | /**
|
99 | Returns the Capitalized form of a string
|
100 |
|
101 | ```javascript
|
102 | 'innerHTML'.capitalize() // 'InnerHTML'
|
103 | 'action_name'.capitalize() // 'Action_name'
|
104 | 'css-class-name'.capitalize() // 'Css-class-name'
|
105 | 'my favorite items'.capitalize() // 'My favorite items'
|
106 | ```
|
107 | */
|
108 | function capitalize(str) {
|
109 | return str.charAt(0).toUpperCase() + str.substring(1);
|
110 | }
|
111 | exports.capitalize = capitalize;
|
112 | /**
|
113 | Returns the plural form of a string
|
114 |
|
115 | ```javascript
|
116 | 'innerHTML'.pluralize() // 'innerHTMLs'
|
117 | 'action_name'.pluralize() // 'actionNames'
|
118 | 'css-class-name'.pluralize() // 'cssClassNames'
|
119 | 'regex'.pluralize() // 'regexes'
|
120 | 'user'.pluralize() // 'users'
|
121 | ```
|
122 | */
|
123 | function pluralize(str) {
|
124 | return camelize([/([^aeiou])y$/, /()fe?$/, /([^aeiou]o|[sxz]|[cs]h)$/].map(function (c, i) { return (str = str.replace(c, "$1".concat('iv'[i] || '', "e"))); }) && str + 's');
|
125 | }
|
126 | exports.pluralize = pluralize;
|
127 | function group(name, group) {
|
128 | return group ? "".concat(group, "/").concat(name) : name;
|
129 | }
|
130 | exports.group = group;
|
131 | function featurePath(group, flat, path, name) {
|
132 | if (group && !flat) {
|
133 | return "../../".concat(path, "/").concat(name, "/");
|
134 | }
|
135 | return group ? "../".concat(path, "/") : './';
|
136 | }
|
137 | exports.featurePath = featurePath;
|
138 | //# sourceMappingURL=strings.js.map |
\ | No newline at end of file |