diff --git a/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js b/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js new file mode 100644 index 0000000000000..4edbf698d9e19 --- /dev/null +++ b/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js @@ -0,0 +1,7 @@ +const sanitizeName = require(`../sanitize-name`) + +it(`removes unsupported characters from name`, () => { + const name = `one-two-three` + const output = sanitizeName(name) + expect(output).not.toContain(`-`) +}) diff --git a/packages/gatsby-source-mongodb/src/gatsby-node.js b/packages/gatsby-source-mongodb/src/gatsby-node.js index 0a80143ff187a..299c83825aab1 100644 --- a/packages/gatsby-source-mongodb/src/gatsby-node.js +++ b/packages/gatsby-source-mongodb/src/gatsby-node.js @@ -1,6 +1,7 @@ const MongoClient = require(`mongodb`).MongoClient const crypto = require(`crypto`) const prepareMappingChildNode = require(`./mapping`) +const sanitizeName = require(`./sanitize-name`) const queryString = require(`query-string`) exports.sourceNodes = ( @@ -130,10 +131,6 @@ function createNodes( }) } -function sanitizeName(s) { - return s.replace(/[^_a-zA-Z0-9]/, ``).replace(/\b\w/g, l => l.toUpperCase()) -} - function getConnectionExtraParams(extraParams) { let connectionSuffix if (extraParams) { diff --git a/packages/gatsby-source-mongodb/src/sanitize-name.js b/packages/gatsby-source-mongodb/src/sanitize-name.js new file mode 100644 index 0000000000000..2487eb8eb92c3 --- /dev/null +++ b/packages/gatsby-source-mongodb/src/sanitize-name.js @@ -0,0 +1,3 @@ +module.exports = function sanitizeName(s) { + return s.replace(/[^_a-zA-Z0-9]/g, ``).replace(/\b\w/g, l => l.toUpperCase()) +}