@mongez/reinforcements 1.2.5 → 2.0.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 (412) hide show
  1. package/README.md +1208 -0
  2. package/cjs/Collection/ImmutableCollection.d.ts +643 -0
  3. package/cjs/Collection/ImmutableCollection.js +1751 -0
  4. package/cjs/Random/random.d.ts +36 -0
  5. package/cjs/Random/random.js +87 -0
  6. package/cjs/__helpers/tslib/tslib.es6.js +102 -0
  7. package/cjs/array/average.d.ts +7 -0
  8. package/cjs/array/average.js +15 -0
  9. package/cjs/array/chunk.d.ts +5 -0
  10. package/cjs/array/chunk.js +15 -0
  11. package/cjs/array/count.d.ts +5 -0
  12. package/cjs/array/count.js +19 -0
  13. package/cjs/array/countBy.d.ts +5 -0
  14. package/cjs/array/countBy.js +23 -0
  15. package/cjs/array/even.d.ts +7 -0
  16. package/cjs/array/even.js +18 -0
  17. package/cjs/array/evenIndexes.d.ts +5 -0
  18. package/cjs/array/evenIndexes.js +13 -0
  19. package/cjs/array/groupBy.d.ts +8 -0
  20. package/cjs/array/groupBy.js +113 -0
  21. package/cjs/array/max.d.ts +7 -0
  22. package/cjs/array/max.js +23 -0
  23. package/cjs/array/median.d.ts +7 -0
  24. package/cjs/array/median.js +35 -0
  25. package/cjs/array/min.d.ts +7 -0
  26. package/cjs/array/min.js +23 -0
  27. package/cjs/array/odd.d.ts +7 -0
  28. package/cjs/array/odd.js +18 -0
  29. package/cjs/array/oddIndexes.d.ts +5 -0
  30. package/cjs/array/oddIndexes.js +13 -0
  31. package/cjs/array/pluck.d.ts +9 -0
  32. package/cjs/array/pluck.js +30 -0
  33. package/cjs/array/prependUnique.d.ts +6 -0
  34. package/cjs/array/prependUnique.js +20 -0
  35. package/cjs/array/pushUnique.d.ts +6 -0
  36. package/cjs/array/pushUnique.js +20 -0
  37. package/cjs/array/sum.d.ts +7 -0
  38. package/cjs/array/sum.js +31 -0
  39. package/cjs/array/unique.d.ts +5 -0
  40. package/cjs/array/unique.js +18 -0
  41. package/cjs/index.d.ts +51 -23
  42. package/cjs/index.js +110 -1
  43. package/cjs/mixed/areEqual/areEqual.d.ts +5 -0
  44. package/cjs/mixed/areEqual/areEqual.js +25 -0
  45. package/cjs/mixed/clone/clone.d.ts +5 -0
  46. package/cjs/mixed/clone/clone.js +19 -0
  47. package/cjs/mixed/shuffle/shuffle.d.ts +5 -0
  48. package/cjs/mixed/shuffle/shuffle.js +16 -0
  49. package/cjs/number/round.d.ts +5 -0
  50. package/cjs/number/round.js +14 -0
  51. package/cjs/object/except.d.ts +5 -0
  52. package/cjs/object/except.js +20 -0
  53. package/cjs/object/flatten.d.ts +5 -0
  54. package/cjs/object/flatten.js +55 -0
  55. package/cjs/object/get.d.ts +5 -0
  56. package/cjs/object/get.js +20 -0
  57. package/cjs/object/map.d.ts +5 -0
  58. package/cjs/object/map.js +12 -0
  59. package/cjs/object/merge.d.ts +2 -0
  60. package/cjs/object/merge.js +126 -0
  61. package/cjs/object/obj.d.ts +27 -0
  62. package/cjs/object/obj.js +30 -0
  63. package/cjs/object/only.d.ts +5 -0
  64. package/cjs/object/only.js +35 -0
  65. package/cjs/object/set.d.ts +6 -0
  66. package/cjs/object/set.js +30 -0
  67. package/cjs/object/sort.d.ts +5 -0
  68. package/cjs/object/sort.js +20 -0
  69. package/cjs/string/capitalize.d.ts +7 -0
  70. package/cjs/string/capitalize.js +19 -0
  71. package/cjs/string/extension.d.ts +5 -0
  72. package/cjs/string/extension.js +12 -0
  73. package/cjs/string/ltrim.d.ts +8 -0
  74. package/cjs/string/ltrim.js +20 -0
  75. package/cjs/string/readMoreChars.d.ts +6 -0
  76. package/cjs/string/readMoreChars.js +15 -0
  77. package/cjs/string/readMoreWords.d.ts +6 -0
  78. package/cjs/string/readMoreWords.js +18 -0
  79. package/cjs/string/removeFirst.d.ts +8 -0
  80. package/cjs/string/removeFirst.js +15 -0
  81. package/cjs/string/removeLast.d.ts +8 -0
  82. package/cjs/string/removeLast.js +15 -0
  83. package/cjs/string/repeatsOf.d.ts +8 -0
  84. package/cjs/string/repeatsOf.js +21 -0
  85. package/cjs/string/replaceAll.d.ts +9 -0
  86. package/cjs/string/replaceAll.js +16 -0
  87. package/cjs/string/replaceFirst.d.ts +9 -0
  88. package/cjs/string/replaceFirst.js +16 -0
  89. package/cjs/string/replaceLast.d.ts +9 -0
  90. package/cjs/string/replaceLast.js +22 -0
  91. package/cjs/string/rtrim.d.ts +8 -0
  92. package/cjs/string/rtrim.js +20 -0
  93. package/cjs/string/startsWithArabic.d.ts +3 -0
  94. package/cjs/string/startsWithArabic.js +19 -0
  95. package/cjs/string/toCamelCase.d.ts +2 -0
  96. package/cjs/string/toCamelCase.js +18 -0
  97. package/cjs/string/toInputName.d.ts +9 -0
  98. package/cjs/string/toInputName.js +47 -0
  99. package/cjs/string/toSnakeCase.d.ts +8 -0
  100. package/cjs/string/toSnakeCase.js +24 -0
  101. package/cjs/string/toStudlyCase.d.ts +10 -0
  102. package/cjs/string/toStudlyCase.js +26 -0
  103. package/cjs/string/trim.d.ts +8 -0
  104. package/cjs/string/trim.js +24 -0
  105. package/cjs/string/ucfirst.d.ts +7 -0
  106. package/cjs/string/ucfirst.js +12 -0
  107. package/cjs/types.d.ts +4 -0
  108. package/cjs/types.js +79 -0
  109. package/cjs/utils/debounce.d.ts +2 -0
  110. package/cjs/utils/debounce.js +20 -0
  111. package/cjs/utils/escapeRegex.d.ts +5 -0
  112. package/cjs/utils/escapeRegex.js +10 -0
  113. package/docs/VERSION-1.md +1074 -0
  114. package/docs/collection-todo.md +56 -0
  115. package/docs/collection.md +2586 -0
  116. package/docs/todo.md +3 -0
  117. package/esm/Collection/ImmutableCollection.d.ts +643 -0
  118. package/esm/Collection/ImmutableCollection.js +1672 -0
  119. package/esm/Random/random.d.ts +36 -0
  120. package/esm/Random/random.js +85 -0
  121. package/esm/__helpers/tslib/tslib.es6.js +95 -0
  122. package/esm/array/average.d.ts +7 -0
  123. package/esm/array/average.js +13 -0
  124. package/esm/array/chunk.d.ts +5 -0
  125. package/esm/array/chunk.js +13 -0
  126. package/esm/array/count.d.ts +5 -0
  127. package/esm/array/count.js +17 -0
  128. package/esm/array/countBy.d.ts +5 -0
  129. package/esm/array/countBy.js +21 -0
  130. package/esm/array/even.d.ts +7 -0
  131. package/esm/array/even.js +16 -0
  132. package/esm/array/evenIndexes.d.ts +5 -0
  133. package/esm/array/evenIndexes.js +11 -0
  134. package/esm/array/groupBy.d.ts +8 -0
  135. package/esm/array/groupBy.js +111 -0
  136. package/esm/array/max.d.ts +7 -0
  137. package/esm/array/max.js +21 -0
  138. package/esm/array/median.d.ts +7 -0
  139. package/esm/array/median.js +33 -0
  140. package/esm/array/min.d.ts +7 -0
  141. package/esm/array/min.js +21 -0
  142. package/esm/array/odd.d.ts +7 -0
  143. package/esm/array/odd.js +16 -0
  144. package/esm/array/oddIndexes.d.ts +5 -0
  145. package/esm/array/oddIndexes.js +11 -0
  146. package/esm/array/pluck.d.ts +9 -0
  147. package/esm/array/pluck.js +28 -0
  148. package/esm/array/prependUnique.d.ts +6 -0
  149. package/esm/array/prependUnique.js +18 -0
  150. package/esm/array/pushUnique.d.ts +6 -0
  151. package/esm/array/pushUnique.js +18 -0
  152. package/esm/array/sum.d.ts +7 -0
  153. package/esm/array/sum.js +29 -0
  154. package/esm/array/unique.d.ts +5 -0
  155. package/esm/array/unique.js +16 -0
  156. package/esm/index.d.ts +51 -23
  157. package/esm/index.js +57 -1
  158. package/esm/mixed/areEqual/areEqual.d.ts +5 -0
  159. package/esm/mixed/areEqual/areEqual.js +23 -0
  160. package/esm/mixed/clone/clone.d.ts +5 -0
  161. package/esm/mixed/clone/clone.js +17 -0
  162. package/esm/mixed/shuffle/shuffle.d.ts +5 -0
  163. package/esm/mixed/shuffle/shuffle.js +14 -0
  164. package/esm/number/round.d.ts +5 -0
  165. package/esm/number/round.js +12 -0
  166. package/esm/object/except.d.ts +5 -0
  167. package/esm/object/except.js +18 -0
  168. package/esm/object/flatten.d.ts +5 -0
  169. package/esm/object/flatten.js +53 -0
  170. package/esm/object/get.d.ts +5 -0
  171. package/esm/object/get.js +18 -0
  172. package/esm/object/map.d.ts +5 -0
  173. package/esm/object/map.js +10 -0
  174. package/esm/object/merge.d.ts +2 -0
  175. package/esm/object/merge.js +117 -0
  176. package/esm/object/obj.d.ts +27 -0
  177. package/esm/object/obj.js +28 -0
  178. package/esm/object/only.d.ts +5 -0
  179. package/esm/object/only.js +33 -0
  180. package/esm/object/set.d.ts +6 -0
  181. package/esm/object/set.js +28 -0
  182. package/esm/object/sort.d.ts +5 -0
  183. package/esm/object/sort.js +18 -0
  184. package/esm/string/capitalize.d.ts +7 -0
  185. package/esm/string/capitalize.js +17 -0
  186. package/esm/string/extension.d.ts +5 -0
  187. package/esm/string/extension.js +10 -0
  188. package/esm/string/ltrim.d.ts +8 -0
  189. package/esm/string/ltrim.js +18 -0
  190. package/esm/string/readMoreChars.d.ts +6 -0
  191. package/esm/string/readMoreChars.js +13 -0
  192. package/esm/string/readMoreWords.d.ts +6 -0
  193. package/esm/string/readMoreWords.js +16 -0
  194. package/esm/string/removeFirst.d.ts +8 -0
  195. package/esm/string/removeFirst.js +13 -0
  196. package/esm/string/removeLast.d.ts +8 -0
  197. package/esm/string/removeLast.js +13 -0
  198. package/esm/string/repeatsOf.d.ts +8 -0
  199. package/esm/string/repeatsOf.js +19 -0
  200. package/esm/string/replaceAll.d.ts +9 -0
  201. package/esm/string/replaceAll.js +14 -0
  202. package/esm/string/replaceFirst.d.ts +9 -0
  203. package/esm/string/replaceFirst.js +14 -0
  204. package/esm/string/replaceLast.d.ts +9 -0
  205. package/esm/string/replaceLast.js +20 -0
  206. package/esm/string/rtrim.d.ts +8 -0
  207. package/esm/string/rtrim.js +18 -0
  208. package/esm/string/startsWithArabic.d.ts +3 -0
  209. package/esm/string/startsWithArabic.js +14 -0
  210. package/esm/string/toCamelCase.d.ts +2 -0
  211. package/esm/string/toCamelCase.js +16 -0
  212. package/esm/string/toInputName.d.ts +9 -0
  213. package/esm/string/toInputName.js +44 -0
  214. package/esm/string/toSnakeCase.d.ts +8 -0
  215. package/esm/string/toSnakeCase.js +22 -0
  216. package/esm/string/toStudlyCase.d.ts +10 -0
  217. package/esm/string/toStudlyCase.js +24 -0
  218. package/esm/string/trim.d.ts +8 -0
  219. package/esm/string/trim.js +22 -0
  220. package/esm/string/ucfirst.d.ts +7 -0
  221. package/esm/string/ucfirst.js +10 -0
  222. package/esm/types.d.ts +4 -0
  223. package/esm/types.js +75 -0
  224. package/esm/utils/debounce.d.ts +2 -0
  225. package/esm/utils/debounce.js +18 -0
  226. package/esm/utils/escapeRegex.d.ts +5 -0
  227. package/esm/utils/escapeRegex.js +8 -0
  228. package/package.json +32 -6
  229. package/cjs/arr.d.ts +0 -67
  230. package/cjs/arr.d.ts.map +0 -1
  231. package/cjs/arr.js +0 -1
  232. package/cjs/contracts/arrayable.d.ts +0 -51
  233. package/cjs/contracts/arrayable.d.ts.map +0 -1
  234. package/cjs/contracts/iterable.d.ts +0 -4
  235. package/cjs/contracts/iterable.d.ts.map +0 -1
  236. package/cjs/index.d.ts.map +0 -1
  237. package/cjs/obj.d.ts +0 -9
  238. package/cjs/obj.d.ts.map +0 -1
  239. package/cjs/obj.js +0 -1
  240. package/cjs/utilities/escapeRegex.d.ts +0 -2
  241. package/cjs/utilities/escapeRegex.d.ts.map +0 -1
  242. package/cjs/utilities/escapeRegex.js +0 -1
  243. package/cjs/utilities/object/clone.d.ts +0 -2
  244. package/cjs/utilities/object/clone.d.ts.map +0 -1
  245. package/cjs/utilities/object/clone.js +0 -1
  246. package/cjs/utilities/object/get.d.ts +0 -2
  247. package/cjs/utilities/object/get.d.ts.map +0 -1
  248. package/cjs/utilities/object/get.js +0 -1
  249. package/cjs/utilities/object/merge.d.ts +0 -2
  250. package/cjs/utilities/object/merge.d.ts.map +0 -1
  251. package/cjs/utilities/object/merge.js +0 -1
  252. package/cjs/utilities/object/only.d.ts +0 -2
  253. package/cjs/utilities/object/only.d.ts.map +0 -1
  254. package/cjs/utilities/object/only.js +0 -1
  255. package/cjs/utilities/object/set.d.ts +0 -2
  256. package/cjs/utilities/object/set.d.ts.map +0 -1
  257. package/cjs/utilities/object/set.js +0 -1
  258. package/cjs/utilities/object/sort.d.ts +0 -2
  259. package/cjs/utilities/object/sort.d.ts.map +0 -1
  260. package/cjs/utilities/object/sort.js +0 -1
  261. package/cjs/utilities/random.d.ts +0 -6
  262. package/cjs/utilities/random.d.ts.map +0 -1
  263. package/cjs/utilities/random.js +0 -1
  264. package/cjs/utilities/str/capitalize.d.ts +0 -2
  265. package/cjs/utilities/str/capitalize.d.ts.map +0 -1
  266. package/cjs/utilities/str/capitalize.js +0 -1
  267. package/cjs/utilities/str/extension.d.ts +0 -2
  268. package/cjs/utilities/str/extension.d.ts.map +0 -1
  269. package/cjs/utilities/str/extension.js +0 -1
  270. package/cjs/utilities/str/ltrim.d.ts +0 -2
  271. package/cjs/utilities/str/ltrim.d.ts.map +0 -1
  272. package/cjs/utilities/str/ltrim.js +0 -1
  273. package/cjs/utilities/str/readMoreChars.d.ts +0 -2
  274. package/cjs/utilities/str/readMoreChars.d.ts.map +0 -1
  275. package/cjs/utilities/str/readMoreChars.js +0 -1
  276. package/cjs/utilities/str/readMoreWords.d.ts +0 -2
  277. package/cjs/utilities/str/readMoreWords.d.ts.map +0 -1
  278. package/cjs/utilities/str/readMoreWords.js +0 -1
  279. package/cjs/utilities/str/removeFirst.d.ts +0 -2
  280. package/cjs/utilities/str/removeFirst.d.ts.map +0 -1
  281. package/cjs/utilities/str/removeFirst.js +0 -1
  282. package/cjs/utilities/str/removeLast.d.ts +0 -2
  283. package/cjs/utilities/str/removeLast.d.ts.map +0 -1
  284. package/cjs/utilities/str/removeLast.js +0 -1
  285. package/cjs/utilities/str/repeatsOf.d.ts +0 -2
  286. package/cjs/utilities/str/repeatsOf.d.ts.map +0 -1
  287. package/cjs/utilities/str/repeatsOf.js +0 -1
  288. package/cjs/utilities/str/replaceAll.d.ts +0 -2
  289. package/cjs/utilities/str/replaceAll.d.ts.map +0 -1
  290. package/cjs/utilities/str/replaceAll.js +0 -1
  291. package/cjs/utilities/str/replaceFirst.d.ts +0 -2
  292. package/cjs/utilities/str/replaceFirst.d.ts.map +0 -1
  293. package/cjs/utilities/str/replaceFirst.js +0 -1
  294. package/cjs/utilities/str/replaceLast.d.ts +0 -2
  295. package/cjs/utilities/str/replaceLast.d.ts.map +0 -1
  296. package/cjs/utilities/str/replaceLast.js +0 -1
  297. package/cjs/utilities/str/rtrim.d.ts +0 -2
  298. package/cjs/utilities/str/rtrim.d.ts.map +0 -1
  299. package/cjs/utilities/str/rtrim.js +0 -1
  300. package/cjs/utilities/str/sprintf.d.ts +0 -3
  301. package/cjs/utilities/str/sprintf.d.ts.map +0 -1
  302. package/cjs/utilities/str/sprintf.js +0 -1
  303. package/cjs/utilities/str/toCamelCase.d.ts +0 -2
  304. package/cjs/utilities/str/toCamelCase.d.ts.map +0 -1
  305. package/cjs/utilities/str/toCamelCase.js +0 -1
  306. package/cjs/utilities/str/toInputName.d.ts +0 -2
  307. package/cjs/utilities/str/toInputName.d.ts.map +0 -1
  308. package/cjs/utilities/str/toInputName.js +0 -1
  309. package/cjs/utilities/str/toSnakeCase.d.ts +0 -2
  310. package/cjs/utilities/str/toSnakeCase.d.ts.map +0 -1
  311. package/cjs/utilities/str/toSnakeCase.js +0 -1
  312. package/cjs/utilities/str/toStudlyCase.d.ts +0 -2
  313. package/cjs/utilities/str/toStudlyCase.d.ts.map +0 -1
  314. package/cjs/utilities/str/toStudlyCase.js +0 -1
  315. package/cjs/utilities/str/trim.d.ts +0 -2
  316. package/cjs/utilities/str/trim.d.ts.map +0 -1
  317. package/cjs/utilities/str/trim.js +0 -1
  318. package/cjs/utilities/str/ucfirst.d.ts +0 -2
  319. package/cjs/utilities/str/ucfirst.d.ts.map +0 -1
  320. package/cjs/utilities/str/ucfirst.js +0 -1
  321. package/esm/arr.d.ts +0 -67
  322. package/esm/arr.d.ts.map +0 -1
  323. package/esm/arr.js +0 -1
  324. package/esm/contracts/arrayable.d.ts +0 -51
  325. package/esm/contracts/arrayable.d.ts.map +0 -1
  326. package/esm/contracts/iterable.d.ts +0 -4
  327. package/esm/contracts/iterable.d.ts.map +0 -1
  328. package/esm/index.d.ts.map +0 -1
  329. package/esm/obj.d.ts +0 -9
  330. package/esm/obj.d.ts.map +0 -1
  331. package/esm/obj.js +0 -1
  332. package/esm/utilities/escapeRegex.d.ts +0 -2
  333. package/esm/utilities/escapeRegex.d.ts.map +0 -1
  334. package/esm/utilities/escapeRegex.js +0 -1
  335. package/esm/utilities/object/clone.d.ts +0 -2
  336. package/esm/utilities/object/clone.d.ts.map +0 -1
  337. package/esm/utilities/object/clone.js +0 -1
  338. package/esm/utilities/object/get.d.ts +0 -2
  339. package/esm/utilities/object/get.d.ts.map +0 -1
  340. package/esm/utilities/object/get.js +0 -1
  341. package/esm/utilities/object/merge.d.ts +0 -2
  342. package/esm/utilities/object/merge.d.ts.map +0 -1
  343. package/esm/utilities/object/merge.js +0 -1
  344. package/esm/utilities/object/only.d.ts +0 -2
  345. package/esm/utilities/object/only.d.ts.map +0 -1
  346. package/esm/utilities/object/only.js +0 -1
  347. package/esm/utilities/object/set.d.ts +0 -2
  348. package/esm/utilities/object/set.d.ts.map +0 -1
  349. package/esm/utilities/object/set.js +0 -1
  350. package/esm/utilities/object/sort.d.ts +0 -2
  351. package/esm/utilities/object/sort.d.ts.map +0 -1
  352. package/esm/utilities/object/sort.js +0 -1
  353. package/esm/utilities/random.d.ts +0 -6
  354. package/esm/utilities/random.d.ts.map +0 -1
  355. package/esm/utilities/random.js +0 -1
  356. package/esm/utilities/str/capitalize.d.ts +0 -2
  357. package/esm/utilities/str/capitalize.d.ts.map +0 -1
  358. package/esm/utilities/str/capitalize.js +0 -1
  359. package/esm/utilities/str/extension.d.ts +0 -2
  360. package/esm/utilities/str/extension.d.ts.map +0 -1
  361. package/esm/utilities/str/extension.js +0 -1
  362. package/esm/utilities/str/ltrim.d.ts +0 -2
  363. package/esm/utilities/str/ltrim.d.ts.map +0 -1
  364. package/esm/utilities/str/ltrim.js +0 -1
  365. package/esm/utilities/str/readMoreChars.d.ts +0 -2
  366. package/esm/utilities/str/readMoreChars.d.ts.map +0 -1
  367. package/esm/utilities/str/readMoreChars.js +0 -1
  368. package/esm/utilities/str/readMoreWords.d.ts +0 -2
  369. package/esm/utilities/str/readMoreWords.d.ts.map +0 -1
  370. package/esm/utilities/str/readMoreWords.js +0 -1
  371. package/esm/utilities/str/removeFirst.d.ts +0 -2
  372. package/esm/utilities/str/removeFirst.d.ts.map +0 -1
  373. package/esm/utilities/str/removeFirst.js +0 -1
  374. package/esm/utilities/str/removeLast.d.ts +0 -2
  375. package/esm/utilities/str/removeLast.d.ts.map +0 -1
  376. package/esm/utilities/str/removeLast.js +0 -1
  377. package/esm/utilities/str/repeatsOf.d.ts +0 -2
  378. package/esm/utilities/str/repeatsOf.d.ts.map +0 -1
  379. package/esm/utilities/str/repeatsOf.js +0 -1
  380. package/esm/utilities/str/replaceAll.d.ts +0 -2
  381. package/esm/utilities/str/replaceAll.d.ts.map +0 -1
  382. package/esm/utilities/str/replaceAll.js +0 -1
  383. package/esm/utilities/str/replaceFirst.d.ts +0 -2
  384. package/esm/utilities/str/replaceFirst.d.ts.map +0 -1
  385. package/esm/utilities/str/replaceFirst.js +0 -1
  386. package/esm/utilities/str/replaceLast.d.ts +0 -2
  387. package/esm/utilities/str/replaceLast.d.ts.map +0 -1
  388. package/esm/utilities/str/replaceLast.js +0 -1
  389. package/esm/utilities/str/rtrim.d.ts +0 -2
  390. package/esm/utilities/str/rtrim.d.ts.map +0 -1
  391. package/esm/utilities/str/rtrim.js +0 -1
  392. package/esm/utilities/str/sprintf.d.ts +0 -3
  393. package/esm/utilities/str/sprintf.d.ts.map +0 -1
  394. package/esm/utilities/str/sprintf.js +0 -1
  395. package/esm/utilities/str/toCamelCase.d.ts +0 -2
  396. package/esm/utilities/str/toCamelCase.d.ts.map +0 -1
  397. package/esm/utilities/str/toCamelCase.js +0 -1
  398. package/esm/utilities/str/toInputName.d.ts +0 -2
  399. package/esm/utilities/str/toInputName.d.ts.map +0 -1
  400. package/esm/utilities/str/toInputName.js +0 -1
  401. package/esm/utilities/str/toSnakeCase.d.ts +0 -2
  402. package/esm/utilities/str/toSnakeCase.d.ts.map +0 -1
  403. package/esm/utilities/str/toSnakeCase.js +0 -1
  404. package/esm/utilities/str/toStudlyCase.d.ts +0 -2
  405. package/esm/utilities/str/toStudlyCase.d.ts.map +0 -1
  406. package/esm/utilities/str/toStudlyCase.js +0 -1
  407. package/esm/utilities/str/trim.d.ts +0 -2
  408. package/esm/utilities/str/trim.d.ts.map +0 -1
  409. package/esm/utilities/str/trim.js +0 -1
  410. package/esm/utilities/str/ucfirst.d.ts +0 -2
  411. package/esm/utilities/str/ucfirst.d.ts.map +0 -1
  412. package/esm/utilities/str/ucfirst.js +0 -1
package/README.md ADDED
@@ -0,0 +1,1208 @@
1
+ # Reinforcements
2
+
3
+ `Reinforcements` is a node js package written in `Typescript` to give a massive support for variant data like `Strings`, `Arrays`, `Objects` ... and so on.
4
+
5
+ For version 1 documentation, please visit [here](./docs/VERSION-1.md)
6
+
7
+ ## Installation
8
+
9
+ `yarn add @mongez/reinforcements`
10
+
11
+ or using `npm`
12
+
13
+ `npm i @mongez/reinforcements`
14
+
15
+ ## Usage
16
+
17
+ ## Collections
18
+
19
+ Reinforcements is shipped with a powerful collection class that can be used to manipulate arrays of objects, here are some example of usage.
20
+
21
+ ```ts
22
+ import { collect } from '@mongez/reinforcements';
23
+
24
+ const collection = collect([
25
+ { name: 'John', age: 20 },
26
+ { name: 'Jane', age: 25 },
27
+ { name: 'Jack', age: 30 },
28
+ ]);
29
+
30
+ // get the first item
31
+ const firstItem = collection.first();
32
+
33
+ // get the last item
34
+ const lastItem = collection.last();
35
+
36
+ // get the item at index 1
37
+ const itemAtIndex1 = collection.at(1);
38
+
39
+ // get users with age greater than 25
40
+ const users = collection.where('age', '>', 25);
41
+
42
+ // get users with age greater than 25 and less than 30
43
+ const users = collection.where('age', '>', 25).where('age', '<', 30);
44
+ ```
45
+
46
+ You can see the entire documentation in [Collection](./docs/Collection.md) Page.
47
+
48
+ ## Working with objects
49
+
50
+ Reinforcements is shipped with `Obj` object which provides good utilities for working with objects.
51
+
52
+ ```ts
53
+ import { Obj } from "@mongez/reinforcements";
54
+
55
+ let user = {
56
+ id: 1,
57
+ name: {
58
+ first: "Hasan",
59
+ last: "Zohdy",
60
+ },
61
+ address: {
62
+ country: "Egypt",
63
+ building: {
64
+ number: 12,
65
+ floor: {
66
+ number: 3,
67
+ },
68
+ },
69
+ },
70
+ };
71
+
72
+ Obj.get(user, "id"); // 1
73
+ Obj.get(user, "name"); // {first: 'Hasan', last: 'Zohdy'}
74
+ Obj.get(user, "name.first"); // Hasan
75
+ Obj.get(user, "address.country"); // Egypt
76
+ Obj.get(user, "address.building.number"); // 12
77
+ Obj.get(user, "address.building.floor.number"); // 3
78
+ ```
79
+
80
+ As we can see in the previous example, we can get values from objects using **dot.notation.syntax**.
81
+
82
+ If the key is missing in the object, we may return default value instead.
83
+
84
+ ```ts
85
+ Obj.get(user, "email", "no-email"); // no-email
86
+ ```
87
+
88
+ You can also import `get` function directly from the package.
89
+
90
+ ```ts
91
+ import { get } from "@mongez/reinforcements";
92
+
93
+ get(user, "id"); // 1
94
+ ```
95
+
96
+ ### Setting value in object
97
+
98
+ This works exactly but `Obj.set(object, key, value)` will set the value to the given object, which means it won't return **a new object** but the same object.
99
+
100
+ ```ts
101
+ import { Obj } from "@mongez/reinforcements";
102
+
103
+ let user = {
104
+ id: 1,
105
+ name: {
106
+ first: "Hasan",
107
+ last: "Zohdy",
108
+ },
109
+ address: {
110
+ country: "Egypt",
111
+ building: {
112
+ number: 12,
113
+ floor: {
114
+ number: 3,
115
+ },
116
+ },
117
+ },
118
+ };
119
+
120
+ Obj.set(user, "email", "hassanzohdy@gmail.com");
121
+ Obj.set(user, "address.building.floor.apartment", 36);
122
+ Obj.set(user, "job.title", "Software Engineer");
123
+ ```
124
+
125
+ In the previous example, we've three different cases, first case which would not be used with `Obj.set` which is setting one level key to the given object `user`, in this case we added `email` key.
126
+
127
+ In the second scenario, we added a new nested key in `address.building.floor` object, which is `apartment`, this would be a nice case to use `Obj.set`.
128
+
129
+ The last scenario, we don't have `job` key, the function will create `job` key then set `job.title` inside it.
130
+
131
+ The final user object will be:
132
+
133
+ ```json
134
+ {
135
+ "id": 1,
136
+ "email": "hassanzohdy@gmail.com",
137
+ "job": {
138
+ "title": "Software Engineer"
139
+ },
140
+ "name": {
141
+ "first": "Hasan",
142
+ "last": "Zohdy"
143
+ },
144
+ "address": {
145
+ "country": "Egypt",
146
+ "building": {
147
+ "number": 12,
148
+ "floor": {
149
+ "number": 3,
150
+ "apartment": 36
151
+ }
152
+ }
153
+ }
154
+ }
155
+ ```
156
+
157
+ You can also import `set` function directly from the package.
158
+
159
+ ```ts
160
+ import { set } from "@mongez/reinforcements";
161
+
162
+ set(user, "email", "hassanzohdy@gmail.com");
163
+ ```
164
+
165
+ ### Merging objects deeply
166
+
167
+ Another good feature from `Obj` object is to merge objects deeply.
168
+
169
+ You may use `Obj.merge` or import `merge` directly from the package.
170
+
171
+ ```ts
172
+ import { Obj } from "@mongez/reinforcements";
173
+
174
+ const user = {
175
+ id: 1,
176
+ name: "Hasan Zohdy",
177
+ };
178
+
179
+ const userJob = {
180
+ job: {
181
+ title: "Software Engineer",
182
+ level: "Senior",
183
+ },
184
+ };
185
+
186
+ const userWithJob = Obj.merge(user, userJob);
187
+ ```
188
+
189
+ Final output:
190
+
191
+ ```json
192
+ {
193
+ "id": 1,
194
+ "name": "Hasan Zohdy",
195
+ "job": {
196
+ "title": "Software Engineer",
197
+ "level": "Senior"
198
+ }
199
+ }
200
+ ```
201
+
202
+ But why not simply using the following syntax?
203
+
204
+ ```ts
205
+ const user = {
206
+ id: 1,
207
+ name: "Hasan Zohdy",
208
+ };
209
+
210
+ const userJob = {
211
+ job: {
212
+ title: "Software Engineer",
213
+ level: "Senior",
214
+ },
215
+ };
216
+
217
+ const userWithJob = { ...user, ...userJob };
218
+ // OR
219
+ const userWithJob = Object.assign({}, user, userJob);
220
+ ```
221
+
222
+ In the previous example, that would be the proper approach as the merging depth here is simple, but let's take another example.
223
+
224
+ ```ts
225
+ import { Obj } from "@mongez/reinforcements";
226
+
227
+ const user = {
228
+ id: 1,
229
+ name: "Hasan Zohdy",
230
+ job: {
231
+ title: "Software Engineer",
232
+ },
233
+ };
234
+
235
+ const userJob = {
236
+ job: {
237
+ level: "Senior",
238
+ },
239
+ };
240
+
241
+ const userWithJob = Obj.merge(user, userJob);
242
+ ```
243
+
244
+ The output will be:
245
+
246
+ ```json
247
+ {
248
+ "id": 1,
249
+ "name": "Hasan Zohdy",
250
+ "job": {
251
+ "title": "Software Engineer",
252
+ "level": "Senior"
253
+ }
254
+ }
255
+ ```
256
+
257
+ But when using spread syntax or `Object.assign` will give us a different value.
258
+
259
+ ```ts
260
+ const user = {
261
+ id: 1,
262
+ name: "Hasan Zohdy",
263
+ job: {
264
+ title: "Software Engineer",
265
+ },
266
+ };
267
+
268
+ const userJob = {
269
+ job: {
270
+ level: "Senior",
271
+ },
272
+ };
273
+
274
+ const userWithJob = { ...user, ...userJob };
275
+ // OR
276
+ const userWithJob = Object.assign({}, user, userJob);
277
+ ```
278
+
279
+ ```json
280
+ {
281
+ "id": 1,
282
+ "name": "Hasan Zohdy",
283
+ "job": {
284
+ "level": "Senior"
285
+ }
286
+ }
287
+ ```
288
+
289
+ You can also import `merge` function directly from the package.
290
+
291
+ ```ts
292
+ import { merge } from "@mongez/reinforcements";
293
+
294
+ const userWithJob = merge(user, userJob);
295
+ ```
296
+
297
+ ### Clone objects
298
+
299
+ You can also make a **deep copy** for the given object using `Obj.clone` or `clone`
300
+
301
+ ```ts
302
+ const user = {
303
+ id: 1,
304
+ name: {
305
+ first: "Hasan",
306
+ },
307
+ };
308
+
309
+ const normalClonedUser = { ...user };
310
+
311
+ normalClonedUser.name.first = "Ali";
312
+
313
+ // both will be the same as only the top level is deeply copied but nested objects are shallow copies
314
+ console.log(normalClonedUser.name.first); // Ali
315
+ console.log(user.name.first); // Ali
316
+ ```
317
+
318
+ Now using `Obj.clone`
319
+
320
+ ```ts
321
+ import { Obj } from "@mongez/reinforcements";
322
+
323
+ const user = {
324
+ id: 1,
325
+ name: {
326
+ first: "Hasan",
327
+ },
328
+ };
329
+
330
+ const normalClonedUser = Obj.clone(user);
331
+
332
+ cloned.name.first = "Ali";
333
+
334
+ console.log(cloned.name.first); // Ali
335
+ // Here the original object is kept untouched
336
+ console.log(user.name.first); // Hasan
337
+ ```
338
+
339
+ ### Getting certain values from object
340
+
341
+ To get a new object from the base object with only list of keys, use `Obj.only(object: object, keys: string[]): object`
342
+
343
+ ```ts
344
+ import { Obj } from "@mongez/reinforcements";
345
+
346
+ const user = {
347
+ id: 1,
348
+ name: "Hasan Zohdy",
349
+ email: "hassanzohdy@gmail.com",
350
+ job: {
351
+ title: "Software Engineer",
352
+ },
353
+ address: {
354
+ country: "Egypt",
355
+ building: {
356
+ number: 12,
357
+ floor: {
358
+ number: 3,
359
+ },
360
+ },
361
+ },
362
+ };
363
+
364
+ const simpleUserData = Obj.only(user, ["id", "name", "email"]); // {id: 1, name: 'Hasan Zohdy', email: 'hassanzohdy@gmail.com'}
365
+ ```
366
+
367
+ You can also import `only` function directly from the package.
368
+
369
+ ```ts
370
+ import { only } from "@mongez/reinforcements";
371
+
372
+ const simpleUserData = only(user, ["id", "name", "email"]);
373
+ ```
374
+
375
+ ### Getting all object except for certain keys
376
+
377
+ This is the reverse of `obj.only`, which returns the entire object except for the given keys.
378
+
379
+ ```ts
380
+ import { Obj } from "@mongez/reinforcements";
381
+
382
+ const user = {
383
+ id: 1,
384
+ name: "Hasan Zohdy",
385
+ email: "hassanzohdy@gmail.com",
386
+ job: {
387
+ title: "Software Engineer",
388
+ },
389
+ address: {
390
+ country: "Egypt",
391
+ building: {
392
+ number: 12,
393
+ floor: {
394
+ number: 3,
395
+ },
396
+ },
397
+ },
398
+ };
399
+
400
+ const simpleUserData = Obj.except(user, ["id", "address", "email"]); // { name: 'Hasan Zohdy', email: 'hassanzohdy@gmail.com', job: {title: 'Software Engineer'}}
401
+ ```
402
+
403
+ You can also import `except` function directly from the package.
404
+
405
+ ```ts
406
+ import { except } from "@mongez/reinforcements";
407
+
408
+ const simpleUserData = except(user, ["id", "address", "email"]);
409
+ ```
410
+
411
+ ### Flatten objects
412
+
413
+ We can flatten any big fat objects into one object, with only one dimension.
414
+
415
+ ```ts
416
+ import { Obj } from "@mongez/reinforcements";
417
+
418
+ const user = {
419
+ id: 1,
420
+ name: "Hasan Zohdy",
421
+ email: "hassanzohdy@gmail.com",
422
+ job: {
423
+ title: "Software Engineer",
424
+ },
425
+ address: {
426
+ country: "Egypt",
427
+ building: {
428
+ number: 12,
429
+ floor: {
430
+ number: 3,
431
+ },
432
+ },
433
+ },
434
+ };
435
+
436
+ console.log(Obj.flatten(user));
437
+ ```
438
+
439
+ Output:
440
+
441
+ ```json
442
+ {
443
+ "id": 1,
444
+ "name": "Hasan Zohdy",
445
+ "email": "hassanzohdy@gmail.com",
446
+ "job.title": "Software Engineer",
447
+ "address.country": "Egypt",
448
+ "address.building.number": 12,
449
+ "address.building.floor.number": 3
450
+ }
451
+ ```
452
+
453
+ You may set the separator by passing second argument to the function.
454
+
455
+ ```ts
456
+ import { Obj } from "@mongez/reinforcements";
457
+
458
+ const user = {
459
+ id: 1,
460
+ name: "Hasan Zohdy",
461
+ email: "hassanzohdy@gmail.com",
462
+ job: {
463
+ title: "Software Engineer",
464
+ },
465
+ address: {
466
+ country: "Egypt",
467
+ building: {
468
+ number: 12,
469
+ floor: {
470
+ number: 3,
471
+ },
472
+ },
473
+ },
474
+ };
475
+
476
+ console.log(Obj.flatten(user, "->"));
477
+ ```
478
+
479
+ Output:
480
+
481
+ ```json
482
+ {
483
+ "id": 1,
484
+ "name": "Hasan Zohdy",
485
+ "email": "hassanzohdy@gmail.com",
486
+ "job->title": "Software Engineer",
487
+ "address->country": "Egypt",
488
+ "address->building->number": 12,
489
+ "address->building->floor->number": 3
490
+ }
491
+ ```
492
+
493
+ You can also import `flatten` function directly from the package.
494
+
495
+ ```ts
496
+ import { flatten } from "@mongez/reinforcements";
497
+
498
+ console.log(flatten(user));
499
+ ```
500
+
501
+ ### Sort object by its keys
502
+
503
+ To sort objects based on their keys alphabets recursively use `Obj.sort(object: object, recursive: boolean = true): object` function.
504
+
505
+ ```ts
506
+ import { Obj } from "@mongez/reinforcements";
507
+
508
+ const user = {
509
+ id: 1,
510
+ name: "Hasan Zohdy",
511
+ email: "hassanzohdy@gmail.com",
512
+ job: {
513
+ title: "Software Engineer",
514
+ },
515
+ address: {
516
+ country: "Egypt",
517
+ building: {
518
+ number: 12,
519
+ floor: {
520
+ number: 3,
521
+ },
522
+ },
523
+ },
524
+ };
525
+
526
+ console.log(Obj.sort(user));
527
+ ```
528
+
529
+ Output:
530
+
531
+ ```json
532
+ {
533
+ "address": {
534
+ "building": {
535
+ "floor": {
536
+ "number": 3
537
+ },
538
+ "number": 12
539
+ },
540
+ "country": "Egypt"
541
+ },
542
+ "email": "hassanzohdy@gmail.com",
543
+ "id": 1,
544
+ "job": {
545
+ "title": "Software Engineer"
546
+ },
547
+ "name": "Hasan Zohdy"
548
+ }
549
+ ```
550
+
551
+ To sort the object only the first level, pass the second argument as false.
552
+
553
+ ```ts
554
+ import { Obj } from "@mongez/reinforcements";
555
+
556
+ const user = {
557
+ id: 1,
558
+ name: "Hasan Zohdy",
559
+ email: "hassanzohdy@gmail.com",
560
+ job: {
561
+ title: "Software Engineer",
562
+ },
563
+ address: {
564
+ country: "Egypt",
565
+ building: {
566
+ number: 12,
567
+ floor: {
568
+ number: 3,
569
+ },
570
+ },
571
+ },
572
+ };
573
+
574
+ console.log(Obj.sort(user, false));
575
+ ```
576
+
577
+ Output:
578
+
579
+ ```json
580
+ {
581
+ "address": {
582
+ "country": "Egypt",
583
+ "building": {
584
+ "number": 12,
585
+ "floor": {
586
+ "number": 3
587
+ }
588
+ }
589
+ },
590
+ "email": "hassanzohdy@gmail.com",
591
+ "id": 1,
592
+ "job": {
593
+ "title": "Software Engineer"
594
+ },
595
+ "name": "Hasan Zohdy"
596
+ }
597
+ ```
598
+
599
+ You can also import `sort` function directly from the package.
600
+
601
+ ```ts
602
+ import { sort } from "@mongez/reinforcements";
603
+
604
+ console.log(sort(user));
605
+ ```
606
+
607
+ ## Equal Values
608
+
609
+ Using `areEqual` function will check if the given two values equal to each other, it will validate against any type such as objects, arrays, strings, numbers, booleans, null, undefined, symbols.
610
+
611
+ ```ts
612
+ import { areEqual } from "@mongez/reinforcements";
613
+
614
+ console.log(areEqual(1, 1)); // true
615
+
616
+ console.log(areEqual("1", 1)); // false
617
+
618
+ console.log(areEqual("1", "1")); // true
619
+
620
+ console.log(areEqual(true, true)); // true
621
+
622
+ console.log(areEqual(true, false)); // false
623
+
624
+ console.log(areEqual(null, null)); // true
625
+
626
+ console.log(areEqual(undefined, undefined)); // true
627
+
628
+ console.log(areEqual(Symbol("1"), Symbol("1"))); // false
629
+
630
+ console.log(areEqual(Symbol("1"), Symbol("2"))); // false
631
+
632
+ console.log(areEqual([1, 2, 3], [1, 2, 3])); // true
633
+
634
+ console.log(areEqual([1, 2, 3], [1, 2, 3, 4])); // false
635
+
636
+ console.log(areEqual({ id: 1 }, { id: 1 })); // true
637
+
638
+ console.log(areEqual({ id: 1 }, { id: 2 })); // false
639
+ ```
640
+
641
+ ## Generating Random Values
642
+
643
+ Another good feature is `Random` object, which allows us to generate variant random values of different types.
644
+
645
+ ### Generate random string
646
+
647
+ To generate a random string use `Random.string(length: number = 32): string` method.
648
+
649
+ ```ts
650
+ import { Random } from "@mongez/reinforcements";
651
+
652
+ Random.string(); // 4G8JyA4uM5YVMbkqVaoYnW6GzPcC64Fy
653
+ ```
654
+
655
+ To generate a random string with certain length, just pass the length value to the function.
656
+
657
+ ```ts
658
+ import { Random } from "@mongez/reinforcements";
659
+
660
+ Random.string(12); // P057C06VPwxl
661
+ ```
662
+
663
+ ### Generate random integer
664
+
665
+ To generate a random integer use `Random.int(min: number = 1, max: number = 9999999): number` method.
666
+
667
+ ```ts
668
+ import { Random } from "@mongez/reinforcements";
669
+
670
+ Random.int(); // 7387115
671
+ Random.int(); // 9411554
672
+ Random.int(); // 691593
673
+ ```
674
+
675
+ To set min value, pass first argument with minimum value
676
+
677
+ ```ts
678
+ import { Random } from "@mongez/reinforcements";
679
+
680
+ Random.int(10); // 7387115
681
+ ```
682
+
683
+ To set min and max value, pass second argument as well with maximum value
684
+
685
+ ```ts
686
+ import { Random } from "@mongez/reinforcements";
687
+
688
+ Random.int(10, 100); // 36
689
+ ```
690
+
691
+ > `Random.integer` is an alias to `Random.int`.
692
+
693
+ ### Generate random html id
694
+
695
+ This function will generate a valid random html id string `Random.id(length: number = 6, startsWith: string = "el-"): string`.
696
+
697
+ ```ts
698
+ import { Random } from "@mongez/reinforcements";
699
+
700
+ Random.id(); // el-SDFefdvgtr2e3qw
701
+ Random.id(); // el-fasrg3q
702
+ ```
703
+
704
+ You may set the length as first argument and/or set the id prefix as second argument (**default is el-**).
705
+
706
+ ### Generate random boolean value
707
+
708
+ To generate random boolean value use `Random.bool(): boolean` or `Random.boolean(): boolean`
709
+
710
+ ```ts
711
+ import { Random } from "@mongez/reinforcements";
712
+
713
+ Random.bool(); // true
714
+ Random.bool(); // true
715
+ Random.bool(); // false
716
+ Random.boolean(); // false
717
+ Random.boolean(); // true
718
+ Random.boolean(); // false
719
+ ```
720
+
721
+ ### Generate random color
722
+
723
+ To generate random color use `Random.color(): string` method.
724
+
725
+ ```ts
726
+ import { Random } from "@mongez/reinforcements";
727
+
728
+ Random.color(); // #f2f2f2
729
+ ```
730
+
731
+ ### Generate random date
732
+
733
+ To generate random date use `Random.date(min: Date = new Date(1970, 1, 1), max: Date = new Date()): Date` method.
734
+
735
+ ```ts
736
+ import { Random } from "@mongez/reinforcements";
737
+
738
+ Random.date(); // 2020-12-12T12:12:12.000Z
739
+
740
+ // Get random date between two dates
741
+ Random.date(new Date(2010, 1, 1), new Date(2020, 1, 1)); // 2015-12-12T12:12:12.000Z
742
+
743
+ // Get random date that is higher than the given date
744
+ Random.date(new Date(2010, 1, 1)); // 2015-12-12T12:12:12.000Z
745
+
746
+ // Get random date that is lower than the given date
747
+ Random.date(null, new Date(2010, 1, 1)); // 2005-12-12T12:12:12.000Z
748
+ ```
749
+
750
+ ## Round float numbers
751
+
752
+ To round float numbers, use `round(value: number, precision: number = 2): number`.
753
+
754
+ ```ts
755
+ import { round } from "@mongez/reinforcements";
756
+
757
+ console.log(round(10.0001)); // 10
758
+ console.log(round(10.0478878)); // 10.04
759
+ console.log(round(10.6987894849)); // 10.69
760
+ console.log(round(10.6987894849, 3)); // 10.698
761
+ ```
762
+
763
+ ## Working With Strings
764
+
765
+ The following list defines all available string utilities
766
+
767
+ - `capitalize`
768
+ - `toCamelCase`
769
+ - `toSnakeCase`
770
+ - `toStudlyCase`
771
+ - `ucfirst`
772
+ - `toInputName`
773
+ - `extension`
774
+ - `readMoreChars`
775
+ - `readMoreWords`
776
+ - `replaceFirst`
777
+ - `replaceLast`
778
+ - `replaceAll`
779
+ - `removeFirst`
780
+ - `removeLast`
781
+ - `repeatsOf`
782
+ - `ltrim`
783
+ - `trim`
784
+ - `rtrim`
785
+ - `startsWithArabic`
786
+
787
+ ### Capitalize words
788
+
789
+ Capitalize each word in string Separated by whitespace `capitalize(string: string): string`.
790
+
791
+ ```ts
792
+ import { capitalize } from "@mongez/reinforcements";
793
+
794
+ const words = "hello world";
795
+
796
+ console.log(capitalize(words)); // Hello World
797
+ ```
798
+
799
+ ### Convert string to camel case
800
+
801
+ Convert string to camel case, each word in string Separated by **whitespace** **underscores** or **dashes** `toCamelCase(string: string, separator: string = "\\s+|-|/|_|\\."): string`.
802
+
803
+ ```ts
804
+ import { toCamelCase } from "@mongez/reinforcements";
805
+
806
+ const words = "hello world";
807
+
808
+ console.log(toCamelCase(words)); // helloWorld
809
+ ```
810
+
811
+ Any of following will be used as a separator for the text, `.` | `-` | `whitespace` | `/`, you can set the separator as second argument though.
812
+
813
+ ### Convert string to snake case
814
+
815
+ Convert string to snake case, each word in string Separated by **whitespace** or **dashes** `toSnakeCase(string: string): string`.
816
+
817
+ The final output of the text will be all letters in lower case string separated by \_ **underscores**.
818
+
819
+ ```ts
820
+ import { toSnakeCase } from "@mongez/reinforcements";
821
+
822
+ const words = "hello world";
823
+
824
+ console.log(toSnakeCase(words)); // hello_world
825
+ ```
826
+
827
+ ### Convert string to studly case
828
+
829
+ Convert string to studly case, each word in string Separated by **whitespace**, **underscores** or **dashes** `toStudlyCase(string: string, separator: string = "-|\\.|_|\\s"): string`.
830
+
831
+ The final output will be capitalizing each word and glue it together without any separators such as **whitespace**, **under scores** or **dashes**.
832
+
833
+ ```ts
834
+ import { toStudlyCase } from "@mongez/reinforcements";
835
+
836
+ const words = "hello world";
837
+
838
+ console.log(toStudlyCase(words)); // HelloWorld
839
+ ```
840
+
841
+ ### Capitalize first word of string
842
+
843
+ Capitalize only first word of string `ucfirst(string: string): string`.
844
+
845
+ ```ts
846
+ import { ucfirst } from "@mongez/reinforcements";
847
+
848
+ const words = "hello world";
849
+
850
+ console.log(ucfirst(words)); // Hello world
851
+ ```
852
+
853
+ ### To input name
854
+
855
+ Convert dot notation syntax to valid html input name `toInputName(string: string): string`.
856
+
857
+ ```ts
858
+ import { toInputName } from "@mongez/reinforcements";
859
+
860
+ const name = "user.name";
861
+
862
+ console.log(toInputName(name)); // user[name]
863
+ console.log(toInputName("keywords.en.list[]")); // keywords[en][list][]
864
+ ```
865
+
866
+ ### Get extension of string
867
+
868
+ Get the last extension in the string, the string that is suffix to last dot `.`.
869
+
870
+ `extension(string: string): string`
871
+
872
+ ```ts
873
+ import { extension } from "@mongez/reinforcements";
874
+
875
+ const file = "my-image.png";
876
+
877
+ console.log(extension(file)); //png
878
+ ```
879
+
880
+ ### Read more characters
881
+
882
+ This function will cut off the string when characters reach limit, and append three dots `...` at the end of the string.
883
+
884
+ `readMoreChars(string: string, length: number, readMoreDots: string = '...'): string`
885
+
886
+ ```ts
887
+ import { readMoreChars } from "@mongez/reinforcements";
888
+
889
+ const string = "This is a fine words list";
890
+
891
+ console.log(readMoreChars(string, 20)); // This is a fine words...
892
+
893
+ // if the given limit is equal to or more than string length, then the entire string will be returned without any dots
894
+ console.log(readMoreChars(string, 30)); // This is a fine words list
895
+
896
+ // change the three dots to something else
897
+
898
+ const string = "This is a fine words list";
899
+
900
+ console.log(readMoreChars(string, 20, " >>")); // This is a fine words >>
901
+ ```
902
+
903
+ ### Read more words
904
+
905
+ This function will cut off the string when words reach the given limit, and append three dots `...` at the end of the string.
906
+
907
+ This works based on total number of whitespace in the string.
908
+
909
+ `readMoreWords(string: string, length: number, readMoreDots: string = '...'): string`
910
+
911
+ ```ts
912
+ import { readMoreWords } from "@mongez/reinforcements";
913
+
914
+ const string = "This is a fine words list";
915
+
916
+ console.log(readMoreWords(string, 4)); // This is a fine...
917
+
918
+ // if the given limit is equal to or more than words length, then the entire string will be returned without any dots
919
+ console.log(readMoreWords(string, 6)); // This is a fine words list
920
+
921
+ // change the three dots to something else
922
+
923
+ const string = "This is a fine words list";
924
+
925
+ console.log(readMoreWords(string, 4, " >>")); // This is a fine >>
926
+ ```
927
+
928
+ ### Remove first matched string
929
+
930
+ Remove the first matched needle to the given string.
931
+
932
+ `removeFirst(string: string, needle: string): string`
933
+
934
+ ```ts
935
+ import { removeFirst } from "@mongez/reinforcements";
936
+
937
+ const words = "welcome home buddy, your are not safe at your home!";
938
+
939
+ console.log(removeFirst(words, "home")); // welcome buddy, your are not safe at your home!
940
+ ```
941
+
942
+ ### Replace first matched string
943
+
944
+ Replace the first matched needle to the given string.
945
+
946
+ `replaceFirst(string:string, needle: string, replacement: string): string`
947
+
948
+ ```ts
949
+ import { replaceFirst } from "@mongez/reinforcements";
950
+
951
+ const words = "welcome home buddy, your are not safe at your home!";
952
+
953
+ console.log(replaceFirst(words, "home", "country")); // welcome country buddy, your are not safe at your home!
954
+ ```
955
+
956
+ ### Replace last matched string
957
+
958
+ Replace the last matched needle to the given string.
959
+
960
+ `replaceLast(string:string, needle: string, replacement: string): string`
961
+
962
+ ```ts
963
+ import { replaceLast } from "@mongez/reinforcements";
964
+
965
+ const words = "welcome home buddy, your are not safe at your home!";
966
+
967
+ console.log(replaceLast(words, "home", "country")); // welcome home buddy, your are not safe at your country!
968
+ ```
969
+
970
+ ### Replace all matched string
971
+
972
+ Replace all matched words to the given string.
973
+
974
+ `replaceAll(string: string, searchText:string, replacement: string): string`
975
+
976
+ ```ts
977
+ import { replaceAll } from "@mongez/reinforcements";
978
+
979
+ const words = "welcome home buddy, your are not safe at your home!";
980
+
981
+ console.log(replaceAll(words, "home", "country")); // welcome country buddy, your are not safe at your country!
982
+ ```
983
+
984
+ ### Remove last matched string
985
+
986
+ Remove the last matched needle to the given string.
987
+
988
+ `removeLast(string: string, needle: string): string`
989
+
990
+ ```ts
991
+ import { removeLast } from "@mongez/reinforcements";
992
+
993
+ const words = "welcome home buddy, your are not safe at your home!";
994
+
995
+ console.log(removeLast(words, "home")); // welcome home buddy, your are not safe at your !
996
+ ```
997
+
998
+ ### Count repeats of needle in a string
999
+
1000
+ Count repeats of a needle in the given string.
1001
+
1002
+ `repeatsOf(string: string, needle: string, caseSensitive: boolean = true): number`
1003
+
1004
+ ```ts
1005
+ import { repeatsOf } from "@mongez/reinforcements";
1006
+
1007
+ const words = "welcome home buddy, your are not safe at your home!";
1008
+
1009
+ console.log(repeatsOf(words, "home")); // 2
1010
+ ```
1011
+
1012
+ You may also detect number of repetitions ignoring case sensitive.
1013
+
1014
+ ```ts
1015
+ import { repeatsOf } from "@mongez/reinforcements";
1016
+
1017
+ // note the first Home is capitalized
1018
+ const words = "welcome Home buddy, your are not safe at your home!";
1019
+
1020
+ // case sensitive
1021
+ console.log(repeatsOf(words, "home")); // 1
1022
+ // case insensitive
1023
+ console.log(repeatsOf(words, "home", false)); // 2
1024
+ ```
1025
+
1026
+ ### Trimming values from string
1027
+
1028
+ Trim value from the start and the end of a string.
1029
+
1030
+ `trim(string: string, needle: string = ' '): string`
1031
+
1032
+ ```ts
1033
+ import { trim } from "@mongez/reinforcements";
1034
+
1035
+ const string = " space at the start and at the end ";
1036
+
1037
+ console.log(trim(string)); // "space at the start and at the end"
1038
+ ```
1039
+
1040
+ But why not use [String.trim()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim) directly? well they both will give you same functionality except that `trim()` function trims any value not only white space.
1041
+
1042
+ Remove certain value:
1043
+
1044
+ ```ts
1045
+ import { trim } from "@mongez/reinforcements";
1046
+
1047
+ const string = "/home/";
1048
+
1049
+ console.log(trim(string, "/")); // home
1050
+ ```
1051
+
1052
+ ### Left Trimming values from string
1053
+
1054
+ Trim value from the start of a string.
1055
+
1056
+ `ltrim(string: string, needle: string = ' '): string`
1057
+
1058
+ ```ts
1059
+ import { ltrim } from "@mongez/reinforcements";
1060
+
1061
+ const string = " A space at the start and keep space at the end ";
1062
+
1063
+ console.log(ltrim(string)); // "A space at the start and keep space at the end "
1064
+ ```
1065
+
1066
+ Remove certain value:
1067
+
1068
+ ```ts
1069
+ import { ltrim } from "@mongez/reinforcements";
1070
+
1071
+ const string = "home/";
1072
+
1073
+ console.log(ltrim(string, "/")); // home/
1074
+ ```
1075
+
1076
+ ### Right Trimming values from string
1077
+
1078
+ Trim value from the end of a string.
1079
+
1080
+ `rtrim(string: string, needle: string = ' '): string`
1081
+
1082
+ ```ts
1083
+ import { rtrim } from "@mongez/reinforcements";
1084
+
1085
+ const string = " Keep A space at the start and remove space at the end ";
1086
+
1087
+ console.log(rtrim(string)); // " Keep A space at the start and remove space at the end"
1088
+ ```
1089
+
1090
+ Remove certain value:
1091
+
1092
+ ```ts
1093
+ import { ltrim } from "@mongez/reinforcements";
1094
+
1095
+ const string = "home/";
1096
+
1097
+ console.log(rtrim(string, "/")); // /home
1098
+ ```
1099
+
1100
+ ## Detect if string starts with Arabic
1101
+
1102
+ Determine if the string starts with Arabic letter.
1103
+
1104
+ `startsWithArabic(text: string, trimmed: boolean = true): boolean {`
1105
+
1106
+ ```ts
1107
+ import { startsWithArabic } from "@mongez/reinforcements";
1108
+
1109
+ const string = "English Text";
1110
+
1111
+ const arabicString = "مرحبا";
1112
+
1113
+ console.log(startsWithArabic(string)); // false
1114
+ console.log(startsWithArabic(arabicString)); // true
1115
+ ```
1116
+
1117
+ ## Debounce
1118
+
1119
+ `debounce(callback: Function, timer: number = 0): void`
1120
+
1121
+ You can debounce your functions using `debounce` to prevent multiple calls.
1122
+
1123
+ > This debounce function will be called instantly and will not return a callback function.
1124
+
1125
+ ```tsx
1126
+ import { debounce } from "@mongez/reinforcements";
1127
+
1128
+ function sendEmail(e: any) {
1129
+ sendEmailApi(e.target);
1130
+ }
1131
+
1132
+ // If user clicked 5 times, it will make 5 ajax calls
1133
+
1134
+ <button click={sendEmail}>Send Email</button>;
1135
+ ```
1136
+
1137
+ Now when using `debounce`
1138
+
1139
+ ```tsx
1140
+ import { debounce } from "@mongez/reinforcements";
1141
+
1142
+ function sendEmail(e: any) {
1143
+ debounce(() => {
1144
+ sendEmailApi(e.target);
1145
+ });
1146
+ }
1147
+
1148
+ // If user clicked 5 times, it will make only one ajax call
1149
+
1150
+ <button click={sendEmail}>Send Email</button>;
1151
+ ```
1152
+
1153
+ You can also set a timer when to trigger the function
1154
+
1155
+ ```tsx
1156
+ import { debounce } from "@mongez/reinforcements";
1157
+
1158
+ function sendEmail(e: any) {
1159
+ // wait 3 seconds before calling the function
1160
+ debounce(() => {
1161
+ sendEmailApi(e.target);
1162
+ }, 150);
1163
+ }
1164
+
1165
+ // If user clicked 5 times, it will make only one ajax call
1166
+
1167
+ <button click={sendEmail}>Send Email</button>;
1168
+ ```
1169
+
1170
+ ## Tests
1171
+
1172
+ To run tests run `npm run test` or `yarn test`
1173
+
1174
+ ## TODO
1175
+
1176
+ If you want to contribute to this package, you can check the [todo list page](./docs/todo.md).
1177
+
1178
+ ## Change Log
1179
+
1180
+ - 2.0.0 (24 Oct 2022)
1181
+ - Fully refactored the code.
1182
+ - Added Immutable Collections class.
1183
+ - 1.0.28 (11 Aug 2022)
1184
+ - Fixed object merge call.
1185
+ - 1.0.27 (11 Aug 2022)
1186
+ - Added test.
1187
+ - `toCamelCase` now will use the dot `.` as separator.
1188
+ - `toCamelCase`'s separator is not explicit as second argument.
1189
+ - 1.0.26 (08 Jun 2022)
1190
+ - Removed `sprintf-js` from dependencies.
1191
+ - 1.0.25 (08 Jun 2022)
1192
+ - Fixed Flatten method with empty arrays.
1193
+ - 1.0.23 (03 Jun 2022)
1194
+ - Added [debounce](#debounce) function.
1195
+ - Added `/` to be replaced in `toCamelCase` `toStudlyCase` and `toSnakeCase`.
1196
+ - 1.0.22 (10 Feb 2022)
1197
+ - Added [Obj.except](#getting-all-object-except-for-certain-keys) method.
1198
+ - 1.0.21 (28 Jan 2022)
1199
+ - Fixed `objOnly` method that adds undefined values if key does not exist on the given object.
1200
+ - 1.0.19 (15 Jan 2022)
1201
+ - Added [Clone objects](#clone-objects) function.
1202
+ - 1.0.18 (15 Jan 2022)
1203
+ - Added [Flatten objects](#flatten-objects) function.
1204
+
1205
+ ## TODO
1206
+
1207
+ - Create tests.
1208
+ - Implements Array helpers list.