dce-reactkit 3.6.14 → 3.6.15
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.
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefix a word or name with "a" or "an" depending on whether it starts with a
|
|
3
|
+
* vowel or not
|
|
4
|
+
* @author Gabe Abrams
|
|
5
|
+
* @param text the text to prefix
|
|
6
|
+
* @param capitalize whether to capitalize the "A" or "An"
|
|
7
|
+
* @returns the text prefixed with "a" or "an"
|
|
8
|
+
*/
|
|
9
|
+
declare const prefixWithAOrAn: (text: string, capitalize?: boolean) => string;
|
|
10
|
+
export default prefixWithAOrAn;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefix a word or name with "a" or "an" depending on whether it starts with a
|
|
3
|
+
* vowel or not
|
|
4
|
+
* @author Gabe Abrams
|
|
5
|
+
* @param text the text to prefix
|
|
6
|
+
* @param capitalize whether to capitalize the "A" or "An"
|
|
7
|
+
* @returns the text prefixed with "a" or "an"
|
|
8
|
+
*/
|
|
9
|
+
declare const prefixWithAOrAn: (text: string, capitalize?: boolean) => string;
|
|
10
|
+
export default prefixWithAOrAn;
|
package/package.json
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Constants
|
|
2
|
+
const VOWELS = ['a', 'e', 'i', 'o', 'u'];
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Prefix a word or name with "a" or "an" depending on whether it starts with a
|
|
6
|
+
* vowel or not
|
|
7
|
+
* @author Gabe Abrams
|
|
8
|
+
* @param text the text to prefix
|
|
9
|
+
* @param capitalize whether to capitalize the "A" or "An"
|
|
10
|
+
* @returns the text prefixed with "a" or "an"
|
|
11
|
+
*/
|
|
12
|
+
const prefixWithAOrAn = (text: string, capitalize = false): string => {
|
|
13
|
+
// Get the first letter
|
|
14
|
+
const firstLetter = text.charAt(0).toLowerCase();
|
|
15
|
+
|
|
16
|
+
// Check if starts with vowel
|
|
17
|
+
const startsWithVowel = VOWELS.includes(firstLetter);
|
|
18
|
+
|
|
19
|
+
// Determine prefix
|
|
20
|
+
let prefix = startsWithVowel ? 'an' : 'a';
|
|
21
|
+
if (capitalize) {
|
|
22
|
+
prefix = prefix.charAt(0).toUpperCase() + prefix.substring(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Return the text prefixed with "a" or "an"
|
|
26
|
+
return `${prefix} ${text}`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default prefixWithAOrAn;
|