MCPcopy Create free account
hub / github.com/chavyleung/scripts / init

Function init

zaker/zaker.js:89–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87}
88
89function init() {
90 isSurge = () => {
91 return undefined === this.$httpClient ? false : true
92 }
93 isQuanX = () => {
94 return undefined === this.$task ? false : true
95 }
96 getdata = (key) => {
97 if (isSurge()) return $persistentStore.read(key)
98 if (isQuanX()) return $prefs.valueForKey(key)
99 }
100 setdata = (key, val) => {
101 if (isSurge()) return $persistentStore.write(key, val)
102 if (isQuanX()) return $prefs.setValueForKey(key, val)
103 }
104 msg = (title, subtitle, body) => {
105 if (isSurge()) $notification.post(title, subtitle, body)
106 if (isQuanX()) $notify(title, subtitle, body)
107 }
108 log = (message) => console.log(message)
109 get = (url, cb) => {
110 if (isSurge()) {
111 $httpClient.get(url, cb)
112 }
113 if (isQuanX()) {
114 url.method = 'GET'
115 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
116 }
117 }
118 post = (url, cb) => {
119 if (isSurge()) {
120 $httpClient.post(url, cb)
121 }
122 if (isQuanX()) {
123 url.method = 'POST'
124 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
125 }
126 }
127 put = (url, cb) => {
128 if (isSurge()) {
129 $httpClient.put(url, cb)
130 }
131 if (isQuanX()) {
132 url.method = 'PUT'
133 $task.fetch(url).then((resp) => cb(null, {}, resp.body))
134 }
135 }
136 done = (value = {}) => {
137 $done(value)
138 }
139 return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, put, done }
140}

Callers 1

zaker.jsFile · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected