Skip to content

Commit

Permalink
Merge pull request #10 from chasefleming/chasefleming/symbols
Browse files Browse the repository at this point in the history
feature - add symbols
  • Loading branch information
chasefleming authored Apr 22, 2022
2 parents 715d1cb + dc32118 commit 5c5445d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
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 }
11 changes: 11 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
})

0 comments on commit 5c5445d

Please sign in to comment.