@mhmdhammoud/meritt-utils 1.0.4 → 1.0.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/ReleaseNotes.md +17 -2
- package/dist/lib/formatter.d.ts +12 -0
- package/dist/lib/formatter.js +26 -0
- package/package.json +1 -4
- package/src/lib/formatter.ts +29 -1
package/ReleaseNotes.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## Version 1.0.5
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added toUpperTitle method that accepts a string and removes all non alphanumeric characters and capitalizes each letter of every first word
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import {Formatter} from '@mhmdhammoud/meritt-utils'
|
|
11
|
+
|
|
12
|
+
// Usage Example
|
|
13
|
+
const sentence:string = "hello__world$$99"
|
|
14
|
+
console.log(Formatter.toUpperTitle(sentence))
|
|
15
|
+
|
|
16
|
+
console : Hello World 99
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
|
|
3
20
|
## Version 1.0.4
|
|
4
21
|
|
|
5
22
|
### Added
|
|
@@ -41,9 +58,7 @@ const slug = Formatter.slugify('My Product Name') // my-product-name
|
|
|
41
58
|
### Fixes and Improvements
|
|
42
59
|
|
|
43
60
|
- Fixed bug in Crypto class where encrypting a string with a key that is not a number would throw an error
|
|
44
|
-
|
|
45
61
|
- Improved Crypto class to allow encrypting and decrypting numbers and objects
|
|
46
|
-
|
|
47
62
|
- Documented Crypto class
|
|
48
63
|
|
|
49
64
|
## Version 1.0.2
|
package/dist/lib/formatter.d.ts
CHANGED
|
@@ -28,6 +28,18 @@ declare class Formatter {
|
|
|
28
28
|
* ```
|
|
29
29
|
* */
|
|
30
30
|
obfuscate: (email: string) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Capitalizes the first letter of each word in a sentence and removes non-alphanumeric characters.
|
|
33
|
+
* @param sentence - The input sentence to be processed.
|
|
34
|
+
* @returns A new sentence with the first letter of each word capitalized and non-alphanumeric characters removed.
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const sentence = 'this is34354345a---sentence'
|
|
38
|
+
* const newSentence = ToUpperTitle(sentence)
|
|
39
|
+
* console.log(newSentence) // 'This Is A Sentence'
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
toUpperTitle: (sentence: string) => string;
|
|
31
43
|
/**
|
|
32
44
|
* @remarks Generates a slug from a given string
|
|
33
45
|
* @param title - string to be converted to slug
|
package/dist/lib/formatter.js
CHANGED
|
@@ -78,6 +78,32 @@ class Formatter {
|
|
|
78
78
|
email.slice(2, separatorIndex).replace(/./g, '*') +
|
|
79
79
|
email.slice(separatorIndex));
|
|
80
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Capitalizes the first letter of each word in a sentence and removes non-alphanumeric characters.
|
|
83
|
+
* @param sentence - The input sentence to be processed.
|
|
84
|
+
* @returns A new sentence with the first letter of each word capitalized and non-alphanumeric characters removed.
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const sentence = 'this is34354345a---sentence'
|
|
88
|
+
* const newSentence = ToUpperTitle(sentence)
|
|
89
|
+
* console.log(newSentence) // 'This Is A Sentence'
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
this.toUpperTitle = (sentence) => {
|
|
93
|
+
if (typeof sentence !== 'string')
|
|
94
|
+
throw new Error('Provide a valid string');
|
|
95
|
+
if (!sentence)
|
|
96
|
+
throw new Error('Provide a valid string');
|
|
97
|
+
const sanitizedSentence = sentence.replace(/[^a-zA-Z0-9]+/g, ' ');
|
|
98
|
+
const words = sanitizedSentence.split(' ');
|
|
99
|
+
const capitalizedWords = [];
|
|
100
|
+
for (let i = 0; i < words.length; i++) {
|
|
101
|
+
const word = words[i];
|
|
102
|
+
const capitalizedWord = word.charAt(0).toUpperCase() + word.slice(1);
|
|
103
|
+
capitalizedWords.push(capitalizedWord);
|
|
104
|
+
}
|
|
105
|
+
return capitalizedWords.join(' ');
|
|
106
|
+
};
|
|
81
107
|
/**
|
|
82
108
|
* @remarks Generates a slug from a given string
|
|
83
109
|
* @param title - string to be converted to slug
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mhmdhammoud/meritt-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -21,9 +21,6 @@
|
|
|
21
21
|
"lint": "eslint src --fix",
|
|
22
22
|
"prepublish": "npm run build"
|
|
23
23
|
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"dotenv": "^10.0.0"
|
|
26
|
-
},
|
|
27
24
|
"devDependencies": {
|
|
28
25
|
"ts-node-dev": "^1.1.8",
|
|
29
26
|
"typescript": "^4.6.3",
|
package/src/lib/formatter.ts
CHANGED
|
@@ -16,7 +16,7 @@ class Formatter {
|
|
|
16
16
|
* // => 'Hello-World'
|
|
17
17
|
* ```
|
|
18
18
|
* */
|
|
19
|
-
toUpperFirst = (_: string | number, withSpacing = true) => {
|
|
19
|
+
toUpperFirst = (_: string | number, withSpacing = true): string => {
|
|
20
20
|
if (typeof _ !== 'string') throw new Error('Provide a valid string')
|
|
21
21
|
if (withSpacing) {
|
|
22
22
|
return _.split(' ')
|
|
@@ -79,6 +79,34 @@ class Formatter {
|
|
|
79
79
|
)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Capitalizes the first letter of each word in a sentence and removes non-alphanumeric characters.
|
|
84
|
+
* @param sentence - The input sentence to be processed.
|
|
85
|
+
* @returns A new sentence with the first letter of each word capitalized and non-alphanumeric characters removed.
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const sentence = 'this is34354345a---sentence'
|
|
89
|
+
* const newSentence = ToUpperTitle(sentence)
|
|
90
|
+
* console.log(newSentence) // 'This Is A Sentence'
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
toUpperTitle = (sentence: string): string => {
|
|
94
|
+
if (typeof sentence !== 'string') throw new Error('Provide a valid string')
|
|
95
|
+
if (!sentence) throw new Error('Provide a valid string')
|
|
96
|
+
|
|
97
|
+
const sanitizedSentence = sentence.replace(/[^a-zA-Z0-9]+/g, ' ')
|
|
98
|
+
const words = sanitizedSentence.split(' ')
|
|
99
|
+
const capitalizedWords = []
|
|
100
|
+
|
|
101
|
+
for (let i = 0; i < words.length; i++) {
|
|
102
|
+
const word = words[i]
|
|
103
|
+
const capitalizedWord = word.charAt(0).toUpperCase() + word.slice(1)
|
|
104
|
+
capitalizedWords.push(capitalizedWord)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return capitalizedWords.join(' ')
|
|
108
|
+
}
|
|
109
|
+
|
|
82
110
|
/**
|
|
83
111
|
* @remarks Generates a slug from a given string
|
|
84
112
|
* @param title - string to be converted to slug
|