Skip to content

Commit

Permalink
✨ Filter social network inputs to remove potential @ (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slashgear authored and kefranabg committed Jul 8, 2019
1 parent b2be60e commit ccae357
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@
"contributions": [
"code"
]
},
{
"login": "Slashgear",
"name": "Antoine Caron",
"avatar_url": "https://avatars0.githubusercontent.com/u/6263857?v=4",
"profile": "http://slashgear.github.io/",
"contributions": [
"code",
"test",
"ideas"
]
}
],
"contributorsPerLine": 7,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Feel free to check [issues page](https://github.com/kefranabg/readme-md-generato
<tr>
<td align="center"><a href="https://github.com/hgb123"><img src="https://avatars0.githubusercontent.com/u/18468577?v=4" width="75px;" alt="Bao Ho"/><br /><sub><b>Bao Ho</b></sub></a><br /><a href="https://github.com/kefranabg/readme-md-generator/commits?author=hgb123" title="Code">💻</a> <a href="https://github.com/kefranabg/readme-md-generator/commits?author=hgb123" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/zizizi17"><img src="https://avatars0.githubusercontent.com/u/10571073?v=4" width="75px;" alt="Sasha Semanyuk"/><br /><sub><b>Sasha Semanyuk</b></sub></a><br /><a href="https://github.com/kefranabg/readme-md-generator/commits?author=zizizi17" title="Code">💻</a></td>
<td align="center"><a href="http://slashgear.github.io/"><img src="https://avatars0.githubusercontent.com/u/6263857?v=4" width="75px;" alt="Antoine Caron"/><br /><sub><b>Antoine Caron</b></sub></a><br /><a href="https://github.com/kefranabg/readme-md-generator/commits?author=Slashgear" title="Code">💻</a> <a href="https://github.com/kefranabg/readme-md-generator/commits?author=Slashgear" title="Tests">⚠️</a> <a href="#ideas-Slashgear" title="Ideas, Planning, & Feedback">🤔</a></td>
</tr>
</table>

Expand Down
5 changes: 4 additions & 1 deletion src/questions/author-github.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { cleanSocialNetworkUsername } = require('../utils')

module.exports = projectInfos => ({
type: 'input',
message: '👤 Github username (use empty value to skip)',
name: 'authorGithubUsername',
default: projectInfos.githubUsername
default: projectInfos.githubUsername,
filter: cleanSocialNetworkUsername
})
3 changes: 2 additions & 1 deletion src/questions/author-github.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe('askAuthorGithub', () => {
type: 'input',
message: '👤 Github username (use empty value to skip)',
name: 'authorGithubUsername',
default: githubUsername
default: githubUsername,
filter: expect.any(Function)
})
})
})
5 changes: 4 additions & 1 deletion src/questions/author-twitter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const { cleanSocialNetworkUsername } = require('../utils')

module.exports = () => ({
type: 'input',
message: '🐦 Twitter username (use empty value to skip)',
name: 'authorTwitterUsername'
name: 'authorTwitterUsername',
filter: cleanSocialNetworkUsername
})
3 changes: 2 additions & 1 deletion src/questions/author-twitter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('askAuthorTwitter', () => {
expect(result).toEqual({
type: 'input',
message: '🐦 Twitter username (use empty value to skip)',
name: 'authorTwitterUsername'
name: 'authorTwitterUsername',
filter: expect.any(Function)
})
})
})
11 changes: 10 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,21 @@ const getDefaultAnswers = questions =>
{}
)

/**
* Clean social network username by removing the @ prefix
*
* @param input social network username input
* @returns {*} input without the prefix
*/
const cleanSocialNetworkUsername = input => input.replace(/^@/, '')

module.exports = {
getPackageJson,
showEndMessage,
getProjectName,
END_MSG,
BOXEN_CONFIG,
getDefaultAnswers,
getDefaultAnswer
getDefaultAnswer,
cleanSocialNetworkUsername
}
13 changes: 12 additions & 1 deletion src/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const {
END_MSG,
BOXEN_CONFIG,
getDefaultAnswer,
getDefaultAnswers
getDefaultAnswers,
cleanSocialNetworkUsername
} = require('./utils')

jest.mock('load-json-file')
Expand Down Expand Up @@ -195,4 +196,14 @@ describe('utils', () => {
})
})
})

describe('cleanSocialNetworkUsername', () => {
it('should remove prefixed @', () => {
expect(cleanSocialNetworkUsername('@Slashgear_')).toEqual('Slashgear_')
})

it('should return the same string when string is not prefixed', () => {
expect(cleanSocialNetworkUsername('Slashgear_')).toEqual('Slashgear_')
})
})
})

0 comments on commit ccae357

Please sign in to comment.