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
package/index.js CHANGED
@@ -1,119 +1,119 @@
1
- import arrangeArray from './src/arrange-array.js'
2
- import defaultsDeep from './src/defaults-deep.js'
3
- import delay from './src/delay.js'
4
- import extractText from './src/extract-text.js'
5
- import filterDuplicate from './src/filter-duplicate.js'
6
- import filterIndex from './src/filter-index.js'
7
- import getKeyByValue from './src/get-key-by-value.js'
8
- import getIndex from './src/get-index.js'
9
- import includes from './src/includes.js'
10
- import isClass from './src/is-class.js'
11
- import isSet from './src/is-set.js'
12
- import { log, logError } from './src/log.js'
13
- import paginate from './src/paginate.js'
14
- import pascalCase from './src/pascal-case.js'
15
- import round from './src/round.js'
16
- import secToHms from './src/sec-to-hms.js'
17
- import setImmediate from './src/set-immediate.js'
18
- import titleize from './src/titleize.js'
19
- import mergeObjectsByKey from './src/merge-objects-by-key.js'
20
- import formatText from './src/format-text.js'
21
- import resolvePath from './src/resolve-path.js'
22
- import shim from './src/shim.js'
23
- import currentLoc from './src/current-loc.js'
24
- import parseArgsArgv from './src/parse-args-argv.js'
25
- import parseEnv from './src/parse-env.js'
26
- import parseDuration from './src/parse-duration.js'
27
- import parseObject from './src/parse-object.js'
28
- import randomRange from './src/random-range.js'
29
- import generateId from './src/generate-id.js'
30
- import fillObject from './src/fill-object.js'
31
- import parseKvString from './src/parse-kv-string.js'
32
- import without from './src/without.js'
33
- import textToArray from './src/text-to-array.js'
34
- import getCallerFilename from './src/get-caller-filename.js'
35
- import getGlobalModuleDir from './src/get-global-module-dir.js'
36
- import setTimeout from './src/set-timeout.js'
37
- import setInterval from './src/set-interval.js'
38
-
39
- export {
40
- arrangeArray,
41
- currentLoc,
42
- defaultsDeep,
43
- delay,
44
- extractText,
45
- formatText,
46
- fillObject,
47
- filterDuplicate,
48
- filterIndex,
49
- generateId,
50
- getCallerFilename,
51
- getGlobalModuleDir,
52
- getIndex,
53
- getKeyByValue,
54
- includes,
55
- isClass,
56
- isSet,
57
- log,
58
- logError,
59
- mergeObjectsByKey,
60
- paginate,
61
- parseArgsArgv,
62
- parseDuration,
63
- parseEnv,
64
- parseKvString,
65
- parseObject,
66
- pascalCase,
67
- randomRange,
68
- resolvePath,
69
- round,
70
- secToHms,
71
- setImmediate,
72
- setInterval,
73
- setTimeout,
74
- shim,
75
- textToArray,
76
- titleize,
77
- without
78
- }
79
-
80
- export default {
81
- arrangeArray,
82
- currentLoc,
83
- defaultsDeep,
84
- delay,
85
- extractText,
86
- formatText,
87
- fillObject,
88
- filterDuplicate,
89
- filterIndex,
90
- generateId,
91
- getCallerFilename,
92
- getGlobalModuleDir,
93
- getIndex,
94
- getKeyByValue,
95
- includes,
96
- isClass,
97
- isSet,
98
- log,
99
- logError,
100
- mergeObjectsByKey,
101
- paginate,
102
- parseArgsArgv,
103
- parseDuration,
104
- parseEnv,
105
- parseKvString,
106
- parseObject,
107
- pascalCase,
108
- randomRange,
109
- resolvePath,
110
- round,
111
- secToHms,
112
- setImmediate,
113
- setTimeout,
114
- setInterval,
115
- shim,
116
- textToArray,
117
- titleize,
118
- without
119
- }
1
+ import arrangeArray from './src/arrange-array.js'
2
+ import defaultsDeep from './src/defaults-deep.js'
3
+ import delay from './src/delay.js'
4
+ import extractText from './src/extract-text.js'
5
+ import filterDuplicate from './src/filter-duplicate.js'
6
+ import filterIndex from './src/filter-index.js'
7
+ import getKeyByValue from './src/get-key-by-value.js'
8
+ import getIndex from './src/get-index.js'
9
+ import includes from './src/includes.js'
10
+ import isClass from './src/is-class.js'
11
+ import isSet from './src/is-set.js'
12
+ import { log, logError } from './src/log.js'
13
+ import paginate from './src/paginate.js'
14
+ import pascalCase from './src/pascal-case.js'
15
+ import round from './src/round.js'
16
+ import secToHms from './src/sec-to-hms.js'
17
+ import setImmediate from './src/set-immediate.js'
18
+ import titleize from './src/titleize.js'
19
+ import mergeObjectsByKey from './src/merge-objects-by-key.js'
20
+ import formatText from './src/format-text.js'
21
+ import resolvePath from './src/resolve-path.js'
22
+ import shim from './src/shim.js'
23
+ import currentLoc from './src/current-loc.js'
24
+ import parseArgsArgv from './src/parse-args-argv.js'
25
+ import parseEnv from './src/parse-env.js'
26
+ import parseDuration from './src/parse-duration.js'
27
+ import parseObject from './src/parse-object.js'
28
+ import randomRange from './src/random-range.js'
29
+ import generateId from './src/generate-id.js'
30
+ import fillObject from './src/fill-object.js'
31
+ import parseKvString from './src/parse-kv-string.js'
32
+ import without from './src/without.js'
33
+ import textToArray from './src/text-to-array.js'
34
+ import getCallerFilename from './src/get-caller-filename.js'
35
+ import getGlobalModuleDir from './src/get-global-module-dir.js'
36
+ import setTimeout from './src/set-timeout.js'
37
+ import setInterval from './src/set-interval.js'
38
+
39
+ export {
40
+ arrangeArray,
41
+ currentLoc,
42
+ defaultsDeep,
43
+ delay,
44
+ extractText,
45
+ formatText,
46
+ fillObject,
47
+ filterDuplicate,
48
+ filterIndex,
49
+ generateId,
50
+ getCallerFilename,
51
+ getGlobalModuleDir,
52
+ getIndex,
53
+ getKeyByValue,
54
+ includes,
55
+ isClass,
56
+ isSet,
57
+ log,
58
+ logError,
59
+ mergeObjectsByKey,
60
+ paginate,
61
+ parseArgsArgv,
62
+ parseDuration,
63
+ parseEnv,
64
+ parseKvString,
65
+ parseObject,
66
+ pascalCase,
67
+ randomRange,
68
+ resolvePath,
69
+ round,
70
+ secToHms,
71
+ setImmediate,
72
+ setInterval,
73
+ setTimeout,
74
+ shim,
75
+ textToArray,
76
+ titleize,
77
+ without
78
+ }
79
+
80
+ export default {
81
+ arrangeArray,
82
+ currentLoc,
83
+ defaultsDeep,
84
+ delay,
85
+ extractText,
86
+ formatText,
87
+ fillObject,
88
+ filterDuplicate,
89
+ filterIndex,
90
+ generateId,
91
+ getCallerFilename,
92
+ getGlobalModuleDir,
93
+ getIndex,
94
+ getKeyByValue,
95
+ includes,
96
+ isClass,
97
+ isSet,
98
+ log,
99
+ logError,
100
+ mergeObjectsByKey,
101
+ paginate,
102
+ parseArgsArgv,
103
+ parseDuration,
104
+ parseEnv,
105
+ parseKvString,
106
+ parseObject,
107
+ pascalCase,
108
+ randomRange,
109
+ resolvePath,
110
+ round,
111
+ secToHms,
112
+ setImmediate,
113
+ setTimeout,
114
+ setInterval,
115
+ shim,
116
+ textToArray,
117
+ titleize,
118
+ without
119
+ }
package/package.json CHANGED
@@ -1,48 +1,48 @@
1
- {
2
- "name": "aneka",
3
- "version": "0.17.5",
4
- "description": "Some usefull function helper for daily use",
5
- "main": "index.js",
6
- "type": "module",
7
- "scripts": {
8
- "build-doc": "jsdoc -c .jsdoc.conf.json",
9
- "test": "mocha"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/ardhi/aneka.git"
14
- },
15
- "keywords": [
16
- "aneka",
17
- "miscellaneous",
18
- "functions"
19
- ],
20
- "author": "Ardhi Lukianto <ardhi.lukianto@gmail.com>",
21
- "license": "MIT",
22
- "bugs": {
23
- "url": "https://github.com/ardhi/aneka/issues"
24
- },
25
- "standard": {
26
- "env": [
27
- "mocha"
28
- ]
29
- },
30
- "homepage": "https://github.com/ardhi/aneka#readme",
31
- "dependencies": {
32
- "@bybrave/proper-lockfile2": "^5.0.0",
33
- "dotenv": "^17.2.3",
34
- "dotenv-parse-variables": "^2.0.0",
35
- "flat": "^6.0.1",
36
- "lodash-es": "^4.17.21",
37
- "ms": "^2.1.3",
38
- "nanoid": "^5.1.6",
39
- "sprintf-js": "^1.1.3",
40
- "yargs": "^18.0.0"
41
- },
42
- "devDependencies": {
43
- "chai": "^6.2.1",
44
- "clean-jsdoc-theme": "^4.3.0",
45
- "jsdoc-plugin-intersection": "^1.0.4",
46
- "mocha": "^11.7.5"
47
- }
48
- }
1
+ {
2
+ "name": "aneka",
3
+ "version": "0.17.7",
4
+ "description": "Some usefull function helper for daily use",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "build-doc": "jsdoc -c .jsdoc.conf.json",
9
+ "test": "mocha"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ardhi/aneka.git"
14
+ },
15
+ "keywords": [
16
+ "aneka",
17
+ "miscellaneous",
18
+ "functions"
19
+ ],
20
+ "author": "Ardhi Lukianto <ardhi.lukianto@gmail.com>",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/ardhi/aneka/issues"
24
+ },
25
+ "standard": {
26
+ "env": [
27
+ "mocha"
28
+ ]
29
+ },
30
+ "homepage": "https://github.com/ardhi/aneka#readme",
31
+ "dependencies": {
32
+ "@bybrave/proper-lockfile2": "^5.0.0",
33
+ "dotenv": "^17.2.3",
34
+ "dotenv-parse-variables": "^2.0.0",
35
+ "flat": "^6.0.1",
36
+ "lodash-es": "^4.17.21",
37
+ "ms": "^2.1.3",
38
+ "nanoid": "^5.1.6",
39
+ "sprintf-js": "^1.1.3",
40
+ "yargs": "^18.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "chai": "^6.2.1",
44
+ "clean-jsdoc-theme": "^4.3.0",
45
+ "jsdoc-plugin-intersection": "^1.0.4",
46
+ "mocha": "^11.7.5"
47
+ }
48
+ }
@@ -1,25 +1,25 @@
1
- import trim from 'lodash-es/trim.js'
2
-
3
- /**
4
- * Reorders items by handling '^' (move to front) and '$' (move to end) prefixes.
5
- *
6
- * @param {Array<string>} inputs Source array.
7
- * @param {boolean} [trimItem=true] Trim each item before processing.
8
- * @returns {Array<string>} Reordered items.
9
- */
10
- function arrangeArray (inputs = [], trimItem = true) {
11
- const first = []
12
- const last = []
13
-
14
- const items = inputs.filter(item => {
15
- if (trimItem) item = trim(item)
16
- if (item[0] === '^') first.push(item.slice(1))
17
- else if (item[0] === '$') last.push(item.slice(1))
18
- return !['^', '$'].includes(item[0])
19
- })
20
- items.unshift(...first)
21
- items.push(...last)
22
- return items
23
- }
24
-
25
- export default arrangeArray
1
+ import trim from 'lodash-es/trim.js'
2
+
3
+ /**
4
+ * Reorders items by handling '^' (move to front) and '$' (move to end) prefixes.
5
+ *
6
+ * @param {Array<string>} inputs Source array.
7
+ * @param {boolean} [trimItem=true] Trim each item before processing.
8
+ * @returns {Array<string>} Reordered items.
9
+ */
10
+ function arrangeArray (inputs = [], trimItem = true) {
11
+ const first = []
12
+ const last = []
13
+
14
+ const items = inputs.filter(item => {
15
+ if (trimItem) item = trim(item)
16
+ if (item[0] === '^') first.push(item.slice(1))
17
+ else if (item[0] === '$') last.push(item.slice(1))
18
+ return !['^', '$'].includes(item[0])
19
+ })
20
+ items.unshift(...first)
21
+ items.push(...last)
22
+ return items
23
+ }
24
+
25
+ export default arrangeArray
@@ -1,35 +1,35 @@
1
- function setProps (properties = {}, options = {}) {
2
- for (const key in properties) {
3
- this[key] = properties[key]
4
- }
5
- for (const key in options) {
6
- this[key] = options[key]
7
- }
8
- }
9
-
10
- /**
11
- * Creates a dynamic class and optionally extends a parent class.
12
- *
13
- * @param {string} className Class name hint.
14
- * @param {Object} [properties={}] Default properties assigned to instances.
15
- * @param {Function} [parent] Parent class to extend.
16
- * @returns {Function} Generated class constructor.
17
- */
18
- function createClass (className, properties = {}, parent) {
19
- let cls = class {
20
- constructor (...options) {
21
- setProps.call(this, properties, ...options)
22
- }
23
- }
24
- if (parent) {
25
- cls = class extends parent {
26
- constructor (options) {
27
- super(options)
28
- setProps.call(this, properties, options)
29
- }
30
- }
31
- }
32
- return cls
33
- }
34
-
35
- export default createClass
1
+ function setProps (properties = {}, options = {}) {
2
+ for (const key in properties) {
3
+ this[key] = properties[key]
4
+ }
5
+ for (const key in options) {
6
+ this[key] = options[key]
7
+ }
8
+ }
9
+
10
+ /**
11
+ * Creates a dynamic class and optionally extends a parent class.
12
+ *
13
+ * @param {string} className Class name hint.
14
+ * @param {Object} [properties={}] Default properties assigned to instances.
15
+ * @param {Function} [parent] Parent class to extend.
16
+ * @returns {Function} Generated class constructor.
17
+ */
18
+ function createClass (className, properties = {}, parent) {
19
+ let cls = class {
20
+ constructor (...options) {
21
+ setProps.call(this, properties, ...options)
22
+ }
23
+ }
24
+ if (parent) {
25
+ cls = class extends parent {
26
+ constructor (options) {
27
+ super(options)
28
+ setProps.call(this, properties, options)
29
+ }
30
+ }
31
+ }
32
+ return cls
33
+ }
34
+
35
+ export default createClass
File without changes
@@ -1,20 +1,20 @@
1
- import mergeWith from 'lodash-es/mergeWith.js'
2
- import isArray from 'lodash-es/isArray.js'
3
-
4
- /**
5
- * Deep-merges objects while replacing arrays from higher-priority inputs.
6
- *
7
- * @param {...Object} args Objects to merge.
8
- * @returns {Object} Merged object.
9
- */
10
- function defaultsDeep (...args) {
11
- const output = {}
12
- args.reverse().forEach(function (item) {
13
- mergeWith(output, item, function (objectValue, sourceValue) {
14
- return isArray(sourceValue) ? sourceValue : undefined
15
- })
16
- })
17
- return output
18
- }
19
-
20
- export default defaultsDeep
1
+ import mergeWith from 'lodash-es/mergeWith.js'
2
+ import isArray from 'lodash-es/isArray.js'
3
+
4
+ /**
5
+ * Deep-merges objects while replacing arrays from higher-priority inputs.
6
+ *
7
+ * @param {...Object} args Objects to merge.
8
+ * @returns {Object} Merged object.
9
+ */
10
+ function defaultsDeep (...args) {
11
+ const output = {}
12
+ args.reverse().forEach(function (item) {
13
+ mergeWith(output, item, function (objectValue, sourceValue) {
14
+ return isArray(sourceValue) ? sourceValue : undefined
15
+ })
16
+ })
17
+ return output
18
+ }
19
+
20
+ export default defaultsDeep
package/src/delay.js CHANGED
@@ -1,19 +1,19 @@
1
- import parseDuration from './parse-duration.js'
2
-
3
- /**
4
- * Waits for a duration and resolves a promise.
5
- *
6
- * @param {number|string} [ms=1000] Delay in milliseconds or a duration string.
7
- * @returns {Promise<void>} Promise resolved after the delay.
8
- */
9
- function delay (ms = 1000) {
10
- ms = parseDuration(ms)
11
- return new Promise((resolve, reject) => {
12
- const timer = setTimeout(() => {
13
- if (timer) clearTimeout(timer)
14
- resolve()
15
- }, ms)
16
- })
17
- }
18
-
19
- export default delay
1
+ import parseDuration from './parse-duration.js'
2
+
3
+ /**
4
+ * Waits for a duration and resolves a promise.
5
+ *
6
+ * @param {number|string} [ms=1000] Delay in milliseconds or a duration string.
7
+ * @returns {Promise<void>} Promise resolved after the delay.
8
+ */
9
+ function delay (ms = 1000) {
10
+ ms = parseDuration(ms)
11
+ return new Promise((resolve, reject) => {
12
+ const timer = setTimeout(() => {
13
+ if (timer) clearTimeout(timer)
14
+ resolve()
15
+ }, ms)
16
+ })
17
+ }
18
+
19
+ export default delay
@@ -1,23 +1,23 @@
1
- /**
2
- * Extracts text between two boundary patterns.
3
- *
4
- * @param {string} text Source text.
5
- * @param {string} patternStart Start marker.
6
- * @param {string} patternEnd End marker.
7
- * @returns {{result: string, pattern: string}} Extracted value and matched pattern.
8
- */
9
- function extractText (text, patternStart, patternEnd) {
10
- let result = ''
11
- const open = text.indexOf(patternStart)
12
- if (open > -1) {
13
- text = text.slice(open + patternStart.length)
14
- const close = text.indexOf(patternEnd)
15
- if (close > -1) {
16
- result = text.slice(0, close)
17
- }
18
- }
19
- const pattern = `${patternStart}${result}${patternEnd}`
20
- return { result, pattern }
21
- }
22
-
23
- export default extractText
1
+ /**
2
+ * Extracts text between two boundary patterns.
3
+ *
4
+ * @param {string} text Source text.
5
+ * @param {string} patternStart Start marker.
6
+ * @param {string} patternEnd End marker.
7
+ * @returns {{result: string, pattern: string}} Extracted value and matched pattern.
8
+ */
9
+ function extractText (text, patternStart, patternEnd) {
10
+ let result = ''
11
+ const open = text.indexOf(patternStart)
12
+ if (open > -1) {
13
+ text = text.slice(open + patternStart.length)
14
+ const close = text.indexOf(patternEnd)
15
+ if (close > -1) {
16
+ result = text.slice(0, close)
17
+ }
18
+ }
19
+ const pattern = `${patternStart}${result}${patternEnd}`
20
+ return { result, pattern }
21
+ }
22
+
23
+ export default extractText
@@ -1,17 +1,17 @@
1
- /**
2
- * Fill object with keys. ```defValue``` is used if the corresponding key doesn't have value
3
- *
4
- * @param {Object} obj - Object to fill
5
- * @param {string[]} keys - Array of keys
6
- * @param {any} defValue - Default value
7
- * @returns {Object}
8
- */
9
- function fillObject (obj = {}, keys = [], defValue) {
10
- const newObj = {}
11
- for (const key of keys) {
12
- newObj[key] = obj[key] ?? defValue
13
- }
14
- return newObj
15
- }
16
-
17
- export default fillObject
1
+ /**
2
+ * Fill object with keys. ```defValue``` is used if the corresponding key doesn't have value
3
+ *
4
+ * @param {Object} obj - Object to fill
5
+ * @param {string[]} keys - Array of keys
6
+ * @param {any} defValue - Default value
7
+ * @returns {Object}
8
+ */
9
+ function fillObject (obj = {}, keys = [], defValue) {
10
+ const newObj = {}
11
+ for (const key of keys) {
12
+ newObj[key] = obj[key] ?? defValue
13
+ }
14
+ return newObj
15
+ }
16
+
17
+ export default fillObject