Skip to content

Commit

Permalink
Add camelToSnake
Browse files Browse the repository at this point in the history
  • Loading branch information
drake.aren committed Aug 22, 2020
1 parent 320b7ef commit 154d86b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ const toCase = (stringToCaseFn) => (value) => {
}
}

const snakeStringToCamel = (value) => {
return value.replace(/_(\w)/g, (m) => m[1].toUpperCase())
}

const snakeStringToCamel = (str) => str.replace(/_(\w)/g, (m) => m[1].toUpperCase())
const snakeToCamel = toCase(snakeStringToCamel)

const camelStringToSnake = (str) => str.replace(/[A-Z]/g, m => `_${m.toLowerCase()}`)
const camelToSnake = toCase(camelStringToSnake)

module.exports = {
snakeToCamel
snakeToCamel,
camelToSnake,
}
3 changes: 2 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const R = require('ramda')
const { snakeToCamel } = require('./index');
const { snakeToCamel, camelToSnake } = require('./index');

it.concurrent('Convert string from snake to camel case', async () => {
expect(snakeToCamel('snake_case')).toBe('snakeCase');
expect(camelToSnake('camelCase')).toBe('camel_case');
});

it.concurrent('Convert array from snake to camel case', async () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oh-my-case",
"version": "1.0.4",
"version": "1.0.5",
"description": "Recursive case to case conversion",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 154d86b

Please sign in to comment.