Skip to main content

conform/
make.rs

1use inflections::Inflect;
2
3/// Removes leading and trailing whitespaces.
4///
5/// # Examples
6///
7/// ```
8/// use conform::make::trim;
9///
10/// assert_eq!(trim("  foo  "), "foo".to_string());
11/// ```
12pub fn trim(string: &str) -> String {
13  string.trim().to_string()
14}
15
16/// Removes leading whitespaces.
17///
18/// # Examples
19///
20/// ```
21/// use conform::make::trim_left;
22///
23/// assert_eq!(trim_left("  foo  "), "foo  ".to_string());
24/// ```
25pub fn trim_left(string: &str) -> String {
26  string.trim_left().to_string()
27}
28
29/// Removes trailing whitespaces.
30///
31/// # Examples
32///
33/// ```
34/// use conform::make::trim_right;
35///
36/// assert_eq!(trim_right("  foo  "), "  foo".to_string());
37/// ```
38pub fn trim_right(string: &str) -> String {
39  string.trim_right().to_string()
40}
41
42/// Converts any case into lower case ignoring separators.
43///
44/// # Examples
45///
46/// ```
47/// use conform::make::lower;
48///
49/// assert_eq!(lower("Foo-Bar"), "foo-bar".to_string());
50/// ```
51pub fn lower(string: &str) -> String {
52  string.to_lowercase()
53}
54
55/// Converts any case into UPPER CASE ignoring separators.
56///
57/// # Examples
58///
59/// ```
60/// use conform::make::upper;
61///
62/// assert_eq!(upper("Foo-Bar"), "FOO-BAR".to_string());
63/// ```
64pub fn upper(string: &str) -> String {
65  string.to_uppercase()
66}
67
68/// Converts any case into traditional sentence case without capitalizing the first letter.
69///
70/// # Examples
71///
72/// ```
73/// use conform::make::sentence;
74///
75/// assert_eq!(sentence("Foo Bar"), "foo bar".to_string());
76/// ```
77pub fn sentence(string: &str) -> String {
78  string.to_sentence_case()
79}
80
81/// Converts any case into title case where *every* word is capitalized.
82///
83/// # Examples
84///
85/// ```
86/// use conform::make::title;
87///
88/// assert_eq!(title("foo bar"), "Foo Bar".to_string());
89/// ```
90pub fn title(string: &str) -> String {
91  string.to_title_case()
92}
93
94/// Converts any case into camelCase.
95///
96/// # Examples
97///
98/// ```
99/// use conform::make::camel;
100///
101/// assert_eq!(camel("foo bar"), "fooBar".to_string());
102/// ```
103pub fn camel(string: &str) -> String {
104  string.to_camel_case()
105}
106
107/// Converts any case into PascalCase.
108///
109/// # Examples
110///
111/// ```
112/// use conform::make::pascal;
113///
114/// assert_eq!(pascal("foo bar"), "FooBar".to_string());
115/// ```
116pub fn pascal(string: &str) -> String {
117  string.to_pascal_case()
118}
119
120/// Converts any case into kebab-case.
121///
122/// # Examples
123///
124/// ```
125/// use conform::make::kebab;
126///
127/// assert_eq!(kebab("Foo Bar"), "foo-bar".to_string());
128/// ```
129pub fn kebab(string: &str) -> String {
130  string.to_kebab_case()
131}
132
133/// Converts any case into Train-Case.
134///
135/// # Examples
136///
137/// ```
138/// use conform::make::train;
139///
140/// assert_eq!(train("foo bar"), "Foo-Bar".to_string());
141/// ```
142pub fn train(string: &str) -> String {
143  string.to_train_case()
144}
145
146/// Converts any case into snake_case.
147///
148/// # Examples
149///
150/// ```
151/// use conform::make::snake;
152///
153/// assert_eq!(snake("Foo Bar"), "foo_bar".to_string());
154/// ```
155pub fn snake(string: &str) -> String {
156  string.to_snake_case()
157}
158
159/// Converts any case into CONSTANT_CASE.
160///
161/// # Examples
162///
163/// ```
164/// use conform::make::constant;
165///
166/// assert_eq!(constant("Foo Bar"), "FOO_BAR".to_string());
167/// ```
168pub fn constant(string: &str) -> String {
169  string.to_constant_case()
170}