@wener/utils 1.0.0 → 1.1.1

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 (338) hide show
  1. package/README.md +5 -3
  2. package/jest.config.js +7 -5
  3. package/lib/cjs/arrays/MaybeArray.js +45 -33
  4. package/lib/cjs/arrays/index.js +17 -5
  5. package/lib/cjs/asyncs/AsyncInterval.js +32 -25
  6. package/lib/cjs/asyncs/LazyPromise.js +41 -24
  7. package/lib/cjs/asyncs/MaybePromise.js +15 -3
  8. package/lib/cjs/asyncs/generatorOfStream.js +33 -28
  9. package/lib/cjs/asyncs/index.js +23 -11
  10. package/lib/cjs/asyncs/isPromise.js +23 -6
  11. package/lib/cjs/asyncs/promiseOfCallback.js +34 -19
  12. package/lib/cjs/asyncs/sleep.js +23 -5
  13. package/lib/cjs/asyncs/timeout.js +42 -28
  14. package/lib/cjs/browsers/copy.js +71 -0
  15. package/lib/cjs/browsers/download.js +44 -33
  16. package/lib/cjs/browsers/getFileFromDataTransfer.js +48 -0
  17. package/lib/cjs/browsers/index.js +20 -8
  18. package/lib/cjs/browsers/loaders.js +48 -35
  19. package/lib/cjs/formats/formatBytes.js +36 -0
  20. package/lib/cjs/index.js +35 -13
  21. package/lib/cjs/io/index.js +17 -5
  22. package/lib/cjs/io/isBuffer.js +23 -10
  23. package/lib/cjs/isomorphics/getGlobalThis.js +32 -27
  24. package/lib/cjs/maths/index.js +17 -5
  25. package/lib/cjs/maths/random.js +34 -19
  26. package/lib/cjs/shim/urljoin.js +70 -0
  27. package/lib/cjs/shim/urljoin.test.js +4 -0
  28. package/lib/cjs/strings/camelCase.js +70 -68
  29. package/lib/cjs/strings/index.js +18 -7
  30. package/lib/cjs/strings/templates.js +26 -18
  31. package/lib/cjs/validations/asserts.js +25 -14
  32. package/lib/cjs/validations/index.js +20 -8
  33. package/lib/cjs/validations/isClass.js +23 -6
  34. package/lib/cjs/validations/isDefined.js +23 -6
  35. package/lib/cjs/validations/isEmptyObject.js +26 -9
  36. package/lib/esm/arrays/MaybeArray.js +29 -29
  37. package/lib/esm/arrays/index.js +1 -2
  38. package/lib/esm/asyncs/AsyncInterval.js +14 -21
  39. package/lib/esm/asyncs/LazyPromise.js +23 -21
  40. package/lib/esm/asyncs/MaybePromise.js +0 -1
  41. package/lib/esm/asyncs/generatorOfStream.js +14 -24
  42. package/lib/esm/asyncs/index.js +7 -8
  43. package/lib/esm/asyncs/isPromise.js +5 -3
  44. package/lib/esm/asyncs/promiseOfCallback.js +16 -16
  45. package/lib/esm/asyncs/sleep.js +4 -2
  46. package/lib/esm/asyncs/timeout.js +24 -25
  47. package/lib/{cjs/browsers/clipboard.d.ts → esm/browsers/copy.d.ts} +0 -0
  48. package/lib/esm/browsers/copy.js +52 -0
  49. package/lib/esm/browsers/download.js +25 -29
  50. package/lib/esm/browsers/getFileFromDataTransfer.d.ts +4 -0
  51. package/lib/esm/browsers/getFileFromDataTransfer.js +29 -0
  52. package/lib/esm/browsers/index.d.ts +2 -2
  53. package/lib/esm/browsers/index.js +4 -5
  54. package/lib/esm/browsers/loaders.js +31 -32
  55. package/lib/esm/formats/formatBytes.d.ts +11 -0
  56. package/lib/esm/formats/formatBytes.js +17 -0
  57. package/lib/esm/index.d.ts +3 -2
  58. package/lib/esm/index.js +15 -10
  59. package/lib/esm/io/index.js +1 -2
  60. package/lib/esm/io/isBuffer.js +5 -7
  61. package/lib/esm/isomorphics/getGlobalThis.d.ts +1 -1
  62. package/lib/esm/isomorphics/getGlobalThis.js +13 -24
  63. package/lib/esm/maths/index.js +1 -2
  64. package/lib/esm/maths/random.d.ts +2 -2
  65. package/lib/esm/maths/random.js +15 -15
  66. package/lib/{cjs/strings → esm/shim}/urljoin.d.ts +1 -0
  67. package/lib/esm/shim/urljoin.js +51 -0
  68. package/lib/{cjs/strings → esm/shim}/urljoin.test.d.ts +0 -0
  69. package/lib/esm/shim/urljoin.test.js +4 -0
  70. package/lib/esm/strings/camelCase.js +52 -64
  71. package/lib/esm/strings/index.d.ts +0 -1
  72. package/lib/esm/strings/index.js +2 -4
  73. package/lib/esm/strings/templates.d.ts +1 -1
  74. package/lib/esm/strings/templates.js +7 -14
  75. package/lib/esm/validations/asserts.js +8 -11
  76. package/lib/esm/validations/index.js +4 -5
  77. package/lib/esm/validations/isClass.js +5 -3
  78. package/lib/esm/validations/isDefined.js +5 -3
  79. package/lib/esm/validations/isEmptyObject.js +8 -6
  80. package/package.json +23 -32
  81. package/src/arrays/MaybeArray.ts +5 -2
  82. package/src/asyncs/timeout.ts +1 -1
  83. package/src/browsers/{clipboard.ts → copy.ts} +0 -0
  84. package/src/browsers/{transfers.ts → getFileFromDataTransfer.ts} +12 -7
  85. package/src/browsers/index.ts +2 -2
  86. package/src/browsers/loaders.ts +1 -1
  87. package/src/formats/formatBytes.ts +30 -0
  88. package/src/index.ts +4 -2
  89. package/src/isomorphics/getGlobalThis.ts +2 -4
  90. package/src/maths/random.ts +5 -5
  91. package/src/shim/urljoin.test.ts +5 -0
  92. package/src/{strings → shim}/urljoin.ts +18 -5
  93. package/src/strings/index.ts +0 -1
  94. package/src/strings/templates.ts +2 -4
  95. package/tsconfig.json +15 -4
  96. package/dist/wener-utils.cjs +0 -882
  97. package/dist/wener-utils.cjs.map +0 -1
  98. package/dist/wener-utils.esm.js +0 -849
  99. package/dist/wener-utils.esm.js.map +0 -1
  100. package/dist/wener-utils.system.js +0 -887
  101. package/dist/wener-utils.system.js.map +0 -1
  102. package/dist/wener-utils.umd.js +0 -886
  103. package/dist/wener-utils.umd.js.map +0 -1
  104. package/index.d.ts +0 -1
  105. package/index.js +0 -10
  106. package/lib/cjs/arrays/MaybeArray.d.ts +0 -5
  107. package/lib/cjs/arrays/MaybeArray.js.map +0 -1
  108. package/lib/cjs/arrays/index.d.ts +0 -1
  109. package/lib/cjs/arrays/index.js.map +0 -1
  110. package/lib/cjs/asyncs/AsyncInterval.d.ts +0 -3
  111. package/lib/cjs/asyncs/AsyncInterval.js.map +0 -1
  112. package/lib/cjs/asyncs/LazyPromise.d.ts +0 -5
  113. package/lib/cjs/asyncs/LazyPromise.js.map +0 -1
  114. package/lib/cjs/asyncs/MaybePromise.d.ts +0 -1
  115. package/lib/cjs/asyncs/MaybePromise.js.map +0 -1
  116. package/lib/cjs/asyncs/generatorOfStream.d.ts +0 -1
  117. package/lib/cjs/asyncs/generatorOfStream.js.map +0 -1
  118. package/lib/cjs/asyncs/index.d.ts +0 -7
  119. package/lib/cjs/asyncs/index.js.map +0 -1
  120. package/lib/cjs/asyncs/isPromise.d.ts +0 -1
  121. package/lib/cjs/asyncs/isPromise.js.map +0 -1
  122. package/lib/cjs/asyncs/promiseOfCallback.d.ts +0 -1
  123. package/lib/cjs/asyncs/promiseOfCallback.js.map +0 -1
  124. package/lib/cjs/asyncs/sleep.d.ts +0 -1
  125. package/lib/cjs/asyncs/sleep.js.map +0 -1
  126. package/lib/cjs/asyncs/timeout.d.ts +0 -4
  127. package/lib/cjs/asyncs/timeout.js.map +0 -1
  128. package/lib/cjs/browsers/clipboard.js +0 -56
  129. package/lib/cjs/browsers/clipboard.js.map +0 -1
  130. package/lib/cjs/browsers/download.d.ts +0 -4
  131. package/lib/cjs/browsers/download.js.map +0 -1
  132. package/lib/cjs/browsers/index.d.ts +0 -4
  133. package/lib/cjs/browsers/index.js.map +0 -1
  134. package/lib/cjs/browsers/loaders.d.ts +0 -6
  135. package/lib/cjs/browsers/loaders.js.map +0 -1
  136. package/lib/cjs/browsers/transfers.d.ts +0 -4
  137. package/lib/cjs/browsers/transfers.js +0 -38
  138. package/lib/cjs/browsers/transfers.js.map +0 -1
  139. package/lib/cjs/envs/index.d.ts +0 -1
  140. package/lib/cjs/envs/index.js +0 -5
  141. package/lib/cjs/envs/index.js.map +0 -1
  142. package/lib/cjs/envs/isDev.d.ts +0 -1
  143. package/lib/cjs/envs/isDev.js +0 -8
  144. package/lib/cjs/envs/isDev.js.map +0 -1
  145. package/lib/cjs/index.d.ts +0 -9
  146. package/lib/cjs/index.js.map +0 -1
  147. package/lib/cjs/io/index.d.ts +0 -1
  148. package/lib/cjs/io/index.js.map +0 -1
  149. package/lib/cjs/io/isBuffer.d.ts +0 -2
  150. package/lib/cjs/io/isBuffer.js.map +0 -1
  151. package/lib/cjs/isomorphics/getGlobalThis.d.ts +0 -9
  152. package/lib/cjs/isomorphics/getGlobalThis.js.map +0 -1
  153. package/lib/cjs/isomorphics/index.d.ts +0 -1
  154. package/lib/cjs/isomorphics/index.js +0 -5
  155. package/lib/cjs/isomorphics/index.js.map +0 -1
  156. package/lib/cjs/maths/index.d.ts +0 -1
  157. package/lib/cjs/maths/index.js.map +0 -1
  158. package/lib/cjs/maths/random.d.ts +0 -3
  159. package/lib/cjs/maths/random.js.map +0 -1
  160. package/lib/cjs/strings/camelCase.d.ts +0 -4
  161. package/lib/cjs/strings/camelCase.js.map +0 -1
  162. package/lib/cjs/strings/index.d.ts +0 -3
  163. package/lib/cjs/strings/index.js.map +0 -1
  164. package/lib/cjs/strings/templates.d.ts +0 -7
  165. package/lib/cjs/strings/templates.js.map +0 -1
  166. package/lib/cjs/strings/urljoin.js +0 -61
  167. package/lib/cjs/strings/urljoin.js.map +0 -1
  168. package/lib/cjs/strings/urljoin.test.js +0 -7
  169. package/lib/cjs/strings/urljoin.test.js.map +0 -1
  170. package/lib/cjs/validations/asserts.d.ts +0 -2
  171. package/lib/cjs/validations/asserts.js.map +0 -1
  172. package/lib/cjs/validations/index.d.ts +0 -4
  173. package/lib/cjs/validations/index.js.map +0 -1
  174. package/lib/cjs/validations/isClass.d.ts +0 -1
  175. package/lib/cjs/validations/isClass.js.map +0 -1
  176. package/lib/cjs/validations/isDefined.d.ts +0 -1
  177. package/lib/cjs/validations/isDefined.js.map +0 -1
  178. package/lib/cjs/validations/isEmptyObject.d.ts +0 -1
  179. package/lib/cjs/validations/isEmptyObject.js.map +0 -1
  180. package/lib/esm/arrays/MaybeArray.js.map +0 -1
  181. package/lib/esm/arrays/index.js.map +0 -1
  182. package/lib/esm/asyncs/AsyncInterval.js.map +0 -1
  183. package/lib/esm/asyncs/LazyPromise.js.map +0 -1
  184. package/lib/esm/asyncs/MaybePromise.js.map +0 -1
  185. package/lib/esm/asyncs/generatorOfStream.js.map +0 -1
  186. package/lib/esm/asyncs/index.js.map +0 -1
  187. package/lib/esm/asyncs/isPromise.js.map +0 -1
  188. package/lib/esm/asyncs/promiseOfCallback.js.map +0 -1
  189. package/lib/esm/asyncs/sleep.js.map +0 -1
  190. package/lib/esm/asyncs/timeout.js.map +0 -1
  191. package/lib/esm/browsers/clipboard.d.ts +0 -1
  192. package/lib/esm/browsers/clipboard.js +0 -52
  193. package/lib/esm/browsers/clipboard.js.map +0 -1
  194. package/lib/esm/browsers/download.js.map +0 -1
  195. package/lib/esm/browsers/index.js.map +0 -1
  196. package/lib/esm/browsers/loaders.js.map +0 -1
  197. package/lib/esm/browsers/transfers.d.ts +0 -4
  198. package/lib/esm/browsers/transfers.js +0 -34
  199. package/lib/esm/browsers/transfers.js.map +0 -1
  200. package/lib/esm/envs/index.d.ts +0 -1
  201. package/lib/esm/envs/index.js +0 -2
  202. package/lib/esm/envs/index.js.map +0 -1
  203. package/lib/esm/envs/isDev.d.ts +0 -1
  204. package/lib/esm/envs/isDev.js +0 -5
  205. package/lib/esm/envs/isDev.js.map +0 -1
  206. package/lib/esm/index.js.map +0 -1
  207. package/lib/esm/io/index.js.map +0 -1
  208. package/lib/esm/io/isBuffer.js.map +0 -1
  209. package/lib/esm/isomorphics/getGlobalThis.js.map +0 -1
  210. package/lib/esm/isomorphics/index.d.ts +0 -1
  211. package/lib/esm/isomorphics/index.js +0 -2
  212. package/lib/esm/isomorphics/index.js.map +0 -1
  213. package/lib/esm/maths/index.js.map +0 -1
  214. package/lib/esm/maths/random.js.map +0 -1
  215. package/lib/esm/strings/camelCase.js.map +0 -1
  216. package/lib/esm/strings/index.js.map +0 -1
  217. package/lib/esm/strings/templates.js.map +0 -1
  218. package/lib/esm/strings/urljoin.d.ts +0 -1
  219. package/lib/esm/strings/urljoin.js +0 -57
  220. package/lib/esm/strings/urljoin.js.map +0 -1
  221. package/lib/esm/strings/urljoin.test.d.ts +0 -1
  222. package/lib/esm/strings/urljoin.test.js +0 -5
  223. package/lib/esm/strings/urljoin.test.js.map +0 -1
  224. package/lib/esm/validations/asserts.js.map +0 -1
  225. package/lib/esm/validations/index.js.map +0 -1
  226. package/lib/esm/validations/isClass.js.map +0 -1
  227. package/lib/esm/validations/isDefined.js.map +0 -1
  228. package/lib/esm/validations/isEmptyObject.js.map +0 -1
  229. package/lib/esnext/arrays/MaybeArray.d.ts +0 -5
  230. package/lib/esnext/arrays/MaybeArray.js +0 -33
  231. package/lib/esnext/arrays/MaybeArray.js.map +0 -1
  232. package/lib/esnext/arrays/index.d.ts +0 -1
  233. package/lib/esnext/arrays/index.js +0 -2
  234. package/lib/esnext/arrays/index.js.map +0 -1
  235. package/lib/esnext/asyncs/AsyncInterval.d.ts +0 -3
  236. package/lib/esnext/asyncs/AsyncInterval.js +0 -23
  237. package/lib/esnext/asyncs/AsyncInterval.js.map +0 -1
  238. package/lib/esnext/asyncs/LazyPromise.d.ts +0 -5
  239. package/lib/esnext/asyncs/LazyPromise.js +0 -22
  240. package/lib/esnext/asyncs/LazyPromise.js.map +0 -1
  241. package/lib/esnext/asyncs/MaybePromise.d.ts +0 -1
  242. package/lib/esnext/asyncs/MaybePromise.js +0 -1
  243. package/lib/esnext/asyncs/MaybePromise.js.map +0 -1
  244. package/lib/esnext/asyncs/generatorOfStream.d.ts +0 -1
  245. package/lib/esnext/asyncs/generatorOfStream.js +0 -26
  246. package/lib/esnext/asyncs/generatorOfStream.js.map +0 -1
  247. package/lib/esnext/asyncs/index.d.ts +0 -7
  248. package/lib/esnext/asyncs/index.js +0 -8
  249. package/lib/esnext/asyncs/index.js.map +0 -1
  250. package/lib/esnext/asyncs/isPromise.d.ts +0 -1
  251. package/lib/esnext/asyncs/isPromise.js +0 -4
  252. package/lib/esnext/asyncs/isPromise.js.map +0 -1
  253. package/lib/esnext/asyncs/promiseOfCallback.d.ts +0 -1
  254. package/lib/esnext/asyncs/promiseOfCallback.js +0 -18
  255. package/lib/esnext/asyncs/promiseOfCallback.js.map +0 -1
  256. package/lib/esnext/asyncs/sleep.d.ts +0 -1
  257. package/lib/esnext/asyncs/sleep.js +0 -2
  258. package/lib/esnext/asyncs/sleep.js.map +0 -1
  259. package/lib/esnext/asyncs/timeout.d.ts +0 -4
  260. package/lib/esnext/asyncs/timeout.js +0 -26
  261. package/lib/esnext/asyncs/timeout.js.map +0 -1
  262. package/lib/esnext/browsers/clipboard.d.ts +0 -1
  263. package/lib/esnext/browsers/clipboard.js +0 -52
  264. package/lib/esnext/browsers/clipboard.js.map +0 -1
  265. package/lib/esnext/browsers/download.d.ts +0 -4
  266. package/lib/esnext/browsers/download.js +0 -32
  267. package/lib/esnext/browsers/download.js.map +0 -1
  268. package/lib/esnext/browsers/index.d.ts +0 -4
  269. package/lib/esnext/browsers/index.js +0 -5
  270. package/lib/esnext/browsers/index.js.map +0 -1
  271. package/lib/esnext/browsers/loaders.d.ts +0 -6
  272. package/lib/esnext/browsers/loaders.js +0 -36
  273. package/lib/esnext/browsers/loaders.js.map +0 -1
  274. package/lib/esnext/browsers/transfers.d.ts +0 -4
  275. package/lib/esnext/browsers/transfers.js +0 -34
  276. package/lib/esnext/browsers/transfers.js.map +0 -1
  277. package/lib/esnext/envs/index.d.ts +0 -1
  278. package/lib/esnext/envs/index.js +0 -2
  279. package/lib/esnext/envs/index.js.map +0 -1
  280. package/lib/esnext/envs/isDev.d.ts +0 -1
  281. package/lib/esnext/envs/isDev.js +0 -5
  282. package/lib/esnext/envs/isDev.js.map +0 -1
  283. package/lib/esnext/index.d.ts +0 -9
  284. package/lib/esnext/index.js +0 -10
  285. package/lib/esnext/index.js.map +0 -1
  286. package/lib/esnext/io/index.d.ts +0 -1
  287. package/lib/esnext/io/index.js +0 -2
  288. package/lib/esnext/io/index.js.map +0 -1
  289. package/lib/esnext/io/isBuffer.d.ts +0 -2
  290. package/lib/esnext/io/isBuffer.js +0 -8
  291. package/lib/esnext/io/isBuffer.js.map +0 -1
  292. package/lib/esnext/isomorphics/getGlobalThis.d.ts +0 -9
  293. package/lib/esnext/isomorphics/getGlobalThis.js +0 -25
  294. package/lib/esnext/isomorphics/getGlobalThis.js.map +0 -1
  295. package/lib/esnext/isomorphics/index.d.ts +0 -1
  296. package/lib/esnext/isomorphics/index.js +0 -2
  297. package/lib/esnext/isomorphics/index.js.map +0 -1
  298. package/lib/esnext/maths/index.d.ts +0 -1
  299. package/lib/esnext/maths/index.js +0 -2
  300. package/lib/esnext/maths/index.js.map +0 -1
  301. package/lib/esnext/maths/random.d.ts +0 -3
  302. package/lib/esnext/maths/random.js +0 -17
  303. package/lib/esnext/maths/random.js.map +0 -1
  304. package/lib/esnext/strings/camelCase.d.ts +0 -4
  305. package/lib/esnext/strings/camelCase.js +0 -69
  306. package/lib/esnext/strings/camelCase.js.map +0 -1
  307. package/lib/esnext/strings/index.d.ts +0 -3
  308. package/lib/esnext/strings/index.js +0 -4
  309. package/lib/esnext/strings/index.js.map +0 -1
  310. package/lib/esnext/strings/templates.d.ts +0 -7
  311. package/lib/esnext/strings/templates.js +0 -15
  312. package/lib/esnext/strings/templates.js.map +0 -1
  313. package/lib/esnext/strings/urljoin.d.ts +0 -1
  314. package/lib/esnext/strings/urljoin.js +0 -57
  315. package/lib/esnext/strings/urljoin.js.map +0 -1
  316. package/lib/esnext/strings/urljoin.test.d.ts +0 -1
  317. package/lib/esnext/strings/urljoin.test.js +0 -5
  318. package/lib/esnext/strings/urljoin.test.js.map +0 -1
  319. package/lib/esnext/validations/asserts.d.ts +0 -2
  320. package/lib/esnext/validations/asserts.js +0 -13
  321. package/lib/esnext/validations/asserts.js.map +0 -1
  322. package/lib/esnext/validations/index.d.ts +0 -4
  323. package/lib/esnext/validations/index.js +0 -5
  324. package/lib/esnext/validations/index.js.map +0 -1
  325. package/lib/esnext/validations/isClass.d.ts +0 -1
  326. package/lib/esnext/validations/isClass.js +0 -4
  327. package/lib/esnext/validations/isClass.js.map +0 -1
  328. package/lib/esnext/validations/isDefined.d.ts +0 -1
  329. package/lib/esnext/validations/isDefined.js +0 -4
  330. package/lib/esnext/validations/isDefined.js.map +0 -1
  331. package/lib/esnext/validations/isEmptyObject.d.ts +0 -1
  332. package/lib/esnext/validations/isEmptyObject.js +0 -7
  333. package/lib/esnext/validations/isEmptyObject.js.map +0 -1
  334. package/rollup.config.ts +0 -85
  335. package/src/envs/index.ts +0 -1
  336. package/src/envs/isDev.ts +0 -3
  337. package/src/isomorphics/index.ts +0 -1
  338. package/src/strings/urljoin.test.ts +0 -5
@@ -1,26 +1,16 @@
1
- import { __generator } from "tslib";
2
- export function generatorOfStream(stream) {
3
- var done;
4
- return __generator(this, function (_a) {
5
- switch (_a.label) {
6
- case 0:
7
- done = false;
8
- stream.on('end', function () {
9
- done = true;
10
- });
11
- _a.label = 1;
12
- case 1:
13
- if (!!done) return [3 /*break*/, 3];
14
- return [4 /*yield*/, new Promise(function (resolve, reject) {
15
- stream.once('data', resolve);
16
- stream.once('end', resolve);
17
- stream.once('error', reject);
18
- })];
19
- case 2:
20
- _a.sent();
21
- return [3 /*break*/, 1];
22
- case 3: return [2 /*return*/];
23
- }
1
+ function* generatorOfStream(stream) {
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);
24
11
  });
12
+ }
25
13
  }
26
- //# sourceMappingURL=generatorOfStream.js.map
14
+ export {
15
+ generatorOfStream
16
+ };
@@ -1,8 +1,7 @@
1
- export * from './LazyPromise';
2
- export * from './AsyncInterval';
3
- export * from './MaybePromise';
4
- export * from './sleep';
5
- export * from './timeout';
6
- export * from './isPromise';
7
- export * from './promiseOfCallback';
8
- //# sourceMappingURL=index.js.map
1
+ export * from "./LazyPromise";
2
+ export * from "./AsyncInterval";
3
+ export * from "./MaybePromise";
4
+ export * from "./sleep";
5
+ export * from "./timeout";
6
+ export * from "./isPromise";
7
+ export * from "./promiseOfCallback";
@@ -1,4 +1,6 @@
1
- export function isPromise(v) {
2
- return v && (v instanceof Promise || (v.then && v.catch));
1
+ function isPromise(v) {
2
+ return v && (v instanceof Promise || v.then && v.catch);
3
3
  }
4
- //# sourceMappingURL=isPromise.js.map
4
+ export {
5
+ isPromise
6
+ };
@@ -1,18 +1,18 @@
1
- export function promiseOfCallback(fun) {
2
- return new Promise(function (resolve, reject) {
3
- try {
4
- fun(function (e, v) {
5
- if (e) {
6
- reject(e);
7
- }
8
- else {
9
- resolve(v);
10
- }
11
- });
1
+ function promiseOfCallback(fun) {
2
+ return new Promise((resolve, reject) => {
3
+ try {
4
+ fun((e, v) => {
5
+ if (e) {
6
+ reject(e);
7
+ } else {
8
+ resolve(v);
12
9
  }
13
- catch (e) {
14
- reject(e);
15
- }
16
- });
10
+ });
11
+ } catch (e) {
12
+ reject(e);
13
+ }
14
+ });
17
15
  }
18
- //# sourceMappingURL=promiseOfCallback.js.map
16
+ export {
17
+ promiseOfCallback
18
+ };
@@ -1,2 +1,4 @@
1
- export var sleep = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); };
2
- //# sourceMappingURL=sleep.js.map
1
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2
+ export {
3
+ sleep
4
+ };
@@ -1,26 +1,25 @@
1
- import { __extends } from "tslib";
2
- export function timeout(v, ms) {
3
- var error = new TimeoutError();
4
- var timeout;
5
- return Promise.race([
6
- v,
7
- new Promise(function (resolve, reject) {
8
- timeout = setTimeout(function () { return reject(error); }, ms);
9
- }),
10
- ]).then(function (v) {
11
- clearTimeout(timeout);
12
- return v;
13
- }, function (e) {
14
- clearTimeout(timeout);
15
- throw e;
16
- });
1
+ function timeout(v, ms) {
2
+ const error = new TimeoutError();
3
+ let timeout2;
4
+ return Promise.race([
5
+ v,
6
+ new Promise((_, reject) => {
7
+ timeout2 = setTimeout(() => reject(error), ms);
8
+ })
9
+ ]).then((v2) => {
10
+ clearTimeout(timeout2);
11
+ return v2;
12
+ }, (e) => {
13
+ clearTimeout(timeout2);
14
+ throw e;
15
+ });
17
16
  }
18
- var TimeoutError = /** @class */ (function (_super) {
19
- __extends(TimeoutError, _super);
20
- function TimeoutError() {
21
- return _super.call(this, 'TimeoutError') || this;
22
- }
23
- return TimeoutError;
24
- }(Error));
25
- export { TimeoutError };
26
- //# sourceMappingURL=timeout.js.map
17
+ class TimeoutError extends Error {
18
+ constructor() {
19
+ super("TimeoutError");
20
+ }
21
+ }
22
+ export {
23
+ TimeoutError,
24
+ timeout
25
+ };
@@ -0,0 +1,52 @@
1
+ let _copy;
2
+ function initCopy() {
3
+ let textArea;
4
+ function isIOS() {
5
+ return navigator.userAgent.match(/ipad|iphone/i);
6
+ }
7
+ function createTextArea(text) {
8
+ textArea = document.createElement("textArea");
9
+ textArea.value = text;
10
+ document.body.appendChild(textArea);
11
+ }
12
+ function selectText() {
13
+ let range, selection;
14
+ if (isIOS()) {
15
+ range = document.createRange();
16
+ range.selectNodeContents(textArea);
17
+ selection = window.getSelection();
18
+ if (selection === null) {
19
+ console.error(`no selection`);
20
+ return;
21
+ }
22
+ selection.removeAllRanges();
23
+ selection.addRange(range);
24
+ textArea.setSelectionRange(0, 999999);
25
+ } else {
26
+ textArea.select();
27
+ }
28
+ }
29
+ function copyToClipboard() {
30
+ document.execCommand("copy");
31
+ document.body.removeChild(textArea);
32
+ }
33
+ _copy = (text) => {
34
+ createTextArea(text);
35
+ selectText();
36
+ copyToClipboard();
37
+ };
38
+ }
39
+ function copy(text) {
40
+ var _a, _b;
41
+ if ((_b = (_a = window.navigator) == null ? void 0 : _a.clipboard) == null ? void 0 : _b.writeText) {
42
+ window.navigator.clipboard.writeText(text);
43
+ return;
44
+ }
45
+ if (!_copy) {
46
+ initCopy();
47
+ }
48
+ _copy(text);
49
+ }
50
+ export {
51
+ copy
52
+ };
@@ -1,32 +1,28 @@
1
- export function download(filename, data, _a) {
2
- var _b = _a === void 0 ? {} : _a, _c = _b.type, type = _c === void 0 ? 'application/octet-stream' : _c, _d = _b.raw, raw = _d === void 0 ? false : _d;
3
- var a = document.createElement('a');
4
- var closer = function () { return null; };
5
- try {
6
- a.download = filename;
7
- // console.info(`downloading ${name}`, data);
8
- // url or data url
9
- if (typeof data === 'string' && /^(https?:|data:)/.test(data) && !raw) {
10
- a.href = data;
11
- }
12
- else if (typeof data === 'string') {
13
- data = new TextEncoder().encode(data);
14
- }
15
- if (data instanceof Uint8Array) {
16
- data = new Blob([data], { type: type });
17
- }
18
- if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
19
- a.href = URL.createObjectURL(data);
20
- closer = function () { return URL.revokeObjectURL(a.href); };
21
- }
22
- else {
23
- console.error("invalid download data", data);
24
- throw new Error("can not download " + Object.getPrototypeOf(data));
25
- }
26
- a.click();
1
+ function download(filename, data, { type = "application/octet-stream", raw = false } = {}) {
2
+ const a = document.createElement("a");
3
+ let closer = () => null;
4
+ try {
5
+ a.download = filename;
6
+ if (typeof data === "string" && /^(https?:|data:)/.test(data) && !raw) {
7
+ a.href = data;
8
+ } else if (typeof data === "string") {
9
+ data = new TextEncoder().encode(data);
27
10
  }
28
- finally {
29
- closer();
11
+ if (data instanceof Uint8Array) {
12
+ data = new Blob([data], { type });
30
13
  }
14
+ if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
15
+ a.href = URL.createObjectURL(data);
16
+ closer = () => URL.revokeObjectURL(a.href);
17
+ } else {
18
+ console.error(`invalid download data`, data);
19
+ throw new Error(`can not download ${Object.getPrototypeOf(data)}`);
20
+ }
21
+ a.click();
22
+ } finally {
23
+ closer();
24
+ }
31
25
  }
32
- //# sourceMappingURL=download.js.map
26
+ export {
27
+ download
28
+ };
@@ -0,0 +1,4 @@
1
+ export declare function getFileFromDataTransfer(dataTransfer?: DataTransfer | null): {
2
+ file?: File;
3
+ name?: string;
4
+ };
@@ -0,0 +1,29 @@
1
+ function getFileFromDataTransfer(dataTransfer) {
2
+ var _a;
3
+ if (!dataTransfer) {
4
+ return {};
5
+ }
6
+ const items = dataTransfer.items ?? [];
7
+ if (items.length >= 2 && items[0].kind === "string" && items[1].kind === "file") {
8
+ const text = dataTransfer.getData("text");
9
+ const file = items[1].getAsFile() ?? ((_a = dataTransfer.files) == null ? void 0 : _a.item(0));
10
+ if (!file) {
11
+ console.error(`no file ${text}`, items[1]);
12
+ return {};
13
+ }
14
+ return { file, name: text };
15
+ } else if (items[0].kind === "file") {
16
+ const file = items[0].getAsFile();
17
+ if (!file) {
18
+ console.error(`no file`, items[0]);
19
+ return {};
20
+ }
21
+ return { file, name: file.name };
22
+ } else {
23
+ console.debug(`file item not match`, Array.from(items).map((v) => ({ type: v.type, kind: v.kind })));
24
+ }
25
+ return {};
26
+ }
27
+ export {
28
+ getFileFromDataTransfer
29
+ };
@@ -1,4 +1,4 @@
1
- export * from './clipboard';
1
+ export * from './copy';
2
2
  export * from './download';
3
3
  export * from './loaders';
4
- export * from './transfers';
4
+ export * from './getFileFromDataTransfer';
@@ -1,5 +1,4 @@
1
- export * from './clipboard';
2
- export * from './download';
3
- export * from './loaders';
4
- export * from './transfers';
5
- //# sourceMappingURL=index.js.map
1
+ export * from "./copy";
2
+ export * from "./download";
3
+ export * from "./loaders";
4
+ export * from "./getFileFromDataTransfer";
@@ -1,36 +1,35 @@
1
1
  function load(el, resolve, reject, options) {
2
- el.onload = resolve;
3
- el.onerror = function (e) {
4
- el.remove();
5
- reject(e);
6
- };
7
- var _a = (options || {}).attributes, attributes = _a === void 0 ? {} : _a;
8
- Object.entries(attributes).forEach(function (_a) {
9
- var k = _a[0], v = _a[1];
10
- return el.setAttribute(k, v);
11
- });
12
- document.head.appendChild(el);
2
+ el.onload = resolve;
3
+ el.onerror = (e) => {
4
+ el.remove();
5
+ reject(e);
6
+ };
7
+ const { attributes = {} } = options || {};
8
+ Object.entries(attributes).forEach(([k, v]) => el.setAttribute(k, v));
9
+ document.head.appendChild(el);
13
10
  }
14
- export function loadScripts(src, options) {
15
- // todo quote ?
16
- if (document.querySelector("script[src=\"" + src + "\"]")) {
17
- return Promise.resolve();
18
- }
19
- return new Promise(function (resolve, reject) {
20
- var el = document.createElement('script');
21
- el.src = src;
22
- load(el, resolve, reject, options);
23
- });
11
+ function loadScripts(src, options) {
12
+ if (document.querySelector(`script[src="${src}"]`)) {
13
+ return Promise.resolve();
14
+ }
15
+ return new Promise((resolve, reject) => {
16
+ const el = document.createElement("script");
17
+ el.src = src;
18
+ load(el, resolve, reject, options);
19
+ });
24
20
  }
25
- export function loadStyles(href, options) {
26
- if (document.querySelector("link[href=\"" + href + "\"]")) {
27
- return Promise.resolve();
28
- }
29
- return new Promise(function (resolve, reject) {
30
- var el = document.createElement('link');
31
- el.rel = 'stylesheet';
32
- el.href = href;
33
- load(el, resolve, reject, options);
34
- });
21
+ function loadStyles(href, options) {
22
+ if (document.querySelector(`link[href="${href}"]`)) {
23
+ return Promise.resolve();
24
+ }
25
+ return new Promise((resolve, reject) => {
26
+ const el = document.createElement("link");
27
+ el.rel = "stylesheet";
28
+ el.href = href;
29
+ load(el, resolve, reject, options);
30
+ });
35
31
  }
36
- //# sourceMappingURL=loaders.js.map
32
+ export {
33
+ loadScripts,
34
+ loadStyles
35
+ };
@@ -0,0 +1,11 @@
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 declare function formatBytes(bytes: number, si?: boolean, dp?: number): string;
@@ -0,0 +1,17 @@
1
+ function formatBytes(bytes, si = false, dp = 1) {
2
+ const thresh = si ? 1e3 : 1024;
3
+ if (Math.abs(bytes) < thresh) {
4
+ return bytes + " B";
5
+ }
6
+ const units = si ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
7
+ let u = -1;
8
+ const r = 10 ** dp;
9
+ do {
10
+ bytes /= thresh;
11
+ ++u;
12
+ } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
13
+ return bytes.toFixed(dp) + " " + units[u];
14
+ }
15
+ export {
16
+ formatBytes
17
+ };
@@ -4,6 +4,7 @@ export * from './validations';
4
4
  export * from './strings';
5
5
  export * from './maths';
6
6
  export * from './io';
7
- export * from './envs';
8
7
  export * from './browsers';
9
- export * from './isomorphics';
8
+ export { getGlobalThis } from './isomorphics/getGlobalThis';
9
+ export { formatBytes } from './formats/formatBytes';
10
+ export { urljoin } from './shim/urljoin';
package/lib/esm/index.js CHANGED
@@ -1,10 +1,15 @@
1
- export * from './arrays/index';
2
- export * from './asyncs';
3
- export * from './validations';
4
- export * from './strings';
5
- export * from './maths';
6
- export * from './io';
7
- export * from './envs';
8
- export * from './browsers';
9
- export * from './isomorphics';
10
- //# sourceMappingURL=index.js.map
1
+ export * from "./arrays/index";
2
+ export * from "./asyncs";
3
+ export * from "./validations";
4
+ export * from "./strings";
5
+ export * from "./maths";
6
+ export * from "./io";
7
+ export * from "./browsers";
8
+ import { getGlobalThis } from "./isomorphics/getGlobalThis";
9
+ import { formatBytes } from "./formats/formatBytes";
10
+ import { urljoin } from "./shim/urljoin";
11
+ export {
12
+ formatBytes,
13
+ getGlobalThis,
14
+ urljoin
15
+ };
@@ -1,2 +1 @@
1
- export * from './isBuffer';
2
- //# sourceMappingURL=index.js.map
1
+ export * from "./isBuffer";
@@ -1,8 +1,6 @@
1
- // https://github.com/feross/is-buffer/blob/master/index.js
2
- export function isBuffer(obj) {
3
- return (obj != null &&
4
- obj.constructor != null &&
5
- typeof obj.constructor.isBuffer === 'function' &&
6
- obj.constructor.isBuffer(obj));
1
+ function isBuffer(obj) {
2
+ return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
7
3
  }
8
- //# sourceMappingURL=isBuffer.js.map
4
+ export {
5
+ isBuffer
6
+ };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * isomorphic globalThis
3
3
  *
4
- * globalThis supported by ff 65, chrome 71, node 12, babel
4
+ * globalThis supported by ff 65, Chrome 71, Node 12, babel
5
5
  *
6
6
  * @see https://caniuse.com/#search=globalThis
7
7
  * @see https://v8.dev/features/globalthis
@@ -1,25 +1,14 @@
1
- var _this = this;
2
- /**
3
- * isomorphic globalThis
4
- *
5
- * globalThis supported by ff 65, chrome 71, node 12, babel
6
- *
7
- * @see https://caniuse.com/#search=globalThis
8
- * @see https://v8.dev/features/globalthis
9
- */
10
- export var getGlobalThis = function () {
11
- if (typeof globalThis !== 'undefined')
12
- return globalThis;
13
- if (typeof self !== 'undefined')
14
- return self;
15
- if (typeof window !== 'undefined')
16
- return window;
17
- if (typeof global !== 'undefined')
18
- return global;
19
- // eslint-disable-next-line
20
- // @ts-ignore
21
- if (typeof _this !== 'undefined')
22
- return _this;
23
- throw new Error('Unable to locate global `this`');
1
+ const getGlobalThis = () => {
2
+ if (typeof globalThis !== "undefined")
3
+ return globalThis;
4
+ if (typeof self !== "undefined")
5
+ return self;
6
+ if (typeof window !== "undefined")
7
+ return window;
8
+ if (typeof global !== "undefined")
9
+ return global;
10
+ throw new Error("Unable to locate global `this`");
11
+ };
12
+ export {
13
+ getGlobalThis
24
14
  };
25
- //# sourceMappingURL=getGlobalThis.js.map
@@ -1,2 +1 @@
1
- export * from './random';
2
- //# sourceMappingURL=index.js.map
1
+ export * from "./random";
@@ -1,3 +1,3 @@
1
- export declare function createRandom({ seed }?: {
2
- seed?: number | undefined;
1
+ export declare function createRandom(o?: {
2
+ seed?: string | number;
3
3
  }): () => number;
@@ -1,17 +1,17 @@
1
- /// javascript pseudo random
2
- export function createRandom(_a) {
3
- var _b = (_a === void 0 ? {} : _a).seed, seed = _b === void 0 ? 0 : _b;
4
- if (typeof seed === 'string') {
5
- var s = seed;
6
- var sum = 0;
7
- for (var i = 0; i < s.length; i++) {
8
- sum += s.charCodeAt(i);
9
- }
10
- seed = sum;
1
+ function createRandom(o = {}) {
2
+ let seed = typeof o.seed === "string" ? 0 : o.seed ?? 0;
3
+ if (typeof o.seed === "string") {
4
+ let sum = 0;
5
+ for (let i = 0; i < o.seed.length; i++) {
6
+ sum += o.seed.charCodeAt(i);
11
7
  }
12
- return function () {
13
- var x = Math.sin(seed++) * 10000;
14
- return x - Math.floor(x);
15
- };
8
+ seed = sum;
9
+ }
10
+ return () => {
11
+ const x = Math.sin(seed++) * 1e4;
12
+ return x - Math.floor(x);
13
+ };
16
14
  }
17
- //# sourceMappingURL=random.js.map
15
+ export {
16
+ createRandom
17
+ };
@@ -1 +1,2 @@
1
1
  export declare function urljoin(...strArray: string[]): string;
2
+ export declare function urljoin(strArray: string[]): string;
@@ -0,0 +1,51 @@
1
+ function urljoin(...args) {
2
+ if (Array.isArray(args[0])) {
3
+ return normalize(args[0]);
4
+ } else {
5
+ return normalize(args);
6
+ }
7
+ }
8
+ function normalize(strArray) {
9
+ const resultArray = [];
10
+ if (strArray.length === 0) {
11
+ return "";
12
+ }
13
+ if (typeof strArray[0] !== "string") {
14
+ throw new TypeError("Url must be a string. Received " + strArray[0]);
15
+ }
16
+ if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
17
+ const first = strArray.shift();
18
+ strArray[0] = first + strArray[0];
19
+ }
20
+ if (strArray[0].match(/^file:\/\/\//)) {
21
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1:///");
22
+ } else {
23
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1://");
24
+ }
25
+ for (let i = 0; i < strArray.length; i++) {
26
+ let component = strArray[i];
27
+ if (typeof component !== "string") {
28
+ throw new TypeError("Url must be a string. Received " + component);
29
+ }
30
+ if (component === "") {
31
+ continue;
32
+ }
33
+ if (i > 0) {
34
+ component = component.replace(/^[\/]+/, "");
35
+ }
36
+ if (i < strArray.length - 1) {
37
+ component = component.replace(/[\/]+$/, "");
38
+ } else {
39
+ component = component.replace(/[\/]+$/, "/");
40
+ }
41
+ resultArray.push(component);
42
+ }
43
+ let str = resultArray.join("/");
44
+ str = str.replace(/\/(\?|&|#[^!])/g, "$1");
45
+ const parts = str.split("?");
46
+ str = parts.shift() + (parts.length > 0 ? "?" : "") + parts.join("&");
47
+ return str;
48
+ }
49
+ export {
50
+ urljoin
51
+ };
File without changes