Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/gatsby-source-mongodb/src/__tests__/utility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { sanitizeName } = require(`../utility`)

it(`removes unsupporterd characters from name`, () => {
Comment thread
harshil1712 marked this conversation as resolved.
Outdated
const name = `one-two-three`
const output = sanitizeName(name)
expect(output.search(/-/)).toEqual(-1)
Comment thread
harshil1712 marked this conversation as resolved.
Outdated
})
5 changes: 1 addition & 4 deletions packages/gatsby-source-mongodb/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const MongoClient = require(`mongodb`).MongoClient
const crypto = require(`crypto`)
const prepareMappingChildNode = require(`./mapping`)
const { sanitizeName } = require(`./utility`)
const _ = require(`lodash`)
Comment thread
harshil1712 marked this conversation as resolved.
Outdated
const queryString = require(`query-string`)

Expand Down Expand Up @@ -131,10 +132,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) {
Expand Down
5 changes: 5 additions & 0 deletions packages/gatsby-source-mongodb/src/utility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function sanitizeName(s) {
Comment thread
harshil1712 marked this conversation as resolved.
Outdated
return s.replace(/[^_a-zA-Z0-9]/g, ``).replace(/\b\w/g, l => l.toUpperCase())
}

exports.sanitizeName = sanitizeName