light-config
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,15 +1,42 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports['default'] = lightConfig; | ||
require('babel-polyfill'); // :( | ||
const DELIMITER = '.'; | ||
var DELIMITER = '.'; | ||
export default function lightConfig(serverConfig, properties) { | ||
function lightConfig(serverConfig, properties) { | ||
var clientConfig = {}; | ||
for (let property of properties) { | ||
if (isSingleLevel(property)) { | ||
clientConfig[property] = serverConfig[property]; | ||
} else { | ||
const propertyTree = property.split(DELIMITER); | ||
clientConfig = Object.assign(clientConfig, createConfigMap(propertyTree, serverConfig)); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var property = _step.value; | ||
if (isSingleLevel(property)) { | ||
clientConfig[property] = serverConfig[property]; | ||
} else { | ||
var propertyTree = property.split(DELIMITER); | ||
clientConfig = Object.assign(clientConfig, createConfigMap(propertyTree, serverConfig)); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator['return']) { | ||
_iterator['return'](); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
@@ -21,9 +48,9 @@ | ||
function createConfigMap(propertyTree, serverConfig) { | ||
const config = {}; | ||
var config = {}; | ||
var lastTargetRef = config; | ||
var lastSourceRef = Object.assign({}, serverConfig); | ||
for (let i = 0; i < propertyTree.length; i++) { | ||
let property = propertyTree[i]; | ||
let hasChild = !!propertyTree[i + 1]; | ||
for (var i = 0; i < propertyTree.length; i++) { | ||
var property = propertyTree[i]; | ||
var hasChild = !!propertyTree[i + 1]; | ||
lastTargetRef[property] = hasChild ? {} : lastSourceRef[property]; | ||
@@ -40,1 +67,2 @@ lastSourceRef = lastSourceRef[property]; | ||
} | ||
module.exports = exports['default']; |
{ | ||
"name": "light-config", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Share specific subsets of your server-side config with the browser", | ||
@@ -31,4 +31,6 @@ "main": "dist/index.js", | ||
"homepage": "https://github.com/jamesseanwright/lightconfig#readme", | ||
"dependencies": { | ||
"babel-polyfill": "^6.0.16" | ||
}, | ||
"devDependencies": { | ||
"babel-polyfill": "^6.0.16", | ||
"chai": "3.4.0", | ||
@@ -35,0 +37,0 @@ "mocha": "2.3.3" |
@@ -1,2 +0,2 @@ | ||
# Light Config | ||
# Light Config [](https://travis-ci.org/jamesseanwright/light-config) | ||
Share specific subsets of your server-side config with the browser | ||
@@ -3,0 +3,0 @@ |
Sorry, the diff of this file is not supported yet
6431
2
55
1
+ Addedbabel-polyfill@^6.0.16
+ Addedbabel-polyfill@6.26.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedregenerator-runtime@0.10.50.11.1(transitive)