Skip to content

Commit

Permalink
Merge pull request #10 from hckrnews/feature/first-draft
Browse files Browse the repository at this point in the history
Add toJSON method
  • Loading branch information
w3nl authored Oct 5, 2021
2 parents 9fd6e0f + be8979a commit 31d8279
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ encoding.in([42]) // false

encoding.valueOf() // 42
encoding.toString() // '42'
encoding.toJSON() // 42

const encoding = Encoding.fromValue('TEXT')
encoding.key // test
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hckrnews/enum",
"description": "Create vanilla JavaScript enums",
"version": "1.3.3",
"version": "1.4.0",
"author": {
"name": "Pieter Wigboldus",
"url": "https://hckr.news/"
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/enum.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,6 @@ describe('Test the encoding enum', () => {
expect(example.in(['something'])).toEqual(false)
expect(example.valueOf()).toEqual(2)
expect(example.toString()).toEqual('2')
expect(example.toJSON()).toEqual(2)
})
})
4 changes: 4 additions & 0 deletions src/enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ export default class Enum {
toString () {
return this.value.toString()
}

toJSON () {
return this.value
}
}

0 comments on commit 31d8279

Please sign in to comment.