@wener/utils 1.0.0-alpha.8 → 1.1.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 (360) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +28 -0
  3. package/dist/utils.cjs +497 -0
  4. package/dist/utils.cjs.map +7 -0
  5. package/dist/utils.js +445 -0
  6. package/dist/utils.js.map +7 -0
  7. package/dist/utils.mjs +475 -0
  8. package/dist/utils.mjs.map +7 -0
  9. package/jest.config.js +8 -6
  10. package/lib/{arrays → cjs/arrays}/MaybeArray.d.ts +1 -0
  11. package/lib/{arrays → cjs/arrays}/MaybeArray.js +8 -0
  12. package/lib/cjs/arrays/MaybeArray.js.map +1 -0
  13. package/lib/{arrays → cjs/arrays}/index.d.ts +0 -0
  14. package/lib/cjs/arrays/index.js +5 -0
  15. package/lib/cjs/arrays/index.js.map +1 -0
  16. package/lib/{asyncs → cjs/asyncs}/AsyncInterval.d.ts +0 -0
  17. package/lib/{asyncs → cjs/asyncs}/AsyncInterval.js +2 -1
  18. package/lib/cjs/asyncs/AsyncInterval.js.map +1 -0
  19. package/lib/{asyncs → cjs/asyncs}/LazyPromise.d.ts +0 -0
  20. package/lib/cjs/asyncs/LazyPromise.js +26 -0
  21. package/lib/cjs/asyncs/LazyPromise.js.map +1 -0
  22. package/lib/cjs/asyncs/MaybePromise.d.ts +1 -0
  23. package/lib/cjs/asyncs/MaybePromise.js +3 -0
  24. package/lib/cjs/asyncs/MaybePromise.js.map +1 -0
  25. package/lib/cjs/asyncs/generatorOfStream.d.ts +1 -0
  26. package/lib/cjs/asyncs/generatorOfStream.js +18 -0
  27. package/lib/cjs/asyncs/generatorOfStream.js.map +1 -0
  28. package/lib/cjs/asyncs/index.d.ts +7 -0
  29. package/lib/cjs/asyncs/index.js +11 -0
  30. package/lib/cjs/asyncs/index.js.map +1 -0
  31. package/lib/cjs/asyncs/isPromise.d.ts +1 -0
  32. package/lib/cjs/asyncs/isPromise.js +8 -0
  33. package/lib/cjs/asyncs/isPromise.js.map +1 -0
  34. package/lib/cjs/asyncs/promiseOfCallback.d.ts +1 -0
  35. package/lib/cjs/asyncs/promiseOfCallback.js +22 -0
  36. package/lib/cjs/asyncs/promiseOfCallback.js.map +1 -0
  37. package/lib/{asyncs → cjs/asyncs}/sleep.d.ts +0 -0
  38. package/lib/cjs/asyncs/sleep.js +6 -0
  39. package/lib/cjs/asyncs/sleep.js.map +1 -0
  40. package/lib/cjs/asyncs/timeout.d.ts +4 -0
  41. package/lib/cjs/asyncs/timeout.js +27 -0
  42. package/lib/cjs/asyncs/timeout.js.map +1 -0
  43. package/lib/{browsers/clipboard.d.ts → cjs/browsers/copy.d.ts} +0 -0
  44. package/lib/{browsers/clipboard.js → cjs/browsers/copy.js} +3 -3
  45. package/lib/cjs/browsers/copy.js.map +1 -0
  46. package/lib/{browsers → cjs/browsers}/download.d.ts +0 -0
  47. package/lib/{browsers → cjs/browsers}/download.js +1 -0
  48. package/lib/cjs/browsers/download.js.map +1 -0
  49. package/lib/cjs/browsers/getFileFromDataTransfer.d.ts +4 -0
  50. package/lib/{browsers/transfers.js → cjs/browsers/getFileFromDataTransfer.js} +15 -11
  51. package/lib/cjs/browsers/getFileFromDataTransfer.js.map +1 -0
  52. package/lib/cjs/browsers/index.d.ts +4 -0
  53. package/lib/cjs/browsers/index.js +8 -0
  54. package/lib/cjs/browsers/index.js.map +1 -0
  55. package/lib/{browsers → cjs/browsers}/loaders.d.ts +0 -0
  56. package/lib/{browsers → cjs/browsers}/loaders.js +2 -1
  57. package/lib/cjs/browsers/loaders.js.map +1 -0
  58. package/lib/cjs/formats/formatBytes.d.ts +11 -0
  59. package/lib/cjs/formats/formatBytes.js +31 -0
  60. package/lib/cjs/formats/formatBytes.js.map +1 -0
  61. package/lib/cjs/index.d.ts +9 -0
  62. package/lib/cjs/index.js +15 -0
  63. package/lib/cjs/index.js.map +1 -0
  64. package/lib/{io → cjs/io}/index.d.ts +0 -0
  65. package/lib/cjs/io/index.js +5 -0
  66. package/lib/{io → cjs/io}/index.js.map +1 -1
  67. package/lib/{io → cjs/io}/isBuffer.d.ts +0 -0
  68. package/lib/{io → cjs/io}/isBuffer.js +1 -0
  69. package/lib/cjs/io/isBuffer.js.map +1 -0
  70. package/lib/{isomorphics → cjs/isomorphics}/getGlobalThis.d.ts +1 -1
  71. package/lib/{isomorphics → cjs/isomorphics}/getGlobalThis.js +5 -6
  72. package/lib/cjs/isomorphics/getGlobalThis.js.map +1 -0
  73. package/lib/{isomorphics → cjs/isomorphics}/index.d.ts +0 -0
  74. package/lib/cjs/isomorphics/index.js +5 -0
  75. package/lib/cjs/isomorphics/index.js.map +1 -0
  76. package/lib/{maths → cjs/maths}/index.d.ts +0 -0
  77. package/lib/cjs/maths/index.js +5 -0
  78. package/lib/{arrays → cjs/maths}/index.js.map +1 -1
  79. package/lib/cjs/maths/random.d.ts +3 -0
  80. package/lib/{maths → cjs/maths}/random.js +6 -5
  81. package/lib/cjs/maths/random.js.map +1 -0
  82. package/lib/{strings → cjs/strings}/camelCase.d.ts +0 -0
  83. package/lib/{strings → cjs/strings}/camelCase.js +2 -1
  84. package/lib/cjs/strings/camelCase.js.map +1 -0
  85. package/lib/{strings → cjs/strings}/index.d.ts +1 -0
  86. package/lib/cjs/strings/index.js +7 -0
  87. package/lib/cjs/strings/index.js.map +1 -0
  88. package/lib/{strings → cjs/strings}/templates.d.ts +1 -1
  89. package/lib/{strings → cjs/strings}/templates.js +3 -3
  90. package/lib/cjs/strings/templates.js.map +1 -0
  91. package/lib/cjs/strings/urljoin.d.ts +2 -0
  92. package/lib/cjs/strings/urljoin.js +69 -0
  93. package/lib/cjs/strings/urljoin.js.map +1 -0
  94. package/lib/cjs/strings/urljoin.test.d.ts +1 -0
  95. package/lib/cjs/strings/urljoin.test.js +7 -0
  96. package/lib/cjs/strings/urljoin.test.js.map +1 -0
  97. package/lib/{validations → cjs/validations}/asserts.d.ts +0 -0
  98. package/lib/{validations → cjs/validations}/asserts.js +1 -0
  99. package/lib/cjs/validations/asserts.js.map +1 -0
  100. package/lib/cjs/validations/index.d.ts +4 -0
  101. package/lib/cjs/validations/index.js +8 -0
  102. package/lib/cjs/validations/index.js.map +1 -0
  103. package/lib/cjs/validations/isClass.d.ts +1 -0
  104. package/lib/cjs/validations/isClass.js +8 -0
  105. package/lib/cjs/validations/isClass.js.map +1 -0
  106. package/lib/cjs/validations/isDefined.d.ts +1 -0
  107. package/lib/cjs/validations/isDefined.js +8 -0
  108. package/lib/cjs/validations/isDefined.js.map +1 -0
  109. package/lib/cjs/validations/isEmptyObject.d.ts +1 -0
  110. package/lib/cjs/validations/isEmptyObject.js +11 -0
  111. package/lib/cjs/validations/isEmptyObject.js.map +1 -0
  112. package/lib/esm/arrays/MaybeArray.d.ts +5 -0
  113. package/lib/esm/arrays/MaybeArray.js +33 -0
  114. package/lib/esm/arrays/index.d.ts +1 -0
  115. package/lib/esm/arrays/index.js +1 -0
  116. package/lib/esm/asyncs/AsyncInterval.d.ts +3 -0
  117. package/lib/esm/asyncs/AsyncInterval.js +16 -0
  118. package/lib/esm/asyncs/LazyPromise.d.ts +5 -0
  119. package/lib/esm/asyncs/LazyPromise.js +24 -0
  120. package/lib/esm/asyncs/MaybePromise.d.ts +1 -0
  121. package/lib/esm/asyncs/MaybePromise.js +0 -0
  122. package/lib/esm/asyncs/generatorOfStream.d.ts +1 -0
  123. package/lib/esm/asyncs/generatorOfStream.js +16 -0
  124. package/lib/esm/asyncs/index.d.ts +7 -0
  125. package/lib/esm/asyncs/index.js +7 -0
  126. package/lib/esm/asyncs/isPromise.d.ts +1 -0
  127. package/lib/esm/asyncs/isPromise.js +6 -0
  128. package/lib/esm/asyncs/promiseOfCallback.d.ts +1 -0
  129. package/lib/esm/asyncs/promiseOfCallback.js +18 -0
  130. package/lib/esm/asyncs/sleep.d.ts +1 -0
  131. package/lib/esm/asyncs/sleep.js +4 -0
  132. package/lib/esm/asyncs/timeout.d.ts +4 -0
  133. package/lib/esm/asyncs/timeout.js +25 -0
  134. package/lib/esm/browsers/copy.d.ts +1 -0
  135. package/lib/esm/browsers/copy.js +52 -0
  136. package/lib/esm/browsers/download.d.ts +4 -0
  137. package/lib/esm/browsers/download.js +28 -0
  138. package/lib/esm/browsers/getFileFromDataTransfer.d.ts +4 -0
  139. package/lib/esm/browsers/getFileFromDataTransfer.js +29 -0
  140. package/lib/esm/browsers/index.d.ts +4 -0
  141. package/lib/esm/browsers/index.js +4 -0
  142. package/lib/esm/browsers/loaders.d.ts +6 -0
  143. package/lib/esm/browsers/loaders.js +35 -0
  144. package/lib/esm/formats/formatBytes.d.ts +11 -0
  145. package/lib/esm/formats/formatBytes.js +17 -0
  146. package/lib/esm/index.d.ts +9 -0
  147. package/lib/esm/index.js +12 -0
  148. package/lib/esm/io/index.d.ts +1 -0
  149. package/lib/esm/io/index.js +1 -0
  150. package/lib/esm/io/isBuffer.d.ts +2 -0
  151. package/lib/esm/io/isBuffer.js +6 -0
  152. package/lib/esm/isomorphics/getGlobalThis.d.ts +9 -0
  153. package/lib/esm/isomorphics/getGlobalThis.js +14 -0
  154. package/lib/esm/isomorphics/index.d.ts +1 -0
  155. package/lib/esm/isomorphics/index.js +1 -0
  156. package/lib/esm/maths/index.d.ts +1 -0
  157. package/lib/esm/maths/index.js +1 -0
  158. package/lib/esm/maths/random.d.ts +3 -0
  159. package/lib/esm/maths/random.js +17 -0
  160. package/lib/esm/strings/camelCase.d.ts +4 -0
  161. package/lib/esm/strings/camelCase.js +57 -0
  162. package/lib/esm/strings/index.d.ts +3 -0
  163. package/lib/esm/strings/index.js +3 -0
  164. package/lib/esm/strings/templates.d.ts +7 -0
  165. package/lib/esm/strings/templates.js +8 -0
  166. package/lib/esm/strings/urljoin.d.ts +2 -0
  167. package/lib/esm/strings/urljoin.js +53 -0
  168. package/lib/esm/strings/urljoin.test.d.ts +1 -0
  169. package/lib/esm/strings/urljoin.test.js +4 -0
  170. package/lib/esm/validations/asserts.d.ts +2 -0
  171. package/lib/esm/validations/asserts.js +10 -0
  172. package/lib/esm/validations/index.d.ts +4 -0
  173. package/lib/esm/validations/index.js +4 -0
  174. package/lib/esm/validations/isClass.d.ts +1 -0
  175. package/lib/esm/validations/isClass.js +6 -0
  176. package/lib/esm/validations/isDefined.d.ts +1 -0
  177. package/lib/esm/validations/isDefined.js +6 -0
  178. package/lib/esm/validations/isEmptyObject.d.ts +1 -0
  179. package/lib/esm/validations/isEmptyObject.js +9 -0
  180. package/lib/esnext/arrays/MaybeArray.d.ts +5 -0
  181. package/lib/esnext/arrays/MaybeArray.js +28 -0
  182. package/lib/esnext/arrays/MaybeArray.js.map +1 -0
  183. package/lib/esnext/arrays/index.d.ts +1 -0
  184. package/lib/esnext/arrays/index.js +2 -0
  185. package/lib/esnext/arrays/index.js.map +1 -0
  186. package/lib/esnext/asyncs/AsyncInterval.d.ts +3 -0
  187. package/lib/esnext/asyncs/AsyncInterval.js +13 -0
  188. package/lib/esnext/asyncs/AsyncInterval.js.map +1 -0
  189. package/lib/esnext/asyncs/LazyPromise.d.ts +5 -0
  190. package/lib/esnext/asyncs/LazyPromise.js +22 -0
  191. package/lib/esnext/asyncs/LazyPromise.js.map +1 -0
  192. package/lib/esnext/asyncs/MaybePromise.d.ts +1 -0
  193. package/lib/esnext/asyncs/MaybePromise.js +2 -0
  194. package/lib/esnext/asyncs/MaybePromise.js.map +1 -0
  195. package/lib/esnext/asyncs/generatorOfStream.d.ts +1 -0
  196. package/lib/esnext/asyncs/generatorOfStream.js +14 -0
  197. package/lib/esnext/asyncs/generatorOfStream.js.map +1 -0
  198. package/lib/esnext/asyncs/index.d.ts +7 -0
  199. package/lib/esnext/asyncs/index.js +8 -0
  200. package/lib/esnext/asyncs/index.js.map +1 -0
  201. package/lib/esnext/asyncs/isPromise.d.ts +1 -0
  202. package/lib/esnext/asyncs/isPromise.js +4 -0
  203. package/lib/esnext/asyncs/isPromise.js.map +1 -0
  204. package/lib/esnext/asyncs/promiseOfCallback.d.ts +1 -0
  205. package/lib/esnext/asyncs/promiseOfCallback.js +18 -0
  206. package/lib/esnext/asyncs/promiseOfCallback.js.map +1 -0
  207. package/lib/esnext/asyncs/sleep.d.ts +1 -0
  208. package/lib/esnext/asyncs/sleep.js +2 -0
  209. package/lib/esnext/asyncs/sleep.js.map +1 -0
  210. package/lib/esnext/asyncs/timeout.d.ts +4 -0
  211. package/lib/esnext/asyncs/timeout.js +22 -0
  212. package/lib/esnext/asyncs/timeout.js.map +1 -0
  213. package/lib/esnext/browsers/copy.d.ts +1 -0
  214. package/lib/esnext/browsers/copy.js +51 -0
  215. package/lib/esnext/browsers/copy.js.map +1 -0
  216. package/lib/esnext/browsers/download.d.ts +4 -0
  217. package/lib/esnext/browsers/download.js +31 -0
  218. package/lib/esnext/browsers/download.js.map +1 -0
  219. package/lib/esnext/browsers/getFileFromDataTransfer.d.ts +4 -0
  220. package/lib/esnext/browsers/getFileFromDataTransfer.js +37 -0
  221. package/lib/esnext/browsers/getFileFromDataTransfer.js.map +1 -0
  222. package/lib/esnext/browsers/index.d.ts +4 -0
  223. package/lib/esnext/browsers/index.js +5 -0
  224. package/lib/esnext/browsers/index.js.map +1 -0
  225. package/lib/esnext/browsers/loaders.d.ts +6 -0
  226. package/lib/esnext/browsers/loaders.js +33 -0
  227. package/lib/esnext/browsers/loaders.js.map +1 -0
  228. package/lib/esnext/formats/formatBytes.d.ts +11 -0
  229. package/lib/esnext/formats/formatBytes.js +27 -0
  230. package/lib/esnext/formats/formatBytes.js.map +1 -0
  231. package/lib/esnext/index.d.ts +9 -0
  232. package/lib/esnext/index.js +10 -0
  233. package/lib/esnext/index.js.map +1 -0
  234. package/lib/esnext/io/index.d.ts +1 -0
  235. package/lib/esnext/io/index.js +2 -0
  236. package/lib/esnext/io/index.js.map +1 -0
  237. package/lib/esnext/io/isBuffer.d.ts +2 -0
  238. package/lib/esnext/io/isBuffer.js +8 -0
  239. package/lib/esnext/io/isBuffer.js.map +1 -0
  240. package/lib/esnext/isomorphics/getGlobalThis.d.ts +9 -0
  241. package/lib/esnext/isomorphics/getGlobalThis.js +21 -0
  242. package/lib/esnext/isomorphics/getGlobalThis.js.map +1 -0
  243. package/lib/esnext/isomorphics/index.d.ts +1 -0
  244. package/lib/esnext/isomorphics/index.js +2 -0
  245. package/lib/esnext/isomorphics/index.js.map +1 -0
  246. package/lib/esnext/maths/index.d.ts +1 -0
  247. package/lib/esnext/maths/index.js +2 -0
  248. package/lib/esnext/maths/index.js.map +1 -0
  249. package/lib/esnext/maths/random.d.ts +3 -0
  250. package/lib/esnext/maths/random.js +16 -0
  251. package/lib/esnext/maths/random.js.map +1 -0
  252. package/lib/esnext/strings/camelCase.d.ts +4 -0
  253. package/lib/esnext/strings/camelCase.js +68 -0
  254. package/lib/esnext/strings/camelCase.js.map +1 -0
  255. package/lib/esnext/strings/index.d.ts +3 -0
  256. package/lib/esnext/strings/index.js +4 -0
  257. package/lib/esnext/strings/index.js.map +1 -0
  258. package/lib/esnext/strings/templates.d.ts +7 -0
  259. package/lib/esnext/strings/templates.js +14 -0
  260. package/lib/esnext/strings/templates.js.map +1 -0
  261. package/lib/esnext/strings/urljoin.d.ts +2 -0
  262. package/lib/esnext/strings/urljoin.js +65 -0
  263. package/lib/esnext/strings/urljoin.js.map +1 -0
  264. package/lib/esnext/strings/urljoin.test.d.ts +1 -0
  265. package/lib/esnext/strings/urljoin.test.js +5 -0
  266. package/lib/esnext/strings/urljoin.test.js.map +1 -0
  267. package/lib/esnext/validations/asserts.d.ts +2 -0
  268. package/lib/esnext/validations/asserts.js +13 -0
  269. package/lib/esnext/validations/asserts.js.map +1 -0
  270. package/lib/esnext/validations/index.d.ts +4 -0
  271. package/lib/esnext/validations/index.js +5 -0
  272. package/lib/esnext/validations/index.js.map +1 -0
  273. package/lib/esnext/validations/isClass.d.ts +1 -0
  274. package/lib/esnext/validations/isClass.js +4 -0
  275. package/lib/esnext/validations/isClass.js.map +1 -0
  276. package/lib/esnext/validations/isDefined.d.ts +1 -0
  277. package/lib/esnext/validations/isDefined.js +4 -0
  278. package/lib/esnext/validations/isDefined.js.map +1 -0
  279. package/lib/esnext/validations/isEmptyObject.d.ts +1 -0
  280. package/lib/esnext/validations/isEmptyObject.js +7 -0
  281. package/lib/esnext/validations/isEmptyObject.js.map +1 -0
  282. package/package.json +36 -32
  283. package/src/arrays/MaybeArray.ts +13 -0
  284. package/src/asyncs/LazyPromise.ts +16 -9
  285. package/src/asyncs/MaybePromise.ts +1 -0
  286. package/src/asyncs/generatorOfStream.ts +13 -0
  287. package/src/asyncs/index.ts +8 -3
  288. package/src/asyncs/isPromise.ts +3 -0
  289. package/src/asyncs/promiseOfCallback.ts +15 -0
  290. package/src/asyncs/timeout.ts +25 -0
  291. package/src/browsers/{clipboard.ts → copy.ts} +0 -0
  292. package/src/browsers/{transfers.ts → getFileFromDataTransfer.ts} +13 -8
  293. package/src/browsers/index.ts +4 -4
  294. package/src/browsers/loaders.ts +7 -2
  295. package/src/formats/formatBytes.ts +30 -0
  296. package/src/index.ts +5 -3
  297. package/src/isomorphics/getGlobalThis.ts +2 -4
  298. package/src/maths/random.ts +5 -5
  299. package/src/strings/camelCase.ts +2 -2
  300. package/src/strings/index.ts +1 -0
  301. package/src/strings/templates.ts +2 -4
  302. package/src/strings/urljoin.test.ts +5 -0
  303. package/src/strings/urljoin.ts +79 -0
  304. package/src/validations/index.ts +3 -0
  305. package/src/validations/isClass.ts +3 -0
  306. package/src/validations/isDefined.ts +3 -0
  307. package/src/validations/isEmptyObject.ts +6 -0
  308. package/tsconfig.json +26 -6
  309. package/dist/utils.es5.js +0 -1759
  310. package/dist/utils.es5.js.map +0 -1
  311. package/dist/utils.umd.js +0 -1769
  312. package/dist/utils.umd.js.map +0 -1
  313. package/lib/arrays/MaybeArray.js.map +0 -1
  314. package/lib/arrays/index.js +0 -7
  315. package/lib/asyncs/AsyncInterval.js.map +0 -1
  316. package/lib/asyncs/LazyPromise.js +0 -18
  317. package/lib/asyncs/LazyPromise.js.map +0 -1
  318. package/lib/asyncs/index.d.ts +0 -3
  319. package/lib/asyncs/index.js +0 -9
  320. package/lib/asyncs/index.js.map +0 -1
  321. package/lib/asyncs/sleep.js +0 -4
  322. package/lib/asyncs/sleep.js.map +0 -1
  323. package/lib/browsers/clipboard.js.map +0 -1
  324. package/lib/browsers/download.js.map +0 -1
  325. package/lib/browsers/index.d.ts +0 -4
  326. package/lib/browsers/index.js +0 -10
  327. package/lib/browsers/index.js.map +0 -1
  328. package/lib/browsers/loaders.js.map +0 -1
  329. package/lib/browsers/transfers.d.ts +0 -4
  330. package/lib/browsers/transfers.js.map +0 -1
  331. package/lib/envs/index.d.ts +0 -1
  332. package/lib/envs/index.js +0 -7
  333. package/lib/envs/index.js.map +0 -1
  334. package/lib/envs/isDev.d.ts +0 -1
  335. package/lib/envs/isDev.js +0 -4
  336. package/lib/envs/isDev.js.map +0 -1
  337. package/lib/index.d.ts +0 -8
  338. package/lib/index.js +0 -14
  339. package/lib/index.js.map +0 -1
  340. package/lib/io/index.js +0 -7
  341. package/lib/io/isBuffer.js.map +0 -1
  342. package/lib/isomorphics/getGlobalThis.js.map +0 -1
  343. package/lib/isomorphics/index.js +0 -7
  344. package/lib/isomorphics/index.js.map +0 -1
  345. package/lib/maths/index.js +0 -7
  346. package/lib/maths/index.js.map +0 -1
  347. package/lib/maths/random.d.ts +0 -3
  348. package/lib/maths/random.js.map +0 -1
  349. package/lib/strings/camelCase.js.map +0 -1
  350. package/lib/strings/index.js +0 -8
  351. package/lib/strings/index.js.map +0 -1
  352. package/lib/strings/templates.js.map +0 -1
  353. package/lib/validations/asserts.js.map +0 -1
  354. package/lib/validations/index.d.ts +0 -1
  355. package/lib/validations/index.js +0 -7
  356. package/lib/validations/index.js.map +0 -1
  357. package/rollup.config.ts +0 -34
  358. package/src/envs/index.ts +0 -1
  359. package/src/envs/isDev.ts +0 -1
  360. package/tsconfig.rollup.json +0 -9
@@ -0,0 +1 @@
1
+ export declare function isEmptyObject(o: any): boolean;
@@ -0,0 +1,7 @@
1
+ export function isEmptyObject(o) {
2
+ if (o === null || o === undefined) {
3
+ return true;
4
+ }
5
+ return o.constructor === Object && Object.keys(o).length === 0;
6
+ }
7
+ //# sourceMappingURL=isEmptyObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isEmptyObject.js","sourceRoot":"","sources":["../../../src/validations/isEmptyObject.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAC,CAAM;IAClC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,EAAE;QACjC,OAAO,IAAI,CAAC;KACb;IACD,OAAO,CAAC,CAAC,WAAW,KAAK,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AACjE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.0.0-alpha.8",
3
+ "version": "1.1.0",
4
4
  "description": "Utils for daily use",
5
5
  "keywords": [
6
6
  "utils",
@@ -9,17 +9,28 @@
9
9
  ],
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://github.com/wener/apis.git"
12
+ "url": "git+https://github.com/wener/wode.git"
13
13
  },
14
14
  "license": "MIT",
15
15
  "author": "wener",
16
- "main": "lib/index.js",
17
- "umd:main": "dist/utils.umd.js",
18
- "module": "dist/utils.es5.js",
19
- "source": "src/index.ts",
20
- "browser": "dist/utils.umd.js",
21
- "typings": "lib/index.d.ts",
16
+ "main": "lib/cjs/index.js",
17
+ "module": "lib/esm/index.js",
18
+ "types": "src/index.ts",
19
+ "esnext": "lib/esnext/index.js",
20
+ "umd:main": "dist/utils.js",
21
+ "unpkg": "dist/utils.js",
22
+ "jsdelivr": "dist/utils.js",
23
+ "jsnext:main": "dist/utils.esm.js",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./lib/esm/index.js",
27
+ "require": "./lib/cjs/index.js"
28
+ }
29
+ },
30
+ "homepage": "https://github.com/wenerme/wode#readme",
22
31
  "files": [
32
+ "index.js",
33
+ "index.d.ts",
23
34
  "lib",
24
35
  "dist",
25
36
  "src",
@@ -32,35 +43,28 @@
32
43
  "tsconfig.json"
33
44
  ],
34
45
  "scripts": {
35
- "prebuild": "rm -rf ./lib ./dist",
36
- "build": "tsc && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src",
37
- "doc": "typedoc --out docs --target es6 --theme minimal --mode file src",
38
- "prepare": "yarn build",
46
+ "build": "make build",
47
+ "clean": "make clean",
48
+ "dev": "make dev",
39
49
  "test": "jest"
40
50
  },
41
51
  "devDependencies": {
42
- "@rollup/plugin-commonjs": "^11.0.2",
43
- "@rollup/plugin-json": "^4.0.2",
44
- "@rollup/plugin-node-resolve": "^7.1.1",
45
- "@rollup/plugin-typescript": "^4.0.0",
46
- "@types/jest": "^25.1.4",
47
- "@types/lodash": "^4.14.149",
48
- "@types/node": "*",
49
- "isomorphic-unfetch": "^3.0.0",
50
- "jest": "^25.1.0",
51
- "lodash": "^4.17.15",
52
- "rollup": "^2.3.2",
53
- "ts-jest": "^25.2.1",
54
- "tslib": "^1.11.1",
55
- "typedoc": "^0.17.3",
56
- "typescript": "^3.8.3"
57
- },
58
- "optionalDependencies": {
59
- "isomorphic-unfetch": "^3.0.0",
60
- "lodash": "^4.17.15"
52
+ "@types/jest": "^27",
53
+ "@types/lodash": "^4",
54
+ "@types/node": "^16",
55
+ "dotenv": "^16",
56
+ "esbuild": "^0.14",
57
+ "jest": "^28",
58
+ "lodash": "^4",
59
+ "ts-jest": "^28",
60
+ "tslib": "^2",
61
+ "typescript": "^4"
61
62
  },
62
63
  "publishConfig": {
63
64
  "access": "public"
64
65
  },
65
- "gitHead": "af72bb31ee9b536c31fb9caeb8aa5349674cc136"
66
+ "engines": {
67
+ "node": "16",
68
+ "npm": "8"
69
+ }
66
70
  }
@@ -1,5 +1,18 @@
1
1
  export type MaybeArray<T> = T | T[];
2
2
 
3
+ export function objectOfMaybeArray<T = any>(
4
+ o: Record<string, MaybeArray<T>>,
5
+ keys: string[] | null = null,
6
+ picker = firstOfMaybeArray
7
+ ): Record<string, T> {
8
+ if (keys === null) {
9
+ return Object.fromEntries(
10
+ Object.entries(o).map(([k, v]) => [k, picker(v)])
11
+ );
12
+ }
13
+ return Object.fromEntries(keys.map((v) => [v, picker(v)])) as any;
14
+ }
15
+
3
16
  export function firstOfMaybeArray<T>(v: MaybeArray<T>): T {
4
17
  if (Array.isArray(v)) {
5
18
  return v[0];
@@ -4,19 +4,26 @@ export type LazyPromise<T> = Promise<T> & {
4
4
  };
5
5
 
6
6
  export function createLazyPromise<T = any>(): LazyPromise<T> {
7
- const promise: LazyPromise<T> = Object.assign(
7
+ const holder = {
8
+ resolve(_: any): void {
9
+ throw new Error('pending resolve');
10
+ },
11
+ reject(_: any): void {
12
+ throw new Error('pending reject');
13
+ },
14
+ };
15
+ return Object.assign(
8
16
  new Promise<T>((resolve, reject) => {
9
- promise.reject = reject;
10
- promise.resolve = resolve;
17
+ holder.reject = reject;
18
+ holder.resolve = resolve;
11
19
  }),
12
20
  {
13
- resolve() {
14
- throw new Error('pending resolve');
21
+ resolve(v: any) {
22
+ holder.resolve(v);
15
23
  },
16
- reject() {
17
- throw new Error('pending reject');
24
+ reject(v: any) {
25
+ holder.resolve(v);
18
26
  },
19
- }
27
+ },
20
28
  );
21
- return promise;
22
29
  }
@@ -0,0 +1 @@
1
+ export type MaybePromise<T> = Promise<T> | T;
@@ -0,0 +1,13 @@
1
+ export function* generatorOfStream<T = any>(stream: any): IterableIterator<Promise<T>> {
2
+ let done = false;
3
+ stream.on('end', () => {
4
+ done = true;
5
+ });
6
+ while (!done) {
7
+ yield new Promise((resolve, reject) => {
8
+ stream.once('data', resolve);
9
+ stream.once('end', resolve);
10
+ stream.once('error', reject);
11
+ });
12
+ }
13
+ }
@@ -1,3 +1,8 @@
1
- export * from './LazyPromise'
2
- export * from './AsyncInterval'
3
- export * from './sleep'
1
+ export * from './LazyPromise';
2
+ export * from './AsyncInterval';
3
+ export * from './MaybePromise';
4
+
5
+ export * from './sleep';
6
+ export * from './timeout';
7
+ export * from './isPromise';
8
+ export * from './promiseOfCallback';
@@ -0,0 +1,3 @@
1
+ export function isPromise<T>(v: any): v is Promise<T> {
2
+ return v && (v instanceof Promise || (v.then && v.catch));
3
+ }
@@ -0,0 +1,15 @@
1
+ export function promiseOfCallback<T>(fun: (cb: (err: any, val?: T) => void) => void) {
2
+ return new Promise<T>((resolve, reject) => {
3
+ try {
4
+ fun((e: any, v: any) => {
5
+ if (e) {
6
+ reject(e);
7
+ } else {
8
+ resolve(v);
9
+ }
10
+ });
11
+ } catch (e) {
12
+ reject(e);
13
+ }
14
+ });
15
+ }
@@ -0,0 +1,25 @@
1
+ export function timeout<T = any>(v: Promise<T>, ms: number): Promise<T> {
2
+ const error = new TimeoutError();
3
+ let timeout: any;
4
+ return Promise.race([
5
+ v,
6
+ new Promise((_, reject) => {
7
+ timeout = setTimeout(() => reject(error), ms);
8
+ }),
9
+ ]).then(
10
+ (v) => {
11
+ clearTimeout(timeout);
12
+ return v;
13
+ },
14
+ (e) => {
15
+ clearTimeout(timeout);
16
+ throw e;
17
+ },
18
+ ) as Promise<T>;
19
+ }
20
+
21
+ export class TimeoutError extends Error {
22
+ constructor() {
23
+ super('TimeoutError');
24
+ }
25
+ }
File without changes
@@ -1,12 +1,17 @@
1
- export function getFile(dataTransfer: DataTransfer): { file: File; filename: string } | null {
2
- const items: DataTransferItemList = dataTransfer?.items ?? ([] as any);
1
+ export function getFileFromDataTransfer(dataTransfer?: DataTransfer | null): { file?: File; name?: string } {
2
+ if (!dataTransfer) {
3
+ return {};
4
+ }
5
+
6
+ const items: DataTransferItemList = dataTransfer.items ?? [];
3
7
 
4
8
  if (items.length >= 2 && items[0].kind === 'string' && items[1].kind === 'file') {
9
+ // name, file
5
10
  const text = dataTransfer.getData('text');
6
11
  const file = items[1].getAsFile() ?? dataTransfer.files?.item(0);
7
12
  if (!file) {
8
13
  console.error(`no file ${text}`, items[1]);
9
- return null;
14
+ return {};
10
15
  }
11
16
 
12
17
  // let type = file.type;
@@ -18,19 +23,19 @@ export function getFile(dataTransfer: DataTransfer): { file: File; filename: str
18
23
  // file = new File([blob], text, {type});
19
24
  // }
20
25
 
21
- return { file, filename: text };
26
+ return { file, name: text };
22
27
  } else if (items[0].kind === 'file') {
23
28
  const file = items[0].getAsFile();
24
29
  if (!file) {
25
30
  console.error(`no file`, items[0]);
26
- return null;
31
+ return {};
27
32
  }
28
- return { file, filename: file.name };
33
+ return { file, name: file.name };
29
34
  } else {
30
35
  console.debug(
31
36
  `file item not match`,
32
- Array.from(items).map((v) => ({ type: v.type, kind: v.kind }))
37
+ Array.from(items).map((v) => ({ type: v.type, kind: v.kind })),
33
38
  );
34
39
  }
35
- return null;
40
+ return {};
36
41
  }
@@ -1,4 +1,4 @@
1
- export * from './clipboard'
2
- export * from './download'
3
- export * from './loaders'
4
- export * from './transfers'
1
+ export * from './copy';
2
+ export * from './download';
3
+ export * from './loaders';
4
+ export * from './getFileFromDataTransfer';
@@ -1,4 +1,9 @@
1
- function load(el: HTMLScriptElement | HTMLLinkElement, resolve: (v: any) => void, reject: Function, options: { attributes: Record<string, string> } | undefined) {
1
+ function load(
2
+ el: HTMLScriptElement | HTMLLinkElement,
3
+ resolve: (v: any) => void,
4
+ reject: (v: any) => void,
5
+ options: { attributes: Record<string, string> } | undefined,
6
+ ) {
2
7
  el.onload = resolve;
3
8
  el.onerror = (e) => {
4
9
  el.remove();
@@ -23,7 +28,7 @@ export function loadScripts(src: string, options?: { attributes: Record<string,
23
28
  }
24
29
 
25
30
  export function loadStyles(href: string, options?: { attributes: Record<string, string> }) {
26
- if (document.querySelector(`link[link="${href}"]`)) {
31
+ if (document.querySelector(`link[href="${href}"]`)) {
27
32
  return Promise.resolve();
28
33
  }
29
34
 
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Format bytes as human-readable text.
3
+ *
4
+ * @param bytes Number of bytes.
5
+ * @param si True to use metric (SI) units, aka powers of 1000. False to use
6
+ * binary (IEC), aka powers of 1024.
7
+ * @param dp Number of decimal places to display.
8
+ *
9
+ * @return Formatted string.
10
+ */
11
+ export function formatBytes(bytes: number, si = false, dp = 1) {
12
+ const thresh = si ? 1000 : 1024;
13
+
14
+ if (Math.abs(bytes) < thresh) {
15
+ return bytes + ' B';
16
+ }
17
+
18
+ const units = si
19
+ ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
20
+ : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
21
+ let u = -1;
22
+ const r = 10 ** dp;
23
+
24
+ do {
25
+ bytes /= thresh;
26
+ ++u;
27
+ } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
28
+
29
+ return bytes.toFixed(dp) + ' ' + units[u];
30
+ }
package/src/index.ts CHANGED
@@ -1,8 +1,10 @@
1
- export * from './arrays';
1
+ export * from './arrays/index';
2
2
  export * from './asyncs';
3
3
  export * from './validations';
4
4
  export * from './strings';
5
5
  export * from './maths';
6
6
  export * from './io';
7
- export * from './envs';
8
- export * as Browsers from './browsers';
7
+ export * from './browsers';
8
+ export * from './isomorphics';
9
+
10
+ export { formatBytes } from './formats/formatBytes';
@@ -3,7 +3,7 @@ declare const global: typeof globalThis;
3
3
  /**
4
4
  * isomorphic globalThis
5
5
  *
6
- * globalThis supported by ff 65, chrome 71, node 12, babel
6
+ * globalThis supported by ff 65, Chrome 71, Node 12, babel
7
7
  *
8
8
  * @see https://caniuse.com/#search=globalThis
9
9
  * @see https://v8.dev/features/globalthis
@@ -13,8 +13,6 @@ export const getGlobalThis = (): typeof globalThis => {
13
13
  if (typeof self !== 'undefined') return self;
14
14
  if (typeof window !== 'undefined') return window;
15
15
  if (typeof global !== 'undefined') return global as any;
16
- // eslint-disable-next-line
17
- // @ts-ignore
18
- if (typeof this !== 'undefined') return this;
16
+ // if (typeof this !== 'undefined') return this;
19
17
  throw new Error('Unable to locate global `this`');
20
18
  };
@@ -1,10 +1,10 @@
1
1
  /// javascript pseudo random
2
- export function createRandom({ seed = 0 } = {}) {
3
- if (typeof seed === 'string') {
4
- const s: string = seed;
2
+ export function createRandom(o: { seed?: string | number } = {}) {
3
+ let seed = typeof o.seed === 'string' ? 0 : o.seed ?? 0;
4
+ if (typeof o.seed === 'string') {
5
5
  let sum = 0;
6
- for (let i = 0; i < s.length; i++) {
7
- sum += s.charCodeAt(i);
6
+ for (let i = 0; i < o.seed.length; i++) {
7
+ sum += o.seed.charCodeAt(i);
8
8
  }
9
9
  seed = sum;
10
10
  }
@@ -41,8 +41,8 @@ export function pascalCase(input: string | string[]) {
41
41
  export function camelCase(
42
42
  input: string | string[],
43
43
  options: { pascalCase: boolean } = {
44
- pascalCase: false
45
- }
44
+ pascalCase: false,
45
+ },
46
46
  ) {
47
47
  if (!(typeof input === 'string' || Array.isArray(input))) {
48
48
  throw new TypeError('Expected the input to be `string | string[]`');
@@ -1,2 +1,3 @@
1
1
  export * from './camelCase';
2
2
  export * from './templates';
3
+ export * from './urljoin';
@@ -1,15 +1,13 @@
1
- import get from 'lodash/get';
2
-
3
1
  /**
4
2
  * 替换类似于 JS 的模板字符串
5
3
  *
6
4
  * @example
7
5
  * templateString('My name is ${name}',{name:'wener'})
8
6
  */
9
- export function templateString(template: string, variables: Record<string, any>) {
7
+ export function templateString(template: string, getter: (v: string) => any) {
10
8
  return template.replace(/\${(.*?)}/g, (_, g) => {
11
9
  // variables[g.trim()]
12
10
  // 支持路径 - 例如 a.b[0]
13
- return get(variables, g.trim());
11
+ return getter(g.trim());
14
12
  });
15
13
  }
@@ -0,0 +1,5 @@
1
+ import { urljoin } from './urljoin';
2
+
3
+ test('join ext', () => {
4
+ expect(urljoin('http://wener.me/sub/', '/a/', '/hello.js')).toBe('http://wener.me/sub/a/hello.js');
5
+ });
@@ -0,0 +1,79 @@
1
+ export function urljoin(...strArray: string[]);
2
+ export function urljoin(strArray: string[]);
3
+
4
+ /**
5
+ * @see {@link https://github.com/jfromaniello/url-join}
6
+ */
7
+ export function urljoin(...args) {
8
+ let input;
9
+
10
+ if (typeof args[0] === 'object') {
11
+ input = args[0];
12
+ } else {
13
+ input = args;
14
+ }
15
+
16
+ return normalize(input);
17
+ }
18
+
19
+ function normalize(strArray: string[]) {
20
+ const resultArray: string[] = [];
21
+ if (strArray.length === 0) {
22
+ return '';
23
+ }
24
+
25
+ if (typeof strArray[0] !== 'string') {
26
+ throw new TypeError('Url must be a string. Received ' + strArray[0]);
27
+ }
28
+
29
+ // If the first part is a plain protocol, we combine it with the next part.
30
+ if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
31
+ const first = strArray.shift();
32
+ strArray[0] = first + strArray[0];
33
+ }
34
+
35
+ // There must be two or three slashes in the file protocol, two slashes in anything else.
36
+ if (strArray[0].match(/^file:\/\/\//)) {
37
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1:///');
38
+ } else {
39
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1://');
40
+ }
41
+
42
+ for (let i = 0; i < strArray.length; i++) {
43
+ let component = strArray[i];
44
+
45
+ if (typeof component !== 'string') {
46
+ throw new TypeError('Url must be a string. Received ' + component);
47
+ }
48
+
49
+ if (component === '') {
50
+ continue;
51
+ }
52
+
53
+ if (i > 0) {
54
+ // Removing the starting slashes for each component but the first.
55
+ component = component.replace(/^[\/]+/, '');
56
+ }
57
+ if (i < strArray.length - 1) {
58
+ // Removing the ending slashes for each component but the last.
59
+ component = component.replace(/[\/]+$/, '');
60
+ } else {
61
+ // For the last component we will combine multiple slashes to a single one.
62
+ component = component.replace(/[\/]+$/, '/');
63
+ }
64
+
65
+ resultArray.push(component);
66
+ }
67
+
68
+ let str = resultArray.join('/');
69
+ // Each input component is now separated by a single slash except the possible first plain protocol part.
70
+
71
+ // remove trailing slash before parameters or hash
72
+ str = str.replace(/\/(\?|&|#[^!])/g, '$1');
73
+
74
+ // replace ? in parameters with &
75
+ const parts = str.split('?');
76
+ str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
77
+
78
+ return str;
79
+ }
@@ -1 +1,4 @@
1
1
  export * from './asserts';
2
+ export * from './isDefined';
3
+ export * from './isEmptyObject';
4
+ export * from './isClass';
@@ -0,0 +1,3 @@
1
+ export function isClass(func: any) {
2
+ return typeof func === 'function' && /^class\s/.test(Function.prototype.toString.call(func));
3
+ }
@@ -0,0 +1,3 @@
1
+ export function isDefined<T = any>(v: T): v is NonNullable<T> {
2
+ return v !== null && v !== undefined;
3
+ }
@@ -0,0 +1,6 @@
1
+ export function isEmptyObject(o: any) {
2
+ if (o === null || o === undefined) {
3
+ return true;
4
+ }
5
+ return o.constructor === Object && Object.keys(o).length === 0;
6
+ }
package/tsconfig.json CHANGED
@@ -1,18 +1,38 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "moduleResolution": "node",
4
- "target": "es2019",
5
- "module": "commonjs",
6
- "lib": ["esnext", "dom"],
4
+ "target": "esnext",
5
+ "module": "esnext",
6
+ "lib": [
7
+ "dom",
8
+ "dom.iterable",
9
+ "es5",
10
+ "es2015.collection",
11
+ "es2015.iterable",
12
+ "esnext"
13
+ ],
7
14
  "strict": true,
8
15
  "sourceMap": true,
9
16
  "skipLibCheck": true,
10
17
  "declaration": true,
18
+ "esModuleInterop": true,
19
+ "importHelpers": true,
11
20
  "allowSyntheticDefaultImports": true,
12
21
  "experimentalDecorators": true,
13
22
  "emitDecoratorMetadata": true,
14
- "outDir": "lib"
23
+ "noImplicitAny": false,
24
+ "noImplicitReturns": true,
25
+ "noUnusedLocals": true,
26
+ "noUnusedParameters": true,
27
+ "pretty": true,
28
+ "removeComments": false,
29
+ "stripInternal": true
15
30
  },
16
- "exclude": ["node_modules", "**/__tests__/*"],
17
- "include": ["src"]
31
+ "exclude": [
32
+ "node_modules",
33
+ "**/__tests__/*"
34
+ ],
35
+ "include": [
36
+ "src"
37
+ ]
18
38
  }