Skip to content

Commit

Permalink
Merge pull request #17 from chasefleming/fix/lower-upper
Browse files Browse the repository at this point in the history
Add missing lowercase and uppercase transformations
  • Loading branch information
chasefleming authored Aug 23, 2023
2 parents 1593db4 + dbafc01 commit cb70a38
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
index.js
index.test.js
index.test.js
.github
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ const createEnum = (type, options = {}) => {

// Apply casing transformations
switch (options.casing) {
case 'lowercase':
value = value.toLowerCase();
break;
case 'uppercase':
value = value.toUpperCase();
break;
case 'camelCase':
value = toCamelCase(value);
break;
Expand Down
18 changes: 18 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@ describe('String Enums', () => {
expect(Winter).toEqual('Winter')
expect(Spring).toEqual('Spring')
})

test('creates enum with lowercase casing', () => {
const { Summer, Autumn, Winter, Spring } = Enum.String({ casing: "lowercase" })

expect(Summer).toEqual('summer')
expect(Autumn).toEqual('autumn')
expect(Winter).toEqual('winter')
expect(Spring).toEqual('spring')
})

test('creates enum with uppercase casing', () => {
const { Summer, Autumn, Winter, Spring } = Enum.String({ casing: "uppercase" })

expect(Summer).toEqual('SUMMER')
expect(Autumn).toEqual('AUTUMN')
expect(Winter).toEqual('WINTER')
expect(Spring).toEqual('SPRING')
})

test('creates enum with snakeCase casing', () => {
const { userId, userAddress, orderNumber } = Enum.String({ casing: 'snakeCase' })

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "enum-xyz",
"type": "module",
"version": "0.3.0",
"version": "0.3.1",
"description": "JavaScript enums using proxies.",
"homepage": "https://github.com/chasefleming/enum-xyz",
"author": "Chase Fleming",
Expand All @@ -21,7 +21,7 @@
"dev": "microbundle watch",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"build": "microbundle",
"publish": "npm run build && npm publish"
"prepublishOnly": "npm test && npm run build"
},
"license": "ISC",
"devDependencies": {
Expand Down

0 comments on commit cb70a38

Please sign in to comment.