diff --git a/README.md b/README.md index 7b0c104..c33f294 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package-lock.json b/package-lock.json index da01ff8..36cdcd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hckrnews/enum", - "version": "1.4.0", + "version": "1.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@hckrnews/enum", - "version": "1.4.0", + "version": "1.4.1", "license": "LGPL-3.0", "devDependencies": { "@babel/core": "^7.12.10", diff --git a/package.json b/package.json index e46b18b..ab23d66 100644 --- a/package.json +++ b/package.json @@ -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/" diff --git a/src/__tests__/enum.spec.js b/src/__tests__/enum.spec.js index fec1d53..69d53ee 100644 --- a/src/__tests__/enum.spec.js +++ b/src/__tests__/enum.spec.js @@ -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]) diff --git a/src/enum.js b/src/enum.js index 0eddd08..eb046de 100644 --- a/src/enum.js +++ b/src/enum.js @@ -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)) {