aneka 0.17.5 → 0.17.7

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 (147) hide show
  1. package/.jsdoc.conf.json +0 -0
  2. package/CHANGES.md +87 -79
  3. package/LICENSE +21 -21
  4. package/README.md +63 -63
  5. package/docs/arrange-array.js.html +0 -0
  6. package/docs/create-class.js.html +0 -0
  7. package/docs/current-loc.js.html +0 -0
  8. package/docs/data/search.json +0 -0
  9. package/docs/defaults-deep.js.html +0 -0
  10. package/docs/delay.js.html +0 -0
  11. package/docs/extract-text.js.html +0 -0
  12. package/docs/fill-object.js.html +0 -0
  13. package/docs/filter-duplicate.js.html +0 -0
  14. package/docs/filter-index.js.html +0 -0
  15. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  16. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  17. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  18. package/docs/format-text.js.html +0 -0
  19. package/docs/generate-id.js.html +0 -0
  20. package/docs/get-caller-filename.js.html +0 -0
  21. package/docs/get-global-module-dir.js.html +0 -0
  22. package/docs/get-index.js.html +0 -0
  23. package/docs/get-key-by-value.js.html +0 -0
  24. package/docs/global.html +0 -0
  25. package/docs/includes.js.html +0 -0
  26. package/docs/index.html +0 -0
  27. package/docs/is-class.js.html +0 -0
  28. package/docs/is-set.js.html +0 -0
  29. package/docs/merge-objects-by-key.js.html +0 -0
  30. package/docs/paginate.js.html +0 -0
  31. package/docs/parse-args-argv.js.html +0 -0
  32. package/docs/parse-duration.js.html +0 -0
  33. package/docs/parse-env.js.html +0 -0
  34. package/docs/parse-kv-string.js.html +0 -0
  35. package/docs/parse-object.js.html +0 -0
  36. package/docs/pascal-case.js.html +0 -0
  37. package/docs/random-range.js.html +0 -0
  38. package/docs/resolve-path.js.html +0 -0
  39. package/docs/round.js.html +0 -0
  40. package/docs/scripts/core.js +0 -0
  41. package/docs/scripts/core.min.js +0 -0
  42. package/docs/scripts/resize.js +0 -0
  43. package/docs/scripts/search.js +0 -0
  44. package/docs/scripts/search.min.js +5 -5
  45. package/docs/scripts/third-party/Apache-License-2.0.txt +0 -0
  46. package/docs/scripts/third-party/fuse.js +0 -0
  47. package/docs/scripts/third-party/hljs-line-num-original.js +0 -0
  48. package/docs/scripts/third-party/hljs-line-num.js +0 -0
  49. package/docs/scripts/third-party/hljs-original.js +0 -0
  50. package/docs/scripts/third-party/hljs.js +0 -0
  51. package/docs/scripts/third-party/popper.js +0 -0
  52. package/docs/scripts/third-party/tippy.js +0 -0
  53. package/docs/scripts/third-party/tocbot.js +0 -0
  54. package/docs/scripts/third-party/tocbot.min.js +0 -0
  55. package/docs/sec-to-hms.js.html +0 -0
  56. package/docs/set-immediate.js.html +0 -0
  57. package/docs/set-interval.js.html +0 -0
  58. package/docs/set-timeout.js.html +0 -0
  59. package/docs/shim.js.html +0 -0
  60. package/docs/static/bitcoin.jpeg +0 -0
  61. package/docs/styles/clean-jsdoc-theme-base.css +0 -0
  62. package/docs/styles/clean-jsdoc-theme-dark.css +0 -0
  63. package/docs/styles/clean-jsdoc-theme-light.css +0 -0
  64. package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -0
  65. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
  66. package/docs/styles/clean-jsdoc-theme.min.css +0 -0
  67. package/docs/text-to-array.js.html +0 -0
  68. package/docs/titleize.js.html +0 -0
  69. package/docs/without.js.html +0 -0
  70. package/index.js +119 -119
  71. package/package.json +48 -48
  72. package/src/arrange-array.js +25 -25
  73. package/src/create-class.js +35 -35
  74. package/src/current-loc.js +0 -0
  75. package/src/defaults-deep.js +20 -20
  76. package/src/delay.js +19 -19
  77. package/src/extract-text.js +23 -23
  78. package/src/fill-object.js +17 -17
  79. package/src/filter-duplicate.js +26 -26
  80. package/src/filter-index.js +17 -17
  81. package/src/format-text.js +88 -88
  82. package/src/generate-id.js +35 -35
  83. package/src/get-caller-filename.js +25 -25
  84. package/src/get-global-module-dir.js +24 -20
  85. package/src/get-index.js +15 -15
  86. package/src/get-key-by-value.js +12 -12
  87. package/src/includes.js +18 -18
  88. package/src/is-class.js +13 -13
  89. package/src/is-set.js +11 -11
  90. package/src/log.js +19 -19
  91. package/src/merge-objects-by-key.js +24 -24
  92. package/src/paginate.js +45 -45
  93. package/src/parse-args-argv.js +0 -0
  94. package/src/parse-duration.js +14 -14
  95. package/src/parse-env.js +0 -0
  96. package/src/parse-kv-string.js +21 -21
  97. package/src/parse-object.js +76 -76
  98. package/src/pascal-case.js +14 -14
  99. package/src/random-range.js +15 -15
  100. package/src/resolve-path.js +0 -0
  101. package/src/round.js +13 -13
  102. package/src/sec-to-hms.js +27 -27
  103. package/src/set-immediate.js +12 -12
  104. package/src/set-interval.js +56 -55
  105. package/src/set-timeout.js +34 -34
  106. package/src/shim.js +28 -28
  107. package/src/text-to-array.js +17 -17
  108. package/src/titleize.js +37 -37
  109. package/src/without.js +18 -18
  110. package/test/arrange-array.js +41 -41
  111. package/test/create-class.js +33 -33
  112. package/test/current-loc.js +24 -24
  113. package/test/defaults-deep.js +19 -19
  114. package/test/delay.js +17 -17
  115. package/test/extract-text.js +17 -17
  116. package/test/fill-object.js +17 -17
  117. package/test/filter-duplicate.js +19 -19
  118. package/test/filter-index.js +17 -17
  119. package/test/format-text.js +26 -26
  120. package/test/generate-id.js +28 -28
  121. package/test/get-caller-filename.js +22 -22
  122. package/test/get-global-module-dir.js +51 -51
  123. package/test/get-index.js +17 -17
  124. package/test/get-key-by-value.js +17 -17
  125. package/test/includes.js +18 -18
  126. package/test/is-class.js +19 -19
  127. package/test/is-set.js +21 -21
  128. package/test/log.js +47 -47
  129. package/test/merge-objects-by-key.js +19 -19
  130. package/test/paginate.js +24 -24
  131. package/test/parse-args-argv.js +63 -63
  132. package/test/parse-duration.js +18 -18
  133. package/test/parse-env.js +35 -35
  134. package/test/parse-kv-string.js +17 -17
  135. package/test/parse-object.js +30 -30
  136. package/test/pascal-case.js +18 -18
  137. package/test/random-range.js +21 -21
  138. package/test/resolve-path.js +22 -22
  139. package/test/round.js +19 -19
  140. package/test/sec-to-hms.js +18 -18
  141. package/test/set-immediate.js +17 -17
  142. package/test/set-interval.js +196 -180
  143. package/test/set-timeout.js +120 -120
  144. package/test/shim.js +34 -34
  145. package/test/text-to-array.js +18 -18
  146. package/test/titleize.js +27 -27
  147. package/test/without.js +17 -17
@@ -1,26 +1,26 @@
1
- /**
2
- * Filter array of duplicates
3
- *
4
- * @param {Array} inputs - Array to filter from. Must be an array of objects
5
- * @param {string} key - Key's object
6
- */
7
-
8
- function filterDuplicate (inputs, key) {
9
- const seen = new Set()
10
- const dups = new Set()
11
-
12
- inputs.forEach(item => {
13
- const val = item[key]
14
- if (seen.has(val)) {
15
- dups.add(val)
16
- } else {
17
- seen.add(val)
18
- }
19
- })
20
-
21
- return inputs.filter(item => {
22
- return dups.has(item[key])
23
- })
24
- }
25
-
26
- export default filterDuplicate
1
+ /**
2
+ * Filter array of duplicates
3
+ *
4
+ * @param {Array} inputs - Array to filter from. Must be an array of objects
5
+ * @param {string} key - Key's object
6
+ */
7
+
8
+ function filterDuplicate (inputs, key) {
9
+ const seen = new Set()
10
+ const dups = new Set()
11
+
12
+ inputs.forEach(item => {
13
+ const val = item[key]
14
+ if (seen.has(val)) {
15
+ dups.add(val)
16
+ } else {
17
+ seen.add(val)
18
+ }
19
+ })
20
+
21
+ return inputs.filter(item => {
22
+ return dups.has(item[key])
23
+ })
24
+ }
25
+
26
+ export default filterDuplicate
@@ -1,17 +1,17 @@
1
- /**
2
- * Filter array's indexes
3
- *
4
- * @param {Array} inputs - Array to filter from
5
- * @param {Object} matcher - Function to match conditions. If returns ```true```, the running index will be added to the result
6
- * @returns {Array} Filtered indexes
7
- */
8
-
9
- function filterIndex (inputs, matcher) {
10
- const indexes = inputs.reduce((accumulator, current, index) => {
11
- if (matcher(current)) accumulator.push(index)
12
- return accumulator
13
- }, [])
14
- return indexes
15
- }
16
-
17
- export default filterIndex
1
+ /**
2
+ * Filter array's indexes
3
+ *
4
+ * @param {Array} inputs - Array to filter from
5
+ * @param {Object} matcher - Function to match conditions. If returns ```true```, the running index will be added to the result
6
+ * @returns {Array} Filtered indexes
7
+ */
8
+
9
+ function filterIndex (inputs, matcher) {
10
+ const indexes = inputs.reduce((accumulator, current, index) => {
11
+ if (matcher(current)) accumulator.push(index)
12
+ return accumulator
13
+ }, [])
14
+ return indexes
15
+ }
16
+
17
+ export default filterIndex
@@ -1,88 +1,88 @@
1
- import { sprintf } from 'sprintf-js'
2
- import pascalCase from './pascal-case.js'
3
- import secToHms from './sec-to-hms.js'
4
- import {
5
- camelCase,
6
- capitalize,
7
- escape,
8
- kebabCase,
9
- toLower,
10
- toUpper,
11
- lowerFirst,
12
- upperFirst,
13
- snakeCase,
14
- startCase,
15
- trim,
16
- unescape,
17
- keys,
18
- find
19
- } from 'lodash-es'
20
-
21
- const modifier = {
22
- camelCase,
23
- capitalize,
24
- escape,
25
- kebabCase,
26
- toLower,
27
- toUpper,
28
- lowerFirst,
29
- upperFirst,
30
- snakeCase,
31
- startCase,
32
- trim,
33
- unescape,
34
- pascalCase,
35
- secToHms
36
- }
37
-
38
- const modifiers = keys(modifier)
39
-
40
- const pipe = '|'
41
- const tokens = ['b', 'c', 'd', 'i', 'e', 'u', 'f', 'g', 'o', 's', 't', 'T', 'v', 'x', 'X', 'j']
42
-
43
- /**
44
- * Format text according using sprintf with extra ability to run its arguments through a serie of modifiers
45
- * Modifier must be place right after a token prepended with pipe ``|``` symbols.
46
- * You can put as many mofifiers as you want.
47
- *
48
- * E.g:
49
- * ```javascript
50
- * const text = 'Collected %s|toLower|upperFirst: %d'
51
- * const result = this.app.lib.formatText(text, 'iTeMs', 10)
52
- * console.log(result) // Collected Items: 10
53
- * ```
54
- *
55
- * @param {string} text - Text to be formatted
56
- * @param {...any} args - Argumennts
57
- * @returns {string} Formatted text
58
- */
59
- function formatText (text, ...args) {
60
- if (!text.includes(pipe)) return sprintf(text, ...args)
61
- const items = text.split('%')
62
- let newText = text.replaceAll('%%', '\t\t')
63
- const newArgs = ['', ...args]
64
- for (const idx in items) {
65
- const item = items[idx]
66
- if (tokens.includes(item[0])) {
67
- const parts = item.split(pipe)
68
- parts.shift()
69
- for (const part of parts) {
70
- let mod = modifier[part]
71
- if (!mod) {
72
- const fn = find(modifiers, name => part.slice(0, name.length) === name)
73
- if (fn) mod = modifier[fn]
74
- }
75
- if (mod) newArgs[idx] = mod(newArgs[idx])
76
- }
77
- }
78
- }
79
- newText = newText.replaceAll('\t\t', '%%')
80
- for (const key of keys(modifier)) {
81
- newText = newText.replaceAll(`${pipe}${key}`, '')
82
- }
83
- newText = newText.replace(pipe, '')
84
- newArgs.shift()
85
- return sprintf(newText, ...newArgs)
86
- }
87
-
88
- export default formatText
1
+ import { sprintf } from 'sprintf-js'
2
+ import pascalCase from './pascal-case.js'
3
+ import secToHms from './sec-to-hms.js'
4
+ import {
5
+ camelCase,
6
+ capitalize,
7
+ escape,
8
+ kebabCase,
9
+ toLower,
10
+ toUpper,
11
+ lowerFirst,
12
+ upperFirst,
13
+ snakeCase,
14
+ startCase,
15
+ trim,
16
+ unescape,
17
+ keys,
18
+ find
19
+ } from 'lodash-es'
20
+
21
+ const modifier = {
22
+ camelCase,
23
+ capitalize,
24
+ escape,
25
+ kebabCase,
26
+ toLower,
27
+ toUpper,
28
+ lowerFirst,
29
+ upperFirst,
30
+ snakeCase,
31
+ startCase,
32
+ trim,
33
+ unescape,
34
+ pascalCase,
35
+ secToHms
36
+ }
37
+
38
+ const modifiers = keys(modifier)
39
+
40
+ const pipe = '|'
41
+ const tokens = ['b', 'c', 'd', 'i', 'e', 'u', 'f', 'g', 'o', 's', 't', 'T', 'v', 'x', 'X', 'j']
42
+
43
+ /**
44
+ * Format text according using sprintf with extra ability to run its arguments through a serie of modifiers
45
+ * Modifier must be place right after a token prepended with pipe ``|``` symbols.
46
+ * You can put as many mofifiers as you want.
47
+ *
48
+ * E.g:
49
+ * ```javascript
50
+ * const text = 'Collected %s|toLower|upperFirst: %d'
51
+ * const result = this.app.lib.formatText(text, 'iTeMs', 10)
52
+ * console.log(result) // Collected Items: 10
53
+ * ```
54
+ *
55
+ * @param {string} text - Text to be formatted
56
+ * @param {...any} args - Argumennts
57
+ * @returns {string} Formatted text
58
+ */
59
+ function formatText (text, ...args) {
60
+ if (!text.includes(pipe)) return sprintf(text, ...args)
61
+ const items = text.split('%')
62
+ let newText = text.replaceAll('%%', '\t\t')
63
+ const newArgs = ['', ...args]
64
+ for (const idx in items) {
65
+ const item = items[idx]
66
+ if (tokens.includes(item[0])) {
67
+ const parts = item.split(pipe)
68
+ parts.shift()
69
+ for (const part of parts) {
70
+ let mod = modifier[part]
71
+ if (!mod) {
72
+ const fn = find(modifiers, name => part.slice(0, name.length) === name)
73
+ if (fn) mod = modifier[fn]
74
+ }
75
+ if (mod) newArgs[idx] = mod(newArgs[idx])
76
+ }
77
+ }
78
+ }
79
+ newText = newText.replaceAll('\t\t', '%%')
80
+ for (const key of keys(modifier)) {
81
+ newText = newText.replaceAll(`${pipe}${key}`, '')
82
+ }
83
+ newText = newText.replace(pipe, '')
84
+ newArgs.shift()
85
+ return sprintf(newText, ...newArgs)
86
+ }
87
+
88
+ export default formatText
@@ -1,35 +1,35 @@
1
- import { customAlphabet } from 'nanoid'
2
-
3
- /**
4
- * Generate unique random characters that can be used as ID. Use {@link https://github.com/ai/nanoid|nanoid} under the hood
5
- *
6
- * @method
7
- * @memberof module:Lib
8
- * @param {(boolean|string|Object)} [options={}] - Options. If set to ```true``` or ```alpha```, it will generate alphaphet only characters. If set to ```int```, it will generate integer only characters. Otherwise:
9
- * @param {string} [options.pattern] - Character pattern to use. Defaults to all available alphanumeric characters
10
- * @param {number} [options.length=13] - Length of resulted characters
11
- * @param {string} [options.case] - If set to ```lower``` to use lower cased pattern only. For upper cased pattern, set it to ```upper```
12
- * @param {boolean} [options.returnInstance] - Set to ```true``` to return {@link https://github.com/ai/nanoid|nanoid} instance instead of string
13
- * @returns {(string|Object)} Return string or instance of {@link https://github.com/ai/nanoid|nanoid}
14
- */
15
- function generateId (options = {}) {
16
- let type
17
- if (options === true) options = 'alpha'
18
- if (options === 'int') {
19
- type = options
20
- options = { pattern: '0123456789', length: 15 }
21
- } else if (options === 'alpha') {
22
- type = options
23
- options = { pattern: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', length: 15 }
24
- }
25
- let { pattern, length = 13, returnInstance } = options
26
- pattern = pattern ?? 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
27
- if (options.case === 'lower') pattern = pattern.toLowerCase()
28
- else if (options.case === 'upper') pattern = pattern.toUpperCase()
29
- const nid = customAlphabet(pattern, length)
30
- if (returnInstance) return nid
31
- const value = nid()
32
- return type === 'int' ? parseInt(value) : value
33
- }
34
-
35
- export default generateId
1
+ import { customAlphabet } from 'nanoid'
2
+
3
+ /**
4
+ * Generate unique random characters that can be used as ID. Use {@link https://github.com/ai/nanoid|nanoid} under the hood
5
+ *
6
+ * @method
7
+ * @memberof module:Lib
8
+ * @param {(boolean|string|Object)} [options={}] - Options. If set to ```true``` or ```alpha```, it will generate alphaphet only characters. If set to ```int```, it will generate integer only characters. Otherwise:
9
+ * @param {string} [options.pattern] - Character pattern to use. Defaults to all available alphanumeric characters
10
+ * @param {number} [options.length=13] - Length of resulted characters
11
+ * @param {string} [options.case] - If set to ```lower``` to use lower cased pattern only. For upper cased pattern, set it to ```upper```
12
+ * @param {boolean} [options.returnInstance] - Set to ```true``` to return {@link https://github.com/ai/nanoid|nanoid} instance instead of string
13
+ * @returns {(string|Object)} Return string or instance of {@link https://github.com/ai/nanoid|nanoid}
14
+ */
15
+ function generateId (options = {}) {
16
+ let type
17
+ if (options === true) options = 'alpha'
18
+ if (options === 'int') {
19
+ type = options
20
+ options = { pattern: '0123456789', length: 15 }
21
+ } else if (options === 'alpha') {
22
+ type = options
23
+ options = { pattern: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', length: 15 }
24
+ }
25
+ let { pattern, length = 13, returnInstance } = options
26
+ pattern = pattern ?? 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
27
+ if (options.case === 'lower') pattern = pattern.toLowerCase()
28
+ else if (options.case === 'upper') pattern = pattern.toUpperCase()
29
+ const nid = customAlphabet(pattern, length)
30
+ if (returnInstance) return nid
31
+ const value = nid()
32
+ return type === 'int' ? parseInt(value) : value
33
+ }
34
+
35
+ export default generateId
@@ -1,25 +1,25 @@
1
- /**
2
- * Returns the caller file path from the current stack trace.
3
- *
4
- * @returns {string|undefined} Caller file path.
5
- */
6
- function getCallerFilename () {
7
- const originalFunc = Error.prepareStackTrace
8
- let callerfile
9
-
10
- try {
11
- const err = new Error()
12
- Error.prepareStackTrace = (_, stack) => stack
13
- const currentfile = err.stack.shift().getFileName()
14
-
15
- while (err.stack.length) {
16
- callerfile = err.stack.shift().getFileName()
17
- if (currentfile !== callerfile) break
18
- }
19
- } catch (e) {}
20
-
21
- Error.prepareStackTrace = originalFunc
22
- return callerfile
23
- }
24
-
25
- export default getCallerFilename
1
+ /**
2
+ * Returns the caller file path from the current stack trace.
3
+ *
4
+ * @returns {string|undefined} Caller file path.
5
+ */
6
+ function getCallerFilename () {
7
+ const originalFunc = Error.prepareStackTrace
8
+ let callerfile
9
+
10
+ try {
11
+ const err = new Error()
12
+ Error.prepareStackTrace = (_, stack) => stack
13
+ const currentfile = err.stack.shift().getFileName()
14
+
15
+ while (err.stack.length) {
16
+ callerfile = err.stack.shift().getFileName()
17
+ if (currentfile !== callerfile) break
18
+ }
19
+ } catch (e) {}
20
+
21
+ Error.prepareStackTrace = originalFunc
22
+ return callerfile
23
+ }
24
+
25
+ export default getCallerFilename
@@ -1,20 +1,24 @@
1
- import path from 'path'
2
- import resolvePath from './resolve-path.js'
3
-
4
- /**
5
- * Get the node global module directory.
6
- *
7
- * @returns {string} Absolute path to the global module directory
8
- */
9
- function getGlobalModuleDir () {
10
- const execDir = path.dirname(process.execPath)
11
- if (process.platform === 'win32') {
12
- const appDataPath = process.env.APPDATA
13
- ? path.join(process.env.APPDATA, 'npm', 'node_modules')
14
- : null
15
- return resolvePath(appDataPath || path.join(execDir, 'node_modules'))
16
- }
17
- return resolvePath(path.join(execDir, '..', 'lib', 'node_modules'))
18
- }
19
-
20
- export default getGlobalModuleDir
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+ import resolvePath from './resolve-path.js'
4
+
5
+ /**
6
+ * Get the node global module directory.
7
+ *
8
+ * @returns {string} Absolute path to the global module directory
9
+ */
10
+ function getGlobalModuleDir () {
11
+ const execDir = path.dirname(process.execPath)
12
+ const realExecDir = fs.realpathSync(execDir)
13
+ if (process.platform === 'win32') {
14
+ const isNvm = process.env.NVM_HOME || realExecDir.toLowerCase().includes('\\nvm\\')
15
+ if (isNvm) return resolvePath(path.join(realExecDir, 'node_modules'))
16
+ const appDataPath = process.env.APPDATA
17
+ ? path.join(process.env.APPDATA, 'npm', 'node_modules')
18
+ : null
19
+ return resolvePath(appDataPath || path.join(execDir, 'node_modules'))
20
+ }
21
+ return resolvePath(path.join(execDir, '..', 'lib', 'node_modules'))
22
+ }
23
+
24
+ export default getGlobalModuleDir
package/src/get-index.js CHANGED
@@ -1,15 +1,15 @@
1
- /**
2
- * Returns indexes of items that match a predicate.
3
- *
4
- * @param {Array<any>} inputs Input array.
5
- * @param {Function} matcher Predicate function.
6
- * @returns {Array<number>} Matching indexes.
7
- */
8
- function getIndex (inputs = [], matcher) {
9
- return inputs.map((val, idx) => {
10
- if (matcher(val)) return idx
11
- return null
12
- }).filter(val => val !== null)
13
- }
14
-
15
- export default getIndex
1
+ /**
2
+ * Returns indexes of items that match a predicate.
3
+ *
4
+ * @param {Array<any>} inputs Input array.
5
+ * @param {Function} matcher Predicate function.
6
+ * @returns {Array<number>} Matching indexes.
7
+ */
8
+ function getIndex (inputs = [], matcher) {
9
+ return inputs.map((val, idx) => {
10
+ if (matcher(val)) return idx
11
+ return null
12
+ }).filter(val => val !== null)
13
+ }
14
+
15
+ export default getIndex
@@ -1,12 +1,12 @@
1
- /**
2
- * Finds an object key by value.
3
- *
4
- * @param {Object} object Source object.
5
- * @param {any} value Value to find.
6
- * @returns {string|undefined} Matching key.
7
- */
8
- function getKeyByValue (object, value) {
9
- return Object.keys(object).find(key => object[key] === value)
10
- }
11
-
12
- export default getKeyByValue
1
+ /**
2
+ * Finds an object key by value.
3
+ *
4
+ * @param {Object} object Source object.
5
+ * @param {any} value Value to find.
6
+ * @returns {string|undefined} Matching key.
7
+ */
8
+ function getKeyByValue (object, value) {
9
+ return Object.keys(object).find(key => object[key] === value)
10
+ }
11
+
12
+ export default getKeyByValue
package/src/includes.js CHANGED
@@ -1,18 +1,18 @@
1
- /**
2
- * Checks whether at least one matcher value exists in an array.
3
- *
4
- * @param {string|Array<string>} [matcher=[]] Single matcher or list of matchers.
5
- * @param {Array<string>} [array=[]] Array to inspect.
6
- * @returns {boolean} True when any matcher is found.
7
- */
8
- function includes (matcher = [], array = []) {
9
- if (typeof matcher === 'string') matcher = [matcher]
10
- let found = false
11
- for (const m of matcher) {
12
- found = array.includes(m)
13
- if (found) break
14
- }
15
- return found
16
- }
17
-
18
- export default includes
1
+ /**
2
+ * Checks whether at least one matcher value exists in an array.
3
+ *
4
+ * @param {string|Array<string>} [matcher=[]] Single matcher or list of matchers.
5
+ * @param {Array<string>} [array=[]] Array to inspect.
6
+ * @returns {boolean} True when any matcher is found.
7
+ */
8
+ function includes (matcher = [], array = []) {
9
+ if (typeof matcher === 'string') matcher = [matcher]
10
+ let found = false
11
+ for (const m of matcher) {
12
+ found = array.includes(m)
13
+ if (found) break
14
+ }
15
+ return found
16
+ }
17
+
18
+ export default includes
package/src/is-class.js CHANGED
@@ -1,13 +1,13 @@
1
- /**
2
- * Checks whether a value appears to be a class constructor.
3
- *
4
- * @param {any} item Value to test.
5
- * @returns {boolean} True when item is class-like.
6
- */
7
- function isClass (item) {
8
- return typeof item === 'function' &&
9
- Object.prototype.hasOwnProperty.call(item, 'prototype') &&
10
- !Object.prototype.hasOwnProperty.call(item, 'arguments')
11
- }
12
-
13
- export default isClass
1
+ /**
2
+ * Checks whether a value appears to be a class constructor.
3
+ *
4
+ * @param {any} item Value to test.
5
+ * @returns {boolean} True when item is class-like.
6
+ */
7
+ function isClass (item) {
8
+ return typeof item === 'function' &&
9
+ Object.prototype.hasOwnProperty.call(item, 'prototype') &&
10
+ !Object.prototype.hasOwnProperty.call(item, 'arguments')
11
+ }
12
+
13
+ export default isClass
package/src/is-set.js CHANGED
@@ -1,11 +1,11 @@
1
- /**
2
- * Checks whether a value is neither null nor undefined.
3
- *
4
- * @param {any} item Value to test.
5
- * @returns {boolean} True when value is set.
6
- */
7
- function isSet (item) {
8
- return ![undefined, null].includes(item)
9
- }
10
-
11
- export default isSet
1
+ /**
2
+ * Checks whether a value is neither null nor undefined.
3
+ *
4
+ * @param {any} item Value to test.
5
+ * @returns {boolean} True when value is set.
6
+ */
7
+ function isSet (item) {
8
+ return ![undefined, null].includes(item)
9
+ }
10
+
11
+ export default isSet
package/src/log.js CHANGED
@@ -1,19 +1,19 @@
1
- import { sprintf } from 'sprintf-js'
2
-
3
- function format (fn, ...items) {
4
- const date = (new Date()).toISOString()
5
- const label = typeof items[0] === 'string' ? items[0] : undefined
6
- if (label) {
7
- items.shift()
8
- return fn(sprintf(`[${date}] ${label}`, ...items))
9
- }
10
- return fn(...items)
11
- }
12
-
13
- export function log (...items) {
14
- return format(console.log, ...items)
15
- }
16
-
17
- export function logError (...items) {
18
- return format(console.error, ...items)
19
- }
1
+ import { sprintf } from 'sprintf-js'
2
+
3
+ function format (fn, ...items) {
4
+ const date = (new Date()).toISOString()
5
+ const label = typeof items[0] === 'string' ? items[0] : undefined
6
+ if (label) {
7
+ items.shift()
8
+ return fn(sprintf(`[${date}] ${label}`, ...items))
9
+ }
10
+ return fn(...items)
11
+ }
12
+
13
+ export function log (...items) {
14
+ return format(console.log, ...items)
15
+ }
16
+
17
+ export function logError (...items) {
18
+ return format(console.error, ...items)
19
+ }
@@ -1,24 +1,24 @@
1
- /**
2
- * Merges objects by a shared key, where later objects override earlier fields.
3
- *
4
- * @param {Array<Object>} inputs Source objects.
5
- * @param {string} key Field name used for grouping.
6
- * @returns {Array<Object>} Merged objects.
7
- */
8
- function mergeObjectsByKey (inputs, key) {
9
- const uniqueMap = new Map()
10
-
11
- for (const item of inputs) {
12
- const keyValue = item[key]
13
- if (uniqueMap.has(keyValue)) {
14
- const existingObject = uniqueMap.get(keyValue)
15
- uniqueMap.set(keyValue, { ...existingObject, ...item })
16
- } else {
17
- uniqueMap.set(keyValue, item)
18
- }
19
- }
20
-
21
- return Array.from(uniqueMap.values())
22
- }
23
-
24
- export default mergeObjectsByKey
1
+ /**
2
+ * Merges objects by a shared key, where later objects override earlier fields.
3
+ *
4
+ * @param {Array<Object>} inputs Source objects.
5
+ * @param {string} key Field name used for grouping.
6
+ * @returns {Array<Object>} Merged objects.
7
+ */
8
+ function mergeObjectsByKey (inputs, key) {
9
+ const uniqueMap = new Map()
10
+
11
+ for (const item of inputs) {
12
+ const keyValue = item[key]
13
+ if (uniqueMap.has(keyValue)) {
14
+ const existingObject = uniqueMap.get(keyValue)
15
+ uniqueMap.set(keyValue, { ...existingObject, ...item })
16
+ } else {
17
+ uniqueMap.set(keyValue, item)
18
+ }
19
+ }
20
+
21
+ return Array.from(uniqueMap.values())
22
+ }
23
+
24
+ export default mergeObjectsByKey