@ezez/utils 4.5.0 → 4.7.0

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 (375) hide show
  1. package/.github/workflows/docs.yml +4 -3
  2. package/CHANGELOG.md +20 -1
  3. package/README.md +19 -6
  4. package/dist/assertProps.d.ts +6 -0
  5. package/dist/assertProps.d.ts.map +1 -0
  6. package/dist/assertProps.js +11 -0
  7. package/dist/assertProps.js.map +1 -0
  8. package/dist/cap.d.ts.map +1 -1
  9. package/dist/cap.js.map +1 -1
  10. package/dist/capitalize.d.ts.map +1 -1
  11. package/dist/capitalize.js.map +1 -1
  12. package/dist/compareArrays.d.ts +4 -4
  13. package/dist/compareArrays.d.ts.map +1 -1
  14. package/dist/compareArrays.js.map +1 -1
  15. package/dist/ensureError.d.ts.map +1 -1
  16. package/dist/ensureError.js +3 -1
  17. package/dist/ensureError.js.map +1 -1
  18. package/dist/ensurePrefix.d.ts.map +1 -1
  19. package/dist/ensurePrefix.js.map +1 -1
  20. package/dist/ensureSuffix.d.ts.map +1 -1
  21. package/dist/ensureSuffix.js.map +1 -1
  22. package/dist/escapeRegExp.d.ts.map +1 -1
  23. package/dist/escapeRegExp.js.map +1 -1
  24. package/dist/formatDate.d.ts.map +1 -1
  25. package/dist/formatDate.js.map +1 -1
  26. package/dist/getMultiple.d.ts.map +1 -1
  27. package/dist/getMultiple.js.map +1 -1
  28. package/dist/hasProps.d.ts +3 -0
  29. package/dist/hasProps.d.ts.map +1 -0
  30. package/dist/hasProps.js +16 -0
  31. package/dist/hasProps.js.map +1 -0
  32. package/dist/ignore.d.ts +3 -0
  33. package/dist/ignore.d.ts.map +1 -0
  34. package/dist/ignore.js +16 -0
  35. package/dist/ignore.js.map +1 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/isEmpty.d.ts.map +1 -1
  41. package/dist/isEmpty.js +4 -4
  42. package/dist/isEmpty.js.map +1 -1
  43. package/dist/isNumericString.d.ts.map +1 -1
  44. package/dist/isNumericString.js.map +1 -1
  45. package/dist/isPlainObject.d.ts.map +1 -1
  46. package/dist/isPlainObject.js.map +1 -1
  47. package/dist/match.d.ts.map +1 -1
  48. package/dist/match.js.map +1 -1
  49. package/dist/memoize.d.ts.map +1 -1
  50. package/dist/memoize.js.map +1 -1
  51. package/dist/mostFrequent.d.ts.map +1 -1
  52. package/dist/mostFrequent.js.map +1 -1
  53. package/dist/noop.d.ts.map +1 -1
  54. package/dist/noop.js.map +1 -1
  55. package/dist/occurrences.d.ts.map +1 -1
  56. package/dist/occurrences.js.map +1 -1
  57. package/dist/removeCommonProperties.d.ts.map +1 -1
  58. package/dist/removeCommonProperties.js.map +1 -1
  59. package/dist/replace.d.ts.map +1 -1
  60. package/dist/replace.js.map +1 -1
  61. package/dist/rethrow.d.ts +1 -1
  62. package/dist/rethrow.d.ts.map +1 -1
  63. package/dist/rethrow.js.map +1 -1
  64. package/dist/round.d.ts.map +1 -1
  65. package/dist/round.js.map +1 -1
  66. package/dist/safe.d.ts.map +1 -1
  67. package/dist/safe.js.map +1 -1
  68. package/dist/scale.d.ts.map +1 -1
  69. package/dist/scale.js.map +1 -1
  70. package/dist/seq.d.ts.map +1 -1
  71. package/dist/seq.js +5 -1
  72. package/dist/seq.js.map +1 -1
  73. package/dist/serialize.d.ts.map +1 -1
  74. package/dist/serialize.js +2 -2
  75. package/dist/serialize.js.map +1 -1
  76. package/dist/serializeToBuffer/serializeToBuffer.d.ts.map +1 -1
  77. package/dist/serializeToBuffer/serializeToBuffer.js.map +1 -1
  78. package/dist/serializeToBuffer/unserializeFromBuffer.d.ts.map +1 -1
  79. package/dist/serializeToBuffer/unserializeFromBuffer.js.map +1 -1
  80. package/dist/setImmutable.js.map +1 -1
  81. package/dist/sortBy.d.ts +1 -1
  82. package/dist/sortBy.d.ts.map +1 -1
  83. package/dist/sortBy.js.map +1 -1
  84. package/dist/sortByMultiple.d.ts +1 -1
  85. package/dist/sortByMultiple.d.ts.map +1 -1
  86. package/dist/sortByMultiple.js.map +1 -1
  87. package/dist/trim.d.ts.map +1 -1
  88. package/dist/trim.js +1 -1
  89. package/dist/trim.js.map +1 -1
  90. package/dist/trimEnd.d.ts.map +1 -1
  91. package/dist/trimEnd.js.map +1 -1
  92. package/dist/trimStart.d.ts.map +1 -1
  93. package/dist/trimStart.js.map +1 -1
  94. package/dist/unique.d.ts +1 -1
  95. package/dist/unique.d.ts.map +1 -1
  96. package/dist/unique.js.map +1 -1
  97. package/dist/utils/utils.js +1 -0
  98. package/dist/utils/utils.js.map +1 -1
  99. package/dist/wait.d.ts.map +1 -1
  100. package/dist/wait.js.map +1 -1
  101. package/dist/waitFor.d.ts.map +1 -1
  102. package/dist/waitFor.js.map +1 -1
  103. package/dist/waitSync.d.ts.map +1 -1
  104. package/dist/waitSync.js.map +1 -1
  105. package/docs/assets/hierarchy.js +1 -0
  106. package/docs/assets/icons.js +1 -1
  107. package/docs/assets/icons.svg +1 -1
  108. package/docs/assets/main.js +5 -5
  109. package/docs/assets/navigation.js +1 -1
  110. package/docs/assets/search.js +1 -1
  111. package/docs/assets/style.css +1405 -1288
  112. package/docs/documents/Changelog.html +377 -0
  113. package/docs/functions/index.cap.html +3 -3
  114. package/docs/functions/index.capitalize.html +7 -7
  115. package/docs/functions/index.coalesce.html +8 -8
  116. package/docs/functions/index.compareArrays.html +5 -5
  117. package/docs/functions/index.compareProps.html +5 -5
  118. package/docs/functions/index.deserialize.html +4 -4
  119. package/docs/functions/index.ensureArray.html +3 -3
  120. package/docs/functions/index.ensureDate.html +6 -6
  121. package/docs/functions/index.ensureError.html +6 -6
  122. package/docs/functions/index.ensurePrefix.html +5 -5
  123. package/docs/functions/index.ensureSuffix.html +5 -5
  124. package/docs/functions/index.ensureTimestamp.html +6 -6
  125. package/docs/functions/index.escapeRegExp.html +5 -5
  126. package/docs/functions/index.formatDate.html +5 -2
  127. package/docs/functions/index.get.html +8 -8
  128. package/docs/functions/index.getMultiple.html +6 -6
  129. package/docs/functions/index.ignore.html +8 -0
  130. package/docs/functions/index.insertSeparator.html +5 -5
  131. package/docs/functions/index.isEmpty.html +12 -13
  132. package/docs/functions/index.isNumericString.html +3 -3
  133. package/docs/functions/index.isPlainObject.html +8 -8
  134. package/docs/functions/index.last.html +7 -7
  135. package/docs/functions/index.later-1.html +3 -3
  136. package/docs/functions/index.mapAsync.html +5 -5
  137. package/docs/functions/index.mapValues.html +7 -7
  138. package/docs/functions/index.match.html +7 -4
  139. package/docs/functions/index.memoize.html +4 -4
  140. package/docs/functions/index.merge.html +6 -6
  141. package/docs/functions/index.mostFrequent.html +2 -2
  142. package/docs/functions/index.noop.html +2 -2
  143. package/docs/functions/index.occurrences.html +7 -6
  144. package/docs/functions/index.omit.html +7 -7
  145. package/docs/functions/index.pick.html +7 -7
  146. package/docs/functions/index.pull.html +2 -2
  147. package/docs/functions/index.race.html +5 -5
  148. package/docs/functions/index.remove.html +2 -2
  149. package/docs/functions/index.removeCommonProperties.html +5 -5
  150. package/docs/functions/index.replace.html +6 -6
  151. package/docs/functions/index.replaceDeep.html +3 -3
  152. package/docs/functions/index.rethrow.html +2 -2
  153. package/docs/functions/index.retry.html +4 -4
  154. package/docs/functions/index.round.html +4 -4
  155. package/docs/functions/index.safe.html +5 -5
  156. package/docs/functions/index.sample.html +4 -4
  157. package/docs/functions/index.samples.html +3 -3
  158. package/docs/functions/index.scale.html +2 -2
  159. package/docs/functions/index.seq.html +7 -7
  160. package/docs/functions/index.seqEarlyBreak.html +6 -6
  161. package/docs/functions/index.serialize.html +3 -3
  162. package/docs/functions/index.serializeToBuffer.html +7 -7
  163. package/docs/functions/index.set.html +8 -8
  164. package/docs/functions/index.setImmutable.html +7 -7
  165. package/docs/functions/index.shuffle.html +3 -3
  166. package/docs/functions/index.sortBy.html +3 -3
  167. package/docs/functions/index.sortByMultiple.html +5 -5
  168. package/docs/functions/index.sortProps.html +4 -4
  169. package/docs/functions/index.stripPrefix.html +3 -3
  170. package/docs/functions/index.stripSuffix.html +3 -3
  171. package/docs/functions/index.throttle.html +4 -4
  172. package/docs/functions/index.toggle.html +4 -4
  173. package/docs/functions/index.trim.html +4 -4
  174. package/docs/functions/index.trimEnd.html +4 -4
  175. package/docs/functions/index.trimStart.html +4 -4
  176. package/docs/functions/index.truthy.html +4 -4
  177. package/docs/functions/index.unique.html +4 -4
  178. package/docs/functions/index.unserializeFromBuffer.html +6 -6
  179. package/docs/functions/index.wait.html +3 -3
  180. package/docs/functions/index.waitFor.html +4 -4
  181. package/docs/functions/index.waitSync.html +3 -3
  182. package/docs/index.html +35 -22
  183. package/docs/interfaces/index.ComparePropsOptions.html +4 -4
  184. package/docs/interfaces/index.GetMultipleSource.html +3 -3
  185. package/docs/interfaces/index.GetSource.html +3 -3
  186. package/docs/interfaces/index.IsNumericStringOptions.html +5 -5
  187. package/docs/interfaces/index.OccurencesOptions.html +2 -2
  188. package/docs/interfaces/index.SetImmutableSource.html +3 -3
  189. package/docs/interfaces/index.SetSource.html +3 -3
  190. package/docs/interfaces/index.ThrottleOptions.html +3 -3
  191. package/docs/interfaces/index.ThrottledFunctionExtras.html +4 -4
  192. package/docs/modules/index.html +1 -93
  193. package/docs/modules.html +1 -3
  194. package/docs/types/index.CustomDeserializers.html +1 -1
  195. package/docs/types/index.CustomSerializers.html +1 -1
  196. package/docs/types/index.Later.html +4 -4
  197. package/docs/types/index.MapValuesFn.html +7 -7
  198. package/docs/types/index.MatchCallback.html +1 -1
  199. package/docs/types/index.MergeTwo.html +2 -2
  200. package/docs/types/index.SeqEarlyBreaker.html +4 -4
  201. package/docs/types/index.SeqFn.html +3 -3
  202. package/docs/types/index.SeqFunctions.html +3 -3
  203. package/docs/types/index.SetImmutablePath.html +2 -2
  204. package/docs/types/index.ThrottledFunction.html +1 -1
  205. package/docs/variables/index.mapValuesUNSET.html +2 -2
  206. package/docs/variables/index.mergeUNSET.html +3 -3
  207. package/esm/assertProps.d.ts +6 -0
  208. package/esm/assertProps.d.ts.map +1 -0
  209. package/esm/assertProps.js +8 -0
  210. package/esm/assertProps.js.map +1 -0
  211. package/esm/cap.d.ts.map +1 -1
  212. package/esm/cap.js.map +1 -1
  213. package/esm/capitalize.d.ts.map +1 -1
  214. package/esm/capitalize.js.map +1 -1
  215. package/esm/compareArrays.d.ts +4 -4
  216. package/esm/compareArrays.d.ts.map +1 -1
  217. package/esm/compareArrays.js.map +1 -1
  218. package/esm/ensureError.d.ts.map +1 -1
  219. package/esm/ensureError.js +3 -1
  220. package/esm/ensureError.js.map +1 -1
  221. package/esm/ensurePrefix.d.ts.map +1 -1
  222. package/esm/ensurePrefix.js.map +1 -1
  223. package/esm/ensureSuffix.d.ts.map +1 -1
  224. package/esm/ensureSuffix.js.map +1 -1
  225. package/esm/escapeRegExp.d.ts.map +1 -1
  226. package/esm/escapeRegExp.js.map +1 -1
  227. package/esm/formatDate.d.ts.map +1 -1
  228. package/esm/formatDate.js.map +1 -1
  229. package/esm/getMultiple.d.ts.map +1 -1
  230. package/esm/getMultiple.js.map +1 -1
  231. package/esm/hasProps.d.ts +3 -0
  232. package/esm/hasProps.d.ts.map +1 -0
  233. package/esm/hasProps.js +13 -0
  234. package/esm/hasProps.js.map +1 -0
  235. package/esm/ignore.d.ts +3 -0
  236. package/esm/ignore.d.ts.map +1 -0
  237. package/esm/ignore.js +13 -0
  238. package/esm/ignore.js.map +1 -0
  239. package/esm/index.d.ts +1 -0
  240. package/esm/index.d.ts.map +1 -1
  241. package/esm/index.js +1 -0
  242. package/esm/index.js.map +1 -1
  243. package/esm/isEmpty.d.ts.map +1 -1
  244. package/esm/isEmpty.js +4 -4
  245. package/esm/isEmpty.js.map +1 -1
  246. package/esm/isNumericString.d.ts.map +1 -1
  247. package/esm/isNumericString.js.map +1 -1
  248. package/esm/isPlainObject.d.ts.map +1 -1
  249. package/esm/isPlainObject.js.map +1 -1
  250. package/esm/match.d.ts.map +1 -1
  251. package/esm/match.js.map +1 -1
  252. package/esm/memoize.d.ts.map +1 -1
  253. package/esm/memoize.js.map +1 -1
  254. package/esm/mostFrequent.d.ts.map +1 -1
  255. package/esm/mostFrequent.js.map +1 -1
  256. package/esm/noop.d.ts.map +1 -1
  257. package/esm/noop.js.map +1 -1
  258. package/esm/occurrences.d.ts.map +1 -1
  259. package/esm/occurrences.js.map +1 -1
  260. package/esm/removeCommonProperties.d.ts.map +1 -1
  261. package/esm/removeCommonProperties.js.map +1 -1
  262. package/esm/replace.d.ts.map +1 -1
  263. package/esm/replace.js.map +1 -1
  264. package/esm/rethrow.d.ts +1 -1
  265. package/esm/rethrow.d.ts.map +1 -1
  266. package/esm/rethrow.js.map +1 -1
  267. package/esm/round.d.ts.map +1 -1
  268. package/esm/round.js.map +1 -1
  269. package/esm/safe.d.ts.map +1 -1
  270. package/esm/safe.js.map +1 -1
  271. package/esm/scale.d.ts.map +1 -1
  272. package/esm/scale.js.map +1 -1
  273. package/esm/seq.d.ts.map +1 -1
  274. package/esm/seq.js +5 -1
  275. package/esm/seq.js.map +1 -1
  276. package/esm/serialize.d.ts.map +1 -1
  277. package/esm/serialize.js +2 -2
  278. package/esm/serialize.js.map +1 -1
  279. package/esm/serializeToBuffer/serializeToBuffer.d.ts.map +1 -1
  280. package/esm/serializeToBuffer/serializeToBuffer.js.map +1 -1
  281. package/esm/serializeToBuffer/unserializeFromBuffer.d.ts.map +1 -1
  282. package/esm/serializeToBuffer/unserializeFromBuffer.js.map +1 -1
  283. package/esm/setImmutable.js.map +1 -1
  284. package/esm/sortBy.d.ts +1 -1
  285. package/esm/sortBy.d.ts.map +1 -1
  286. package/esm/sortBy.js.map +1 -1
  287. package/esm/sortByMultiple.d.ts +1 -1
  288. package/esm/sortByMultiple.d.ts.map +1 -1
  289. package/esm/sortByMultiple.js.map +1 -1
  290. package/esm/trim.d.ts.map +1 -1
  291. package/esm/trim.js +1 -1
  292. package/esm/trim.js.map +1 -1
  293. package/esm/trimEnd.d.ts.map +1 -1
  294. package/esm/trimEnd.js.map +1 -1
  295. package/esm/trimStart.d.ts.map +1 -1
  296. package/esm/trimStart.js.map +1 -1
  297. package/esm/unique.d.ts +1 -1
  298. package/esm/unique.d.ts.map +1 -1
  299. package/esm/unique.js.map +1 -1
  300. package/esm/utils/utils.js +1 -0
  301. package/esm/utils/utils.js.map +1 -1
  302. package/esm/wait.d.ts.map +1 -1
  303. package/esm/wait.js.map +1 -1
  304. package/esm/waitFor.d.ts.map +1 -1
  305. package/esm/waitFor.js.map +1 -1
  306. package/esm/waitSync.d.ts.map +1 -1
  307. package/esm/waitSync.js.map +1 -1
  308. package/package.json +31 -34
  309. package/src/assertProps.spec.ts +128 -0
  310. package/src/assertProps.ts +37 -0
  311. package/src/cap.ts +1 -1
  312. package/src/capitalize.ts +3 -3
  313. package/src/compareArrays.ts +2 -3
  314. package/src/deserialize.spec.ts +2 -1
  315. package/src/ensureError.ts +6 -2
  316. package/src/ensurePrefix.ts +1 -1
  317. package/src/ensureSuffix.ts +1 -1
  318. package/src/escapeRegExp.ts +1 -1
  319. package/src/formatDate.ts +7 -2
  320. package/src/get.spec.ts +0 -1
  321. package/src/getMultiple.ts +0 -1
  322. package/src/hasProps.spec.ts +122 -0
  323. package/src/hasProps.ts +36 -0
  324. package/src/ignore.spec.ts +80 -0
  325. package/src/ignore.ts +38 -0
  326. package/src/index.ts +1 -0
  327. package/src/isEmpty.ts +9 -15
  328. package/src/isNumericString.ts +1 -1
  329. package/src/isPlainObject.ts +1 -1
  330. package/src/later.spec.ts +1 -0
  331. package/src/mapAsync.ts +4 -4
  332. package/src/match.ts +2 -1
  333. package/src/memoize.spec.ts +1 -1
  334. package/src/memoize.ts +1 -1
  335. package/src/mostFrequent.spec.ts +2 -0
  336. package/src/mostFrequent.ts +0 -1
  337. package/src/noop.ts +1 -1
  338. package/src/occurrences.ts +1 -1
  339. package/src/remove.spec.ts +1 -1
  340. package/src/removeCommonProperties.spec.ts +2 -0
  341. package/src/removeCommonProperties.ts +1 -1
  342. package/src/replace.ts +1 -1
  343. package/src/replaceDeep.spec.ts +2 -0
  344. package/src/replaceDeepByFn.spec.ts +2 -0
  345. package/src/rethrow.ts +1 -1
  346. package/src/round.ts +1 -1
  347. package/src/safe.ts +2 -1
  348. package/src/scale.ts +1 -1
  349. package/src/seq.ts +7 -3
  350. package/src/serialize.spec.ts +2 -1
  351. package/src/serialize.ts +3 -3
  352. package/src/serializeToBuffer/serialization.spec.ts +2 -2
  353. package/src/serializeToBuffer/serializeToBuffer.ts +0 -1
  354. package/src/serializeToBuffer/unserializeFromBuffer.ts +0 -1
  355. package/src/setImmutable.ts +1 -1
  356. package/src/sortBy.ts +3 -1
  357. package/src/sortByMultiple.ts +5 -3
  358. package/src/toggle.spec.ts +2 -0
  359. package/src/trim.spec.ts +2 -0
  360. package/src/trim.ts +3 -2
  361. package/src/trimEnd.spec.ts +2 -0
  362. package/src/trimEnd.ts +1 -1
  363. package/src/trimStart.spec.ts +2 -0
  364. package/src/trimStart.ts +1 -1
  365. package/src/unique.ts +2 -2
  366. package/src/wait.ts +1 -1
  367. package/src/waitFor.spec.ts +9 -8
  368. package/src/waitFor.ts +1 -1
  369. package/src/waitSync.spec.ts +2 -0
  370. package/src/waitSync.ts +1 -1
  371. package/.prettierignore +0 -3
  372. package/.prettierrc.json +0 -1
  373. package/docs/documents/CHANGELOG.html +0 -357
  374. package/pnpm-lock.yaml +0 -6529
  375. package/typedoc.cjs +0 -3
@@ -7,7 +7,7 @@
7
7
  * @example isPlainObject(5); // returns false
8
8
  * @param value - value to test
9
9
  */
10
- const isPlainObject = (value: unknown) => Boolean(
10
+ const isPlainObject = (value: unknown): boolean => Boolean(
11
11
  value
12
12
  && typeof value === "object"
13
13
  && (
package/src/later.spec.ts CHANGED
@@ -28,6 +28,7 @@ describe("later", () => {
28
28
  const l = later();
29
29
  l.reject(new Error("foo"));
30
30
 
31
+ // eslint-disable-next-line @typescript-eslint/await-thenable
31
32
  await l.promise.must.reject.with.error("foo");
32
33
  });
33
34
  });
package/src/mapAsync.ts CHANGED
@@ -7,10 +7,10 @@ const DEFAULT_WAIT_TIME = 1;
7
7
  * Non-blocking version of `Array.prototype.map`, it will pause the map loop every `pauseEvery`. Keep in mind that
8
8
  * depending on your code workload the pause interval and duration may be exact or longer than specified. It's the same
9
9
  * single thread JavaScript nature setTimeout have to follow.
10
- * @param {Array} context - original array
11
- * @param {function} callback - map function
12
- * @param {number} pauseEvery - pause after this many ms
13
- * @param {number} pauseTime - how long to wait on pause
10
+ * @param context - original array
11
+ * @param callback - map function
12
+ * @param pauseEvery - pause after this many ms
13
+ * @param pauseTime - how long to wait on pause
14
14
  */
15
15
  const mapAsync = async <T, Y>(
16
16
  context: readonly T[],
package/src/match.ts CHANGED
@@ -4,8 +4,9 @@ type MatchCallback<T> = (value: T) => boolean;
4
4
  * A `Array.prototype.filter`-like function that splits the results into two groups - matched and unmatched
5
5
  * @param {Array} list - original array
6
6
  * @param {function} fn - function matching elements
7
+ * @deprecated - use `Map.groupBy` instead for even more robustness
7
8
  */
8
- const match = <T>(list: T[], fn: MatchCallback<T>) => {
9
+ const match = <T>(list: T[], fn: MatchCallback<T>): { matched: T[]; unmatched: T[] } => {
9
10
  const matched: T[] = [];
10
11
  const unmatched: T[] = [];
11
12
  list.forEach(item => {
@@ -1,8 +1,8 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-shadow
2
2
  import must from "must";
3
3
 
4
+ // @ts-ignore
4
5
  import createSpy from "../test/createSpy";
5
-
6
6
  import { memoize } from "./memoize";
7
7
 
8
8
  describe("memoize", () => {
package/src/memoize.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * @param fn - function to memoize
11
11
  * @returns memoized function
12
12
  */
13
- const memoize = <Args extends unknown[], Ret>(fn: (...args: Args) => Ret) => {
13
+ const memoize = <Args extends unknown[], Ret>(fn: (...args: Args) => Ret): (this: unknown, ...args: Args) => Ret => {
14
14
  let lastArgs: Args | undefined, lastResult: Ret, lastThis: unknown;
15
15
 
16
16
  return function memoized(this: unknown, ...args: Args): Ret {
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import { mostFrequent } from "./mostFrequent.js";
2
4
 
3
5
  describe("mostFrequent", () => {
@@ -3,7 +3,6 @@
3
3
  * @param {Array} array
4
4
  */
5
5
  const mostFrequent = <T>(array: T[]): T => {
6
- // eslint-disable-next-line @typescript-eslint/no-shadow
7
6
  let top = 0,
8
7
  topValue = array[0];
9
8
 
package/src/noop.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * No-operation function. It does nothing and returns nothing.
3
3
  */
4
- const noop = () => undefined;
4
+ const noop = (): undefined => undefined;
5
5
 
6
6
  export {
7
7
  noop,
@@ -18,7 +18,7 @@ const NOT_FOUND = -1;
18
18
  * @param {object} [options] - options
19
19
  * @param {boolean} [options.overlap=false] - allow overlapping matches, ie "aa" in "aaa" will return 2 instead of 1
20
20
  */
21
- const occurrences = (string: string, search: string, { overlap }: Options = {}) => {
21
+ const occurrences = (string: string, search: string, { overlap }: Options = {}): number => {
22
22
  if (typeof string !== "string") {
23
23
  throw new TypeError("Expected a string");
24
24
  }
@@ -1,7 +1,7 @@
1
1
  import { remove as _remove } from "lodash";
2
2
 
3
+ // @ts-ignore
3
4
  import createSpy from "../test/createSpy.js";
4
-
5
5
  import { remove } from "./remove.js";
6
6
 
7
7
  describe("remove", () => {
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import { removeCommonProperties } from "./removeCommonProperties.js";
2
4
 
3
5
  describe("removeCommonProperties", () => {
@@ -22,7 +22,7 @@ type Obj = Record<string, unknown>;
22
22
  * @example removeCommonProperties({ title: "Hello", author: "John"}, { title: "Hello 2", author: "John" }, { title: "Hello 3", author: "Matt" });
23
23
  * // targets: { title: "Hello 2", author: "John" }, { title: "Hello 3", author: "Matt" }
24
24
  */
25
- const removeCommonProperties = (source: Obj, target1: Obj, ...targetN: Obj[]) => {
25
+ const removeCommonProperties = (source: Obj, target1: Obj, ...targetN: Obj[]): void => {
26
26
  const targets = [target1, ...targetN];
27
27
  const keys = Object.keys(source);
28
28
  for (const key of keys) {
package/src/replace.ts CHANGED
@@ -7,7 +7,7 @@ import { escapeRegExp } from "./escapeRegExp.js";
7
7
  * @example replace("Hello, %name%!", { "%name%: "John" }) // "Hello, John!"
8
8
  * @example replace("Hello, %name%! Nice to meet you %name%!", { "%name%": "Jane" }) // "Hello, Jane! Nice to meet you Jane!"
9
9
  */
10
- const replace = (source: string, replaceMap: Record<string, string>) => {
10
+ const replace = (source: string, replaceMap: Record<string, string>): string => {
11
11
  const keys = Object.keys(replaceMap);
12
12
  if (keys.length === 0) {
13
13
  return source;
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import { replaceDeep } from "./replaceDeep";
2
4
 
3
5
  class MyClass {
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import { replaceDeepByFn } from "./replaceDeepByFn";
2
4
 
3
5
  class MyClass {
package/src/rethrow.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Throws given value.
3
3
  * @param {*} e
4
4
  */
5
- const rethrow = (e: unknown) => {
5
+ const rethrow = (e: unknown): void => {
6
6
  // eslint-disable-next-line @typescript-eslint/only-throw-error
7
7
  throw e;
8
8
  };
package/src/round.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * @param value - value to round
11
11
  * @param precision - precision to round to
12
12
  */
13
- const round = (value: number, precision?: number) => {
13
+ const round = (value: number, precision?: number): number => {
14
14
  // eslint-disable-next-line @typescript-eslint/no-magic-numbers
15
15
  const multiplier = Math.pow(10, precision || 0);
16
16
  return Math.round(value * multiplier) / multiplier;
package/src/safe.ts CHANGED
@@ -10,11 +10,12 @@ function safe<T, Y>(fn: () => T, def: Y): T | Y;
10
10
  * safe(() => JSON.parse(unknownString), null); // if unknownString is not a valid JSON, null will be returned
11
11
  * safe(() => trySomethingComplicated(), defaultValue); // if trySomethingComplicated throws, defaultValue will be returned
12
12
  */
13
- function safe<T, Y>(fn: () => T, def?: Y) { // eslint-disable-line func-style
13
+ function safe<T, Y>(fn: () => T, def?: Y): T | (Y extends undefined ? undefined : Y) {
14
14
  try {
15
15
  return fn();
16
16
  }
17
17
  catch {
18
+ // @ts-ignore ts can't do conditional returns in runtime
18
19
  return def;
19
20
  }
20
21
  }
package/src/scale.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * @param {number} toMax
10
10
  * @param {number} number
11
11
  */
12
- const scale = (fromMin: number, fromMax: number, toMin: number, toMax: number, number: number) => {
12
+ const scale = (fromMin: number, fromMax: number, toMin: number, toMax: number, number: number): number => {
13
13
  return toMin + ((number - fromMin) / (fromMax - fromMin) * (toMax - toMin));
14
14
  };
15
15
 
package/src/seq.ts CHANGED
@@ -48,7 +48,11 @@ const run = <T>(list: Fn<T>[], earlyBreaker?: EarlyBreaker): Promise<T> => {
48
48
  }
49
49
  const fn = promises.shift();
50
50
  if (typeof fn !== "function") {
51
- const finalError = new Error("Every function had thrown.");
51
+ const finalError = new Error("Every function had thrown.", {
52
+ cause: {
53
+ errors,
54
+ },
55
+ });
52
56
  // @ts-expect-error More details on error object are wanted
53
57
  finalError.details = { errors };
54
58
  reject(finalError);
@@ -73,7 +77,7 @@ const run = <T>(list: Fn<T>[], earlyBreaker?: EarlyBreaker): Promise<T> => {
73
77
  * arguments with array
74
78
  * @returns {*} - whatever gets returned from given functions
75
79
  */
76
- const seqEarlyBreak = <T>(earlyBreaker: EarlyBreaker | undefined, ...args: Functions<T>) => {
80
+ const seqEarlyBreak = <T>(earlyBreaker: EarlyBreaker | undefined, ...args: Functions<T>): Promise<T> => {
77
81
  if (args.length === 1) {
78
82
  return run(Array.isArray(args[0]) ? args[0] : [args[0]], earlyBreaker);
79
83
  }
@@ -91,7 +95,7 @@ const seqEarlyBreak = <T>(earlyBreaker: EarlyBreaker | undefined, ...args: Funct
91
95
  * arguments with array
92
96
  * @returns {*} - whatever gets returned from given functions
93
97
  */
94
- const seq = <T>(...fns: Functions<T>) => {
98
+ const seq = <T>(...fns: Functions<T>): Promise<T> => {
95
99
  return seqEarlyBreak(undefined, ...fns);
96
100
  };
97
101
 
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import type { CustomSerializers } from "./serialize";
2
4
 
3
5
  import { serialize } from "./serialize";
@@ -9,7 +11,6 @@ interface Test {
9
11
  class Person {
10
12
  public name: string;
11
13
 
12
- // eslint-disable-next-line @typescript-eslint/no-shadow
13
14
  public constructor(name: string) {
14
15
  this.name = name;
15
16
  }
package/src/serialize.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { sortProps } from "./sortProps.js";
2
- import { replaceDeepByFn } from "./replaceDeepByFn.js";
3
1
  import { isPlainObject } from "./isPlainObject.js";
2
+ import { replaceDeepByFn } from "./replaceDeepByFn.js";
3
+ import { sortProps } from "./sortProps.js";
4
4
  import { DataWrapper } from "./utils/utils.js";
5
5
 
6
6
  type CustomSerializers = {
@@ -34,7 +34,7 @@ type Options = {
34
34
  * @param customSerializers - an object with custom serializers
35
35
  * @param options - options
36
36
  */
37
- const serialize = (data: unknown, customSerializers?: CustomSerializers, options?: Options) => { // eslint-disable-line max-lines-per-function
37
+ const serialize = (data: unknown, customSerializers?: CustomSerializers, options?: Options): string => { // eslint-disable-line max-lines-per-function
38
38
  const sourceData = Object.keys(customSerializers ?? {}).length
39
39
  ? replaceDeepByFn(
40
40
  data,
@@ -1,7 +1,7 @@
1
1
  import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
2
 
3
- import { unserializeFromBuffer } from "./unserializeFromBuffer";
4
3
  import { serializeToBuffer } from "./serializeToBuffer";
4
+ import { unserializeFromBuffer } from "./unserializeFromBuffer";
5
5
 
6
6
  const serialize = serializeToBuffer.bind(null, Buffer, []);
7
7
  const unserialize = unserializeFromBuffer.bind(null, Buffer, []);
@@ -41,7 +41,7 @@ describe("serialization", () => {
41
41
  });
42
42
 
43
43
  it("serializes JSON-looking string", async () => {
44
- const data = [`"TEST"`];
44
+ const data = ["\"TEST\""];
45
45
  must(unserialize(serialize(...data))).eql(data);
46
46
  });
47
47
 
@@ -1,5 +1,4 @@
1
1
  import { serialize } from "../serialize.js";
2
-
3
2
  import { BINARY_MARK_BIN, BINARY_MARK_JSON, BINARY_MARK_STRING } from "./const.js";
4
3
 
5
4
  type SerializeArgs = Parameters<typeof serialize> extends [any, ...infer Rest] ? Rest : never; // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -1,5 +1,4 @@
1
1
  import { deserialize } from "../deserialize.js";
2
-
3
2
  import { BINARY_MARK_BIN, BINARY_MARK_MAP, BINARY_MARK_STRING } from "./const.js";
4
3
 
5
4
  const MAX_DATA_PARTS = 4;
@@ -9,7 +9,7 @@ const isObject = (value: unknown) => (typeof value === "object" || typeof value
9
9
 
10
10
  const clone = (value: unknown[] | Source) => {
11
11
  if (Array.isArray(value)) {
12
- return [...value as never as unknown[]]; // typecasts to satisfy eslint
12
+ return [...value];
13
13
  }
14
14
  return { ...value };
15
15
  };
package/src/sortBy.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
2
+
1
3
  import { sortByMultiple } from "./sortByMultiple.js";
2
4
 
3
5
  /**
@@ -10,7 +12,7 @@ import { sortByMultiple } from "./sortByMultiple.js";
10
12
  */
11
13
  const sortBy = <T extends Record<string | number | symbol, any>>( // eslint-disable-line @typescript-eslint/no-explicit-any
12
14
  propertyName: keyof T, asc = true, defaultValue: unknown = null,
13
- ) => (a: T, b: T) => {
15
+ ) => (a: T, b: T): -1 | 0 | 1 => {
14
16
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
15
17
  return sortByMultiple([propertyName], asc, { [propertyName]: defaultValue } as Partial<Record<keyof T, any>>)(a, b);
16
18
  };
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
2
+
1
3
  /**
2
4
  * Returns a function that can be used as a callback to `.sort()` method. Returned function will sort array by given
3
5
  * properties.
@@ -34,12 +36,12 @@ const sortByMultiple = <
34
36
  ascending: boolean | Record<K[number], boolean> = true,
35
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
38
  defaultValues?: Partial<Record<K[number], any>>, // Force defaultValues to use only keys from K
37
- ): ((a: T, b: T) => number) => (a: T, b: T) => {
39
+ ): ((a: T, b: T) => 1 | -1 | 0) => (a: T, b: T): 1 | -1 | 0 => {
38
40
  for (const propertyName of propertyNames) {
39
41
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
40
42
  const asc = typeof ascending === "boolean" ? ascending : (ascending[propertyName] ?? true);
41
- const aBiggerValue = asc ? 1 : -1; // eslint-disable-line @typescript-eslint/no-magic-numbers
42
- const bBiggerValue = asc ? -1 : 1; // eslint-disable-line @typescript-eslint/no-magic-numbers
43
+ const aBiggerValue = asc ? 1 : -1;
44
+ const bBiggerValue = asc ? -1 : 1;
43
45
 
44
46
  const aValue = a[propertyName] ?? defaultValues?.[propertyName];
45
47
  const bValue = b[propertyName] ?? defaultValues?.[propertyName];
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import { toggle } from "./toggle.js";
2
4
 
3
5
  describe("toggle", () => {
package/src/trim.spec.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import { trim } from "./trim";
2
4
 
3
5
  describe("trim", () => {
package/src/trim.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { trimStart } from "./trimStart.js";
2
1
  import { trimEnd } from "./trimEnd.js";
2
+ import { trimStart } from "./trimStart.js";
3
3
 
4
4
  /**
5
5
  * Removes given characters from both sides of the string.
@@ -14,10 +14,11 @@ import { trimEnd } from "./trimEnd.js";
14
14
  * trim("!aaa!!!", "!"); // "aaa"
15
15
  * trim("!aaa!!!", "!!!"); // "!aaa"
16
16
  */
17
- const trim = (source: string, characters: string) => {
17
+ const trim = (source: string, characters: string): string => {
18
18
  return trimStart(trimEnd(source, characters), characters);
19
19
  };
20
20
 
21
21
  export {
22
22
  trim,
23
23
  };
24
+
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import { trimEnd } from "./trimEnd";
2
4
 
3
5
  describe("trimEnd", () => {
package/src/trimEnd.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * trimEnd("abcxzyz", "yz"); // "abcxz"
10
10
  * trimEnd("!aaa!!", "!"); // "!aaa"
11
11
  */
12
- const trimEnd = (source: string, characters: string) => {
12
+ const trimEnd = (source: string, characters: string): string => {
13
13
  let s = source;
14
14
  while (s.endsWith(characters)) {
15
15
  s = s.slice(0, -characters.length);
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import { trimStart } from "./trimStart";
2
4
 
3
5
  describe("trimStart", () => {
package/src/trimStart.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * trimStart("abbcb", "ab"); // "bcb"
10
10
  * trimStart("!!aaa!", "!"); // "aaa!"
11
11
  */
12
- const trimStart = (source: string, characters: string) => {
12
+ const trimStart = (source: string, characters: string): string => {
13
13
  let s = source;
14
14
  while (s.startsWith(characters)) {
15
15
  s = s.slice(characters.length);
package/src/unique.ts CHANGED
@@ -3,8 +3,8 @@
3
3
  * @param arr - source array
4
4
  * @example unique([1, 2, 3, 2, 1]) // [1, 2, 3]
5
5
  */
6
- const unique = <T extends unknown[]>(arr: T): T => {
7
- return [...new Set(arr)] as T;
6
+ const unique = <T>(arr: T[]): T[] => {
7
+ return [...new Set(arr)];
8
8
  };
9
9
 
10
10
  export {
package/src/wait.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * @param {number} timeMs - time to wait
4
4
  * @returns {Promise<void>}
5
5
  */
6
- const wait = (timeMs = 0) => {
6
+ const wait = (timeMs = 0): Promise<void> => {
7
7
  return new Promise<void>((resolve) => {
8
8
  setTimeout(() => { resolve(); }, timeMs);
9
9
  });
@@ -1,10 +1,10 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-shadow
2
2
  import must from "must";
3
3
 
4
+ // @ts-ignore
4
5
  import createSpy from "../test/createSpy";
5
-
6
- import { waitFor } from "./waitFor";
7
6
  import { wait } from "./wait";
7
+ import { waitFor } from "./waitFor";
8
8
 
9
9
  describe("waitFor", () => {
10
10
  it("calls function multiple times until it returns truthy value", async () => {
@@ -91,12 +91,13 @@ describe("waitFor", () => {
91
91
 
92
92
  it("crashes if check function crashes", async () => {
93
93
  await waitFor(() => {
94
+ // @ts-ignore
94
95
  throw new Error(5);
95
- }, 40).then(() => {
96
+ }, { interval: 40 }).then(() => {
96
97
  throw new Error("Should not resolve");
97
- }, (e) => {
98
+ }, (e: unknown) => {
98
99
  must(e).instanceOf(Error);
99
- must(e.message).equal("[waitFor] check function threw an error");
100
+ must((e as Error).message).equal("[waitFor] check function threw an error");
100
101
  });
101
102
  });
102
103
 
@@ -134,11 +135,11 @@ describe("waitFor", () => {
134
135
  it("by crashing if check function returns rejected promise", async () => {
135
136
  await waitFor(() => {
136
137
  return Promise.reject(new Error("oops"));
137
- }, 40).then(() => {
138
+ }, { interval: 40 }).then(() => {
138
139
  throw new Error("Should not resolve");
139
- }, (e) => {
140
+ }, (e: unknown) => {
140
141
  must(e).instanceOf(Error);
141
- must(e.message).equal("[waitFor] check function threw an error");
142
+ must((e as Error).message).equal("[waitFor] check function threw an error");
142
143
  });
143
144
  });
144
145
  });
package/src/waitFor.ts CHANGED
@@ -39,7 +39,7 @@ const defaultOptions: Required<Options> = {
39
39
  * @param fn - callback function
40
40
  * @param options - options object
41
41
  */
42
- const waitFor = <T>(fn: () => MaybePromise<T>, options: Options = defaultOptions) => {
42
+ const waitFor = <T>(fn: () => MaybePromise<T>, options: Options = defaultOptions): Promise<T> => {
43
43
  return new Promise<T>((resolve, reject) => {
44
44
  let intervalTimer: TTimeout, failTimer: TTimeout;
45
45
 
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import { waitSync } from "./waitSync.js";
2
4
 
3
5
  describe("wait", () => {
package/src/waitSync.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * @param {number} timeMs - time to wait
4
4
  * @returns {Promise<void>}
5
5
  */
6
- const waitSync = (timeMs = 0) => {
6
+ const waitSync = (timeMs = 0): void => {
7
7
  const s = Date.now();
8
8
  // eslint-disable-next-line no-empty
9
9
  while (Date.now() - s < timeMs) {}
package/.prettierignore DELETED
@@ -1,3 +0,0 @@
1
- *.js
2
- *.ts
3
- *.tsx
package/.prettierrc.json DELETED
@@ -1 +0,0 @@
1
- {}