diff --git a/.all-contributorsrc b/.all-contributorsrc
index 55d09e2..d0d38c4 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -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,
diff --git a/README.md b/README.md
index 4924585..1fc5497 100644
--- a/README.md
+++ b/README.md
@@ -105,6 +105,7 @@ Feel free to check [issues page](https://github.com/kefranabg/readme-md-generato
Bao Ho 💻 ⚠️ |
Sasha Semanyuk 💻 |
+ Antoine Caron 💻 ⚠️ 🤔 |
diff --git a/src/questions/author-github.js b/src/questions/author-github.js
index 51f0e0b..6648b43 100644
--- a/src/questions/author-github.js
+++ b/src/questions/author-github.js
@@ -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
})
diff --git a/src/questions/author-github.spec.js b/src/questions/author-github.spec.js
index c51726b..06d1bae 100644
--- a/src/questions/author-github.spec.js
+++ b/src/questions/author-github.spec.js
@@ -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)
})
})
})
diff --git a/src/questions/author-twitter.js b/src/questions/author-twitter.js
index a9d4ffa..145d5d9 100644
--- a/src/questions/author-twitter.js
+++ b/src/questions/author-twitter.js
@@ -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
})
diff --git a/src/questions/author-twitter.spec.js b/src/questions/author-twitter.spec.js
index 287b144..9e77a15 100644
--- a/src/questions/author-twitter.spec.js
+++ b/src/questions/author-twitter.spec.js
@@ -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)
})
})
})
diff --git a/src/utils.js b/src/utils.js
index 967feff..cb4d059 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -96,6 +96,14 @@ 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,
@@ -103,5 +111,6 @@ module.exports = {
END_MSG,
BOXEN_CONFIG,
getDefaultAnswers,
- getDefaultAnswer
+ getDefaultAnswer,
+ cleanSocialNetworkUsername
}
diff --git a/src/utils.spec.js b/src/utils.spec.js
index 87a3c32..047f01a 100644
--- a/src/utils.spec.js
+++ b/src/utils.spec.js
@@ -14,7 +14,8 @@ const {
END_MSG,
BOXEN_CONFIG,
getDefaultAnswer,
- getDefaultAnswers
+ getDefaultAnswers,
+ cleanSocialNetworkUsername
} = require('./utils')
jest.mock('load-json-file')
@@ -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_')
+ })
+ })
})