From dc321182f69c75b29ea10678df123dccfdd8cda2 Mon Sep 17 00:00:00 2001 From: Chase Fleming Date: Thu, 21 Apr 2022 17:21:21 -0700 Subject: [PATCH] feature - add symbols --- CHANGELOG.md | 1 + index.js | 8 ++++++-- index.test.js | 11 +++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c35b92d..8dd9e5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- 2022-04-21 - Add symbols enum option - 2022-04-19 - Create named and default exports ## [0.0.6] - 2022-02-16 diff --git a/index.js b/index.js index 3f4ccce..25c286a 100644 --- a/index.js +++ b/index.js @@ -19,5 +19,9 @@ const NumericAt = (startIndex) => { const Numeric = NumericAt(0) -const Enum = { String, StringLower, Numeric, NumericAt } -export { Enum as default, String, StringLower, Numeric, NumericAt } \ No newline at end of file +const SymbolFn = new Proxy({}, { + get: (_, name) => Symbol(name) +}) + +const Enum = { String, StringLower, Numeric, NumericAt, Symbol: SymbolFn } +export { Enum as default, String, StringLower, Numeric, NumericAt, SymbolFn as Symbol } \ No newline at end of file diff --git a/index.test.js b/index.test.js index bd70744..39fc825 100644 --- a/index.test.js +++ b/index.test.js @@ -34,4 +34,15 @@ test('creates enum and assigns numeric value starting at index of choice', () => expect(B).toBe(2) expect(C).toBe(3) expect(D).toBe(4) +}) + +test('creates enum and assigns symbol values', () => { + const { blue, red } = Enum.Symbol + const { blue: blueMood, happy } = Enum.Symbol + + expect(blue).toBe(blue) + expect(blue).not.toBe(red) + expect(blue).not.toBe(blueMood) + expect(blue).not.toBe('blue') + expect(blue).not.toBe(Symbol('blue')) }) \ No newline at end of file