Skip to content

Commit

Permalink
Add the create method
Browse files Browse the repository at this point in the history
  • Loading branch information
w3nl committed Oct 5, 2021
1 parent be8979a commit 0423adc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ encoding.valueOf() // 42
encoding.toString() // '42'
encoding.toJSON() // 42

const encoding = Encoding.create('test')
encoding.key // 'test'
encoding.value // 'TEXT'

const encoding = Encoding.fromValue('TEXT')
encoding.key // test
encoding.value // TEXT
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.4.0",
"version": "1.4.1",
"author": {
"name": "Pieter Wigboldus",
"url": "https://hckr.news/"
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/enum.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('Test the encoding enum', () => {
static 'test3' = 3
}

const example = Example.fromKey('test2')
const example = Example.create('test2')
expect(example.key).toEqual('test2')
expect(example.value).toEqual(2)
expect(example.values).toEqual([1, 2, 3])
Expand Down
4 changes: 4 additions & 0 deletions src/enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export default class Enum {
return Object.fromEntries(Object.entries(this))
}

static create (key) {
return this.fromKey(key)
}

static fromKey (key) {
const newEnum = new this()
if (!newEnum.isValidKey(key)) {
Expand Down

0 comments on commit 0423adc

Please sign in to comment.