@vinicunca/perkakas 0.3.1 → 0.3.5

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/dist/commonjs/array/all-pass.js +2 -2
  2. package/dist/commonjs/array/any-pass.js +2 -2
  3. package/dist/commonjs/array/chunk.js +3 -3
  4. package/dist/commonjs/array/concat.js +2 -2
  5. package/dist/commonjs/array/count-by.js +8 -6
  6. package/dist/commonjs/array/difference-with.js +5 -15
  7. package/dist/commonjs/array/difference.js +5 -15
  8. package/dist/commonjs/array/drop-first-by.js +1 -1
  9. package/dist/commonjs/array/drop-last-while.js +2 -2
  10. package/dist/commonjs/array/drop-last.js +3 -3
  11. package/dist/commonjs/array/drop-while.js +2 -2
  12. package/dist/commonjs/array/drop.js +5 -12
  13. package/dist/commonjs/array/filter.js +3 -16
  14. package/dist/commonjs/array/find-index.js +12 -25
  15. package/dist/commonjs/array/find-last-index.js +3 -3
  16. package/dist/commonjs/array/find-last.js +3 -3
  17. package/dist/commonjs/array/find.js +10 -22
  18. package/dist/commonjs/array/first.js +4 -10
  19. package/dist/commonjs/array/flat-map-to-obj.js +10 -9
  20. package/dist/commonjs/array/flat-map.js +5 -15
  21. package/dist/commonjs/array/flatten-deep.js +9 -19
  22. package/dist/commonjs/array/flatten.js +5 -17
  23. package/dist/commonjs/array/for-each.js +18 -22
  24. package/dist/commonjs/array/group-by.js +5 -5
  25. package/dist/commonjs/array/index-by.js +20 -7
  26. package/dist/commonjs/array/index.js +4 -0
  27. package/dist/commonjs/array/intersection-with.js +5 -15
  28. package/dist/commonjs/array/intersection.js +6 -16
  29. package/dist/commonjs/array/last.js +2 -2
  30. package/dist/commonjs/array/length.js +2 -2
  31. package/dist/commonjs/array/map-to-obj.js +8 -7
  32. package/dist/commonjs/array/map.js +11 -15
  33. package/dist/commonjs/array/max-by.js +6 -6
  34. package/dist/commonjs/array/mean-by.js +6 -6
  35. package/dist/commonjs/array/merge-all.js +5 -1
  36. package/dist/commonjs/array/min-by.js +6 -6
  37. package/dist/commonjs/array/only.js +3 -6
  38. package/dist/commonjs/array/partition.js +5 -5
  39. package/dist/commonjs/array/range.js +2 -2
  40. package/dist/commonjs/array/rank-by.js +1 -1
  41. package/dist/commonjs/array/reduce.js +3 -3
  42. package/dist/commonjs/array/reject.js +9 -22
  43. package/dist/commonjs/array/reverse.js +2 -2
  44. package/dist/commonjs/array/sample.js +1 -1
  45. package/dist/commonjs/array/shuffle.js +3 -3
  46. package/dist/commonjs/array/sort-by.js +5 -43
  47. package/dist/commonjs/array/sort.js +3 -3
  48. package/dist/commonjs/array/sorted-index-by.js +19 -0
  49. package/dist/commonjs/array/sorted-index-with.js +15 -0
  50. package/dist/commonjs/array/sorted-index.js +12 -0
  51. package/dist/commonjs/array/sorted-last-index-by.js +19 -0
  52. package/dist/commonjs/array/sorted-last-index.js +12 -0
  53. package/dist/commonjs/array/splice.js +3 -3
  54. package/dist/commonjs/array/split-at.js +3 -3
  55. package/dist/commonjs/array/split-when.js +6 -6
  56. package/dist/commonjs/array/sum-by.js +6 -6
  57. package/dist/commonjs/array/swap-indices.js +7 -7
  58. package/dist/commonjs/array/take-first-by.js +1 -1
  59. package/dist/commonjs/array/take-while.js +2 -2
  60. package/dist/commonjs/array/take.js +8 -21
  61. package/dist/commonjs/array/uniq-by.js +4 -11
  62. package/dist/commonjs/array/uniq-with.js +8 -18
  63. package/dist/commonjs/array/uniq.js +4 -11
  64. package/dist/commonjs/array/zip-obj.js +2 -2
  65. package/dist/commonjs/array/zip-with.js +4 -4
  66. package/dist/commonjs/array/zip.js +2 -2
  67. package/dist/commonjs/function/create-pipe.js +1 -1
  68. package/dist/commonjs/function/index.js +1 -0
  69. package/dist/commonjs/function/pipe.js +18 -24
  70. package/dist/commonjs/function/purry.js +8 -9
  71. package/dist/commonjs/function/times.js +18 -0
  72. package/dist/commonjs/guard/is-defined.js +1 -1
  73. package/dist/commonjs/guard/is-empty.js +4 -4
  74. package/dist/commonjs/guard/is-nil.js +1 -1
  75. package/dist/commonjs/guard/is-not.js +1 -3
  76. package/dist/commonjs/number/add.js +2 -2
  77. package/dist/commonjs/number/clamp.js +6 -6
  78. package/dist/commonjs/number/divide.js +2 -2
  79. package/dist/commonjs/number/multiply.js +2 -2
  80. package/dist/commonjs/number/subtract.js +2 -2
  81. package/dist/commonjs/object/add-prop.js +2 -2
  82. package/dist/commonjs/object/clone.js +5 -5
  83. package/dist/commonjs/object/equals.js +48 -52
  84. package/dist/commonjs/object/for-each-obj.js +9 -9
  85. package/dist/commonjs/object/from-pairs.js +6 -2
  86. package/dist/commonjs/object/invert.js +5 -3
  87. package/dist/commonjs/object/keys.js +3 -2
  88. package/dist/commonjs/object/map-keys.js +2 -2
  89. package/dist/commonjs/object/map-values.js +2 -2
  90. package/dist/commonjs/object/merge-deep.js +2 -2
  91. package/dist/commonjs/object/merge.js +2 -2
  92. package/dist/commonjs/object/omit-by.js +7 -6
  93. package/dist/commonjs/object/omit.js +2 -2
  94. package/dist/commonjs/object/path-or.js +6 -6
  95. package/dist/commonjs/object/pick-by.js +9 -8
  96. package/dist/commonjs/object/pick.js +7 -9
  97. package/dist/commonjs/object/set-path.js +14 -15
  98. package/dist/commonjs/object/set.js +2 -2
  99. package/dist/commonjs/object/swap-props.js +2 -2
  100. package/dist/commonjs/string/random-string.js +11 -5
  101. package/dist/commonjs/string/string-to-path.js +5 -5
  102. package/dist/commonjs/utils/binary-search-cutoff-index.js +19 -0
  103. package/dist/commonjs/utils/heap.js +1 -1
  104. package/dist/commonjs/utils/purry-order-rules.js +1 -1
  105. package/dist/commonjs/utils/quick-select.js +2 -2
  106. package/dist/commonjs/utils/reduce-lazy.js +9 -6
  107. package/dist/commonjs/utils/to-single.js +1 -2
  108. package/dist/es/array/all-pass.js +2 -2
  109. package/dist/es/array/any-pass.js +2 -2
  110. package/dist/es/array/chunk.js +3 -3
  111. package/dist/es/array/concat.js +2 -2
  112. package/dist/es/array/count-by.js +8 -6
  113. package/dist/es/array/difference-with.js +5 -15
  114. package/dist/es/array/difference.js +5 -15
  115. package/dist/es/array/drop-first-by.js +1 -1
  116. package/dist/es/array/drop-last-while.js +2 -2
  117. package/dist/es/array/drop-last.js +3 -3
  118. package/dist/es/array/drop-while.js +2 -2
  119. package/dist/es/array/drop.js +5 -12
  120. package/dist/es/array/filter.js +3 -16
  121. package/dist/es/array/find-index.js +12 -25
  122. package/dist/es/array/find-last-index.js +3 -3
  123. package/dist/es/array/find-last.js +3 -3
  124. package/dist/es/array/find.js +10 -22
  125. package/dist/es/array/first.js +4 -10
  126. package/dist/es/array/flat-map-to-obj.js +10 -9
  127. package/dist/es/array/flat-map.js +5 -15
  128. package/dist/es/array/flatten-deep.js +9 -19
  129. package/dist/es/array/flatten.js +5 -17
  130. package/dist/es/array/for-each.js +18 -22
  131. package/dist/es/array/group-by.js +5 -5
  132. package/dist/es/array/index-by.js +20 -7
  133. package/dist/es/array/index.js +4 -0
  134. package/dist/es/array/intersection-with.js +5 -15
  135. package/dist/es/array/intersection.js +6 -16
  136. package/dist/es/array/last.js +2 -2
  137. package/dist/es/array/length.js +2 -2
  138. package/dist/es/array/map-to-obj.js +8 -7
  139. package/dist/es/array/map.js +11 -15
  140. package/dist/es/array/max-by.js +6 -6
  141. package/dist/es/array/mean-by.js +6 -6
  142. package/dist/es/array/merge-all.js +5 -1
  143. package/dist/es/array/min-by.js +6 -6
  144. package/dist/es/array/only.js +3 -6
  145. package/dist/es/array/partition.js +5 -5
  146. package/dist/es/array/range.js +2 -2
  147. package/dist/es/array/rank-by.js +1 -1
  148. package/dist/es/array/reduce.js +3 -3
  149. package/dist/es/array/reject.js +9 -22
  150. package/dist/es/array/reverse.js +2 -2
  151. package/dist/es/array/sample.js +1 -1
  152. package/dist/es/array/shuffle.js +3 -3
  153. package/dist/es/array/sort-by.js +5 -43
  154. package/dist/es/array/sort.js +3 -3
  155. package/dist/es/array/sorted-index-by.js +15 -0
  156. package/dist/es/array/sorted-index-with.js +11 -0
  157. package/dist/es/array/sorted-index.js +8 -0
  158. package/dist/es/array/sorted-last-index-by.js +15 -0
  159. package/dist/es/array/sorted-last-index.js +8 -0
  160. package/dist/es/array/splice.js +3 -3
  161. package/dist/es/array/split-at.js +3 -3
  162. package/dist/es/array/split-when.js +6 -6
  163. package/dist/es/array/sum-by.js +6 -6
  164. package/dist/es/array/swap-indices.js +7 -7
  165. package/dist/es/array/take-first-by.js +1 -1
  166. package/dist/es/array/take-while.js +2 -2
  167. package/dist/es/array/take.js +8 -21
  168. package/dist/es/array/uniq-by.js +4 -11
  169. package/dist/es/array/uniq-with.js +8 -18
  170. package/dist/es/array/uniq.js +4 -11
  171. package/dist/es/array/zip-obj.js +2 -2
  172. package/dist/es/array/zip-with.js +4 -4
  173. package/dist/es/array/zip.js +2 -2
  174. package/dist/es/function/index.js +1 -0
  175. package/dist/es/function/pipe.js +18 -24
  176. package/dist/es/function/purry.js +8 -9
  177. package/dist/es/function/times.js +14 -0
  178. package/dist/es/guard/is-defined.js +1 -1
  179. package/dist/es/guard/is-empty.js +4 -4
  180. package/dist/es/guard/is-nil.js +1 -1
  181. package/dist/es/guard/is-not.js +1 -3
  182. package/dist/es/number/add.js +2 -2
  183. package/dist/es/number/clamp.js +6 -6
  184. package/dist/es/number/divide.js +2 -2
  185. package/dist/es/number/multiply.js +2 -2
  186. package/dist/es/number/subtract.js +2 -2
  187. package/dist/es/object/add-prop.js +2 -2
  188. package/dist/es/object/clone.js +5 -5
  189. package/dist/es/object/equals.js +48 -52
  190. package/dist/es/object/for-each-obj.js +9 -9
  191. package/dist/es/object/from-pairs.js +5 -1
  192. package/dist/es/object/invert.js +5 -3
  193. package/dist/es/object/keys.js +3 -2
  194. package/dist/es/object/map-keys.js +2 -2
  195. package/dist/es/object/map-values.js +2 -2
  196. package/dist/es/object/merge-deep.js +2 -2
  197. package/dist/es/object/merge.js +2 -2
  198. package/dist/es/object/omit-by.js +7 -6
  199. package/dist/es/object/omit.js +2 -2
  200. package/dist/es/object/path-or.js +6 -6
  201. package/dist/es/object/pick-by.js +9 -8
  202. package/dist/es/object/pick.js +7 -9
  203. package/dist/es/object/set-path.js +12 -13
  204. package/dist/es/object/set.js +2 -2
  205. package/dist/es/object/swap-props.js +2 -2
  206. package/dist/es/string/random-string.js +11 -5
  207. package/dist/es/string/string-to-path.js +5 -5
  208. package/dist/es/utils/binary-search-cutoff-index.js +15 -0
  209. package/dist/es/utils/heap.js +1 -1
  210. package/dist/es/utils/purry-order-rules.js +1 -1
  211. package/dist/es/utils/quick-select.js +2 -2
  212. package/dist/es/utils/reduce-lazy.js +9 -6
  213. package/dist/es/utils/to-single.js +1 -2
  214. package/dist/metadata.json +7915 -4373
  215. package/dist/types/array/count-by.d.ts.map +1 -1
  216. package/dist/types/array/difference-with.d.ts +2 -2
  217. package/dist/types/array/difference-with.d.ts.map +1 -1
  218. package/dist/types/array/difference.d.ts +2 -2
  219. package/dist/types/array/difference.d.ts.map +1 -1
  220. package/dist/types/array/drop.d.ts +2 -2
  221. package/dist/types/array/drop.d.ts.map +1 -1
  222. package/dist/types/array/filter.d.ts +5 -5
  223. package/dist/types/array/filter.d.ts.map +1 -1
  224. package/dist/types/array/find-index.d.ts +5 -20
  225. package/dist/types/array/find-index.d.ts.map +1 -1
  226. package/dist/types/array/find.d.ts +5 -12
  227. package/dist/types/array/find.d.ts.map +1 -1
  228. package/dist/types/array/first.d.ts +2 -5
  229. package/dist/types/array/first.d.ts.map +1 -1
  230. package/dist/types/array/flat-map-to-obj.d.ts +4 -4
  231. package/dist/types/array/flat-map-to-obj.d.ts.map +1 -1
  232. package/dist/types/array/flat-map.d.ts +2 -11
  233. package/dist/types/array/flat-map.d.ts.map +1 -1
  234. package/dist/types/array/flatten-deep.d.ts +15 -5
  235. package/dist/types/array/flatten-deep.d.ts.map +1 -1
  236. package/dist/types/array/flatten.d.ts +17 -2
  237. package/dist/types/array/flatten.d.ts.map +1 -1
  238. package/dist/types/array/for-each.d.ts +3 -3
  239. package/dist/types/array/for-each.d.ts.map +1 -1
  240. package/dist/types/array/group-by.d.ts.map +1 -1
  241. package/dist/types/array/index-by.d.ts +25 -6
  242. package/dist/types/array/index-by.d.ts.map +1 -1
  243. package/dist/types/array/index.d.ts +4 -0
  244. package/dist/types/array/index.d.ts.map +1 -1
  245. package/dist/types/array/intersection-with.d.ts +2 -2
  246. package/dist/types/array/intersection-with.d.ts.map +1 -1
  247. package/dist/types/array/intersection.d.ts +2 -2
  248. package/dist/types/array/intersection.d.ts.map +1 -1
  249. package/dist/types/array/last.d.ts +13 -4
  250. package/dist/types/array/last.d.ts.map +1 -1
  251. package/dist/types/array/map.d.ts +3 -3
  252. package/dist/types/array/map.d.ts.map +1 -1
  253. package/dist/types/array/max-by.d.ts.map +1 -1
  254. package/dist/types/array/mean-by.d.ts.map +1 -1
  255. package/dist/types/array/merge-all.d.ts +1 -1
  256. package/dist/types/array/merge-all.d.ts.map +1 -1
  257. package/dist/types/array/min-by.d.ts.map +1 -1
  258. package/dist/types/array/reduce.d.ts +2 -2
  259. package/dist/types/array/reduce.d.ts.map +1 -1
  260. package/dist/types/array/reject.d.ts +3 -3
  261. package/dist/types/array/reject.d.ts.map +1 -1
  262. package/dist/types/array/sort-by.d.ts +33 -33
  263. package/dist/types/array/sort-by.d.ts.map +1 -1
  264. package/dist/types/array/sort.d.ts.map +1 -1
  265. package/dist/types/array/sorted-index-by.d.ts +63 -0
  266. package/dist/types/array/sorted-index-by.d.ts.map +1 -0
  267. package/dist/types/array/sorted-index-with.d.ts +65 -0
  268. package/dist/types/array/sorted-index-with.d.ts.map +1 -0
  269. package/dist/types/array/sorted-index.d.ts +47 -0
  270. package/dist/types/array/sorted-index.d.ts.map +1 -0
  271. package/dist/types/array/sorted-last-index-by.d.ts +63 -0
  272. package/dist/types/array/sorted-last-index-by.d.ts.map +1 -0
  273. package/dist/types/array/sorted-last-index.d.ts +47 -0
  274. package/dist/types/array/sorted-last-index.d.ts.map +1 -0
  275. package/dist/types/array/sum-by.d.ts.map +1 -1
  276. package/dist/types/array/take.d.ts +2 -2
  277. package/dist/types/array/take.d.ts.map +1 -1
  278. package/dist/types/array/uniq-with.d.ts +3 -3
  279. package/dist/types/array/uniq-with.d.ts.map +1 -1
  280. package/dist/types/array/uniq.d.ts +15 -4
  281. package/dist/types/array/uniq.d.ts.map +1 -1
  282. package/dist/types/array/zip-obj.d.ts +2 -2
  283. package/dist/types/array/zip-obj.d.ts.map +1 -1
  284. package/dist/types/array/zip.d.ts.map +1 -1
  285. package/dist/types/function/conditional.d.ts.map +1 -1
  286. package/dist/types/function/index.d.ts +1 -0
  287. package/dist/types/function/index.d.ts.map +1 -1
  288. package/dist/types/function/noop.d.ts.map +1 -1
  289. package/dist/types/function/pipe.d.ts +21 -0
  290. package/dist/types/function/pipe.d.ts.map +1 -1
  291. package/dist/types/function/purry.d.ts +21 -6
  292. package/dist/types/function/purry.d.ts.map +1 -1
  293. package/dist/types/function/times.d.ts +29 -0
  294. package/dist/types/function/times.d.ts.map +1 -0
  295. package/dist/types/guard/is-empty.d.ts +15 -4
  296. package/dist/types/guard/is-empty.d.ts.map +1 -1
  297. package/dist/types/guard/is-not.d.ts +1 -1
  298. package/dist/types/guard/is-not.d.ts.map +1 -1
  299. package/dist/types/guard/is-object.d.ts +1 -1
  300. package/dist/types/guard/is-object.d.ts.map +1 -1
  301. package/dist/types/number/clamp.d.ts +7 -8
  302. package/dist/types/number/clamp.d.ts.map +1 -1
  303. package/dist/types/object/add-prop.d.ts +2 -2
  304. package/dist/types/object/add-prop.d.ts.map +1 -1
  305. package/dist/types/object/equals.d.ts +2 -2
  306. package/dist/types/object/equals.d.ts.map +1 -1
  307. package/dist/types/object/for-each-obj.d.ts +6 -6
  308. package/dist/types/object/for-each-obj.d.ts.map +1 -1
  309. package/dist/types/object/from-pairs.d.ts +9 -0
  310. package/dist/types/object/from-pairs.d.ts.map +1 -1
  311. package/dist/types/object/keys.d.ts +8 -4
  312. package/dist/types/object/keys.d.ts.map +1 -1
  313. package/dist/types/object/pick.d.ts +9 -9
  314. package/dist/types/object/pick.d.ts.map +1 -1
  315. package/dist/types/object/prop.d.ts.map +1 -1
  316. package/dist/types/object/set-path.d.ts +1 -1
  317. package/dist/types/object/set-path.d.ts.map +1 -1
  318. package/dist/types/object/to-pairs.d.ts +1 -1
  319. package/dist/types/object/to-pairs.d.ts.map +1 -1
  320. package/dist/types/string/random-string.d.ts +6 -2
  321. package/dist/types/string/random-string.d.ts.map +1 -1
  322. package/dist/types/string/string-to-path.d.ts.map +1 -1
  323. package/dist/types/type/type.d.ts.map +1 -1
  324. package/dist/types/utils/binary-search-cutoff-index.d.ts +2 -0
  325. package/dist/types/utils/binary-search-cutoff-index.d.ts.map +1 -0
  326. package/dist/types/utils/narrow.d.ts +1 -1
  327. package/dist/types/utils/narrow.d.ts.map +1 -1
  328. package/dist/types/utils/purry-on.d.ts +1 -1
  329. package/dist/types/utils/purry-on.d.ts.map +1 -1
  330. package/dist/types/utils/reduce-lazy.d.ts +2 -21
  331. package/dist/types/utils/reduce-lazy.d.ts.map +1 -1
  332. package/dist/types/utils/swap-in-place.d.ts.map +1 -1
  333. package/dist/types/utils/to-single.d.ts +4 -2
  334. package/dist/types/utils/to-single.d.ts.map +1 -1
  335. package/dist/types/utils/types.d.ts +2 -2
  336. package/dist/types/utils/types.d.ts.map +1 -1
  337. package/dist/types/utils/with-precision.d.ts.map +1 -1
  338. package/package.json +2 -4
@@ -1,47 +1,9 @@
1
- import { purry } from '../function/purry';
2
- const ALL_DIRECTIONS = ['asc', 'desc'];
3
- const COMPARATOR = {
4
- asc: (x, y) => x > y,
5
- desc: (x, y) => x < y,
6
- };
7
- export function sortBy(arrayOrSortRule, ...sortRules) {
8
- const args = isSortRule(arrayOrSortRule)
9
- ? [[arrayOrSortRule, ...sortRules]]
10
- : [arrayOrSortRule, sortRules];
11
- return purry(_sortBy, args);
1
+ import { purryOrderRules } from '../utils/purry-order-rules';
2
+ export function sortBy(...args) {
3
+ return purryOrderRules(_sortBy, args);
12
4
  }
13
- function isSortRule(x) {
14
- if (typeof x === 'function') {
15
- return true;
16
- }
17
- const [maybeProjection, maybeDirection, ...rest] = x;
18
- if (rest.length > 0) {
19
- return false;
20
- }
21
- return (typeof maybeProjection === 'function'
22
- && ALL_DIRECTIONS.includes(maybeDirection));
23
- }
24
- function _sortBy(array, sorts) {
25
- return [...array].sort(comparer(...sorts));
26
- }
27
- function comparer(primaryRule, secondaryRule, ...otherRules) {
28
- const projector = typeof primaryRule === 'function' ? primaryRule : primaryRule[0];
29
- const direction = typeof primaryRule === 'function' ? 'asc' : primaryRule[1];
30
- const comparator = COMPARATOR[direction];
31
- const nextComparer = secondaryRule === undefined
32
- ? undefined
33
- : comparer(secondaryRule, ...otherRules);
34
- return (a, b) => {
35
- const projectedA = projector(a);
36
- const projectedB = projector(b);
37
- if (comparator(projectedA, projectedB)) {
38
- return 1;
39
- }
40
- if (comparator(projectedB, projectedA)) {
41
- return -1;
42
- }
43
- return nextComparer?.(a, b) ?? 0;
44
- };
5
+ function _sortBy(data, compareFn) {
6
+ return data.slice().sort(compareFn);
45
7
  }
46
8
  (function (sortBy) {
47
9
  sortBy.strict = sortBy;
@@ -1,9 +1,9 @@
1
1
  import { purry } from '../function/purry';
2
2
  export function sort(...args) {
3
- return purry(_sort, args);
3
+ return purry(sort_, args);
4
4
  }
5
- function _sort(items, cmp) {
6
- const ret = [...items];
5
+ function sort_(items, cmp) {
6
+ const ret = items.slice();
7
7
  ret.sort(cmp);
8
8
  return ret;
9
9
  }
@@ -0,0 +1,15 @@
1
+ import { purry } from '../function/purry';
2
+ import { binarySearchCutoffIndex } from '../utils/binary-search-cutoff-index';
3
+ export function sortedIndexBy(...args) {
4
+ return purry(sortedIndexByImplementation, args);
5
+ }
6
+ (function (sortedIndexBy) {
7
+ function indexed(...args) {
8
+ return purry(sortedIndexByImplementation, args);
9
+ }
10
+ sortedIndexBy.indexed = indexed;
11
+ })(sortedIndexBy || (sortedIndexBy = {}));
12
+ function sortedIndexByImplementation(array, item, valueFunction) {
13
+ const value = valueFunction(item);
14
+ return binarySearchCutoffIndex(array, (pivot, index) => valueFunction(pivot, index) < value);
15
+ }
@@ -0,0 +1,11 @@
1
+ import { purry } from '../function/purry';
2
+ import { binarySearchCutoffIndex } from '../utils/binary-search-cutoff-index';
3
+ export function sortedIndexWith(...args) {
4
+ return purry(binarySearchCutoffIndex, args);
5
+ }
6
+ (function (sortedIndexWith) {
7
+ function indexed(...args) {
8
+ return purry(binarySearchCutoffIndex, args);
9
+ }
10
+ sortedIndexWith.indexed = indexed;
11
+ })(sortedIndexWith || (sortedIndexWith = {}));
@@ -0,0 +1,8 @@
1
+ import { purry } from '../function/purry';
2
+ import { binarySearchCutoffIndex } from '../utils/binary-search-cutoff-index';
3
+ export function sortedIndex(...args) {
4
+ return purry(sortedIndexImplementation, args);
5
+ }
6
+ function sortedIndexImplementation(array, item) {
7
+ return binarySearchCutoffIndex(array, (pivot) => pivot < item);
8
+ }
@@ -0,0 +1,15 @@
1
+ import { purry } from '../function/purry';
2
+ import { binarySearchCutoffIndex } from '../utils/binary-search-cutoff-index';
3
+ export function sortedLastIndexBy(...args) {
4
+ return purry(sortedLastIndexByImplementation, args);
5
+ }
6
+ (function (sortedLastIndexBy) {
7
+ function indexed(...args) {
8
+ return purry(sortedLastIndexByImplementation, args);
9
+ }
10
+ sortedLastIndexBy.indexed = indexed;
11
+ })(sortedLastIndexBy || (sortedLastIndexBy = {}));
12
+ function sortedLastIndexByImplementation(array, item, valueFunction) {
13
+ const value = valueFunction(item);
14
+ return binarySearchCutoffIndex(array, (pivot, index) => valueFunction(pivot, index) <= value);
15
+ }
@@ -0,0 +1,8 @@
1
+ import { purry } from '../function/purry';
2
+ import { binarySearchCutoffIndex } from '../utils/binary-search-cutoff-index';
3
+ export function sortedLastIndex(...args) {
4
+ return purry(sortedLastIndexImplementation, args);
5
+ }
6
+ function sortedLastIndexImplementation(array, item) {
7
+ return binarySearchCutoffIndex(array, (pivot) => pivot <= item);
8
+ }
@@ -1,9 +1,9 @@
1
1
  import { purry } from '../function/purry';
2
2
  export function splice(...args) {
3
- return purry(_splice, args);
3
+ return purry(splice_, args);
4
4
  }
5
- function _splice(items, start, deleteCount, replacement) {
6
- const result = [...items];
5
+ function splice_(items, start, deleteCount, replacement) {
6
+ const result = items.slice();
7
7
  result.splice(start, deleteCount, ...replacement);
8
8
  return result;
9
9
  }
@@ -1,9 +1,9 @@
1
1
  import { purry } from '../function/purry';
2
2
  export function splitAt(...args) {
3
- return purry(_splitAt, args);
3
+ return purry(splitAt_, args);
4
4
  }
5
- function _splitAt(array, index) {
6
- const copy = [...array];
5
+ function splitAt_(array, index) {
6
+ const copy = array.slice();
7
7
  const tail = copy.splice(index);
8
8
  return [copy, tail];
9
9
  }
@@ -1,13 +1,13 @@
1
1
  import { purry } from '../function/purry';
2
2
  import { splitAt } from './split-at';
3
3
  export function splitWhen(...args) {
4
- return purry(_splitWhen, args);
4
+ return purry(splitWhen_, args);
5
5
  }
6
- function _splitWhen(array, fn) {
7
- for (let i = 0; i < array.length; i++) {
8
- if (fn(array[i])) {
9
- return splitAt(array, i);
6
+ function splitWhen_(array, fn) {
7
+ for (const [index, item] of array.entries()) {
8
+ if (fn(item)) {
9
+ return splitAt(array, index);
10
10
  }
11
11
  }
12
- return [array, []];
12
+ return [array.slice(), []];
13
13
  }
@@ -1,20 +1,20 @@
1
1
  import { purry } from '../function/purry';
2
- function _sumBy(indexed) {
2
+ function sumBy_(indexed) {
3
3
  return (array, fn) => {
4
4
  let sum = 0;
5
- array.forEach((item, i) => {
6
- const summand = indexed ? fn(item, i, array) : fn(item);
5
+ for (const [index, item] of array.entries()) {
6
+ const summand = indexed ? fn(item, index, array) : fn(item);
7
7
  sum += summand;
8
- });
8
+ }
9
9
  return sum;
10
10
  };
11
11
  }
12
12
  export function sumBy(...args) {
13
- return purry(_sumBy(false), args);
13
+ return purry(sumBy_(false), args);
14
14
  }
15
15
  (function (sumBy) {
16
16
  function indexed(...args) {
17
- return purry(_sumBy(true), args);
17
+ return purry(sumBy_(true), args);
18
18
  }
19
19
  sumBy.indexed = indexed;
20
20
  })(sumBy || (sumBy = {}));
@@ -1,13 +1,13 @@
1
1
  import { purry } from '../function/purry';
2
2
  export function swapIndices(...args) {
3
- return purry(_swapIndices, args);
3
+ return purry(swapIndices_, args);
4
4
  }
5
- function _swapIndices(item, index1, index2) {
5
+ function swapIndices_(item, index1, index2) {
6
6
  return typeof item === 'string'
7
- ? _swapString(item, index1, index2)
8
- : _swapArray(item, index1, index2);
7
+ ? swapString_(item, index1, index2)
8
+ : swapArray_(item, index1, index2);
9
9
  }
10
- function _swapArray(item, index1, index2) {
10
+ function swapArray_(item, index1, index2) {
11
11
  const result = item.slice();
12
12
  if (Number.isNaN(index1) || Number.isNaN(index2)) {
13
13
  return result;
@@ -24,7 +24,7 @@ function _swapArray(item, index1, index2) {
24
24
  result[positiveIndexB] = item[positiveIndexA];
25
25
  return result;
26
26
  }
27
- function _swapString(item, index1, index2) {
28
- const result = _swapArray(item.split(''), index1, index2);
27
+ function swapString_(item, index1, index2) {
28
+ const result = swapArray_(item.split(''), index1, index2);
29
29
  return result.join('');
30
30
  }
@@ -8,7 +8,7 @@ function takeFirstByImplementation(data, compareFn, n) {
8
8
  return [];
9
9
  }
10
10
  if (n >= data.length) {
11
- return [...data];
11
+ return data.slice();
12
12
  }
13
13
  const heap = data.slice(0, n);
14
14
  heapify(heap, compareFn);
@@ -1,8 +1,8 @@
1
1
  import { purry } from '../function/purry';
2
2
  export function takeWhile(...args) {
3
- return purry(_takeWhile, args);
3
+ return purry(takeWhile_, args);
4
4
  }
5
- function _takeWhile(array, fn) {
5
+ function takeWhile_(array, fn) {
6
6
  const ret = [];
7
7
  for (const item of array) {
8
8
  if (!fn(item)) {
@@ -1,33 +1,20 @@
1
1
  import { purry } from '../function/purry';
2
2
  import { reduceLazy } from '../utils/reduce-lazy';
3
3
  export function take(...args) {
4
- return purry(_take, args, take.lazy);
4
+ return purry(take_, args, take.lazy);
5
5
  }
6
- function _take(array, n) {
6
+ function take_(array, n) {
7
7
  return reduceLazy(array, take.lazy(n));
8
8
  }
9
9
  (function (take) {
10
10
  function lazy(n) {
11
+ if (n <= 0) {
12
+ return () => ({ done: true, hasNext: false });
13
+ }
14
+ let remaining = n;
11
15
  return (value) => {
12
- if (n === 0) {
13
- return {
14
- done: true,
15
- hasNext: false,
16
- };
17
- }
18
- n--;
19
- if (n === 0) {
20
- return {
21
- done: true,
22
- hasNext: true,
23
- next: value,
24
- };
25
- }
26
- return {
27
- done: false,
28
- hasNext: true,
29
- next: value,
30
- };
16
+ remaining -= 1;
17
+ return { done: remaining <= 0, hasNext: true, next: value };
31
18
  };
32
19
  }
33
20
  take.lazy = lazy;
@@ -1,9 +1,9 @@
1
1
  import { purry } from '../function/purry';
2
2
  import { reduceLazy } from '../utils/reduce-lazy';
3
3
  export function uniqBy(...args) {
4
- return purry(_uniqBy, args, lazyUniqBy);
4
+ return purry(uniqBy_, args, lazyUniqBy);
5
5
  }
6
- function _uniqBy(array, transformer) {
6
+ function uniqBy_(array, transformer) {
7
7
  return reduceLazy(array, lazyUniqBy(transformer));
8
8
  }
9
9
  function lazyUniqBy(transformer) {
@@ -11,16 +11,9 @@ function lazyUniqBy(transformer) {
11
11
  return (value) => {
12
12
  const appliedItem = transformer(value);
13
13
  if (set.has(appliedItem)) {
14
- return {
15
- done: false,
16
- hasNext: false,
17
- };
14
+ return { done: false, hasNext: false };
18
15
  }
19
16
  set.add(appliedItem);
20
- return {
21
- done: false,
22
- hasNext: true,
23
- next: value,
24
- };
17
+ return { done: false, hasNext: true, next: value };
25
18
  };
26
19
  }
@@ -2,28 +2,18 @@ import { purry } from '../function/purry';
2
2
  import { reduceLazy } from '../utils/reduce-lazy';
3
3
  import { toLazyIndexed } from '../utils/to-lazy-indexed';
4
4
  export function uniqWith(...args) {
5
- return purry(_uniqWith, args, uniqWith.lazy);
5
+ return purry(uniqWith_, args, uniqWith.lazy);
6
6
  }
7
- function _uniqWith(array, isEquals) {
7
+ function uniqWith_(array, isEquals) {
8
8
  const lazy = uniqWith.lazy(isEquals);
9
9
  return reduceLazy(array, lazy, true);
10
10
  }
11
- function _lazy(isEquals) {
12
- return (value, index, array) => {
13
- if (array
14
- && array.findIndex((otherValue) => isEquals(value, otherValue)) === index) {
15
- return {
16
- done: false,
17
- hasNext: true,
18
- next: value,
19
- };
20
- }
21
- return {
22
- done: false,
23
- hasNext: false,
24
- };
25
- };
11
+ function lazy_(isEquals) {
12
+ return (value, index, array) => array !== undefined
13
+ && array.findIndex((otherValue) => isEquals(value, otherValue)) === index
14
+ ? { done: false, hasNext: true, next: value }
15
+ : { done: false, hasNext: false };
26
16
  }
27
17
  (function (uniqWith) {
28
- uniqWith.lazy = toLazyIndexed(_lazy);
18
+ uniqWith.lazy = toLazyIndexed(lazy_);
29
19
  })(uniqWith || (uniqWith = {}));
@@ -1,9 +1,9 @@
1
1
  import { purry } from '../function/purry';
2
2
  import { reduceLazy } from '../utils/reduce-lazy';
3
3
  export function uniq(...args) {
4
- return purry(_uniq, args, uniq.lazy);
4
+ return purry(uniq_, args, uniq.lazy);
5
5
  }
6
- function _uniq(array) {
6
+ function uniq_(array) {
7
7
  return reduceLazy(array, uniq.lazy());
8
8
  }
9
9
  (function (uniq) {
@@ -11,17 +11,10 @@ function _uniq(array) {
11
11
  const set = new Set();
12
12
  return (value) => {
13
13
  if (set.has(value)) {
14
- return {
15
- done: false,
16
- hasNext: false,
17
- };
14
+ return { done: false, hasNext: false };
18
15
  }
19
16
  set.add(value);
20
- return {
21
- done: false,
22
- hasNext: true,
23
- next: value,
24
- };
17
+ return { done: false, hasNext: true, next: value };
25
18
  };
26
19
  }
27
20
  uniq.lazy = lazy;
@@ -1,8 +1,8 @@
1
1
  import { purry } from '../function/purry';
2
2
  export function zipObj(...args) {
3
- return purry(_zipObj, args);
3
+ return purry(zipObj_, args);
4
4
  }
5
- function _zipObj(first, second) {
5
+ function zipObj_(first, second) {
6
6
  const resultLength = first.length > second.length ? second.length : first.length;
7
7
  const result = {};
8
8
  for (let i = 0; i < resultLength; i++) {
@@ -1,15 +1,15 @@
1
1
  export function zipWith(arg0, arg1, arg2) {
2
2
  if (typeof arg0 === 'function') {
3
3
  return arg1 === undefined
4
- ? (f, s) => _zipWith(f, s, arg0)
5
- : (f) => _zipWith(f, arg1, arg0);
4
+ ? (f, s) => zipWith_(f, s, arg0)
5
+ : (f) => zipWith_(f, arg1, arg0);
6
6
  }
7
7
  if (arg1 === undefined || arg2 === undefined) {
8
8
  throw new Error('zipWith: Missing arguments in dataFirst function call');
9
9
  }
10
- return _zipWith(arg0, arg1, arg2);
10
+ return zipWith_(arg0, arg1, arg2);
11
11
  }
12
- function _zipWith(first, second, fn) {
12
+ function zipWith_(first, second, fn) {
13
13
  const resultLength = first.length > second.length ? second.length : first.length;
14
14
  const result = [];
15
15
  for (let i = 0; i < resultLength; i++) {
@@ -1,8 +1,8 @@
1
1
  import { purry } from '../function/purry';
2
2
  export function zip(...args) {
3
- return purry(_zip, args);
3
+ return purry(zip_, args);
4
4
  }
5
- function _zip(first, second) {
5
+ function zip_(first, second) {
6
6
  const resultLength = first.length > second.length ? second.length : first.length;
7
7
  const result = [];
8
8
  for (let i = 0; i < resultLength; i++) {
@@ -7,3 +7,4 @@ export * from './debounce';
7
7
  export * from './pipe';
8
8
  export * from './purry';
9
9
  export * from './sleep';
10
+ export * from './times';
@@ -1,18 +1,18 @@
1
1
  export function pipe(input, ...operations) {
2
2
  let output = input;
3
- const lazyOperations = operations.map((op) => 'lazy' in op ? toPipedLazy(op) : undefined);
3
+ const lazyOperations = operations.map((op) => 'lazy' in op ? prepareLazyOperation(op) : undefined);
4
4
  let operationIndex = 0;
5
5
  while (operationIndex < operations.length) {
6
6
  const lazyOperation = lazyOperations[operationIndex];
7
7
  if (lazyOperation === undefined || !isIterable(output)) {
8
8
  const operation = operations[operationIndex];
9
9
  output = operation(output);
10
- operationIndex++;
10
+ operationIndex += 1;
11
11
  continue;
12
12
  }
13
13
  const lazySequence = [];
14
- for (let j = operationIndex; j < operations.length; j++) {
15
- const lazyOp = lazyOperations[j];
14
+ for (let index = operationIndex; index < operations.length; index++) {
15
+ const lazyOp = lazyOperations[index];
16
16
  if (lazyOp === undefined) {
17
17
  break;
18
18
  }
@@ -34,12 +34,7 @@ export function pipe(input, ...operations) {
34
34
  }
35
35
  }
36
36
  const { isSingle } = lazySequence[lazySequence.length - 1];
37
- if (isSingle) {
38
- output = accumulator[0];
39
- }
40
- else {
41
- output = accumulator;
42
- }
37
+ output = isSingle ? accumulator[0] : accumulator;
43
38
  operationIndex += lazySequence.length;
44
39
  }
45
40
  return output;
@@ -49,28 +44,27 @@ function processItem_(item, accumulator, lazySequence) {
49
44
  accumulator.push(item);
50
45
  return false;
51
46
  }
47
+ let currentItem = item;
52
48
  let lazyResult = { done: false, hasNext: false };
53
49
  let isDone = false;
54
- for (let i = 0; i < lazySequence.length; i++) {
55
- const lazyFn = lazySequence[i];
50
+ for (const [operationsIndex, lazyFn] of lazySequence.entries()) {
56
51
  const { index, isIndexed, items } = lazyFn;
57
- items.push(item);
58
- lazyResult = isIndexed ? lazyFn(item, index, items) : lazyFn(item);
59
- lazyFn.index++;
52
+ items.push(currentItem);
53
+ lazyResult = isIndexed
54
+ ? lazyFn(currentItem, index, items)
55
+ : lazyFn(currentItem);
56
+ lazyFn.index += 1;
60
57
  if (lazyResult.hasNext) {
61
- if (lazyResult.hasMany) {
62
- const nextValues = lazyResult.next;
63
- for (const subItem of nextValues) {
64
- const subResult = processItem_(subItem, accumulator, lazySequence.slice(i + 1));
58
+ if (lazyResult.hasMany ?? false) {
59
+ for (const subItem of lazyResult.next) {
60
+ const subResult = processItem_(subItem, accumulator, lazySequence.slice(operationsIndex + 1));
65
61
  if (subResult) {
66
62
  return true;
67
63
  }
68
64
  }
69
65
  return false;
70
66
  }
71
- else {
72
- item = lazyResult.next;
73
- }
67
+ currentItem = lazyResult.next;
74
68
  }
75
69
  if (!lazyResult.hasNext) {
76
70
  break;
@@ -80,11 +74,11 @@ function processItem_(item, accumulator, lazySequence) {
80
74
  }
81
75
  }
82
76
  if (lazyResult.hasNext) {
83
- accumulator.push(item);
77
+ accumulator.push(currentItem);
84
78
  }
85
79
  return isDone;
86
80
  }
87
- function toPipedLazy(op) {
81
+ function prepareLazyOperation(op) {
88
82
  const { lazy, lazyArgs } = op;
89
83
  const fn = lazy(...(lazyArgs ?? []));
90
84
  return Object.assign(fn, {
@@ -1,16 +1,15 @@
1
- export function purry(fn, args, lazy) {
1
+ export function purry(fn, args, lazyFactory) {
2
+ const callArgs = Array.from(args);
2
3
  const diff = fn.length - args.length;
3
- const arrayArgs = Array.from(args);
4
4
  if (diff === 0) {
5
- return fn(...arrayArgs);
5
+ return fn(...callArgs);
6
6
  }
7
7
  if (diff === 1) {
8
- const ret = (data) => fn(data, ...arrayArgs);
9
- if (lazy || fn.lazy) {
10
- ret.lazy = lazy || fn.lazy;
11
- ret.lazyArgs = args;
12
- }
13
- return ret;
8
+ const ret = (data) => fn(data, ...callArgs);
9
+ const lazy = lazyFactory ?? fn.lazy;
10
+ return lazy === undefined
11
+ ? ret
12
+ : Object.assign(ret, { lazy, lazyArgs: args });
14
13
  }
15
14
  throw new Error('Wrong number of arguments');
16
15
  }
@@ -0,0 +1,14 @@
1
+ import { purry } from './purry';
2
+ export function times(...args) {
3
+ return purry(times_, args);
4
+ }
5
+ function times_(count, fn) {
6
+ if (count < 0) {
7
+ throw new RangeError('n must be a non-negative number');
8
+ }
9
+ const res = [];
10
+ for (let i = 0; i < count; i++) {
11
+ res.push(fn(i));
12
+ }
13
+ return res;
14
+ }
@@ -1,5 +1,5 @@
1
1
  export function isDefined(data) {
2
- return typeof data !== 'undefined' && data !== null;
2
+ return data !== undefined && data !== null;
3
3
  }
4
4
  (function (isDefined) {
5
5
  function strict(data) {
@@ -2,14 +2,14 @@ import { isArray } from './is-array';
2
2
  import { isObject } from './is-object';
3
3
  import { isString } from './is-string';
4
4
  export function isEmpty(data) {
5
+ if (data === undefined) {
6
+ return true;
7
+ }
5
8
  if (isArray(data) || isString(data)) {
6
9
  return data.length === 0;
7
10
  }
8
11
  if (isObject(data)) {
9
- for (const _ in data) {
10
- return false;
11
- }
12
- return !(data instanceof RegExp);
12
+ return Object.keys(data).length === 0;
13
13
  }
14
14
  return false;
15
15
  }
@@ -1,3 +1,3 @@
1
1
  export function isNil(data) {
2
- return data == null;
2
+ return data === null || data === undefined;
3
3
  }
@@ -1,5 +1,3 @@
1
1
  export function isNot(predicate) {
2
- return (data) => {
3
- return !predicate(data);
4
- };
2
+ return (data) => !predicate(data);
5
3
  }
@@ -1,7 +1,7 @@
1
1
  import { purry } from '../function/purry';
2
2
  export function add(...args) {
3
- return purry(_add, args);
3
+ return purry(add_, args);
4
4
  }
5
- function _add(value, addend) {
5
+ function add_(value, addend) {
6
6
  return value + addend;
7
7
  }