aneka 0.0.4 → 0.0.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aneka",
3
- "version": "0.0.4",
3
+ "version": "0.0.8",
4
4
  "description": "cemacemla",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,6 +21,10 @@
21
21
  },
22
22
  "homepage": "https://github.com/ardhi/aneka#readme",
23
23
  "dependencies": {
24
- "lodash": "^4.17.21"
24
+ "axios": "^0.24.0",
25
+ "global-dirs": "^3.0.0",
26
+ "lodash": "^4.17.21",
27
+ "log-timestamp": "^0.3.0",
28
+ "query-string": "^7.0.1"
25
29
  }
26
30
  }
@@ -0,0 +1,19 @@
1
+ const requireGlobal = require('./require-global')
2
+ const path = require('path')
3
+
4
+ module.exports = name => {
5
+ let mod
6
+ try {
7
+ mod = require(path.resolve(name))
8
+ } catch (err) {
9
+ try {
10
+ mod = require(name)
11
+ } catch (err) {
12
+ try {
13
+ mod = requireGlobal(name)
14
+ } catch (err) {}
15
+ }
16
+ }
17
+ if (!mod) throw new Error(`Can't load "${name}" as file nor local/global module`)
18
+ return mod
19
+ }
@@ -0,0 +1,19 @@
1
+ // Taken from: https://github.com/sindresorhus/import-global/blob/main/index.js
2
+ const path = require('path')
3
+ const globalDirs = require('global-dirs')
4
+
5
+ module.exports = moduleId => {
6
+ try {
7
+ return require(path.join(globalDirs.yarn.packages, moduleId))
8
+ } catch (err) {
9
+ return require(path.join(globalDirs.npm.packages, moduleId))
10
+ }
11
+ }
12
+
13
+ module.exports.silent = moduleId => {
14
+ try {
15
+ return module.exports(moduleId)
16
+ } catch (err) {
17
+ return null
18
+ }
19
+ }
@@ -0,0 +1,5 @@
1
+ const print = require('./print')
2
+
3
+ module.exports = msg => {
4
+ print(msg, true, 'error')
5
+ }
@@ -0,0 +1,52 @@
1
+ const axios = require('axios')
2
+ const { has, isString, omit } = require('lodash')
3
+ const qs = require('query-string')
4
+
5
+ const handleSuccess = (resp, opts, cfg) => {
6
+ return resp.data
7
+ }
8
+
9
+ const handleError = (err, opts, cfg) => {
10
+ return err
11
+ }
12
+
13
+ module.exports = function (opts = {}, cfg = {}) {
14
+ return new Promise((resolve, reject) => {
15
+ if (isString(opts)) opts = { url: opts }
16
+ opts.params = opts.params || {}
17
+ if (!has(cfg, 'cacheBuster')) cfg.cacheBuster = true
18
+ if (cfg.cacheBuster) opts.params[cfg.cacheBusterKey || '_'] = Date.now()
19
+ if (cfg.streamHandler) {
20
+ opts.url = `${opts.url}?${qs.stringify(opts.params)}`
21
+ let error
22
+ fetch(opts.url, omit(opts, ['url', 'params']))
23
+ .then(resp => {
24
+ if (!resp.ok) {
25
+ error = resp
26
+ return false
27
+ }
28
+ return cfg.streamHandler(resp)
29
+ })
30
+ .then(resp => {
31
+ if (!resp) return false
32
+ resolve(handleSuccess({ data: resp }, opts, cfg))
33
+ })
34
+ .then(resp => {
35
+ const e = new Error(error.statusText)
36
+ e.status = error.status
37
+ reject(handleError(e, opts, cfg))
38
+ })
39
+ .catch(err => {
40
+ reject(handleError(err, opts, cfg))
41
+ })
42
+ return
43
+ }
44
+ axios(opts)
45
+ .then(resp => {
46
+ resolve(handleSuccess(resp, opts, cfg))
47
+ })
48
+ .catch(err => {
49
+ reject(handleError(err, opts, cfg))
50
+ })
51
+ })
52
+ }
@@ -0,0 +1,7 @@
1
+ require('log-timestamp')
2
+
3
+ module.exports = (msg, terminate, method = 'log') => {
4
+ if (method === true) method = 'log'
5
+ console[method](msg)
6
+ if (terminate) process.exit(1)
7
+ }
@@ -1,4 +1,4 @@
1
- import { forOwn } from 'lodash'
1
+ const { forOwn } = require('lodash')
2
2
 
3
3
  module.exports = function(params) {
4
4
  const result = {}