https://github.com/aleclarson/keymirror
A flexible key mirror. { key1: "key1", key2: "key2" }
https://github.com/aleclarson/keymirror
Last synced: 11 months ago
JSON representation
A flexible key mirror. { key1: "key1", key2: "key2" }
- Host: GitHub
- URL: https://github.com/aleclarson/keymirror
- Owner: aleclarson
- License: mit
- Created: 2015-03-26T03:46:57.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-12-05T14:34:26.000Z (over 7 years ago)
- Last Synced: 2025-03-11T12:33:43.284Z (over 1 year ago)
- Language: CoffeeScript
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### keymirror 1.0.0 
**TODO:** Rewrite this using [`Type`](https://github.com/aleclarson/Type) if we can.
```coffee
KeyMirror = require "keymirror"
# Construct an empty KeyMirror.
m1 = KeyMirror()
m1._keys # []
m1._length # 0
# Add your keys.
m1._add "a", "b", "c"
m1._keys # ["a", "b", "c"]
# Access your keys.
m1.a # "a"
m1.b # "b"
m1.c # "c"
# Remove your keys.
m1._remove "a", "c"
# Construct a KeyMirror from Arrays, Strings, Objects, and even KeyMirrors.
m2 = KeyMirror ["d"], "e", { f: 0 }, m1
m2._keys # ["b", "d", "e", "f"]
# Mix in those types after creation.
m2._add ["x"], { y: false }, "r2d2"
m2._keys # ["b", "d", "e", "f", "x", "y", "r2d2"]
# Clone a KeyMirror with clear intent.
m3 = m1._clone()
m3._keys # ["b"]
m3 is m1 # false
```