aneka 0.0.23 → 0.0.25

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,30 +1,31 @@
1
- {
2
- "name": "aneka",
3
- "version": "0.0.23",
4
- "description": "cemacemla",
5
- "main": "src/index.js",
6
- "scripts": {
7
- "test": "jest"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/ardhi/aneka.git"
12
- },
13
- "keywords": [
14
- "aneka",
15
- "functions"
16
- ],
17
- "author": "Ardhi Lukianto <ardhi@lukianto.com>",
18
- "license": "MIT",
19
- "bugs": {
20
- "url": "https://github.com/ardhi/aneka/issues"
21
- },
22
- "homepage": "https://github.com/ardhi/aneka#readme",
23
- "dependencies": {
24
- "axios": "^0.24.0",
25
- "fast-glob": "^3.2.7",
26
- "global-dirs": "^3.0.0",
27
- "lodash": "^4.17.21",
28
- "query-string": "^7.0.1"
29
- }
30
- }
1
+ {
2
+ "name": "aneka",
3
+ "version": "0.0.25",
4
+ "description": "cemacemla",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/ardhi/aneka.git"
12
+ },
13
+ "keywords": [
14
+ "aneka",
15
+ "functions"
16
+ ],
17
+ "author": "Ardhi Lukianto <ardhi@lukianto.com>",
18
+ "license": "MIT",
19
+ "bugs": {
20
+ "url": "https://github.com/ardhi/aneka/issues"
21
+ },
22
+ "homepage": "https://github.com/ardhi/aneka#readme",
23
+ "dependencies": {
24
+ "axios": "^0.24.0",
25
+ "fast-glob": "^3.2.7",
26
+ "global-dirs": "^3.0.0",
27
+ "lodash": "^4.17.21",
28
+ "query-string": "^7.0.1",
29
+ "worker-timers": "^7.0.63"
30
+ }
31
+ }
@@ -1,11 +1,11 @@
1
- const { each, concat, reject, find } = require('lodash')
2
-
3
- module.exports = function (coll = [], col = '', names = []) {
4
- const picked = []
5
- const misc = reject(coll, c => names.includes(c[col]))
6
- each(names, n => {
7
- const item = find(coll, c => c[col] === n)
8
- if (item) picked.push(item)
9
- })
10
- return concat(picked, misc)
11
- }
1
+ const { each, concat, reject, find } = require('lodash')
2
+
3
+ module.exports = function (coll = [], col = '', names = []) {
4
+ const picked = []
5
+ const misc = reject(coll, c => names.includes(c[col]))
6
+ each(names, n => {
7
+ const item = find(coll, c => c[col] === n)
8
+ if (item) picked.push(item)
9
+ })
10
+ return concat(picked, misc)
11
+ }
@@ -1,7 +1,7 @@
1
- // source: https://flaviocopes.com/how-to-divide-collay-js/
2
-
3
- module.exports = function (coll, itemCount) {
4
- return new Array(Math.ceil(coll.length / itemCount))
5
- .fill()
6
- .map(_ => coll.splice(0, itemCount))
7
- }
1
+ // source: https://flaviocopes.com/how-to-divide-collay-js/
2
+
3
+ module.exports = function (coll, itemCount) {
4
+ return new Array(Math.ceil(coll.length / itemCount))
5
+ .fill()
6
+ .map(_ => coll.splice(0, itemCount))
7
+ }
@@ -1,10 +1,10 @@
1
- const { findIndex, set, pullAt, each } = require('lodash')
2
-
3
- module.exports = function (items, collection, key = 'id') {
4
- const idxs = []
5
- each(items, item => {
6
- const idx = findIndex(collection, set({}, key, item[key]))
7
- if (idx > -1) idxs.push(idx)
8
- })
9
- return pullAt(idxs)
10
- }
1
+ const { findIndex, set, pullAt, each } = require('lodash')
2
+
3
+ module.exports = function (items, collection, key = 'id') {
4
+ const idxs = []
5
+ each(items, item => {
6
+ const idx = findIndex(collection, set({}, key, item[key]))
7
+ if (idx > -1) idxs.push(idx)
8
+ })
9
+ return pullAt(idxs)
10
+ }
@@ -1,7 +1,7 @@
1
- const upsert = require('./upsert')
2
-
3
- module.exports = function (items, collection, key = 'id', tsCol, insert) {
4
- for (let i = 0; i < items.length; i++) {
5
- upsert(items[i], collection, key, tsCol, insert)
6
- }
7
- }
1
+ const upsert = require('./upsert')
2
+
3
+ module.exports = function (items, collection, key = 'id', tsCol, insert) {
4
+ for (let i = 0; i < items.length; i++) {
5
+ upsert(items[i], collection, key, tsCol, insert)
6
+ }
7
+ }
@@ -1,16 +1,16 @@
1
- // source: https://flaviocopes.com/how-to-divide-collay-js/
2
- module.exports = function (coll, groupCount) {
3
- const result = []
4
- for (let i = 0; i < groupCount; i++) {
5
- result.push([])
6
- }
7
- const wordsPerLine = Math.ceil(coll.length / groupCount)
8
- for (let line = 0; line < groupCount; line++) {
9
- for (let i = 0; i < wordsPerLine; i++) {
10
- const value = coll[i + line * wordsPerLine]
11
- if (!value) continue
12
- result[line].push(value)
13
- }
14
- }
15
- return result
16
- }
1
+ // source: https://flaviocopes.com/how-to-divide-collay-js/
2
+ module.exports = function (coll, groupCount) {
3
+ const result = []
4
+ for (let i = 0; i < groupCount; i++) {
5
+ result.push([])
6
+ }
7
+ const wordsPerLine = Math.ceil(coll.length / groupCount)
8
+ for (let line = 0; line < groupCount; line++) {
9
+ for (let i = 0; i < wordsPerLine; i++) {
10
+ const value = coll[i + line * wordsPerLine]
11
+ if (!value) continue
12
+ result[line].push(value)
13
+ }
14
+ }
15
+ return result
16
+ }
@@ -1,6 +1,6 @@
1
- const { map, filter, includes, uniq } = require('lodash')
2
-
3
- module.exports = function (collection, prop = 'id') {
4
- // based on: https://stackoverflow.com/questions/31681732/lodash-get-duplicate-values-from-an-array
5
- return uniq(filter(map(collection, prop), (val, i, iter) => includes(iter, val, i + 1)))
6
- }
1
+ const { map, filter, includes, uniq } = require('lodash')
2
+
3
+ module.exports = function (collection, prop = 'id') {
4
+ // based on: https://stackoverflow.com/questions/31681732/lodash-get-duplicate-values-from-an-array
5
+ return uniq(filter(map(collection, prop), (val, i, iter) => includes(iter, val, i + 1)))
6
+ }
@@ -1,13 +1,13 @@
1
- module.exports = function (coll, page = 1, rowsPerPage = 25) {
2
- const total = coll.length
3
- const offset = (page - 1) * rowsPerPage
4
- const rows = coll.slice(offset, offset + rowsPerPage)
5
-
6
- return {
7
- rows,
8
- page,
9
- rowsPerPage,
10
- total,
11
- totalPages: Math.ceil(coll.length / rowsPerPage)
12
- }
13
- }
1
+ module.exports = function (coll, page = 1, rowsPerPage = 25) {
2
+ const total = coll.length
3
+ const offset = (page - 1) * rowsPerPage
4
+ const rows = coll.slice(offset, offset + rowsPerPage)
5
+
6
+ return {
7
+ rows,
8
+ page,
9
+ rowsPerPage,
10
+ total,
11
+ totalPages: Math.ceil(coll.length / rowsPerPage)
12
+ }
13
+ }
@@ -1,6 +1,6 @@
1
- const { findIndex, set, pullAt } = require('lodash')
2
-
3
- module.exports = function (item, collection, key = 'id') {
4
- const idx = findIndex(collection, set({}, key, item[key]))
5
- return pullAt(collection, [idx])
6
- }
1
+ const { findIndex, set, pullAt } = require('lodash')
2
+
3
+ module.exports = function (item, collection, key = 'id') {
4
+ const idx = findIndex(collection, set({}, key, item[key]))
5
+ return pullAt(collection, [idx])
6
+ }
@@ -1,11 +1,11 @@
1
- module.exports = function (collection, prop) {
2
- const result = []
3
- const map = new Map()
4
- for (const item of collection) {
5
- if (!map.has(item[prop])) {
6
- map.set(item[prop], true)
7
- result.push(item)
8
- }
9
- }
10
- return result
11
- }
1
+ module.exports = function (collection, prop) {
2
+ const result = []
3
+ const map = new Map()
4
+ for (const item of collection) {
5
+ if (!map.has(item[prop])) {
6
+ map.set(item[prop], true)
7
+ result.push(item)
8
+ }
9
+ }
10
+ return result
11
+ }
@@ -1,15 +1,15 @@
1
- const { findIndex, set } = require('lodash')
2
-
3
- module.exports = function (item, collection, key = 'id', tsCol, insert) {
4
- const idx = findIndex(collection, set({}, key, item[key]))
5
- if (idx > -1) {
6
- if (tsCol) {
7
- if (item[tsCol] > collection[idx][tsCol]) collection[idx] = item
8
- } else {
9
- collection[idx] = item
10
- }
11
- } else {
12
- if (insert) collection.unshift(item)
13
- else collection.push(item)
14
- }
15
- }
1
+ const { findIndex, set } = require('lodash')
2
+
3
+ module.exports = function (item, collection, key = 'id', tsCol, insert) {
4
+ const idx = findIndex(collection, set({}, key, item[key]))
5
+ if (idx > -1) {
6
+ if (tsCol) {
7
+ if (item[tsCol] > collection[idx][tsCol]) collection[idx] = item
8
+ } else {
9
+ collection[idx] = item
10
+ }
11
+ } else {
12
+ if (insert) collection.unshift(item)
13
+ else collection.push(item)
14
+ }
15
+ }
@@ -1,6 +1,6 @@
1
- module.exports = function (array, sep = ', ', lastSep = ' and ') {
2
- if (array.length < 2) return `${array[0]}`
3
- const clone = array.slice(0)
4
- const last = clone.pop()
5
- return `${clone.join(sep)}${lastSep}${last}`
1
+ module.exports = function (array, sep = ', ', lastSep = ' and ') {
2
+ if (array.length < 2) return `${array[0]}`
3
+ const clone = array.slice(0)
4
+ const last = clone.pop()
5
+ return `${clone.join(sep)}${lastSep}${last}`
6
6
  }
@@ -1,5 +1,5 @@
1
- const { upperFirst, camelCase } = require('lodash')
2
-
3
- module.exports = function (text) {
4
- return upperFirst(camelCase(text))
5
- }
1
+ const { upperFirst, camelCase } = require('lodash')
2
+
3
+ module.exports = function (text) {
4
+ return upperFirst(camelCase(text))
5
+ }
@@ -1,7 +1,7 @@
1
- const path = require('path')
2
-
3
- module.exports = function (item, useSlash = true) {
4
- item = path.resolve(item)
5
- if (useSlash) item = item.replace(/\\/g, '/')
6
- return item
7
- }
1
+ const path = require('path')
2
+
3
+ module.exports = function (item, useSlash = true) {
4
+ item = path.resolve(item)
5
+ if (useSlash) item = item.replace(/\\/g, '/')
6
+ return item
7
+ }
package/src/index.js CHANGED
@@ -1,37 +1,37 @@
1
- module.exports = {
2
- // collection
3
- arrange: require('./collection/arrange'),
4
- breakArray: require('./collection/break'),
5
- bulkRemove: require('./collection/bulk-remove'),
6
- bulkUpsert: require('./collection/bulk-upsert'),
7
- divideArray: require('./collection/divide'),
8
- findDuplicate: require('./collection/find-duplicate'),
9
- paginate: require('./collection/paginate'),
10
- removeFromArray: require('./collection/remove'),
11
- uniqByProp: require('./collection/uniq-by-prop'),
12
- upsert: require('./collection/upsert'),
13
- // format
14
- pascalCase: require('./format/pascal-case'),
15
- humanJoin: require('./format/human-join'),
16
- // fs
17
- pathResolve: require('./fs/path-resolve'),
18
- // loader
19
- getGlobalModuleDir: require('./loader/get-global-module-dir'),
20
- getModuleDir: require('./loader/get-module-dir'),
21
- getModuleDirDeep: require('./loader/get-module-dir-deep'),
22
- requireDeep: require('./loader/require-deep'),
23
- requireBase: require('./loader/require-base'),
24
- requireBaseDeep: require('./loader/require-base-deep'),
25
- requireGlobal: require('./loader/require-global'),
26
- // misc
27
- delay: require('./misc/delay'),
28
- fatal: require('./misc/fatal'),
29
- fetchUrl: require('./misc/fetch-url'),
30
- isSet: require('./misc/is-set'),
31
- print: require('./misc/print'),
32
- parseBool: require('./misc/parse-bool'),
33
- dump: require('./misc/dump'),
34
- setImmediatePromise: require('./misc/set-immediate-promise'),
35
- // object
36
- sanitizeObject: require('./object/sanitize')
1
+ module.exports = {
2
+ // collection
3
+ arrange: require('./collection/arrange'),
4
+ breakArray: require('./collection/break'),
5
+ bulkRemove: require('./collection/bulk-remove'),
6
+ bulkUpsert: require('./collection/bulk-upsert'),
7
+ divideArray: require('./collection/divide'),
8
+ findDuplicate: require('./collection/find-duplicate'),
9
+ paginate: require('./collection/paginate'),
10
+ removeFromArray: require('./collection/remove'),
11
+ uniqByProp: require('./collection/uniq-by-prop'),
12
+ upsert: require('./collection/upsert'),
13
+ // format
14
+ pascalCase: require('./format/pascal-case'),
15
+ humanJoin: require('./format/human-join'),
16
+ // fs
17
+ pathResolve: require('./fs/path-resolve'),
18
+ // loader
19
+ getGlobalModuleDir: require('./loader/get-global-module-dir'),
20
+ getModuleDir: require('./loader/get-module-dir'),
21
+ getModuleDirDeep: require('./loader/get-module-dir-deep'),
22
+ requireDeep: require('./loader/require-deep'),
23
+ requireBase: require('./loader/require-base'),
24
+ requireBaseDeep: require('./loader/require-base-deep'),
25
+ requireGlobal: require('./loader/require-global'),
26
+ // misc
27
+ delay: require('./misc/delay'),
28
+ fatal: require('./misc/fatal'),
29
+ fetchUrl: require('./misc/fetch-url'),
30
+ isSet: require('./misc/is-set'),
31
+ print: require('./misc/print'),
32
+ parseBool: require('./misc/parse-bool'),
33
+ dump: require('./misc/dump'),
34
+ setImmediatePromise: require('./misc/set-immediate-promise'),
35
+ // object
36
+ sanitizeObject: require('./object/sanitize')
37
37
  }
@@ -1,11 +1,11 @@
1
- const globalDirs = require('global-dirs')
2
- const path = require('path')
3
- const pathResolve = require('../fs/path-resolve')
4
-
5
- module.exports = function (moduleId) {
6
- try {
7
- return pathResolve(path.dirname(require.resolve(path.join(globalDirs.yarn.packages, moduleId, 'package.json'))))
8
- } catch (err) {
9
- return pathResolve(path.dirname(require.resolve(path.join(globalDirs.npm.packages, moduleId, 'package.json'))))
10
- }
11
- }
1
+ const globalDirs = require('global-dirs')
2
+ const path = require('path')
3
+ const pathResolve = require('../fs/path-resolve')
4
+
5
+ module.exports = function (moduleId) {
6
+ try {
7
+ return pathResolve(path.dirname(require.resolve(path.join(globalDirs.yarn.packages, moduleId, 'package.json'))))
8
+ } catch (err) {
9
+ return pathResolve(path.dirname(require.resolve(path.join(globalDirs.npm.packages, moduleId, 'package.json'))))
10
+ }
11
+ }
@@ -1,25 +1,25 @@
1
- const pathResolve = require('../fs/path-resolve')
2
- const getGlobalModuleDir = require('./get-global-module-dir')
3
- const path = require('path')
4
-
5
- module.exports = function (name) {
6
- const pkg = name + '/package.json'
7
- let pkgFile
8
- try {
9
- pkgFile = require.resolve(pathResolve(pkg))
10
- } catch (err) {
11
- try {
12
- pkgFile = require.resolve(pkg)
13
- } catch (err) {
14
- try {
15
- pkgFile = require.resolve(process.cwd() + '/node_modules/' + pkg)
16
- } catch (err) {
17
- try {
18
- pkgFile = getGlobalModuleDir(pkg)
19
- } catch (err) {}
20
- }
21
- }
22
- }
23
- if (!pkgFile) throw new Error(`Can't get module directory '${name}' as file nor local/global module`)
24
- return pathResolve(path.dirname(pkgFile))
25
- }
1
+ const pathResolve = require('../fs/path-resolve')
2
+ const getGlobalModuleDir = require('./get-global-module-dir')
3
+ const path = require('path')
4
+
5
+ module.exports = function (name) {
6
+ const pkg = name + '/package.json'
7
+ let pkgFile
8
+ try {
9
+ pkgFile = require.resolve(pathResolve(pkg))
10
+ } catch (err) {
11
+ try {
12
+ pkgFile = require.resolve(pkg)
13
+ } catch (err) {
14
+ try {
15
+ pkgFile = require.resolve(process.cwd() + '/node_modules/' + pkg)
16
+ } catch (err) {
17
+ try {
18
+ pkgFile = getGlobalModuleDir(pkg)
19
+ } catch (err) {}
20
+ }
21
+ }
22
+ }
23
+ if (!pkgFile) throw new Error(`Can't get module directory '${name}' as file nor local/global module`)
24
+ return pathResolve(path.dirname(pkgFile))
25
+ }
@@ -1,7 +1,7 @@
1
- const pathResolve = require('../fs/path-resolve')
2
- const path = require('path')
3
-
4
- module.exports = function (name) {
5
- name = name + '/package.json'
6
- return pathResolve(path.dirname(require.resolve(pathResolve(name))))
7
- }
1
+ const pathResolve = require('../fs/path-resolve')
2
+ const path = require('path')
3
+
4
+ module.exports = function (name) {
5
+ name = name + '/package.json'
6
+ return pathResolve(path.dirname(require.resolve(pathResolve(name))))
7
+ }
@@ -1,28 +1,29 @@
1
- const fg = require('fast-glob')
2
- const { map, filter, isFunction } = require('lodash')
3
- const path = require('path')
4
-
5
- const stripExt = file => {
6
- const parts = path.parse(file)
7
- return parts.dir + '/' + parts.name
8
- }
9
-
10
- module.exports = async function (dir, transformer, options = {}) {
11
- if (!dir) throw new Error('Directory is missing')
12
- if (!transformer) throw new Error('Transformer is missing')
13
- const files = await fg(dir + '/*.{json,js}', options.glob)
14
- const strippeds = map(files, f => stripExt(f))
15
- const result = []
16
- for (const file of files) {
17
- const stripped = stripExt(file)
18
- if (filter(strippeds, f => f === stripped).length > 1) throw new (`File '${stripped}.{json,js}' already used`)
19
- try {
20
- let mod = require(file)
21
- if (isFunction(mod)) mod = await mod.call(options.scope)
22
- result.push(await transformer(file, mod, options.transformer))
23
- } catch (err) {
24
- throw err
25
- }
26
- }
27
- return result
28
- }
1
+ const fg = require('fast-glob')
2
+ const { map, filter, isFunction } = require('lodash')
3
+ const path = require('path')
4
+
5
+ const stripExt = file => {
6
+ const parts = path.parse(file)
7
+ return parts.dir + '/' + parts.name
8
+ }
9
+
10
+ module.exports = async function (dir, transformer, options = {}) {
11
+ if (!dir) throw new Error('Directory is missing')
12
+ if (!transformer) throw new Error('Transformer is missing')
13
+ const files = await fg(dir + '/*.{json,js}', options.glob)
14
+ const strippeds = map(files, f => stripExt(f))
15
+ const result = []
16
+ const me = this
17
+ for (const file of files) {
18
+ const stripped = stripExt(file)
19
+ if (filter(strippeds, f => f === stripped).length > 1) throw new (`File '${stripped}.{json,js}' already used`)
20
+ try {
21
+ let mod = require(file)
22
+ if (isFunction(mod)) mod = await mod.call(me, options)
23
+ result.push(await transformer(file, mod, options.transformer))
24
+ } catch (err) {
25
+ throw err
26
+ }
27
+ }
28
+ return result
29
+ }
@@ -1,18 +1,19 @@
1
- const { isFunction } = require('lodash')
2
- const path = require('path')
3
- const pathResolve = require('../fs/path-resolve')
4
-
5
- module.exports = async function (file, options) {
6
- const parsed = path.parse(pathResolve(file))
7
- try {
8
- const mod = require(parsed.dir + '/' + parsed.name + '.js')
9
- if (isFunction(mod)) return await mod(options)
10
- return mod
11
- } catch (err) {
12
- try {
13
- return require(parsed.dir + '/' + parsed.name + '.json')
14
- } catch (err) {
15
- throw err
16
- }
17
- }
18
- }
1
+ const { isFunction } = require('lodash')
2
+ const path = require('path')
3
+ const pathResolve = require('../fs/path-resolve')
4
+
5
+ module.exports = async function (file, options) {
6
+ const parsed = path.parse(pathResolve(file))
7
+ const me = this
8
+ try {
9
+ const mod = require(parsed.dir + '/' + parsed.name + '.js')
10
+ if (isFunction(mod)) return await mod.call(me, options)
11
+ return mod
12
+ } catch (err) {
13
+ try {
14
+ return require(parsed.dir + '/' + parsed.name + '.json')
15
+ } catch (err) {
16
+ throw err
17
+ }
18
+ }
19
+ }
@@ -1,30 +1,30 @@
1
- /*
2
- const getModuleDirDeep = require('./get-module-dir-deep')
3
-
4
- module.exports = function (name) {
5
- return require(getModuleDirDeep(name))
6
- }
7
- */
8
- const requireGlobal = require('./require-global')
9
- const pathResolve = require('../fs/path-resolve')
10
-
11
- module.exports = function (name) {
12
- let mod
13
- try {
14
- mod = require(pathResolve(name))
15
- } catch (err) {
16
- try {
17
- mod = require(name)
18
- } catch (err) {
19
- try {
20
- mod = require(process.cwd() + '/node_modules/' + name)
21
- } catch (err) {
22
- try {
23
- mod = requireGlobal(name)
24
- } catch (err) {}
25
- }
26
- }
27
- }
28
- if (!mod) throw new Error(`Can't load '${name}' as file nor local/global module`)
29
- return mod
30
- }
1
+ /*
2
+ const getModuleDirDeep = require('./get-module-dir-deep')
3
+
4
+ module.exports = function (name) {
5
+ return require(getModuleDirDeep(name))
6
+ }
7
+ */
8
+ const requireGlobal = require('./require-global')
9
+ const pathResolve = require('../fs/path-resolve')
10
+
11
+ module.exports = function (name) {
12
+ let mod
13
+ try {
14
+ mod = require(pathResolve(name))
15
+ } catch (err) {
16
+ try {
17
+ mod = require(name)
18
+ } catch (err) {
19
+ try {
20
+ mod = require(process.cwd() + '/node_modules/' + name)
21
+ } catch (err) {
22
+ try {
23
+ mod = requireGlobal(name)
24
+ } catch (err) {}
25
+ }
26
+ }
27
+ }
28
+ if (!mod) throw new Error(`Can't load '${name}' as file nor local/global module`)
29
+ return mod
30
+ }
@@ -1,5 +1,5 @@
1
- const getGlobalModuleDir = require('./get-global-module-dir')
2
-
3
- module.exports = function (name) {
4
- return require(getGlobalModuleDir(name))
5
- }
1
+ const getGlobalModuleDir = require('./get-global-module-dir')
2
+
3
+ module.exports = function (name) {
4
+ return require(getGlobalModuleDir(name))
5
+ }
package/src/misc/delay.js CHANGED
@@ -1,7 +1,18 @@
1
- module.exports = function (ms = 1000) {
2
- return new Promise((resolve, reject) => {
3
- setTimeout(() => {
4
- resolve()
5
- }, ms)
6
- })
7
- }
1
+ const wt = require('worker-timers')
2
+
3
+ module.exports = function (ms = 1000, useWorker) {
4
+ return new Promise((resolve, reject) => {
5
+ let timer
6
+ if (useWorker) {
7
+ timer = wt.setTimeout(() => {
8
+ if (timer) wt.clearTimeout(timer)
9
+ resolve()
10
+ }, ms)
11
+ } else {
12
+ timer = setTimeout(() => {
13
+ if (timer) clearTimeout(timer)
14
+ resolve()
15
+ }, ms)
16
+ }
17
+ })
18
+ }
package/src/misc/dump.js CHANGED
@@ -1,6 +1,6 @@
1
- const util = require('util')
2
-
3
- module.exports = function (obj) {
4
- const result = util.inspect(obj, false, null, true)
5
- console.log(result)
6
- }
1
+ const util = require('util')
2
+
3
+ module.exports = function (obj) {
4
+ const result = util.inspect(obj, false, null, true)
5
+ console.log(result)
6
+ }
package/src/misc/fatal.js CHANGED
@@ -1,10 +1,10 @@
1
- const print = require('./print')
2
- const { get } = require('lodash')
3
- const isSet = require('./is-set')
4
-
5
- module.exports = function (msg, terminate) {
6
- if (!isSet(terminate)) terminate = true
7
- const debug = get(process, 'env.DEBUG', false)
8
- if (msg instanceof Error) msg = msg.message
9
- print(msg, terminate, debug ? 'trace' : 'error')
10
- }
1
+ const print = require('./print')
2
+ const { get } = require('lodash')
3
+ const isSet = require('./is-set')
4
+
5
+ module.exports = function (msg, terminate) {
6
+ if (!isSet(terminate)) terminate = true
7
+ const debug = get(process, 'env.DEBUG', false)
8
+ if (msg instanceof Error) msg = msg.message
9
+ print(msg, terminate, debug ? 'trace' : 'error')
10
+ }
@@ -1,53 +1,53 @@
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
- if (cfg.raw) return resp
7
- return resp.data
8
- }
9
-
10
- const handleError = (err, opts, cfg) => {
11
- return err
12
- }
13
-
14
- module.exports = function (opts = {}, cfg = {}) {
15
- return new Promise((resolve, reject) => {
16
- if (isString(opts)) opts = { url: opts }
17
- opts.params = opts.params || {}
18
- if (!has(cfg, 'cacheBuster')) cfg.cacheBuster = true
19
- if (cfg.cacheBuster) opts.params[cfg.cacheBusterKey || '_'] = Date.now()
20
- if (cfg.streamHandler) {
21
- opts.url = `${opts.url}?${qs.stringify(opts.params)}`
22
- let error
23
- fetch(opts.url, omit(opts, ['url', 'params']))
24
- .then(resp => {
25
- if (!resp.ok) {
26
- error = resp
27
- return false
28
- }
29
- return cfg.streamHandler(resp)
30
- })
31
- .then(resp => {
32
- if (!resp) return false
33
- resolve(handleSuccess({ data: resp }, opts, cfg))
34
- })
35
- .then(resp => {
36
- const e = new Error(error.statusText)
37
- e.status = error.status
38
- reject(handleError(e, opts, cfg))
39
- })
40
- .catch(err => {
41
- reject(handleError(err, opts, cfg))
42
- })
43
- return
44
- }
45
- axios(opts)
46
- .then(resp => {
47
- resolve(handleSuccess(resp, opts, cfg))
48
- })
49
- .catch(err => {
50
- reject(handleError(err, opts, cfg))
51
- })
52
- })
53
- }
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
+ if (cfg.raw) return resp
7
+ return resp.data
8
+ }
9
+
10
+ const handleError = (err, opts, cfg) => {
11
+ return err
12
+ }
13
+
14
+ module.exports = function (opts = {}, cfg = {}) {
15
+ return new Promise((resolve, reject) => {
16
+ if (isString(opts)) opts = { url: opts }
17
+ opts.params = opts.params || {}
18
+ if (!has(cfg, 'cacheBuster')) cfg.cacheBuster = true
19
+ if (cfg.cacheBuster) opts.params[cfg.cacheBusterKey || '_'] = Date.now()
20
+ if (cfg.streamHandler) {
21
+ opts.url = `${opts.url}?${qs.stringify(opts.params)}`
22
+ let error
23
+ fetch(opts.url, omit(opts, ['url', 'params']))
24
+ .then(resp => {
25
+ if (!resp.ok) {
26
+ error = resp
27
+ return false
28
+ }
29
+ return cfg.streamHandler(resp)
30
+ })
31
+ .then(resp => {
32
+ if (!resp) return false
33
+ resolve(handleSuccess({ data: resp }, opts, cfg))
34
+ })
35
+ .then(resp => {
36
+ const e = new Error(error.statusText)
37
+ e.status = error.status
38
+ reject(handleError(e, opts, cfg))
39
+ })
40
+ .catch(err => {
41
+ reject(handleError(err, opts, cfg))
42
+ })
43
+ return
44
+ }
45
+ axios(opts)
46
+ .then(resp => {
47
+ resolve(handleSuccess(resp, opts, cfg))
48
+ })
49
+ .catch(err => {
50
+ reject(handleError(err, opts, cfg))
51
+ })
52
+ })
53
+ }
@@ -1,3 +1,3 @@
1
- module.exports = function (input) {
2
- return !(input === null || input === undefined)
3
- }
1
+ module.exports = function (input) {
2
+ return !(input === null || input === undefined)
3
+ }
@@ -1,5 +1,5 @@
1
- module.exports = function (input = '', caseInsensitive = false) {
2
- const falsy = ['0', '0n', 'null', 'undefined', 'false', 'NaN', '']
3
- if (caseInsensitive) input = input.toLowerCase()
4
- return !falsy.includes(input)
5
- }
1
+ module.exports = function (input = '', caseInsensitive = false) {
2
+ const falsy = ['0', '0n', 'null', 'undefined', 'false', 'NaN', '']
3
+ if (caseInsensitive) input = input.toLowerCase()
4
+ return !falsy.includes(input)
5
+ }
package/src/misc/print.js CHANGED
@@ -1,5 +1,5 @@
1
- module.exports = (msg, terminate, method = 'log') => {
2
- if (method === true) method = 'log'
3
- console[method](msg)
4
- if (terminate) process.exit(1)
5
- }
1
+ module.exports = (msg, terminate, method = 'log') => {
2
+ if (method === true) method = 'log'
3
+ console[method](msg)
4
+ if (terminate) process.exit(1)
5
+ }
@@ -1,5 +1,5 @@
1
- module.exports = function () {
2
- return new Promise((resolve) => {
3
- setImmediate(() => resolve())
4
- })
5
- }
1
+ module.exports = function () {
2
+ return new Promise((resolve) => {
3
+ setImmediate(() => resolve())
4
+ })
5
+ }
@@ -1,14 +1,14 @@
1
- const { forOwn } = require('lodash')
2
-
3
- module.exports = function(params) {
4
- const result = {}
5
- forOwn(params, (v, k) => {
6
- let val
7
- if (v === 'true') val = true
8
- else if (v === 'false') val = false
9
- else if (Number(v)) val = Number(v)
10
- else val = v
11
- result[k] = val
12
- })
13
- return result
14
- }
1
+ const { forOwn } = require('lodash')
2
+
3
+ module.exports = function(params) {
4
+ const result = {}
5
+ forOwn(params, (v, k) => {
6
+ let val
7
+ if (v === 'true') val = true
8
+ else if (v === 'false') val = false
9
+ else if (Number(v)) val = Number(v)
10
+ else val = v
11
+ result[k] = val
12
+ })
13
+ return result
14
+ }