@ezez/utils 4.4.0 → 4.6.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 (381) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/cap.d.ts.map +1 -1
  3. package/dist/cap.js.map +1 -1
  4. package/dist/capitalize.d.ts.map +1 -1
  5. package/dist/capitalize.js.map +1 -1
  6. package/dist/compareArrays.d.ts +4 -4
  7. package/dist/compareArrays.d.ts.map +1 -1
  8. package/dist/compareArrays.js.map +1 -1
  9. package/dist/deserialize.d.ts +1 -1
  10. package/dist/deserialize.d.ts.map +1 -1
  11. package/dist/deserialize.js +2 -1
  12. package/dist/deserialize.js.map +1 -1
  13. package/dist/ensureError.d.ts.map +1 -1
  14. package/dist/ensureError.js +3 -1
  15. package/dist/ensureError.js.map +1 -1
  16. package/dist/ensurePrefix.d.ts.map +1 -1
  17. package/dist/ensurePrefix.js.map +1 -1
  18. package/dist/ensureSuffix.d.ts.map +1 -1
  19. package/dist/ensureSuffix.js.map +1 -1
  20. package/dist/escapeRegExp.d.ts.map +1 -1
  21. package/dist/escapeRegExp.js.map +1 -1
  22. package/dist/formatDate.d.ts.map +1 -1
  23. package/dist/formatDate.js.map +1 -1
  24. package/dist/getMultiple.d.ts.map +1 -1
  25. package/dist/getMultiple.js.map +1 -1
  26. package/dist/ignore.d.ts +3 -0
  27. package/dist/ignore.d.ts.map +1 -0
  28. package/dist/ignore.js +16 -0
  29. package/dist/ignore.js.map +1 -0
  30. package/dist/index.d.ts +3 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +3 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/isEmpty.d.ts.map +1 -1
  35. package/dist/isEmpty.js +4 -4
  36. package/dist/isEmpty.js.map +1 -1
  37. package/dist/isNumericString.d.ts.map +1 -1
  38. package/dist/isNumericString.js.map +1 -1
  39. package/dist/isPlainObject.d.ts.map +1 -1
  40. package/dist/isPlainObject.js.map +1 -1
  41. package/dist/match.d.ts.map +1 -1
  42. package/dist/match.js.map +1 -1
  43. package/dist/memoize.d.ts.map +1 -1
  44. package/dist/memoize.js.map +1 -1
  45. package/dist/mostFrequent.d.ts.map +1 -1
  46. package/dist/mostFrequent.js.map +1 -1
  47. package/dist/noop.d.ts.map +1 -1
  48. package/dist/noop.js.map +1 -1
  49. package/dist/occurrences.d.ts.map +1 -1
  50. package/dist/occurrences.js.map +1 -1
  51. package/dist/removeCommonProperties.d.ts.map +1 -1
  52. package/dist/removeCommonProperties.js.map +1 -1
  53. package/dist/replace.d.ts.map +1 -1
  54. package/dist/replace.js.map +1 -1
  55. package/dist/rethrow.d.ts +1 -1
  56. package/dist/rethrow.d.ts.map +1 -1
  57. package/dist/rethrow.js.map +1 -1
  58. package/dist/round.d.ts.map +1 -1
  59. package/dist/round.js.map +1 -1
  60. package/dist/safe.d.ts.map +1 -1
  61. package/dist/safe.js.map +1 -1
  62. package/dist/scale.d.ts.map +1 -1
  63. package/dist/scale.js.map +1 -1
  64. package/dist/seq.d.ts.map +1 -1
  65. package/dist/seq.js +5 -1
  66. package/dist/seq.js.map +1 -1
  67. package/dist/serialize.d.ts.map +1 -1
  68. package/dist/serialize.js +2 -2
  69. package/dist/serialize.js.map +1 -1
  70. package/dist/serializeToBuffer/const.d.ts +10 -0
  71. package/dist/serializeToBuffer/const.d.ts.map +1 -0
  72. package/dist/serializeToBuffer/const.js +16 -0
  73. package/dist/serializeToBuffer/const.js.map +1 -0
  74. package/dist/serializeToBuffer/serializeToBuffer.d.ts +5 -0
  75. package/dist/serializeToBuffer/serializeToBuffer.d.ts.map +1 -0
  76. package/dist/serializeToBuffer/serializeToBuffer.js +39 -0
  77. package/dist/serializeToBuffer/serializeToBuffer.js.map +1 -0
  78. package/dist/serializeToBuffer/unserializeFromBuffer.d.ts +5 -0
  79. package/dist/serializeToBuffer/unserializeFromBuffer.d.ts.map +1 -0
  80. package/dist/serializeToBuffer/unserializeFromBuffer.js +52 -0
  81. package/dist/serializeToBuffer/unserializeFromBuffer.js.map +1 -0
  82. package/dist/setImmutable.js.map +1 -1
  83. package/dist/sortBy.d.ts +1 -1
  84. package/dist/sortBy.d.ts.map +1 -1
  85. package/dist/sortBy.js.map +1 -1
  86. package/dist/sortByMultiple.d.ts +1 -1
  87. package/dist/sortByMultiple.d.ts.map +1 -1
  88. package/dist/sortByMultiple.js.map +1 -1
  89. package/dist/trim.d.ts.map +1 -1
  90. package/dist/trim.js +1 -1
  91. package/dist/trim.js.map +1 -1
  92. package/dist/trimEnd.d.ts.map +1 -1
  93. package/dist/trimEnd.js.map +1 -1
  94. package/dist/trimStart.d.ts.map +1 -1
  95. package/dist/trimStart.js.map +1 -1
  96. package/dist/unique.d.ts +1 -1
  97. package/dist/unique.d.ts.map +1 -1
  98. package/dist/unique.js.map +1 -1
  99. package/dist/utils/utils.js +1 -0
  100. package/dist/utils/utils.js.map +1 -1
  101. package/dist/wait.d.ts.map +1 -1
  102. package/dist/wait.js.map +1 -1
  103. package/dist/waitFor.d.ts.map +1 -1
  104. package/dist/waitFor.js.map +1 -1
  105. package/dist/waitSync.d.ts.map +1 -1
  106. package/dist/waitSync.js.map +1 -1
  107. package/docs/assets/hierarchy.js +1 -0
  108. package/docs/assets/icons.js +1 -1
  109. package/docs/assets/icons.svg +1 -1
  110. package/docs/assets/main.js +5 -5
  111. package/docs/assets/navigation.js +1 -1
  112. package/docs/assets/search.js +1 -1
  113. package/docs/assets/style.css +1405 -1288
  114. package/docs/documents/Changelog.html +370 -0
  115. package/docs/functions/index.cap.html +3 -3
  116. package/docs/functions/index.capitalize.html +7 -7
  117. package/docs/functions/index.coalesce.html +8 -8
  118. package/docs/functions/index.compareArrays.html +5 -5
  119. package/docs/functions/index.compareProps.html +5 -5
  120. package/docs/functions/index.deserialize.html +4 -4
  121. package/docs/functions/index.ensureArray.html +3 -3
  122. package/docs/functions/index.ensureDate.html +6 -6
  123. package/docs/functions/index.ensureError.html +6 -6
  124. package/docs/functions/index.ensurePrefix.html +5 -5
  125. package/docs/functions/index.ensureSuffix.html +5 -5
  126. package/docs/functions/index.ensureTimestamp.html +6 -6
  127. package/docs/functions/index.escapeRegExp.html +5 -5
  128. package/docs/functions/index.formatDate.html +5 -2
  129. package/docs/functions/index.get.html +8 -8
  130. package/docs/functions/index.getMultiple.html +6 -6
  131. package/docs/functions/index.ignore.html +8 -0
  132. package/docs/functions/index.insertSeparator.html +5 -5
  133. package/docs/functions/index.isEmpty.html +12 -13
  134. package/docs/functions/index.isNumericString.html +3 -3
  135. package/docs/functions/index.isPlainObject.html +8 -8
  136. package/docs/functions/index.last.html +7 -7
  137. package/docs/functions/index.later-1.html +3 -3
  138. package/docs/functions/index.mapAsync.html +5 -5
  139. package/docs/functions/index.mapValues.html +7 -7
  140. package/docs/functions/index.match.html +4 -4
  141. package/docs/functions/index.memoize.html +4 -4
  142. package/docs/functions/index.merge.html +6 -6
  143. package/docs/functions/index.mostFrequent.html +2 -2
  144. package/docs/functions/index.noop.html +2 -2
  145. package/docs/functions/index.occurrences.html +7 -6
  146. package/docs/functions/index.omit.html +7 -7
  147. package/docs/functions/index.pick.html +7 -7
  148. package/docs/functions/index.pull.html +2 -2
  149. package/docs/functions/index.race.html +5 -5
  150. package/docs/functions/index.remove.html +2 -2
  151. package/docs/functions/index.removeCommonProperties.html +5 -5
  152. package/docs/functions/index.replace.html +6 -6
  153. package/docs/functions/index.replaceDeep.html +3 -3
  154. package/docs/functions/index.rethrow.html +2 -2
  155. package/docs/functions/index.retry.html +4 -4
  156. package/docs/functions/index.round.html +4 -4
  157. package/docs/functions/index.safe.html +5 -5
  158. package/docs/functions/index.sample.html +4 -4
  159. package/docs/functions/index.samples.html +3 -3
  160. package/docs/functions/index.scale.html +2 -2
  161. package/docs/functions/index.seq.html +7 -7
  162. package/docs/functions/index.seqEarlyBreak.html +6 -6
  163. package/docs/functions/index.serialize.html +4 -5
  164. package/docs/functions/index.serializeToBuffer.html +19 -0
  165. package/docs/functions/index.set.html +8 -8
  166. package/docs/functions/index.setImmutable.html +7 -7
  167. package/docs/functions/index.shuffle.html +3 -3
  168. package/docs/functions/index.sortBy.html +3 -3
  169. package/docs/functions/index.sortByMultiple.html +5 -5
  170. package/docs/functions/index.sortProps.html +4 -4
  171. package/docs/functions/index.stripPrefix.html +3 -3
  172. package/docs/functions/index.stripSuffix.html +3 -3
  173. package/docs/functions/index.throttle.html +4 -4
  174. package/docs/functions/index.toggle.html +4 -4
  175. package/docs/functions/index.trim.html +4 -4
  176. package/docs/functions/index.trimEnd.html +4 -4
  177. package/docs/functions/index.trimStart.html +4 -4
  178. package/docs/functions/index.truthy.html +4 -4
  179. package/docs/functions/index.unique.html +4 -4
  180. package/docs/functions/index.unserializeFromBuffer.html +8 -0
  181. package/docs/functions/index.wait.html +3 -3
  182. package/docs/functions/index.waitFor.html +4 -4
  183. package/docs/functions/index.waitSync.html +3 -3
  184. package/docs/index.html +16 -16
  185. package/docs/interfaces/index.ComparePropsOptions.html +4 -4
  186. package/docs/interfaces/index.GetMultipleSource.html +3 -3
  187. package/docs/interfaces/index.GetSource.html +3 -3
  188. package/docs/interfaces/index.IsNumericStringOptions.html +5 -5
  189. package/docs/interfaces/index.OccurencesOptions.html +2 -2
  190. package/docs/interfaces/index.SetImmutableSource.html +3 -3
  191. package/docs/interfaces/index.SetSource.html +3 -3
  192. package/docs/interfaces/index.ThrottleOptions.html +3 -3
  193. package/docs/interfaces/index.ThrottledFunctionExtras.html +4 -4
  194. package/docs/modules/index.html +1 -89
  195. package/docs/modules.html +1 -3
  196. package/docs/types/index.CustomDeserializers.html +1 -1
  197. package/docs/types/index.CustomSerializers.html +1 -1
  198. package/docs/types/index.Later.html +4 -4
  199. package/docs/types/index.MapValuesFn.html +7 -7
  200. package/docs/types/index.MatchCallback.html +1 -1
  201. package/docs/types/index.MergeTwo.html +2 -2
  202. package/docs/types/index.SeqEarlyBreaker.html +4 -4
  203. package/docs/types/index.SeqFn.html +3 -3
  204. package/docs/types/index.SeqFunctions.html +3 -3
  205. package/docs/types/index.SetImmutablePath.html +2 -2
  206. package/docs/types/index.ThrottledFunction.html +1 -1
  207. package/docs/variables/index.mapValuesUNSET.html +2 -2
  208. package/docs/variables/index.mergeUNSET.html +3 -3
  209. package/esm/cap.d.ts.map +1 -1
  210. package/esm/cap.js.map +1 -1
  211. package/esm/capitalize.d.ts.map +1 -1
  212. package/esm/capitalize.js.map +1 -1
  213. package/esm/compareArrays.d.ts +4 -4
  214. package/esm/compareArrays.d.ts.map +1 -1
  215. package/esm/compareArrays.js.map +1 -1
  216. package/esm/deserialize.d.ts +1 -1
  217. package/esm/deserialize.d.ts.map +1 -1
  218. package/esm/deserialize.js +1 -1
  219. package/esm/deserialize.js.map +1 -1
  220. package/esm/ensureError.d.ts.map +1 -1
  221. package/esm/ensureError.js +3 -1
  222. package/esm/ensureError.js.map +1 -1
  223. package/esm/ensurePrefix.d.ts.map +1 -1
  224. package/esm/ensurePrefix.js.map +1 -1
  225. package/esm/ensureSuffix.d.ts.map +1 -1
  226. package/esm/ensureSuffix.js.map +1 -1
  227. package/esm/escapeRegExp.d.ts.map +1 -1
  228. package/esm/escapeRegExp.js.map +1 -1
  229. package/esm/formatDate.d.ts.map +1 -1
  230. package/esm/formatDate.js.map +1 -1
  231. package/esm/getMultiple.d.ts.map +1 -1
  232. package/esm/getMultiple.js.map +1 -1
  233. package/esm/ignore.d.ts +3 -0
  234. package/esm/ignore.d.ts.map +1 -0
  235. package/esm/ignore.js +13 -0
  236. package/esm/ignore.js.map +1 -0
  237. package/esm/index.d.ts +3 -0
  238. package/esm/index.d.ts.map +1 -1
  239. package/esm/index.js +3 -0
  240. package/esm/index.js.map +1 -1
  241. package/esm/isEmpty.d.ts.map +1 -1
  242. package/esm/isEmpty.js +4 -4
  243. package/esm/isEmpty.js.map +1 -1
  244. package/esm/isNumericString.d.ts.map +1 -1
  245. package/esm/isNumericString.js.map +1 -1
  246. package/esm/isPlainObject.d.ts.map +1 -1
  247. package/esm/isPlainObject.js.map +1 -1
  248. package/esm/match.d.ts.map +1 -1
  249. package/esm/match.js.map +1 -1
  250. package/esm/memoize.d.ts.map +1 -1
  251. package/esm/memoize.js.map +1 -1
  252. package/esm/mostFrequent.d.ts.map +1 -1
  253. package/esm/mostFrequent.js.map +1 -1
  254. package/esm/noop.d.ts.map +1 -1
  255. package/esm/noop.js.map +1 -1
  256. package/esm/occurrences.d.ts.map +1 -1
  257. package/esm/occurrences.js.map +1 -1
  258. package/esm/removeCommonProperties.d.ts.map +1 -1
  259. package/esm/removeCommonProperties.js.map +1 -1
  260. package/esm/replace.d.ts.map +1 -1
  261. package/esm/replace.js.map +1 -1
  262. package/esm/rethrow.d.ts +1 -1
  263. package/esm/rethrow.d.ts.map +1 -1
  264. package/esm/rethrow.js.map +1 -1
  265. package/esm/round.d.ts.map +1 -1
  266. package/esm/round.js.map +1 -1
  267. package/esm/safe.d.ts.map +1 -1
  268. package/esm/safe.js.map +1 -1
  269. package/esm/scale.d.ts.map +1 -1
  270. package/esm/scale.js.map +1 -1
  271. package/esm/seq.d.ts.map +1 -1
  272. package/esm/seq.js +5 -1
  273. package/esm/seq.js.map +1 -1
  274. package/esm/serialize.d.ts.map +1 -1
  275. package/esm/serialize.js +2 -2
  276. package/esm/serialize.js.map +1 -1
  277. package/esm/serializeToBuffer/const.d.ts +10 -0
  278. package/esm/serializeToBuffer/const.d.ts.map +1 -0
  279. package/esm/serializeToBuffer/const.js +10 -0
  280. package/esm/serializeToBuffer/const.js.map +1 -0
  281. package/esm/serializeToBuffer/serializeToBuffer.d.ts +5 -0
  282. package/esm/serializeToBuffer/serializeToBuffer.d.ts.map +1 -0
  283. package/esm/serializeToBuffer/serializeToBuffer.js +36 -0
  284. package/esm/serializeToBuffer/serializeToBuffer.js.map +1 -0
  285. package/esm/serializeToBuffer/unserializeFromBuffer.d.ts +5 -0
  286. package/esm/serializeToBuffer/unserializeFromBuffer.d.ts.map +1 -0
  287. package/esm/serializeToBuffer/unserializeFromBuffer.js +48 -0
  288. package/esm/serializeToBuffer/unserializeFromBuffer.js.map +1 -0
  289. package/esm/setImmutable.js.map +1 -1
  290. package/esm/sortBy.d.ts +1 -1
  291. package/esm/sortBy.d.ts.map +1 -1
  292. package/esm/sortBy.js.map +1 -1
  293. package/esm/sortByMultiple.d.ts +1 -1
  294. package/esm/sortByMultiple.d.ts.map +1 -1
  295. package/esm/sortByMultiple.js.map +1 -1
  296. package/esm/trim.d.ts.map +1 -1
  297. package/esm/trim.js +1 -1
  298. package/esm/trim.js.map +1 -1
  299. package/esm/trimEnd.d.ts.map +1 -1
  300. package/esm/trimEnd.js.map +1 -1
  301. package/esm/trimStart.d.ts.map +1 -1
  302. package/esm/trimStart.js.map +1 -1
  303. package/esm/unique.d.ts +1 -1
  304. package/esm/unique.d.ts.map +1 -1
  305. package/esm/unique.js.map +1 -1
  306. package/esm/utils/utils.js +1 -0
  307. package/esm/utils/utils.js.map +1 -1
  308. package/esm/wait.d.ts.map +1 -1
  309. package/esm/wait.js.map +1 -1
  310. package/esm/waitFor.d.ts.map +1 -1
  311. package/esm/waitFor.js.map +1 -1
  312. package/esm/waitSync.d.ts.map +1 -1
  313. package/esm/waitSync.js.map +1 -1
  314. package/package.json +31 -34
  315. package/src/cap.ts +1 -1
  316. package/src/capitalize.ts +3 -3
  317. package/src/compareArrays.ts +2 -3
  318. package/src/deserialize.spec.ts +2 -1
  319. package/src/deserialize.ts +1 -1
  320. package/src/ensureError.ts +6 -2
  321. package/src/ensurePrefix.ts +1 -1
  322. package/src/ensureSuffix.ts +1 -1
  323. package/src/escapeRegExp.ts +1 -1
  324. package/src/formatDate.ts +7 -2
  325. package/src/get.spec.ts +0 -1
  326. package/src/getMultiple.ts +0 -1
  327. package/src/ignore.spec.ts +80 -0
  328. package/src/ignore.ts +38 -0
  329. package/src/index.ts +3 -0
  330. package/src/isEmpty.ts +9 -15
  331. package/src/isNumericString.ts +1 -1
  332. package/src/isPlainObject.ts +1 -1
  333. package/src/later.spec.ts +1 -0
  334. package/src/mapAsync.ts +4 -4
  335. package/src/match.ts +1 -1
  336. package/src/memoize.spec.ts +1 -1
  337. package/src/memoize.ts +1 -1
  338. package/src/mostFrequent.spec.ts +2 -0
  339. package/src/mostFrequent.ts +0 -1
  340. package/src/noop.ts +1 -1
  341. package/src/occurrences.ts +1 -1
  342. package/src/remove.spec.ts +1 -1
  343. package/src/removeCommonProperties.spec.ts +2 -0
  344. package/src/removeCommonProperties.ts +1 -1
  345. package/src/replace.ts +1 -1
  346. package/src/replaceDeep.spec.ts +2 -0
  347. package/src/replaceDeepByFn.spec.ts +2 -0
  348. package/src/rethrow.ts +1 -1
  349. package/src/round.ts +1 -1
  350. package/src/safe.ts +2 -1
  351. package/src/scale.ts +1 -1
  352. package/src/seq.ts +7 -3
  353. package/src/serialize.spec.ts +2 -1
  354. package/src/serialize.ts +4 -5
  355. package/src/serializeToBuffer/const.ts +16 -0
  356. package/src/serializeToBuffer/serialization.spec.ts +61 -0
  357. package/src/serializeToBuffer/serializeToBuffer.spec.ts +43 -0
  358. package/src/serializeToBuffer/serializeToBuffer.ts +89 -0
  359. package/src/serializeToBuffer/unserializeFromBuffer.spec.ts +63 -0
  360. package/src/serializeToBuffer/unserializeFromBuffer.ts +74 -0
  361. package/src/setImmutable.ts +1 -1
  362. package/src/sortBy.ts +3 -1
  363. package/src/sortByMultiple.ts +5 -3
  364. package/src/toggle.spec.ts +2 -0
  365. package/src/trim.spec.ts +2 -0
  366. package/src/trim.ts +3 -2
  367. package/src/trimEnd.spec.ts +2 -0
  368. package/src/trimEnd.ts +1 -1
  369. package/src/trimStart.spec.ts +2 -0
  370. package/src/trimStart.ts +1 -1
  371. package/src/unique.ts +2 -2
  372. package/src/wait.ts +1 -1
  373. package/src/waitFor.spec.ts +9 -8
  374. package/src/waitFor.ts +1 -1
  375. package/src/waitSync.spec.ts +2 -0
  376. package/src/waitSync.ts +1 -1
  377. package/.prettierignore +0 -3
  378. package/.prettierrc.json +0 -1
  379. package/docs/documents/CHANGELOG.html +0 -349
  380. package/pnpm-lock.yaml +0 -6529
  381. package/typedoc.cjs +0 -3
package/package.json CHANGED
@@ -1,28 +1,9 @@
1
1
  {
2
2
  "name": "@ezez/utils",
3
- "version": "4.4.0",
3
+ "version": "4.6.0",
4
4
  "repository": "https://github.com/dzek69/bottom-line.git",
5
5
  "author": "Jacek Nowacki @dzek69 <git-public@dzek.eu>",
6
6
  "license": "MIT",
7
- "scripts": {
8
- "test": "NODE_ENV=test jest",
9
- "test:lodashImports": "node test/lodash-tree.cjs",
10
- "docs": "typedoc src/index.ts --skipErrorChecking --out docs --includeVersion",
11
- "compile": "pnpm run compile:esm && pnpm run compile:cjs",
12
- "compile:esm": "rm -rf esm && tsc --project tsconfig.esm.json && node ./build-scripts/compile.esm.after.mjs",
13
- "compile:cjs": "rm -rf dist && tsc --project tsconfig.cjs.json && node ./build-scripts/compile.cjs.after.mjs",
14
- "typecheck": "tsc --noEmit",
15
- "lint": "eslint src",
16
- "lint:fix": "pnpm run lint --fix",
17
- "prepack": "pnpm run compile",
18
- "prepublishOnly": "pnpm run lint && pnpm run test && pnpm run docs",
19
- "start:dev": "nodemon",
20
- "start:dev:compatibility": "TS_NODE_FILES=true pnpm run start:dev",
21
- "prepare": "husky install",
22
- "updates": "pnpm dlx npm-check-updates --dep prod",
23
- "updates:dev": "pnpm dlx npm-check-updates --dep dev",
24
- "updates:all": "pnpm dlx npm-check-updates"
25
- },
26
7
  "exports": {
27
8
  ".": {
28
9
  "require": "./dist/index.js",
@@ -35,25 +16,25 @@
35
16
  "module": "./esm/index.js",
36
17
  "type": "module",
37
18
  "devDependencies": {
38
- "@babel/core": "^7.24.3",
39
- "@babel/preset-env": "^7.24.3",
40
- "@babel/preset-typescript": "^7.24.1",
41
- "@ezez/eslint": "^0.0.6",
42
- "@types/jest": "^29.5.5",
19
+ "@babel/core": "^7.26.0",
20
+ "@babel/preset-env": "^7.26.0",
21
+ "@babel/preset-typescript": "^7.26.0",
22
+ "@ezez/eslint": "^9.37.4",
23
+ "@types/jest": "^29.5.14",
43
24
  "@types/lodash": "^4.14.168",
44
25
  "@types/node": "^20.8.3",
45
26
  "babel-plugin-module-extension": "^0.1.3",
46
- "fs-extra": "^11.1.1",
27
+ "fs-extra": "^11.3.0",
47
28
  "husky": "^8.0.3",
48
29
  "jest": "^29.7.0",
49
30
  "lodash": "^4.17.21",
50
31
  "must": "^0.13.4",
51
- "nodemon": "^3.0.1",
52
- "prettier": "^3.2.5",
53
- "resolve-tspaths": "^0.8.15",
32
+ "nodemon": "^3.1.9",
33
+ "prettier": "^3.4.2",
34
+ "resolve-tspaths": "^0.8.23",
54
35
  "ts-node": "^10.9.2",
55
- "typedoc": "^0.26.0-beta.1",
56
- "typescript": "^5.4.5"
36
+ "typedoc": "0.27.6",
37
+ "typescript": "^5.7.3"
57
38
  },
58
39
  "husky": {
59
40
  "hooks": {
@@ -61,10 +42,26 @@
61
42
  }
62
43
  },
63
44
  "libraryTemplate": {
64
- "version": "3.12.0",
45
+ "version": "3.14.0",
65
46
  "language": "typescript",
66
47
  "fixDefaultForCommonJS": false,
67
48
  "jsx": false
68
49
  },
69
- "dependencies": {}
70
- }
50
+ "dependencies": {},
51
+ "scripts": {
52
+ "test": "NODE_ENV=test jest",
53
+ "test:lodashImports": "node test/lodash-tree.cjs",
54
+ "docs": "typedoc src/index.ts --skipErrorChecking --out docs --includeVersion",
55
+ "compile": "pnpm run compile:esm && pnpm run compile:cjs",
56
+ "compile:esm": "rm -rf esm && tsc --project tsconfig.esm.json && node ./build-scripts/compile.esm.after.mjs",
57
+ "compile:cjs": "rm -rf dist && tsc --project tsconfig.cjs.json && node ./build-scripts/compile.cjs.after.mjs",
58
+ "typecheck": "tsc --noEmit",
59
+ "lint": "ezlint src",
60
+ "lint:fix": "pnpm run lint --fix",
61
+ "start:dev": "nodemon",
62
+ "start:dev:compatibility": "TS_NODE_FILES=true pnpm run start:dev",
63
+ "updates": "pnpm dlx npm-check-updates --dep prod",
64
+ "updates:dev": "pnpm dlx npm-check-updates --dep dev",
65
+ "updates:all": "pnpm dlx npm-check-updates"
66
+ }
67
+ }
package/src/cap.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * @param {number} upperLimit - upper limit, inclusive
5
5
  * @param {number} [lowerLimit] - lower limit, inclusive
6
6
  */
7
- const cap = (value: number, upperLimit: number, lowerLimit?: number) => {
7
+ const cap = (value: number, upperLimit: number, lowerLimit?: number): number => {
8
8
  if (lowerLimit == null) {
9
9
  return Math.min(value, upperLimit);
10
10
  }
package/src/capitalize.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Capitalize the first letter of a string.
3
- * @param {string} text - source string
4
- * @param {boolean} [restLowercase=false] - should the rest of the string be forced to lowercase?
3
+ * @param text - source string
4
+ * @param restLowercase - should the rest of the string be forced to lowercase?
5
5
  * @example capitalize("hello") // "Hello"
6
6
  * @example capitalize("hello my Friend", true) // "Hello my friend"
7
7
  * @example capitalize("hello my Friend", false) // "Hello my Friend"
8
8
  */
9
- const capitalize = (text: string, restLowercase = false) => {
9
+ const capitalize = (text: string, restLowercase = false): string => {
10
10
  const rest = restLowercase ? text.slice(1).toLowerCase() : text.slice(1);
11
11
  return text.charAt(0).toUpperCase() + rest;
12
12
  };
@@ -9,12 +9,11 @@ import { unique } from "./unique.js";
9
9
  * onlyB - items that exists only in second array,
10
10
  * both - items that exists in both arrays
11
11
  */
12
- const compareArrays = <T extends unknown[]>(arrayA: T, arrayB: T): { onlyA: T; onlyB: T; both: T } => {
12
+ const compareArrays = <T>(arrayA: T[], arrayB: T[]): { onlyA: T[]; onlyB: T[]; both: T[] } => {
13
13
  const onlyA = unique(arrayA.filter((item) => !arrayB.includes(item)));
14
14
  const onlyB = unique(arrayB.filter((item) => !arrayA.includes(item)));
15
15
  const both = unique(arrayA.filter((item) => arrayB.includes(item)));
16
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
17
- return { onlyA, onlyB, both } as { onlyA: T; onlyB: T; both: T };
16
+ return { onlyA, onlyB, both };
18
17
  };
19
18
 
20
19
  export {
@@ -1,3 +1,5 @@
1
+ import must from "must"; // eslint-disable-line @typescript-eslint/no-shadow
2
+
1
3
  import type { CustomDeserializers } from "./deserialize";
2
4
 
3
5
  import { deserialize } from "./deserialize";
@@ -5,7 +7,6 @@ import { deserialize } from "./deserialize";
5
7
  class Person {
6
8
  public name: string;
7
9
 
8
- // eslint-disable-next-line @typescript-eslint/no-shadow
9
10
  public constructor(name: string) {
10
11
  this.name = name;
11
12
  }
@@ -69,6 +69,6 @@ const deserialize = <T>(serializedString: string, customDeserializers?: CustomDe
69
69
  return hasUndefined ? replaceDeep(parsed, UNDEFINED, undefined) : parsed;
70
70
  };
71
71
 
72
- export { deserialize };
72
+ export { deserialize, deserialize as unserialize };
73
73
 
74
74
  export type { CustomDeserializers };
@@ -10,11 +10,15 @@
10
10
  * @param {*} e - value to check
11
11
  * @returns Error - original error or new Error instance
12
12
  */
13
- const ensureError = (e: unknown) => {
13
+ const ensureError = (e: unknown): Error => {
14
14
  if (e instanceof Error) {
15
15
  return e;
16
16
  }
17
- return new Error("Expected error instance, got something else: " + String(e));
17
+
18
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
19
+ return new Error("Expected error instance, got something else: " + String(e), {
20
+ cause: e,
21
+ });
18
22
  };
19
23
 
20
24
  export {
@@ -6,7 +6,7 @@
6
6
  * @param {string} string - string to add prefix to
7
7
  * @param {string} prefix - prefix to add
8
8
  */
9
- const ensurePrefix = (string: string, prefix: string) => {
9
+ const ensurePrefix = (string: string, prefix: string): string => {
10
10
  if (string.startsWith(prefix)) {
11
11
  return string;
12
12
  }
@@ -6,7 +6,7 @@
6
6
  * @param {string} string - string to add suffix to
7
7
  * @param {string} suffix - suffix to add
8
8
  */
9
- const ensureSuffix = (string: string, suffix: string) => {
9
+ const ensureSuffix = (string: string, suffix: string): string => {
10
10
  if (string.endsWith(suffix)) {
11
11
  return string;
12
12
  }
@@ -9,7 +9,7 @@
9
9
  * regex.test(badName); // true
10
10
  * ```
11
11
  */
12
- const escapeRegExp = (string: string) => {
12
+ const escapeRegExp = (string: string): string => {
13
13
  return string.replace(/[/\-\\^$*+?.()|[\]{}]/gu, "\\$&");
14
14
  };
15
15
 
package/src/formatDate.ts CHANGED
@@ -8,10 +8,15 @@ import { ensureDate } from "./ensureDate.js";
8
8
  *
9
9
  * Important: this is work in progress. All locale-based values are not supported yet. Formats that heavily depend on
10
10
  * locale won't ever be supported.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * formatDate(Date.now(), "%Y-%m-%d %H:%M:%S"); // ie: "2024-06-26 14:23:45"
15
+ * ```
11
16
  */
12
17
  const formatDate = (date: Date | number, format: string, locale = "en-US"): string => { // eslint-disable-line max-lines-per-function
13
18
  const d = ensureDate(date);
14
- return format.replace(/%([%a-zA-Z])/gu, (_, c) => {
19
+ return format.replace(/%([%a-zA-Z])/gu, (_, c: string) => {
15
20
  switch (c) {
16
21
  case "%": return "%";
17
22
  // Day
@@ -64,7 +69,7 @@ const formatDate = (date: Date | number, format: string, locale = "en-US"): stri
64
69
  case "n": return "\n";
65
70
  case "t": return "\t";
66
71
  }
67
- return c as string;
72
+ return c;
68
73
  });
69
74
  };
70
75
 
package/src/get.spec.ts CHANGED
@@ -54,7 +54,6 @@ describe("get", () => {
54
54
 
55
55
  it("doesn't parse string as js code, behaves NOT like lodash", () => {
56
56
  // Lodash intention-guessing example, inconsistency detected
57
- // eslint-disable-next-line @typescript-eslint/no-shadow
58
57
  const name = get(testObject, "product[name]");
59
58
  (name === undefined).must.be.true();
60
59
 
@@ -29,7 +29,6 @@ const DEFAULT = {};
29
29
  * @returns {*} - found value or default value
30
30
  */
31
31
  const getMultiple = (source: Source, defaultValue: unknown, ...paths: (string | string[])[]): unknown => {
32
- // eslint-disable-next-line @typescript-eslint/no-shadow
33
32
  const length = paths.length;
34
33
  for (let i = 0; i < length; i++) {
35
34
  const properties = paths[i]!;
@@ -0,0 +1,80 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-shadow
2
+ import must from "must";
3
+
4
+ // @ts-ignore
5
+ import createSpy from "../test/createSpy";
6
+ import { ignore } from "./ignore";
7
+ import { wait } from "./wait";
8
+
9
+ const syncCrashingFunction = createSpy(() => {
10
+ throw new Error("Sync function crashed");
11
+ });
12
+
13
+ const promiseTypedSyncCrashingFunction = createSpy((): Promise<void> => {
14
+ throw new Error("Promise typed sync function crashed");
15
+ });
16
+
17
+ const asyncCrashingFunction = createSpy(async () => {
18
+ throw new Error("Async function crashed");
19
+ });
20
+
21
+ const asyncCrashingFunctionSlow = createSpy(async () => {
22
+ await wait(500);
23
+ throw new Error("Async function crashed");
24
+ });
25
+
26
+ const get5 = createSpy(() => 5);
27
+
28
+ describe("ignore", () => {
29
+ beforeEach(() => {
30
+ syncCrashingFunction.__spy.reset();
31
+ promiseTypedSyncCrashingFunction.__spy.reset();
32
+ asyncCrashingFunction.__spy.reset();
33
+ asyncCrashingFunctionSlow.__spy.reset();
34
+ get5.__spy.reset();
35
+ });
36
+
37
+ it("it should not crash on sync function crash", async () => {
38
+ ignore(syncCrashingFunction);
39
+ ignore(promiseTypedSyncCrashingFunction);
40
+ // ^ technically this is also a sync crash
41
+ });
42
+
43
+ it("it should not crash on async function crash", async () => {
44
+ ignore(asyncCrashingFunction);
45
+ });
46
+
47
+ it("it should not wait for async function", async () => {
48
+ const now = Date.now();
49
+ ignore(asyncCrashingFunctionSlow);
50
+ const after = Date.now();
51
+ if (after - now > 100) {
52
+ throw new Error("Took too long, it waited for the async function");
53
+ }
54
+ });
55
+
56
+ it("should not return a value", async () => {
57
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
58
+ const res = ignore(get5);
59
+ must(res).be.undefined();
60
+ });
61
+
62
+ it("actually calls the function", async () => {
63
+ must(syncCrashingFunction.__spy.calls.length).be.equal(0);
64
+ must(promiseTypedSyncCrashingFunction.__spy.calls.length).be.equal(0);
65
+ must(asyncCrashingFunction.__spy.calls.length).be.equal(0);
66
+ must(get5.__spy.calls.length).be.equal(0);
67
+
68
+ ignore(syncCrashingFunction);
69
+ must(syncCrashingFunction.__spy.calls.length).be.equal(1);
70
+
71
+ ignore(promiseTypedSyncCrashingFunction);
72
+ must(promiseTypedSyncCrashingFunction.__spy.calls.length).be.equal(1);
73
+
74
+ ignore(asyncCrashingFunction);
75
+ must(asyncCrashingFunction.__spy.calls.length).be.equal(1);
76
+
77
+ ignore(get5);
78
+ must(get5.__spy.calls.length).be.equal(1);
79
+ });
80
+ });
package/src/ignore.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * A function that executes a callback and ignores it completely, if it throws an error, returns any value, rejects
3
+ * a promise - it will be all ignored. It will attach a catch handler to any returned promise to avoid unhandled
4
+ * rejections.
5
+ *
6
+ * Use it whenever you want to call a function, but you are not interested in its result or failure.
7
+ *
8
+ * @example
9
+ * ```javascript
10
+ * import { trackPageVisit } from "analytics-service";
11
+ *
12
+ * function onButtonClick() {
13
+ * ignore(() => trackPageVisit("button-click"));
14
+ * // ^ prevent uncaught errors or unhandled promise rejections from trackPageVisit
15
+ * }
16
+ * Promise.resolve(5).then(ignore(trackPageVisit)).then((value) => {
17
+ * console.log(value); // 5, won't ever crash due to errors in trackPageVisit
18
+ * });
19
+ * ```
20
+ * @param callback
21
+ */
22
+ const ignore = (callback: () => unknown): undefined => {
23
+ try {
24
+ // eslint-disable-next-line callback-return
25
+ const p = callback();
26
+ if (p && typeof p === "object"
27
+ && "then" in p && typeof p.then === "function"
28
+ && "catch" in p && typeof p.catch === "function") {
29
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
30
+ p.catch(() => null);
31
+ }
32
+ }
33
+ catch {}
34
+ };
35
+
36
+ export {
37
+ ignore,
38
+ };
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  /* eslint-disable import/max-dependencies */
2
+ export * from "./serializeToBuffer/serializeToBuffer.js";
3
+ export * from "./serializeToBuffer/unserializeFromBuffer.js";
2
4
  export * from "./ensurePrefix.js";
3
5
  export * from "./ensureSuffix.js";
4
6
  export * from "./cap.js";
@@ -15,6 +17,7 @@ export * from "./escapeRegExp.js";
15
17
  export * from "./formatDate.js";
16
18
  export * from "./get.js";
17
19
  export * from "./getMultiple.js";
20
+ export * from "./ignore.js";
18
21
  export * from "./insertSeparator.js";
19
22
  export * from "./isEmpty.js";
20
23
  export * from "./isNumericString.js";
package/src/isEmpty.ts CHANGED
@@ -1,11 +1,3 @@
1
- interface ObjectWithLength {
2
- length: number;
3
- }
4
-
5
- interface ObjectWithSize {
6
- size: number;
7
- }
8
-
9
1
  /**
10
2
  * Returns true if passed argument seems to be empty.
11
3
  * Nil values are empty.
@@ -15,7 +7,7 @@ interface ObjectWithSize {
15
7
  * Arrays and array-like objects are considered empty when length value is 0.
16
8
  * Map, Set and -like objects are considered empty when size value is 0.
17
9
  *
18
- * @param {*} obj - source value
10
+ * @param obj - source value
19
11
  * @example isEmpty({}) // true
20
12
  * @example isEmpty(100) // throws
21
13
  * @example isEmpty([]) // true
@@ -23,9 +15,11 @@ interface ObjectWithSize {
23
15
  * @example isEmpty({ length: 5 }) // false
24
16
  * @example isEmpty({ length: 0 }) // true
25
17
  * @example isEmpty({ size: 0 }) // true
26
- * @returns {boolean} - is value considered empty
18
+ * @returns is value considered empty
19
+ *
20
+ * @deprecated This function is not needed in a modern, type-safe code and is encouraging bad practices in general.
27
21
  */
28
- const isEmpty = (obj: unknown) => {
22
+ const isEmpty = (obj: unknown): boolean => {
29
23
  if (typeof obj === "string") {
30
24
  return !obj.length;
31
25
  }
@@ -38,11 +32,11 @@ const isEmpty = (obj: unknown) => {
38
32
  if (Array.isArray(obj)) {
39
33
  return !Object.keys(obj).length;
40
34
  }
41
- if ("length" in obj) {
42
- return !(obj as ObjectWithLength).length;
35
+ if ("length" in obj && typeof obj.length === "number") {
36
+ return !(obj).length;
43
37
  }
44
- if ("size" in obj) {
45
- return !(obj as ObjectWithSize).size;
38
+ if ("size" in obj && typeof obj.size === "number") {
39
+ return !(obj).size;
46
40
  }
47
41
  return !Object.keys(obj).length;
48
42
  };
@@ -17,7 +17,7 @@ const NOT_FOUND = -1;
17
17
  * @param {boolean} [options.allowInfinity=false] - Allow Infinity and -Infinity (casing matters)
18
18
  * @param {boolean} [options.allowNaN=false] - Allow NaN (casing matters)
19
19
  */
20
- const isNumericString = (string: string, options: Options = {}) => { // eslint-disable-line max-statements, max-lines-per-function
20
+ const isNumericString = (string: string, options: Options = {}): boolean => { // eslint-disable-line max-statements, max-lines-per-function
21
21
  if (typeof string !== "string") {
22
22
  throw new TypeError("Expected a string");
23
23
  }
@@ -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
@@ -5,7 +5,7 @@ type MatchCallback<T> = (value: T) => boolean;
5
5
  * @param {Array} list - original array
6
6
  * @param {function} fn - function matching elements
7
7
  */
8
- const match = <T>(list: T[], fn: MatchCallback<T>) => {
8
+ const match = <T>(list: T[], fn: MatchCallback<T>): { matched: T[]; unmatched: T[] } => {
9
9
  const matched: T[] = [];
10
10
  const unmatched: T[] = [];
11
11
  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
  }