-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(format-phone): adding `formatToPhone` helper, creating tests * feat(format-phone): updating package details * feat(format-monogram): adding `formatToMonogram` helper
- Loading branch information
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# `formatToMonogram` | ||
|
||
Removes all non-numeric characters from a string | ||
|
||
## Arguments | ||
|
||
- `value: String`: value to be format | ||
|
||
## Returns | ||
|
||
- `string: String`: A common string. If not exist number the return default is an empty | ||
|
||
## Usage | ||
|
||
```jsx | ||
import { formatToMonogram } from '@platformbuilders/helpers'; | ||
|
||
formatToMonogram('John Doe'); // return 'JD' | ||
formatToMonogram('John Doe Due'); // return 'JDD' | ||
formatToMonogram('John'); // return 'J' | ||
formatToMonogram(''); // return '' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { formatToMonogram } from '../shared/formatToMonogram'; | ||
|
||
describe('formatToMonogram tests', () => { | ||
it('should format to monogram', () => { | ||
const unformatted = 'John Doe'; | ||
const formatted = formatToMonogram(unformatted); | ||
expect(formatted).toBe('JD'); | ||
}); | ||
it('should format to monogram with 3 words', () => { | ||
const unformatted = 'John Doe Due'; | ||
const formatted = formatToMonogram(unformatted); | ||
expect(formatted).toBe('JDD'); | ||
}); | ||
it('should format to monogram when there is only one word', () => { | ||
const unformatted = 'John'; | ||
const formatted = formatToMonogram(unformatted); | ||
expect(formatted).toBe('J'); | ||
}); | ||
it('should format to monogram when there is no word', () => { | ||
const unformatted = ''; | ||
const formatted = formatToMonogram(unformatted); | ||
expect(formatted).toBe(''); | ||
}); | ||
it('should format to monogram when there is no word', () => { | ||
const unformatted = ''; | ||
const formatted = formatToMonogram(unformatted); | ||
expect(formatted).toBe(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Format string to monogram | ||
* @param value The string to be formatted | ||
* @returns The string formatted to monogram | ||
* @example | ||
* formatToMonogram('John') // J | ||
* formatToMonogram('John Doe') // JD | ||
* formatToMonogram('John Doe Due') // JDD | ||
* formatToMonogram('') // '' | ||
* formatToMonogram() // '' | ||
* | ||
*/ | ||
export const formatToMonogram = (value: string): string => { | ||
if (!value) return ''; | ||
|
||
return value | ||
.trim() | ||
.split(' ') | ||
.map((word) => word[0]) | ||
.join('') | ||
.toUpperCase(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters