STRML/keyMirror
소개
키를 값으로도 사용하는 객체를 만드는 간단한 유틸리티입니다. react/lib/keyMirror를 독립적으로 포팅했습니다.
웹 및 앱 개발측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalKeyMirror
Create an object with values equal to its key names.
I thought react/lib/keyMirror was useful and wanted to reuse it without any dependencies.
This is not my code, this is property of Facebook.
Why?
From this discussion:
The main purpose of keyMirror is to deal with the fact that Closure Compiler advanced mode crushes keys, which allows you to write code like
keyMirror({monkey: null, gorilla: null})
and have it become something like
k({m:null,g:null})
which evaluates to
{m:"m",g:"g"}
at runtime. If it was specified as a list of strings, they wouldn't get crushed matching the property names.
Usage
npm install keymirror
var keyMirror = require('keymirror');
var COLORS = keyMirror({blue: null, red: null});
var myColor = COLORS.blue;
var isColorValid = !!COLORS[myColor];
The last line could not be performed if the values of the generated enum were not equal to their keys.
Input: {key1: val1, key2: val2}
Output: {key1: key1, key2: key2}
I sometimes use this with lodash - use the following upon your first use of lodash to mix it in:
var _ = require('lodash');
_.mixin({keyMirror: require('keymirror')});
// Can now be used as _.keyMirror(object)
관련 프로젝트 살펴보기
불러오는 중…