@kaspernj/api-maker 1.0.195 → 1.0.196

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 +1 -1
  2. package/src/config.js +34 -36
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.195",
19
+ "version": "1.0.196",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
package/src/config.js CHANGED
@@ -1,50 +1,48 @@
1
+ import inflection from "inflection"
2
+
3
+ const accessors = {
4
+ breakPoints: {
5
+ default: [
6
+ ["xxl", 1400],
7
+ ["xl", 1200],
8
+ ["lg", 992],
9
+ ["md", 768],
10
+ ["sm", 576],
11
+ ["xs", 0]
12
+ ],
13
+ required: true
14
+ },
15
+ currenciesCollection: {required: true},
16
+ history: {required: false},
17
+ host: {required: false},
18
+ routes: {required: false},
19
+ routeDefinitions: {required: false}
20
+ }
21
+
1
22
  class ApiMakerConfig {
2
23
  constructor() {
3
24
  if (!global.apiMakerConfigGlobal) global.apiMakerConfigGlobal = {}
4
25
 
5
26
  this.global = global.apiMakerConfigGlobal
6
27
  }
28
+ }
7
29
 
8
- getCurrenciesCollection() {
9
- if (!this.global.currenciesCollection) throw new Error("Currencies collection hasn't been set")
10
-
11
- return this.global.currenciesCollection
12
- }
13
-
14
- getHost() {
15
- const host = this.global.host
16
-
17
- if (typeof host == "function") return host()
18
-
19
- return host
20
- }
21
-
22
- getRouteDefinitions() {
23
- return this.global.routeDefinitions
24
- }
30
+ for (const accessorName in accessors) {
31
+ const accessorData = accessors[accessorName]
32
+ const camelizedAccessor = inflection.camelize(accessorName)
25
33
 
26
- getRoutes() {
27
- return this.global.routes
28
- }
34
+ ApiMakerConfig.prototype[`set${camelizedAccessor}`] = function (newValue) { this.global[accessorName] = newValue }
35
+ ApiMakerConfig.prototype[`get${camelizedAccessor}`] = function (...args) {
36
+ if (!this.global[accessorName]) {
37
+ if (accessorData.default) return accessorData.default
38
+ if (accessorData.required) throw new Error(`${accessorName} hasn't been set`)
39
+ }
29
40
 
30
- setCurrenciesCollection(newCurrenciesCollection) {
31
- this.global.currenciesCollection = newCurrenciesCollection
32
- }
41
+ const value = this.global[accessorName]
33
42
 
34
- setHistory(history) {
35
- this.global.history = history
36
- }
37
-
38
- setHost(host) {
39
- this.global.host = host
40
- }
41
-
42
- setRouteDefinitions(routeDefinitions) {
43
- this.global.routeDefinitions = routeDefinitions
44
- }
43
+ if (typeof value == "function") return value(...args)
45
44
 
46
- setRoutes(routes) {
47
- this.global.routes = routes
45
+ return value
48
46
  }
49
47
  }
50
48