@polylith/config-store 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +14 -0
  2. package/src/index.js +28 -0
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@polylith/config-store",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "Glenn Anderson",
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "deepmerge": "^4.2.2"
13
+ }
14
+ }
package/src/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import deepmerge from 'deepmerge';
2
+
3
+ var configStore = {};
4
+
5
+ function add(config) {
6
+ if (typeof config !== 'object' || Array.isArray(config)) {
7
+ console.warn('Only object can be added to a config');
8
+ }
9
+ deepmerge(configStore, config)
10
+ }
11
+
12
+ function get(key) {
13
+ var parts = key.split('.');
14
+ var result = configStore;
15
+ while (parts.length > 0) {
16
+ let key = parts.shift();
17
+ result = result[key];
18
+
19
+ if (!result) return false;
20
+ }
21
+
22
+ return result;
23
+ }
24
+
25
+ export default {
26
+ add: add,
27
+ get: get,
28
+ }