@8ms/helpers 2.0.30 → 2.0.31
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/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/string/getCapitalised.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCapitalised = void 0;
|
|
4
|
+
const reservedWords_1 = require("./reservedWords");
|
|
4
5
|
/**
|
|
5
6
|
* Convert a string into Capitalised Text.
|
|
6
7
|
* https://stackoverflow.com/a/196991/2664955
|
|
@@ -10,6 +11,12 @@ const getCapitalised = (input, split = "_") => {
|
|
|
10
11
|
return input
|
|
11
12
|
.replace(regex, " ")
|
|
12
13
|
.replace(/\w\S*/g, function (txt) {
|
|
14
|
+
// Check if individual word is reserved
|
|
15
|
+
const reservedWord = (0, reservedWords_1.isReservedWord)(txt);
|
|
16
|
+
if (reservedWord) {
|
|
17
|
+
return reservedWord;
|
|
18
|
+
}
|
|
19
|
+
// Regular capitalization for non-reserved words
|
|
13
20
|
return txt.charAt(0)
|
|
14
21
|
.toUpperCase() + txt.substr(1)
|
|
15
22
|
.toLowerCase();
|
package/string/getProperCase.js
CHANGED
|
@@ -1,25 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getProperCase = void 0;
|
|
4
|
+
const reservedWords_1 = require("./reservedWords");
|
|
4
5
|
/**
|
|
5
6
|
* Return a string "With Proper Casing".
|
|
6
7
|
*/
|
|
7
8
|
const getProperCase = (props) => {
|
|
8
|
-
|
|
9
|
+
const cleanInput = props.input.toString()
|
|
10
|
+
.trim();
|
|
11
|
+
// Don't process if the entire input is a reserved word
|
|
12
|
+
if (reservedWords_1.reservedWords.includes(cleanInput.toUpperCase())) {
|
|
13
|
+
return cleanInput;
|
|
14
|
+
}
|
|
15
|
+
// Build the split pattern - always include spaces
|
|
16
|
+
let splitPattern = /\s+/;
|
|
17
|
+
// Add optional separators based on user preferences
|
|
18
|
+
const separators = [];
|
|
9
19
|
if (props?.hyphen) {
|
|
10
|
-
|
|
11
|
-
.join(" ");
|
|
20
|
+
separators.push("-");
|
|
12
21
|
}
|
|
13
22
|
if (props?.pipe) {
|
|
14
|
-
|
|
15
|
-
.join(" ");
|
|
23
|
+
separators.push("\\|");
|
|
16
24
|
}
|
|
17
25
|
if (props?.underscore) {
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
separators.push("_");
|
|
27
|
+
}
|
|
28
|
+
if (separators.length > 0) {
|
|
29
|
+
splitPattern = new RegExp(`[\\s${separators.join("")}]+`, "g");
|
|
20
30
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.
|
|
31
|
+
// Split the input into words and apply proper casing
|
|
32
|
+
const words = cleanInput.split(splitPattern)
|
|
33
|
+
.filter(word => word.length > 0) // Remove empty strings
|
|
34
|
+
.map(word => {
|
|
35
|
+
// Check if individual word is reserved
|
|
36
|
+
const reservedWord = (0, reservedWords_1.isReservedWord)(word);
|
|
37
|
+
if (reservedWord) {
|
|
38
|
+
return reservedWord;
|
|
39
|
+
}
|
|
40
|
+
// Apply proper case
|
|
41
|
+
return word.charAt(0)
|
|
42
|
+
.toUpperCase() + word.slice(1)
|
|
43
|
+
.toLowerCase();
|
|
44
|
+
});
|
|
45
|
+
return words.join(' ');
|
|
24
46
|
};
|
|
25
47
|
exports.getProperCase = getProperCase;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isReservedWord = exports.reservedWords = void 0;
|
|
4
|
+
exports.reservedWords = [
|
|
5
|
+
"AI",
|
|
6
|
+
"GA4",
|
|
7
|
+
"GSC",
|
|
8
|
+
"OpenAI",
|
|
9
|
+
"PPC",
|
|
10
|
+
"SEO",
|
|
11
|
+
"UpTimeRobot",
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* Check if its a reserved word, the casing may be specific eg, OpenAI.
|
|
15
|
+
*/
|
|
16
|
+
const isReservedWord = (word) => {
|
|
17
|
+
let response = null;
|
|
18
|
+
for (let i = 0; i < exports.reservedWords.length; i++) {
|
|
19
|
+
if (exports.reservedWords[i].toLowerCase() === word.toLowerCase()) {
|
|
20
|
+
response = exports.reservedWords[i];
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return response;
|
|
25
|
+
};
|
|
26
|
+
exports.isReservedWord = isReservedWord;
|