constant-mirror
Advanced tools
Comparing version 1.1.1 to 2.0.0
@@ -1,29 +0,17 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.symbolMirror = undefined; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { keys.push.apply(keys, Object.getOwnPropertySymbols(object)); } if (enumerableOnly) keys = keys.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); return keys; } | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
exports.default = constantMirror; | ||
var _symbolMirror2 = require('./symbolMirror.js'); | ||
var _symbolMirror3 = _interopRequireDefault(_symbolMirror2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
exports.symbolMirror = _symbolMirror3.default; | ||
function constantMirror() { | ||
for (var _len = arguments.length, constants = Array(_len), _key = 0; _key < _len; _key++) { | ||
constants[_key] = arguments[_key]; | ||
} | ||
return constants.reduce(function (obj, constant) { | ||
return constant ? _extends({}, obj, _defineProperty({}, constant, constant)) : obj; | ||
}, {}); | ||
} | ||
/** | ||
* @param {...string} constants | ||
* @returns {Object<string,string>} an object with mirrored string keys and values. | ||
*/ | ||
module.exports = function constantMirror(...constants) { | ||
return constants.reduce((obj, constant) => constant ? _objectSpread({}, obj, { | ||
[constant]: constant | ||
}) : obj, {}); | ||
}; |
{ | ||
"name": "constant-mirror", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "A simple tool for creating objects with keys mirrored as values. Inspired by React's keyMirror.", | ||
@@ -17,23 +17,25 @@ "keywords": [ | ||
], | ||
"engines": { | ||
"node": ">= 6.0.0" | ||
}, | ||
"scripts": { | ||
"build": "babel src --out-dir=lib", | ||
"prebuild": "npm run clean", | ||
"build": "babel src --out-dir=lib --ignore=\"src/**/*.spec.js\"", | ||
"clean": "rimraf coverage lib", | ||
"test:cov": "babel-node $(npm bin)/isparta cover $(npm bin)/_mocha", | ||
"test:watch": "npm run test -- --watch", | ||
"test": "mocha --compilers=js:babel-core/register", | ||
"preversion": "npm run clean && npm run test:cov", | ||
"test": "jest --coverage", | ||
"preversion": "npm test", | ||
"version": "npm run build", | ||
"postversion": "npm run clean && git push && git push --tags", | ||
"prepublish": "npm run clean && npm run build" | ||
"postversion": "git push && git push --tags", | ||
"prepare": "npm run build" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.7.7", | ||
"babel-plugin-transform-export-extensions": "^6.5.0", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-stage-2": "^6.5.0", | ||
"expect.js": "^0.3.1", | ||
"isparta": "^4.0.0", | ||
"mocha": "^2.4.5", | ||
"@babel/cli": "^7.5.0", | ||
"@babel/core": "^7.5.4", | ||
"@babel/preset-env": "^7.5.4", | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb-base": "^13.2.0", | ||
"eslint-plugin-import": "^2.18.0", | ||
"jest": "^24.8.0", | ||
"rimraf": "^2.5.2" | ||
} | ||
} |
@@ -12,7 +12,7 @@ # constant-mirror [](https://www.npmjs.com/package/constant-mirror) [](https://www.npmjs.com/package/constant-mirror) | ||
// ES6 | ||
import constantMirror from 'constant-mirror'; | ||
import mirror from 'constant-mirror'; | ||
// or ES5 | ||
var constantMirror = require('constant-mirror').default; | ||
var mirror = require('constant-mirror'); | ||
constantMirror('HELLO', 'WORLD'); | ||
mirror('HELLO', 'WORLD'); | ||
// => { HELLO: 'HELLO', WORLD: 'WORLD' } | ||
@@ -24,7 +24,7 @@ ``` | ||
// ES6 | ||
import { symbolMirror } from 'constant-mirror'; | ||
import mirror from 'constant-mirror/symbol'; | ||
// or ES5 | ||
var symbolMirror = require('constant-mirror').symbolMirror; | ||
var mirror = require('constant-mirror/symbol'); | ||
symbolMirror('HELLO', 'WORLD'); | ||
mirror('HELLO', 'WORLD'); | ||
// => { HELLO: Symbol(HELLO), WORLD: Symbol(WORLD) } | ||
@@ -31,0 +31,0 @@ ``` |
Sorry, the diff of this file is not supported yet
5757
28