diff --git a/snakeCase/snakeCase.js b/snakeCase/snakeCase.js index d14f180..4dc3af3 100644 --- a/snakeCase/snakeCase.js +++ b/snakeCase/snakeCase.js @@ -1,5 +1,19 @@ -var snakeCase = function() { +const snakeCase = function(string) { + // wtf case + string = string.replace(/\.\./g, " "); -} + // this splits up camelcase IF there are no spaces in the word + if (string.indexOf(" ") < 0) { + string = string.replace(/([A-Z])/g, " $1"); + } -module.exports = snakeCase + return string + .trim() + .toLowerCase() + .replace(/[,\?\.]/g, "") + .replace(/\-/g, " ") + .split(" ") + .join("_"); +}; + +module.exports = snakeCase; diff --git a/snakeCase/snakeCase.spec.js b/snakeCase/snakeCase.spec.js index 7664be0..cf70975 100644 --- a/snakeCase/snakeCase.spec.js +++ b/snakeCase/snakeCase.spec.js @@ -1,23 +1,26 @@ -var snakeCase = require('./snakeCase') +const snakeCase = require("./snakeCase"); -describe('snakeCase', function() { - it('works with simple lowercased phrases', function() { - expect(snakeCase('hello world')).toEqual('hello_world'); +describe("snakeCase", () => { + it("works with simple lowercased phrases", () => { + expect(snakeCase("hello world")).toEqual("hello_world"); }); - xit('works with Caps and punctuation', function() { - expect(snakeCase('Hello, World???')).toEqual('hello_world'); + it("works with Caps and punctuation", () => { + expect(snakeCase("Hello, World???")).toEqual("hello_world"); }); - xit('works with longer phrases', function() { - expect(snakeCase('This is the song that never ends....')).toEqual('this_is_the_song_that_never_ends'); + it("works with longer phrases", () => { + expect(snakeCase("This is the song that never ends....")).toEqual( + "this_is_the_song_that_never_ends" + ); }); - xit('works with camel case', function() { - expect(snakeCase('snakeCase')).toEqual('snake_case'); + it("works with camel case", () => { + expect(snakeCase("snakeCase")).toEqual("snake_case"); }); - xit('works with kebab case', function() { - expect(snakeCase('snake-case')).toEqual('snake_case'); + it("works with kebab case", () => { + expect(snakeCase("snake-case")).toEqual("snake_case"); }); - xit('works with WTF case', function() { - expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome'); + it("works with WTF case", () => { + expect(snakeCase("SnAkE..CaSe..Is..AwEsOmE")).toEqual( + "snake_case_is_awesome" + ); }); - });