atomic-fns 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/string/index.d.ts +190 -0
- package/dist/string/index.js +229 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
|
|
7
7
|
Stop shipping code built for browsers from 2015.
|
|
8
8
|
|
|
9
|
-
You may prefer this because
|
|
9
|
+
You may prefer this library because:
|
|
10
10
|
|
|
11
11
|
* **TypeScript & docs**: Includes type declaration files and js with JSDocs for best in class experience.
|
|
12
12
|
* **Zero deps**: Built from scratch with no runtime dependencies or polyfills.
|
|
13
13
|
* **ESNext**: Uses modern idiomatic syntax, data structures, and control flow techniques.
|
|
14
14
|
* **Modular**: Pick what you need. Supports tree-shaking, no side effects, and works with all bundlers.
|
|
15
15
|
* **Lazy**: Leverage generators, iterators, and functional composition.
|
|
16
|
-
* **Tests**: All modules have comprehensive test suites and
|
|
16
|
+
* **Tests**: All modules have comprehensive test suites and 100% test coverage.
|
|
17
17
|
|
|
18
18
|
## Docs
|
|
19
19
|
|
|
20
|
-
📖 Available at [
|
|
20
|
+
📖 Available at [atomic-fns](atomic-stack.github.io/atomic-fns)
|
|
21
21
|
|
|
22
22
|
## Get Started
|
|
23
23
|
|
|
@@ -69,6 +69,15 @@ When working with objects, functions in this library use these custom operators
|
|
|
69
69
|
|
|
70
70
|
[`Decimal`](https://atomic-stack.github.io/atomic-fns/classes/decimal.Decimal.html) provides support for correct rounded floating point arithmetic, with arbitrary precision.
|
|
71
71
|
|
|
72
|
+
This fixes precision issues with float arithmetic, for example:
|
|
73
|
+
```
|
|
74
|
+
0.1 + 0.1 + 0.1
|
|
75
|
+
// 0.30000000000000004
|
|
76
|
+
|
|
77
|
+
decimal('0.1').add('0.1').add('0.1').toNumber()
|
|
78
|
+
// 0.3
|
|
79
|
+
```
|
|
80
|
+
|
|
72
81
|
Some common base interfaces and typing patterns you may have seen like `Optional`, `Result`, `Comparable`, `Iterator`, and others.
|
|
73
82
|
|
|
74
83
|
### Sorted Containers
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module includes utilities for working with strings.
|
|
3
|
+
*
|
|
4
|
+
* @module string
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Converts only the first character of the given string to upper case. Note that the rest of the characters are preserved.
|
|
8
|
+
* @param {string} s The string
|
|
9
|
+
* @returns {string} Returns the sentence string.
|
|
10
|
+
* @example
|
|
11
|
+
```js
|
|
12
|
+
sentenceCase('a test')
|
|
13
|
+
// 'A test'
|
|
14
|
+
|
|
15
|
+
sentenceCase('TEST')
|
|
16
|
+
// 'TEST'
|
|
17
|
+
```
|
|
18
|
+
* @see {@link capitalize}
|
|
19
|
+
*/
|
|
20
|
+
export declare function sentenceCase(s: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Converts the first character of the given string to upper case and the rest to lower case.
|
|
23
|
+
* @param {string} s The string to capitalize
|
|
24
|
+
* @returns {string} Returns the capitalized string.
|
|
25
|
+
* @example
|
|
26
|
+
```js
|
|
27
|
+
capitalize('TEST')
|
|
28
|
+
// 'Test'
|
|
29
|
+
```
|
|
30
|
+
* @see {@link titleCase}
|
|
31
|
+
*/
|
|
32
|
+
export declare function capitalize(s: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Split a string into an array of its words.
|
|
35
|
+
* @param {string} s The string to split
|
|
36
|
+
* @param {RegExp | string} [pattern] The pattern to match words
|
|
37
|
+
* @returns {string[]} Returns the words array.
|
|
38
|
+
* @example
|
|
39
|
+
```js
|
|
40
|
+
words('lord of the rings')
|
|
41
|
+
// ['lord', 'of', 'the', 'rings']
|
|
42
|
+
```
|
|
43
|
+
*/
|
|
44
|
+
export declare function words(s: string, pattern?: RegExp | string): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Create a new string which is the concatenation of the words in the given input.
|
|
47
|
+
* @param {string} s The string to join
|
|
48
|
+
* @param {string} [sep=' '] The separator to use
|
|
49
|
+
* @returns {string} Returns the joined string.
|
|
50
|
+
* @example
|
|
51
|
+
```js
|
|
52
|
+
join('Lord Of The Rings', '-')
|
|
53
|
+
// 'Lord-Of-The-Rings'
|
|
54
|
+
```
|
|
55
|
+
*/
|
|
56
|
+
export declare function join(s: string, sep?: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Checks if a string contains only alphanumeric characters.
|
|
59
|
+
* @param {string} s The string
|
|
60
|
+
* @returns {boolean} Returns `true` if the string contains only alphanumeric.
|
|
61
|
+
* @example
|
|
62
|
+
```js
|
|
63
|
+
isAlnum('alpha1234')
|
|
64
|
+
// true
|
|
65
|
+
|
|
66
|
+
isAlnum('oops!')
|
|
67
|
+
// false
|
|
68
|
+
```
|
|
69
|
+
*/
|
|
70
|
+
export declare function isAlnum(s: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Checks if a string contains only alphabetic characters.
|
|
73
|
+
* @param {string} s The string
|
|
74
|
+
* @returns {boolean} Returns `true` if the string contains only alphabetic.
|
|
75
|
+
* @example
|
|
76
|
+
```js
|
|
77
|
+
isAlpha('alpha1234')
|
|
78
|
+
// false
|
|
79
|
+
|
|
80
|
+
isAlpha('letters')
|
|
81
|
+
// true
|
|
82
|
+
```
|
|
83
|
+
*/
|
|
84
|
+
export declare function isAlpha(s: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Checks if a string contains only numeric characters.
|
|
87
|
+
* @param {string} s The string
|
|
88
|
+
* @returns {boolean} Returns `true` if the string contains only numeric.
|
|
89
|
+
* @example
|
|
90
|
+
```js
|
|
91
|
+
isNumeric('alpha1234')
|
|
92
|
+
// false
|
|
93
|
+
|
|
94
|
+
isNumeric('1234')
|
|
95
|
+
// true
|
|
96
|
+
```
|
|
97
|
+
*/
|
|
98
|
+
export declare function isNumeric(s: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Returns a new string with only valid ASCII characters
|
|
101
|
+
* @param {string} s The string
|
|
102
|
+
* @returns {string} The ASCII characters in the given string
|
|
103
|
+
* @example
|
|
104
|
+
```js
|
|
105
|
+
asciify('äÄçÇéÉêPHP-MySQLöÖÐþúÚ')
|
|
106
|
+
// 'PHP-MySQL'
|
|
107
|
+
```
|
|
108
|
+
*/
|
|
109
|
+
export declare function asciify(s: string): string;
|
|
110
|
+
/**
|
|
111
|
+
* Replaces any accent characters in the string with non accents.
|
|
112
|
+
* @param {string} s The string
|
|
113
|
+
* @returns {string} The new string without accents
|
|
114
|
+
* @example
|
|
115
|
+
```js
|
|
116
|
+
removeAccents('Antoine de Saint-Exupéry')
|
|
117
|
+
// 'Antoine de Saint-Exupery'
|
|
118
|
+
```
|
|
119
|
+
*/
|
|
120
|
+
export declare function removeAccents(s: string): string;
|
|
121
|
+
/**
|
|
122
|
+
* Capitalizes the first letter of every word in the string.
|
|
123
|
+
* @param {string} s The string to capitalize
|
|
124
|
+
* @returns {string} Returns the title cased string.
|
|
125
|
+
* @example
|
|
126
|
+
```js
|
|
127
|
+
titleCase('lord of the rings')
|
|
128
|
+
// 'Lord Of The Rings'
|
|
129
|
+
```
|
|
130
|
+
@see {@link capitalize}
|
|
131
|
+
*/
|
|
132
|
+
export declare function titleCase(s: string): string;
|
|
133
|
+
/**
|
|
134
|
+
* Converts the string to camel case.
|
|
135
|
+
* @param {string} s The string to convert
|
|
136
|
+
* @returns {string} Returns the camel cased string.
|
|
137
|
+
* @example
|
|
138
|
+
```js
|
|
139
|
+
camelCase('Equipment class name')
|
|
140
|
+
// 'equipmentClassName'
|
|
141
|
+
```
|
|
142
|
+
*/
|
|
143
|
+
export declare function camelCase(s: string): string;
|
|
144
|
+
/**
|
|
145
|
+
* Converts the string to Pascal case.
|
|
146
|
+
* @param {string} s The string to convert
|
|
147
|
+
* @returns {string} Returns the Pascal cased string.
|
|
148
|
+
* @example
|
|
149
|
+
```js
|
|
150
|
+
pascalCase('equipment class name')
|
|
151
|
+
// 'EquipmentClassName'
|
|
152
|
+
```
|
|
153
|
+
*/
|
|
154
|
+
export declare function pascalCase(s: string): string;
|
|
155
|
+
/**
|
|
156
|
+
* Converts the string to snake case.
|
|
157
|
+
* @param {string} s The string to convert
|
|
158
|
+
* @returns {string} Returns the snake cased string.
|
|
159
|
+
* @example
|
|
160
|
+
```js
|
|
161
|
+
snakeCase('Equipment Class Name')
|
|
162
|
+
// 'equipment_class_name'
|
|
163
|
+
```
|
|
164
|
+
*/
|
|
165
|
+
export declare function snakeCase(s: string): string;
|
|
166
|
+
/**
|
|
167
|
+
* Converts a string to kebab case.
|
|
168
|
+
* @param {string} s The string
|
|
169
|
+
* @returns {string} Returns the kebab cased string.
|
|
170
|
+
* @example
|
|
171
|
+
```js
|
|
172
|
+
kebabCase('Equipment Class Name')
|
|
173
|
+
// 'equipment-class-name'
|
|
174
|
+
|
|
175
|
+
kebabCase('equipment_class_name')
|
|
176
|
+
// 'equipment-class-name'
|
|
177
|
+
```
|
|
178
|
+
*/
|
|
179
|
+
export declare function kebabCase(s: string): string;
|
|
180
|
+
/**
|
|
181
|
+
* Returns a url-safe slug for the given string. Note that by default it will preserve any capitalization in the given string.
|
|
182
|
+
* @param {string} s The string
|
|
183
|
+
* @returns {string} A url-safe slug version of the string
|
|
184
|
+
* @example
|
|
185
|
+
```js
|
|
186
|
+
slugify('Antoine de Saint-Exupéry')
|
|
187
|
+
// 'Antoine-de-Saint-Exupery'
|
|
188
|
+
```
|
|
189
|
+
*/
|
|
190
|
+
export declare function slugify(s: string): string;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module includes utilities for working with strings.
|
|
3
|
+
*
|
|
4
|
+
* @module string
|
|
5
|
+
*/
|
|
6
|
+
const WORDS_REGEX = // eslint-disable-next-line no-control-regex
|
|
7
|
+
/[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?:['’](?:d|ll|m|re|s|t|ve))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:D|LL|M|RE|S|T|VE))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:d|ll|m|re|s|t|ve))?|[A-Z\xc0-\xd6\xd8-\xde]+(?:['’](?:D|LL|M|RE|S|T|VE))?|\d*(?:1ST|2ND|3RD|(?![123])\dTH)(?=\b|[a-z_])|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|[A-Z_])|\d+|(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?)*/g;
|
|
8
|
+
/**
|
|
9
|
+
* Converts only the first character of the given string to upper case. Note that the rest of the characters are preserved.
|
|
10
|
+
* @param {string} s The string
|
|
11
|
+
* @returns {string} Returns the sentence string.
|
|
12
|
+
* @example
|
|
13
|
+
```js
|
|
14
|
+
sentenceCase('a test')
|
|
15
|
+
// 'A test'
|
|
16
|
+
|
|
17
|
+
sentenceCase('TEST')
|
|
18
|
+
// 'TEST'
|
|
19
|
+
```
|
|
20
|
+
* @see {@link capitalize}
|
|
21
|
+
*/
|
|
22
|
+
export function sentenceCase(s) {
|
|
23
|
+
return `${(s[0] || '').toLocaleUpperCase()}${s.substring(1) || ''}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converts the first character of the given string to upper case and the rest to lower case.
|
|
27
|
+
* @param {string} s The string to capitalize
|
|
28
|
+
* @returns {string} Returns the capitalized string.
|
|
29
|
+
* @example
|
|
30
|
+
```js
|
|
31
|
+
capitalize('TEST')
|
|
32
|
+
// 'Test'
|
|
33
|
+
```
|
|
34
|
+
* @see {@link titleCase}
|
|
35
|
+
*/
|
|
36
|
+
export function capitalize(s) {
|
|
37
|
+
return `${(s[0] || '').toLocaleUpperCase()}${(s.substring(1) || '').toLocaleLowerCase()}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Split a string into an array of its words.
|
|
41
|
+
* @param {string} s The string to split
|
|
42
|
+
* @param {RegExp | string} [pattern] The pattern to match words
|
|
43
|
+
* @returns {string[]} Returns the words array.
|
|
44
|
+
* @example
|
|
45
|
+
```js
|
|
46
|
+
words('lord of the rings')
|
|
47
|
+
// ['lord', 'of', 'the', 'rings']
|
|
48
|
+
```
|
|
49
|
+
*/
|
|
50
|
+
export function words(s, pattern) {
|
|
51
|
+
if (pattern != null)
|
|
52
|
+
return s.split(pattern);
|
|
53
|
+
return s.match(WORDS_REGEX) || [];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a new string which is the concatenation of the words in the given input.
|
|
57
|
+
* @param {string} s The string to join
|
|
58
|
+
* @param {string} [sep=' '] The separator to use
|
|
59
|
+
* @returns {string} Returns the joined string.
|
|
60
|
+
* @example
|
|
61
|
+
```js
|
|
62
|
+
join('Lord Of The Rings', '-')
|
|
63
|
+
// 'Lord-Of-The-Rings'
|
|
64
|
+
```
|
|
65
|
+
*/
|
|
66
|
+
export function join(s, sep = ' ') {
|
|
67
|
+
return words(s).join(sep);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Checks if a string contains only alphanumeric characters.
|
|
71
|
+
* @param {string} s The string
|
|
72
|
+
* @returns {boolean} Returns `true` if the string contains only alphanumeric.
|
|
73
|
+
* @example
|
|
74
|
+
```js
|
|
75
|
+
isAlnum('alpha1234')
|
|
76
|
+
// true
|
|
77
|
+
|
|
78
|
+
isAlnum('oops!')
|
|
79
|
+
// false
|
|
80
|
+
```
|
|
81
|
+
*/
|
|
82
|
+
export function isAlnum(s) {
|
|
83
|
+
return /^[\p{L}\p{N}]+$/gu.test(s);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Checks if a string contains only alphabetic characters.
|
|
87
|
+
* @param {string} s The string
|
|
88
|
+
* @returns {boolean} Returns `true` if the string contains only alphabetic.
|
|
89
|
+
* @example
|
|
90
|
+
```js
|
|
91
|
+
isAlpha('alpha1234')
|
|
92
|
+
// false
|
|
93
|
+
|
|
94
|
+
isAlpha('letters')
|
|
95
|
+
// true
|
|
96
|
+
```
|
|
97
|
+
*/
|
|
98
|
+
export function isAlpha(s) {
|
|
99
|
+
return /^[\p{L}]+$/gu.test(s);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Checks if a string contains only numeric characters.
|
|
103
|
+
* @param {string} s The string
|
|
104
|
+
* @returns {boolean} Returns `true` if the string contains only numeric.
|
|
105
|
+
* @example
|
|
106
|
+
```js
|
|
107
|
+
isNumeric('alpha1234')
|
|
108
|
+
// false
|
|
109
|
+
|
|
110
|
+
isNumeric('1234')
|
|
111
|
+
// true
|
|
112
|
+
```
|
|
113
|
+
*/
|
|
114
|
+
export function isNumeric(s) {
|
|
115
|
+
return /^[\p{N}]+$/gu.test(s);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Returns a new string with only valid ASCII characters
|
|
119
|
+
* @param {string} s The string
|
|
120
|
+
* @returns {string} The ASCII characters in the given string
|
|
121
|
+
* @example
|
|
122
|
+
```js
|
|
123
|
+
asciify('äÄçÇéÉêPHP-MySQLöÖÐþúÚ')
|
|
124
|
+
// 'PHP-MySQL'
|
|
125
|
+
```
|
|
126
|
+
*/
|
|
127
|
+
export function asciify(s) {
|
|
128
|
+
// eslint-disable-next-line no-control-regex
|
|
129
|
+
return s.replace(/[^\x00-\x7F]/g, '');
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Replaces any accent characters in the string with non accents.
|
|
133
|
+
* @param {string} s The string
|
|
134
|
+
* @returns {string} The new string without accents
|
|
135
|
+
* @example
|
|
136
|
+
```js
|
|
137
|
+
removeAccents('Antoine de Saint-Exupéry')
|
|
138
|
+
// 'Antoine de Saint-Exupery'
|
|
139
|
+
```
|
|
140
|
+
*/
|
|
141
|
+
export function removeAccents(s) {
|
|
142
|
+
return s.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Capitalizes the first letter of every word in the string.
|
|
146
|
+
* @param {string} s The string to capitalize
|
|
147
|
+
* @returns {string} Returns the title cased string.
|
|
148
|
+
* @example
|
|
149
|
+
```js
|
|
150
|
+
titleCase('lord of the rings')
|
|
151
|
+
// 'Lord Of The Rings'
|
|
152
|
+
```
|
|
153
|
+
@see {@link capitalize}
|
|
154
|
+
*/
|
|
155
|
+
export function titleCase(s) {
|
|
156
|
+
return words(s)
|
|
157
|
+
.map((word) => capitalize(word))
|
|
158
|
+
.join(' ');
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Converts the string to camel case.
|
|
162
|
+
* @param {string} s The string to convert
|
|
163
|
+
* @returns {string} Returns the camel cased string.
|
|
164
|
+
* @example
|
|
165
|
+
```js
|
|
166
|
+
camelCase('Equipment class name')
|
|
167
|
+
// 'equipmentClassName'
|
|
168
|
+
```
|
|
169
|
+
*/
|
|
170
|
+
export function camelCase(s) {
|
|
171
|
+
return words(s).reduce((acc, next) => `${acc}${!acc ? next.toLowerCase() : next[0].toUpperCase() + next.slice(1).toLowerCase()}`, '');
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Converts the string to Pascal case.
|
|
175
|
+
* @param {string} s The string to convert
|
|
176
|
+
* @returns {string} Returns the Pascal cased string.
|
|
177
|
+
* @example
|
|
178
|
+
```js
|
|
179
|
+
pascalCase('equipment class name')
|
|
180
|
+
// 'EquipmentClassName'
|
|
181
|
+
```
|
|
182
|
+
*/
|
|
183
|
+
export function pascalCase(s) {
|
|
184
|
+
return sentenceCase(camelCase(s));
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Converts the string to snake case.
|
|
188
|
+
* @param {string} s The string to convert
|
|
189
|
+
* @returns {string} Returns the snake cased string.
|
|
190
|
+
* @example
|
|
191
|
+
```js
|
|
192
|
+
snakeCase('Equipment Class Name')
|
|
193
|
+
// 'equipment_class_name'
|
|
194
|
+
```
|
|
195
|
+
*/
|
|
196
|
+
export function snakeCase(s) {
|
|
197
|
+
return join(s, '_').toLowerCase();
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Converts a string to kebab case.
|
|
201
|
+
* @param {string} s The string
|
|
202
|
+
* @returns {string} Returns the kebab cased string.
|
|
203
|
+
* @example
|
|
204
|
+
```js
|
|
205
|
+
kebabCase('Equipment Class Name')
|
|
206
|
+
// 'equipment-class-name'
|
|
207
|
+
|
|
208
|
+
kebabCase('equipment_class_name')
|
|
209
|
+
// 'equipment-class-name'
|
|
210
|
+
```
|
|
211
|
+
*/
|
|
212
|
+
export function kebabCase(s) {
|
|
213
|
+
return join(s, '-').toLowerCase();
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Returns a url-safe slug for the given string. Note that by default it will preserve any capitalization in the given string.
|
|
217
|
+
* @param {string} s The string
|
|
218
|
+
* @returns {string} A url-safe slug version of the string
|
|
219
|
+
* @example
|
|
220
|
+
```js
|
|
221
|
+
slugify('Antoine de Saint-Exupéry')
|
|
222
|
+
// 'Antoine-de-Saint-Exupery'
|
|
223
|
+
```
|
|
224
|
+
*/
|
|
225
|
+
export function slugify(s) {
|
|
226
|
+
const slug = join(removeAccents(s), '-');
|
|
227
|
+
const urlSafe = slug.replace(/[^a-zA-Z0-9-_]/g, '');
|
|
228
|
+
return urlSafe;
|
|
229
|
+
}
|