@mongez/reinforcements 2.3.1 → 2.3.2

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 (295) hide show
  1. package/README.md +2 -0
  2. package/cjs/Random/random.d.ts +35 -35
  3. package/cjs/Random/random.js +65 -67
  4. package/cjs/Random/random.test.d.ts +2 -0
  5. package/cjs/array/average.d.ts +6 -6
  6. package/cjs/array/average.js +12 -15
  7. package/cjs/array/average.test.d.ts +2 -0
  8. package/cjs/array/chunk.d.ts +4 -4
  9. package/cjs/array/chunk.js +13 -15
  10. package/cjs/array/chunk.test.d.ts +2 -0
  11. package/cjs/array/count.d.ts +4 -4
  12. package/cjs/array/count.js +14 -17
  13. package/cjs/array/count.test.d.ts +2 -0
  14. package/cjs/array/countBy.d.ts +6 -6
  15. package/cjs/array/countBy.js +20 -23
  16. package/cjs/array/countBy.test.d.ts +2 -0
  17. package/cjs/array/even.d.ts +6 -6
  18. package/cjs/array/even.js +15 -18
  19. package/cjs/array/even.test.d.ts +2 -0
  20. package/cjs/array/evenIndexes.d.ts +4 -4
  21. package/cjs/array/evenIndexes.js +9 -11
  22. package/cjs/array/evenIndexes.test.d.ts +2 -0
  23. package/cjs/array/groupBy.d.ts +7 -7
  24. package/cjs/array/groupBy.js +45 -48
  25. package/cjs/array/groupBy.test.d.ts +2 -0
  26. package/cjs/array/max.d.ts +6 -6
  27. package/cjs/array/max.js +20 -23
  28. package/cjs/array/max.test.d.ts +2 -0
  29. package/cjs/array/median.d.ts +6 -6
  30. package/cjs/array/median.js +25 -28
  31. package/cjs/array/median.test.d.ts +2 -0
  32. package/cjs/array/min.d.ts +6 -6
  33. package/cjs/array/min.js +20 -23
  34. package/cjs/array/min.test.d.ts +2 -0
  35. package/cjs/array/odd.d.ts +6 -6
  36. package/cjs/array/odd.js +15 -18
  37. package/cjs/array/odd.test.d.ts +2 -0
  38. package/cjs/array/oddIndexes.d.ts +4 -4
  39. package/cjs/array/oddIndexes.js +9 -11
  40. package/cjs/array/oddIndexes.test.d.ts +2 -0
  41. package/cjs/array/pluck.d.ts +8 -8
  42. package/cjs/array/pluck.js +23 -26
  43. package/cjs/array/pluck.test.d.ts +2 -0
  44. package/cjs/array/pushUnique.d.ts +5 -5
  45. package/cjs/array/pushUnique.js +14 -16
  46. package/cjs/array/pushUnique.test.d.ts +2 -0
  47. package/cjs/array/range.d.ts +4 -4
  48. package/cjs/array/range.js +21 -23
  49. package/cjs/array/range.test.d.ts +2 -0
  50. package/cjs/array/sum.d.ts +6 -6
  51. package/cjs/array/sum.js +28 -31
  52. package/cjs/array/sum.test.d.ts +2 -0
  53. package/cjs/array/unique.d.ts +4 -4
  54. package/cjs/array/unique.js +14 -17
  55. package/cjs/array/unique.test.d.ts +2 -0
  56. package/cjs/array/unshiftUnique.d.ts +5 -5
  57. package/cjs/array/unshiftUnique.js +14 -16
  58. package/cjs/array/unshiftUnique.test.d.ts +2 -0
  59. package/cjs/index.d.ts +56 -56
  60. package/cjs/index.js +56 -59
  61. package/cjs/mixed/areEqual/areEqual.d.ts +4 -4
  62. package/cjs/mixed/areEqual/areEqual.js +23 -25
  63. package/cjs/mixed/areEqual/areEqual.test.d.ts +2 -0
  64. package/cjs/mixed/clone/clone.d.ts +4 -4
  65. package/cjs/mixed/clone/clone.js +12 -18
  66. package/cjs/mixed/clone/clone.test.d.ts +2 -0
  67. package/cjs/mixed/shuffle/shuffle.d.ts +4 -4
  68. package/cjs/mixed/shuffle/shuffle.js +14 -16
  69. package/cjs/mixed/shuffle/shuffle.test.d.ts +2 -0
  70. package/cjs/number/round.d.ts +4 -4
  71. package/cjs/number/round.js +9 -11
  72. package/cjs/object/except.d.ts +4 -4
  73. package/cjs/object/except.js +12 -15
  74. package/cjs/object/except.test.d.ts +2 -0
  75. package/cjs/object/flatten.d.ts +4 -4
  76. package/cjs/object/flatten.js +38 -40
  77. package/cjs/object/flatten.test.d.ts +2 -0
  78. package/cjs/object/get.d.ts +4 -4
  79. package/cjs/object/get.js +24 -26
  80. package/cjs/object/get.test.d.ts +2 -0
  81. package/cjs/object/map.d.ts +4 -4
  82. package/cjs/object/map.js +10 -12
  83. package/cjs/object/merge.d.ts +1 -1
  84. package/cjs/object/merge.js +99 -104
  85. package/cjs/object/merge.test.d.ts +2 -0
  86. package/cjs/object/only.d.ts +4 -4
  87. package/cjs/object/only.js +17 -20
  88. package/cjs/object/only.test.d.ts +2 -0
  89. package/cjs/object/set.d.ts +5 -5
  90. package/cjs/object/set.js +28 -30
  91. package/cjs/object/set.test.d.ts +2 -0
  92. package/cjs/object/sort.d.ts +4 -4
  93. package/cjs/object/sort.js +15 -17
  94. package/cjs/object/unset.d.ts +4 -4
  95. package/cjs/object/unset.js +23 -26
  96. package/cjs/object/unset.test.d.ts +2 -0
  97. package/cjs/string/capitalize.d.ts +6 -6
  98. package/cjs/string/capitalize.js +15 -18
  99. package/cjs/string/extension.d.ts +4 -4
  100. package/cjs/string/extension.js +11 -13
  101. package/cjs/string/initials.d.ts +4 -4
  102. package/cjs/string/initials.js +15 -17
  103. package/cjs/string/initials.test.d.ts +2 -0
  104. package/cjs/string/ltrim.d.ts +7 -7
  105. package/cjs/string/ltrim.js +15 -18
  106. package/cjs/string/readMoreChars.d.ts +5 -5
  107. package/cjs/string/readMoreChars.js +11 -13
  108. package/cjs/string/readMoreWords.d.ts +5 -5
  109. package/cjs/string/readMoreWords.js +14 -16
  110. package/cjs/string/removeFirst.d.ts +7 -7
  111. package/cjs/string/removeFirst.js +13 -16
  112. package/cjs/string/removeLast.d.ts +7 -7
  113. package/cjs/string/removeLast.js +13 -16
  114. package/cjs/string/repeatsOf.d.ts +7 -7
  115. package/cjs/string/repeatsOf.js +17 -19
  116. package/cjs/string/replaceAll.d.ts +8 -8
  117. package/cjs/string/replaceAll.js +14 -17
  118. package/cjs/string/replaceFirst.d.ts +8 -8
  119. package/cjs/string/replaceFirst.js +14 -17
  120. package/cjs/string/replaceLast.d.ts +8 -8
  121. package/cjs/string/replaceLast.js +21 -23
  122. package/cjs/string/rtrim.d.ts +7 -7
  123. package/cjs/string/rtrim.js +15 -18
  124. package/cjs/string/startsWithArabic.d.ts +2 -2
  125. package/cjs/string/startsWithArabic.js +13 -17
  126. package/cjs/string/toCamelCase.d.ts +1 -1
  127. package/cjs/string/toCamelCase.js +11 -14
  128. package/cjs/string/toCamelCase.test.d.ts +2 -0
  129. package/cjs/string/toInputName.d.ts +5 -5
  130. package/cjs/string/toInputName.js +21 -24
  131. package/cjs/string/toKebabCase.d.ts +4 -4
  132. package/cjs/string/toKebabCase.js +10 -13
  133. package/cjs/string/toKebabCase.test.d.ts +2 -0
  134. package/cjs/string/toSnakeCase.d.ts +7 -7
  135. package/cjs/string/toSnakeCase.js +20 -22
  136. package/cjs/string/toSnakeCase.test.d.ts +2 -0
  137. package/cjs/string/toStudlyCase.d.ts +9 -9
  138. package/cjs/string/toStudlyCase.js +19 -22
  139. package/cjs/string/trim.d.ts +7 -7
  140. package/cjs/string/trim.js +19 -22
  141. package/cjs/string/ucfirst.d.ts +6 -6
  142. package/cjs/string/ucfirst.js +11 -13
  143. package/cjs/types.d.ts +1 -1
  144. package/cjs/utils/debounce.d.ts +8 -8
  145. package/cjs/utils/debounce.js +16 -18
  146. package/cjs/utils/escapeRegex.d.ts +4 -4
  147. package/cjs/utils/escapeRegex.js +8 -10
  148. package/cjs/utils/escapeRegex.test.d.ts +2 -0
  149. package/esm/Random/random.d.ts +35 -35
  150. package/esm/Random/random.js +64 -65
  151. package/esm/Random/random.test.d.ts +2 -0
  152. package/esm/array/average.d.ts +6 -6
  153. package/esm/array/average.js +11 -13
  154. package/esm/array/average.test.d.ts +2 -0
  155. package/esm/array/chunk.d.ts +4 -4
  156. package/esm/array/chunk.js +12 -13
  157. package/esm/array/chunk.test.d.ts +2 -0
  158. package/esm/array/count.d.ts +4 -4
  159. package/esm/array/count.js +13 -15
  160. package/esm/array/count.test.d.ts +2 -0
  161. package/esm/array/countBy.d.ts +6 -6
  162. package/esm/array/countBy.js +19 -21
  163. package/esm/array/countBy.test.d.ts +2 -0
  164. package/esm/array/even.d.ts +6 -6
  165. package/esm/array/even.js +14 -16
  166. package/esm/array/even.test.d.ts +2 -0
  167. package/esm/array/evenIndexes.d.ts +4 -4
  168. package/esm/array/evenIndexes.js +8 -9
  169. package/esm/array/evenIndexes.test.d.ts +2 -0
  170. package/esm/array/groupBy.d.ts +7 -7
  171. package/esm/array/groupBy.js +44 -46
  172. package/esm/array/groupBy.test.d.ts +2 -0
  173. package/esm/array/max.d.ts +6 -6
  174. package/esm/array/max.js +19 -21
  175. package/esm/array/max.test.d.ts +2 -0
  176. package/esm/array/median.d.ts +6 -6
  177. package/esm/array/median.js +24 -26
  178. package/esm/array/median.test.d.ts +2 -0
  179. package/esm/array/min.d.ts +6 -6
  180. package/esm/array/min.js +19 -21
  181. package/esm/array/min.test.d.ts +2 -0
  182. package/esm/array/odd.d.ts +6 -6
  183. package/esm/array/odd.js +14 -16
  184. package/esm/array/odd.test.d.ts +2 -0
  185. package/esm/array/oddIndexes.d.ts +4 -4
  186. package/esm/array/oddIndexes.js +8 -9
  187. package/esm/array/oddIndexes.test.d.ts +2 -0
  188. package/esm/array/pluck.d.ts +8 -8
  189. package/esm/array/pluck.js +22 -24
  190. package/esm/array/pluck.test.d.ts +2 -0
  191. package/esm/array/pushUnique.d.ts +5 -5
  192. package/esm/array/pushUnique.js +13 -14
  193. package/esm/array/pushUnique.test.d.ts +2 -0
  194. package/esm/array/range.d.ts +4 -4
  195. package/esm/array/range.js +20 -21
  196. package/esm/array/range.test.d.ts +2 -0
  197. package/esm/array/sum.d.ts +6 -6
  198. package/esm/array/sum.js +27 -29
  199. package/esm/array/sum.test.d.ts +2 -0
  200. package/esm/array/unique.d.ts +4 -4
  201. package/esm/array/unique.js +13 -15
  202. package/esm/array/unique.test.d.ts +2 -0
  203. package/esm/array/unshiftUnique.d.ts +5 -5
  204. package/esm/array/unshiftUnique.js +13 -14
  205. package/esm/array/unshiftUnique.test.d.ts +2 -0
  206. package/esm/index.d.ts +56 -56
  207. package/esm/mixed/areEqual/areEqual.d.ts +4 -4
  208. package/esm/mixed/areEqual/areEqual.js +22 -23
  209. package/esm/mixed/areEqual/areEqual.test.d.ts +2 -0
  210. package/esm/mixed/clone/clone.d.ts +4 -4
  211. package/esm/mixed/clone/clone.js +11 -16
  212. package/esm/mixed/clone/clone.test.d.ts +2 -0
  213. package/esm/mixed/shuffle/shuffle.d.ts +4 -4
  214. package/esm/mixed/shuffle/shuffle.js +13 -14
  215. package/esm/mixed/shuffle/shuffle.test.d.ts +2 -0
  216. package/esm/number/round.d.ts +4 -4
  217. package/esm/number/round.js +8 -9
  218. package/esm/object/except.d.ts +4 -4
  219. package/esm/object/except.js +11 -13
  220. package/esm/object/except.test.d.ts +2 -0
  221. package/esm/object/flatten.d.ts +4 -4
  222. package/esm/object/flatten.js +37 -38
  223. package/esm/object/flatten.test.d.ts +2 -0
  224. package/esm/object/get.d.ts +4 -4
  225. package/esm/object/get.js +23 -24
  226. package/esm/object/get.test.d.ts +2 -0
  227. package/esm/object/map.d.ts +4 -4
  228. package/esm/object/map.js +9 -10
  229. package/esm/object/merge.d.ts +1 -1
  230. package/esm/object/merge.js +94 -96
  231. package/esm/object/merge.test.d.ts +2 -0
  232. package/esm/object/only.d.ts +4 -4
  233. package/esm/object/only.js +16 -18
  234. package/esm/object/only.test.d.ts +2 -0
  235. package/esm/object/set.d.ts +5 -5
  236. package/esm/object/set.js +27 -28
  237. package/esm/object/set.test.d.ts +2 -0
  238. package/esm/object/sort.d.ts +4 -4
  239. package/esm/object/sort.js +14 -15
  240. package/esm/object/unset.d.ts +4 -4
  241. package/esm/object/unset.js +22 -24
  242. package/esm/object/unset.test.d.ts +2 -0
  243. package/esm/string/capitalize.d.ts +6 -6
  244. package/esm/string/capitalize.js +14 -16
  245. package/esm/string/extension.d.ts +4 -4
  246. package/esm/string/extension.js +10 -11
  247. package/esm/string/initials.d.ts +4 -4
  248. package/esm/string/initials.js +14 -15
  249. package/esm/string/initials.test.d.ts +2 -0
  250. package/esm/string/ltrim.d.ts +7 -7
  251. package/esm/string/ltrim.js +14 -16
  252. package/esm/string/readMoreChars.d.ts +5 -5
  253. package/esm/string/readMoreChars.js +10 -11
  254. package/esm/string/readMoreWords.d.ts +5 -5
  255. package/esm/string/readMoreWords.js +13 -14
  256. package/esm/string/removeFirst.d.ts +7 -7
  257. package/esm/string/removeFirst.js +12 -14
  258. package/esm/string/removeLast.d.ts +7 -7
  259. package/esm/string/removeLast.js +12 -14
  260. package/esm/string/repeatsOf.d.ts +7 -7
  261. package/esm/string/repeatsOf.js +16 -17
  262. package/esm/string/replaceAll.d.ts +8 -8
  263. package/esm/string/replaceAll.js +13 -15
  264. package/esm/string/replaceFirst.d.ts +8 -8
  265. package/esm/string/replaceFirst.js +13 -15
  266. package/esm/string/replaceLast.d.ts +8 -8
  267. package/esm/string/replaceLast.js +20 -21
  268. package/esm/string/rtrim.d.ts +7 -7
  269. package/esm/string/rtrim.js +14 -16
  270. package/esm/string/startsWithArabic.d.ts +2 -2
  271. package/esm/string/startsWithArabic.js +10 -12
  272. package/esm/string/toCamelCase.d.ts +1 -1
  273. package/esm/string/toCamelCase.js +10 -12
  274. package/esm/string/toCamelCase.test.d.ts +2 -0
  275. package/esm/string/toInputName.d.ts +5 -5
  276. package/esm/string/toInputName.js +20 -22
  277. package/esm/string/toKebabCase.d.ts +4 -4
  278. package/esm/string/toKebabCase.js +9 -11
  279. package/esm/string/toKebabCase.test.d.ts +2 -0
  280. package/esm/string/toSnakeCase.d.ts +7 -7
  281. package/esm/string/toSnakeCase.js +19 -20
  282. package/esm/string/toSnakeCase.test.d.ts +2 -0
  283. package/esm/string/toStudlyCase.d.ts +9 -9
  284. package/esm/string/toStudlyCase.js +18 -20
  285. package/esm/string/trim.d.ts +7 -7
  286. package/esm/string/trim.js +18 -20
  287. package/esm/string/ucfirst.d.ts +6 -6
  288. package/esm/string/ucfirst.js +10 -11
  289. package/esm/types.d.ts +1 -1
  290. package/esm/utils/debounce.d.ts +8 -8
  291. package/esm/utils/debounce.js +15 -16
  292. package/esm/utils/escapeRegex.d.ts +4 -4
  293. package/esm/utils/escapeRegex.js +7 -8
  294. package/esm/utils/escapeRegex.test.d.ts +2 -0
  295. package/package.json +1 -1
package/cjs/object/get.js CHANGED
@@ -1,26 +1,24 @@
1
- "use strict";
2
-
3
- function getValue(object, keyChain, defaultValue) {
4
- // split the key chain into array by dot
5
- // then loop through the array and get the value of each key until the last key
6
- // then return the value of the last key
7
- return keyChain.split(".").reduce((acc, key) => {
8
- if (acc === undefined || typeof acc !== "object") {
9
- return defaultValue;
10
- }
11
- if (acc === null) return acc;
12
- return acc.hasOwnProperty && acc.hasOwnProperty(key)
13
- ? acc[key]
14
- : defaultValue;
15
- }, object);
16
- }
17
- /**
18
- * Get the value of the given key
19
- */
20
- function get(object, key, defaultValue) {
21
- if (!object) return defaultValue;
22
- if (object[key]) return object[key];
23
- return getValue(object, key, defaultValue);
24
- }
25
-
26
- module.exports = get;
1
+ "use strict";
2
+ function getValue(object, keyChain, defaultValue) {
3
+ // split the key chain into array by dot
4
+ // then loop through the array and get the value of each key until the last key
5
+ // then return the value of the last key
6
+ return keyChain.split(".").reduce((acc, key) => {
7
+ if (acc === undefined || typeof acc !== "object") {
8
+ return defaultValue;
9
+ }
10
+ if (acc === null) return acc;
11
+ return acc.hasOwnProperty && acc.hasOwnProperty(key)
12
+ ? acc[key]
13
+ : defaultValue;
14
+ }, object);
15
+ }
16
+ /**
17
+ * Get the value of the given key
18
+ */
19
+ function get(object, key, defaultValue) {
20
+ if (!object) return defaultValue;
21
+ if (object[key]) return object[key];
22
+ return getValue(object, key, defaultValue);
23
+ }
24
+ module.exports = get;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=get.test.d.ts.map
@@ -1,5 +1,5 @@
1
- /**
2
- * Map the given object into an array
3
- */
4
- export default function map(object: any, callback: (key: string, value: any, object: any) => any): any[];
1
+ /**
2
+ * Map the given object into an array
3
+ */
4
+ export default function map(object: any, callback: (key: string, value: any, object: any) => any): any[];
5
5
  //# sourceMappingURL=map.d.ts.map
package/cjs/object/map.js CHANGED
@@ -1,12 +1,10 @@
1
- "use strict";
2
-
3
- /**
4
- * Map the given object into an array
5
- */
6
- function map(object, callback) {
7
- return Object.keys(object).map(key => {
8
- return callback(key, object[key], object);
9
- });
10
- }
11
-
12
- module.exports = map;
1
+ "use strict";
2
+ /**
3
+ * Map the given object into an array
4
+ */
5
+ function map(object, callback) {
6
+ return Object.keys(object).map(key => {
7
+ return callback(key, object[key], object);
8
+ });
9
+ }
10
+ module.exports = map;
@@ -1,2 +1,2 @@
1
- export default function merge(...objects: any[]): any;
1
+ export default function merge(...objects: any[]): any;
2
2
  //# sourceMappingURL=merge.d.ts.map
@@ -1,104 +1,99 @@
1
- "use strict";
2
-
3
- var Is = require("@mongez/supportive-is");
4
-
5
- function _interopDefaultLegacy(e) {
6
- return e && typeof e === "object" && "default" in e ? e : { default: e };
7
- }
8
-
9
- var Is__default = /*#__PURE__*/ _interopDefaultLegacy(Is);
10
-
11
- /**
12
- * Disclaimer
13
- * This function is originally taken from https://github.com/jhildenbiddle/mergician
14
- * But removed unnecessary parts and added some types, also add some comments and updated constant/variable names and types
15
- */
16
- const isObject = Is__default["default"].plainObject;
17
- function isDescriptor(object) {
18
- if (!isObject(object)) {
19
- return false;
20
- }
21
- return (
22
- ("get" in object && typeof object.get === "function") ||
23
- ("set" in object && typeof object.set === "function") ||
24
- ("value" in object &&
25
- ("writable" in object ||
26
- "enumerable" in object ||
27
- "configurable" in object))
28
- );
29
- }
30
- function merge(...objects) {
31
- if (objects.length === 0 && !objects[0]) return objects[0];
32
- const refinedObjects = [];
33
- for (let object of objects) {
34
- if (isObject(object)) {
35
- refinedObjects.push(object);
36
- }
37
- }
38
- if (refinedObjects.length === 0) {
39
- // return last value
40
- return objects[objects.length - 1];
41
- }
42
- const result = refinedObjects.reduce((targetObject, srcObject) => {
43
- let keys = Object.keys(srcObject);
44
- for (let i = 0; i < keys.length; i++) {
45
- const key = keys[i];
46
- if (key in srcObject === false) {
47
- continue;
48
- }
49
- const srcValue = srcObject[key];
50
- const targetValue = targetObject[key];
51
- let mergedObject = srcValue;
52
- if (Array.isArray(mergedObject)) {
53
- mergedObject = [...mergedObject];
54
- } else if (isObject(mergedObject) && !isDescriptor(mergedObject)) {
55
- if (isObject(targetValue)) {
56
- mergedObject = merge(targetValue, mergedObject);
57
- } else {
58
- mergedObject = merge(mergedObject);
59
- }
60
- }
61
- // New descriptor returned via callback
62
- if (isDescriptor(mergedObject)) {
63
- // Defining properties using Object.defineProperty() works
64
- // different than using the assignment operator (obj.a = 1).
65
- // Specifically, the descriptor properties 'configurable',
66
- // 'enumerable', and 'writable' default to 'false' when
67
- // using Object.defineProperty() but to 'true' when using
68
- // the assignment operator. The code below ensures that
69
- // descriptors returned from callbacks are treated as if
70
- // they were assigned using the assignment operator unless
71
- // those properties are explicitly defined in the
72
- // descriptor. This allow merging properties that may
73
- // otherwise fail due to 'configurable' or 'writable' being
74
- // set to 'false'.
75
- // Accessor and data descriptor
76
- mergedObject.configurable = !("configurable" in mergedObject)
77
- ? true
78
- : mergedObject.configurable;
79
- mergedObject.enumerable = !("enumerable" in mergedObject)
80
- ? true
81
- : mergedObject.enumerable;
82
- // Data descriptor
83
- if ("value" in mergedObject && !("writable" in mergedObject)) {
84
- mergedObject.writable = true;
85
- }
86
- Object.defineProperty(targetObject, key, mergedObject);
87
- } else {
88
- const mergeDescriptor = Object.getOwnPropertyDescriptor(srcObject, key);
89
- // Accessors (getter/setter)
90
- if ("get" in mergeDescriptor) {
91
- Object.defineProperty(targetObject, key, mergeDescriptor);
92
- }
93
- // Standard values
94
- else {
95
- targetObject[key] = mergedObject;
96
- }
97
- }
98
- }
99
- return targetObject;
100
- }, {});
101
- return result;
102
- }
103
-
104
- module.exports = merge;
1
+ "use strict";
2
+ var Is = require("@mongez/supportive-is");
3
+ function _interopDefault(e) {
4
+ return e && e.__esModule ? e : { default: e };
5
+ }
6
+ var Is__default = /*#__PURE__*/ _interopDefault(Is);
7
+ /**
8
+ * Disclaimer
9
+ * This function is originally taken from https://github.com/jhildenbiddle/mergician
10
+ * But removed unnecessary parts and added some types, also add some comments and updated constant/variable names and types
11
+ */
12
+ const isObject = Is__default.default.plainObject;
13
+ function isDescriptor(object) {
14
+ if (!isObject(object)) {
15
+ return false;
16
+ }
17
+ return (
18
+ ("get" in object && typeof object.get === "function") ||
19
+ ("set" in object && typeof object.set === "function") ||
20
+ ("value" in object &&
21
+ ("writable" in object ||
22
+ "enumerable" in object ||
23
+ "configurable" in object))
24
+ );
25
+ }
26
+ function merge(...objects) {
27
+ if (objects.length === 0) return objects[0];
28
+ const refinedObjects = [];
29
+ for (let object of objects) {
30
+ if (isObject(object)) {
31
+ refinedObjects.push(object);
32
+ }
33
+ }
34
+ if (refinedObjects.length === 0) {
35
+ // return last value
36
+ return objects[objects.length - 1];
37
+ }
38
+ const result = refinedObjects.reduce((targetObject, srcObject) => {
39
+ let keys = Object.keys(srcObject);
40
+ for (let i = 0; i < keys.length; i++) {
41
+ const key = keys[i];
42
+ if (key in srcObject === false) {
43
+ continue;
44
+ }
45
+ const srcValue = srcObject[key];
46
+ const targetValue = targetObject[key];
47
+ let mergedObject = srcValue;
48
+ if (Array.isArray(mergedObject)) {
49
+ mergedObject = [...mergedObject];
50
+ } else if (isObject(mergedObject) && !isDescriptor(mergedObject)) {
51
+ if (isObject(targetValue)) {
52
+ mergedObject = merge(targetValue, mergedObject);
53
+ } else {
54
+ mergedObject = merge(mergedObject);
55
+ }
56
+ }
57
+ // New descriptor returned via callback
58
+ if (isDescriptor(mergedObject)) {
59
+ // Defining properties using Object.defineProperty() works
60
+ // different than using the assignment operator (obj.a = 1).
61
+ // Specifically, the descriptor properties 'configurable',
62
+ // 'enumerable', and 'writable' default to 'false' when
63
+ // using Object.defineProperty() but to 'true' when using
64
+ // the assignment operator. The code below ensures that
65
+ // descriptors returned from callbacks are treated as if
66
+ // they were assigned using the assignment operator unless
67
+ // those properties are explicitly defined in the
68
+ // descriptor. This allow merging properties that may
69
+ // otherwise fail due to 'configurable' or 'writable' being
70
+ // set to 'false'.
71
+ // Accessor and data descriptor
72
+ mergedObject.configurable = !("configurable" in mergedObject)
73
+ ? true
74
+ : mergedObject.configurable;
75
+ mergedObject.enumerable = !("enumerable" in mergedObject)
76
+ ? true
77
+ : mergedObject.enumerable;
78
+ // Data descriptor
79
+ if ("value" in mergedObject && !("writable" in mergedObject)) {
80
+ mergedObject.writable = true;
81
+ }
82
+ Object.defineProperty(targetObject, key, mergedObject);
83
+ } else {
84
+ const mergeDescriptor = Object.getOwnPropertyDescriptor(srcObject, key);
85
+ // Accessors (getter/setter)
86
+ if ("get" in mergeDescriptor) {
87
+ Object.defineProperty(targetObject, key, mergeDescriptor);
88
+ }
89
+ // Standard values
90
+ else {
91
+ targetObject[key] = mergedObject;
92
+ }
93
+ }
94
+ }
95
+ return targetObject;
96
+ }, {});
97
+ return result;
98
+ }
99
+ module.exports = merge;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=merge.test.d.ts.map
@@ -1,5 +1,5 @@
1
- /**
2
- * Get only the given keys from the given object
3
- */
4
- export default function only(object: any, keys: Array<string>): any;
1
+ /**
2
+ * Get only the given keys from the given object
3
+ */
4
+ export default function only(object: any, keys: Array<string>): any;
5
5
  //# sourceMappingURL=only.d.ts.map
@@ -1,20 +1,17 @@
1
- "use strict";
2
-
3
- var get = require("./get.js");
4
- var set = require("./set.js");
5
-
6
- /**
7
- * Get only the given keys from the given object
8
- */
9
- function only(object, keys) {
10
- const newObject = {};
11
- for (const key of keys) {
12
- const value = get(object, key, undefined);
13
- if (value !== undefined) {
14
- set(newObject, key, value);
15
- }
16
- }
17
- return newObject;
18
- }
19
-
20
- module.exports = only;
1
+ "use strict";
2
+ var get = require("./get.js"),
3
+ set = require("./set.js");
4
+ /**
5
+ * Get only the given keys from the given object
6
+ */
7
+ function only(object, keys) {
8
+ const newObject = {};
9
+ for (const key of keys) {
10
+ const value = get(object, key, undefined);
11
+ if (value !== undefined) {
12
+ set(newObject, key, value);
13
+ }
14
+ }
15
+ return newObject;
16
+ }
17
+ module.exports = only;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=only.test.d.ts.map
@@ -1,6 +1,6 @@
1
- /**
2
- * Set the given value to the given key
3
- * The key supports dot.notation syntax
4
- */
5
- export default function set(object: Record<string, any>, key: string, value: any): object;
1
+ /**
2
+ * Set the given value to the given key
3
+ * The key supports dot.notation syntax
4
+ */
5
+ export default function set(object: Record<string, any>, key: string, value: any): object;
6
6
  //# sourceMappingURL=set.d.ts.map
package/cjs/object/set.js CHANGED
@@ -1,30 +1,28 @@
1
- "use strict";
2
-
3
- /**
4
- * Set the given value to the given key
5
- * The key supports dot.notation syntax
6
- */
7
- function set(object, key, value) {
8
- if (!object || typeof object !== "object") return object;
9
- if (!key.includes(".")) {
10
- object[key] = value;
11
- return object;
12
- }
13
- const keys = key.split(".");
14
- let currentObject = object;
15
- for (let i = 0; i < keys.length; i++) {
16
- const key = keys[i];
17
- if (i + 1 === keys.length) {
18
- currentObject[key] = value;
19
- } else {
20
- if (typeof currentObject[key] === "undefined") {
21
- currentObject = currentObject[key] = {};
22
- } else {
23
- currentObject = currentObject[key];
24
- }
25
- }
26
- }
27
- return object;
28
- }
29
-
30
- module.exports = set;
1
+ "use strict";
2
+ /**
3
+ * Set the given value to the given key
4
+ * The key supports dot.notation syntax
5
+ */
6
+ function set(object, key, value) {
7
+ if (!object || typeof object !== "object") return object;
8
+ if (!key.includes(".")) {
9
+ object[key] = value;
10
+ return object;
11
+ }
12
+ const keys = key.split(".");
13
+ let currentObject = object;
14
+ for (let i = 0; i < keys.length; i++) {
15
+ const key = keys[i];
16
+ if (i + 1 === keys.length) {
17
+ currentObject[key] = value;
18
+ } else {
19
+ if (typeof currentObject[key] === "undefined") {
20
+ currentObject = currentObject[key] = {};
21
+ } else {
22
+ currentObject = currentObject[key];
23
+ }
24
+ }
25
+ }
26
+ return object;
27
+ }
28
+ module.exports = set;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=set.test.d.ts.map
@@ -1,5 +1,5 @@
1
- /**
2
- * Sort the given object by its keys
3
- */
4
- export default function sort(object: any, recursive?: boolean): any;
1
+ /**
2
+ * Sort the given object by its keys
3
+ */
4
+ export default function sort(object: any, recursive?: boolean): any;
5
5
  //# sourceMappingURL=sort.d.ts.map
@@ -1,17 +1,15 @@
1
- "use strict";
2
-
3
- /**
4
- * Sort the given object by its keys
5
- */
6
- function sort(object, recursive = true) {
7
- if (!object || typeof object !== "object" || Array.isArray(object))
8
- return object;
9
- const sortedObject = {};
10
- const keys = Object.keys(object).sort();
11
- keys.forEach(key => {
12
- sortedObject[key] = recursive ? sort(object[key]) : object[key];
13
- });
14
- return sortedObject;
15
- }
16
-
17
- module.exports = sort;
1
+ "use strict";
2
+ /**
3
+ * Sort the given object by its keys
4
+ */
5
+ function sort(object, recursive = true) {
6
+ if (!object || typeof object !== "object" || Array.isArray(object))
7
+ return object;
8
+ const sortedObject = {};
9
+ const keys = Object.keys(object).sort();
10
+ keys.forEach(key => {
11
+ sortedObject[key] = recursive ? sort(object[key]) : object[key];
12
+ });
13
+ return sortedObject;
14
+ }
15
+ module.exports = sort;
@@ -1,5 +1,5 @@
1
- /**
2
- * Remove the given keys from the given object using dot notation syntax
3
- */
4
- export default function unset(object: any, keys: string[]): any;
1
+ /**
2
+ * Remove the given keys from the given object using dot notation syntax
3
+ */
4
+ export default function unset(object: any, keys: string[]): any;
5
5
  //# sourceMappingURL=unset.d.ts.map
@@ -1,26 +1,23 @@
1
- "use strict";
2
-
3
- var get = require("./get.js");
4
-
5
- /**
6
- * Remove the given keys from the given object using dot notation syntax
7
- */
8
- function unset(object, keys) {
9
- if (!object || typeof object !== "object" || Array.isArray(object))
10
- return object;
11
- // remove the given keys from the given object
12
- // keys can be nested using dot notation syntax
13
- for (const key of keys) {
14
- const keyPath = key.split(".");
15
- if (keyPath.length === 1) {
16
- delete object[key];
17
- } else {
18
- const lastKey = keyPath.pop();
19
- const parent = get(object, keyPath.join("."));
20
- delete parent[lastKey];
21
- }
22
- }
23
- return object;
24
- }
25
-
26
- module.exports = unset;
1
+ "use strict";
2
+ var get = require("./get.js");
3
+ /**
4
+ * Remove the given keys from the given object using dot notation syntax
5
+ */
6
+ function unset(object, keys) {
7
+ if (!object || typeof object !== "object" || Array.isArray(object))
8
+ return object;
9
+ // remove the given keys from the given object
10
+ // keys can be nested using dot notation syntax
11
+ for (const key of keys) {
12
+ const keyPath = key.split(".");
13
+ if (keyPath.length === 1) {
14
+ delete object[key];
15
+ } else {
16
+ const lastKey = keyPath.pop();
17
+ const parent = get(object, keyPath.join("."));
18
+ delete parent[lastKey];
19
+ }
20
+ }
21
+ return object;
22
+ }
23
+ module.exports = unset;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=unset.test.d.ts.map
@@ -1,7 +1,7 @@
1
- /**
2
- * Capitalize the first letter of the string
3
- *
4
- * @return string
5
- */
6
- export default function capitalize(string: string): string;
1
+ /**
2
+ * Capitalize the first letter of the string
3
+ *
4
+ * @return string
5
+ */
6
+ export default function capitalize(string: string): string;
7
7
  //# sourceMappingURL=capitalize.d.ts.map
@@ -1,18 +1,15 @@
1
- "use strict";
2
-
3
- var ucfirst = require("./ucfirst.js");
4
-
5
- /**
6
- * Capitalize the first letter of the string
7
- *
8
- * @return string
9
- */
10
- function capitalize(string) {
11
- if (!string) return "";
12
- return string
13
- .split(" ")
14
- .map(word => ucfirst(word))
15
- .join(" ");
16
- }
17
-
18
- module.exports = capitalize;
1
+ "use strict";
2
+ var ucfirst = require("./ucfirst.js");
3
+ /**
4
+ * Capitalize the first letter of the string
5
+ *
6
+ * @return string
7
+ */
8
+ function capitalize(string) {
9
+ if (!string) return "";
10
+ return string
11
+ .split(" ")
12
+ .map(word => ucfirst(word))
13
+ .join(" ");
14
+ }
15
+ module.exports = capitalize;
@@ -1,5 +1,5 @@
1
- /**
2
- * Get the extension of the file name
3
- */
4
- export default function extension(string: string): string;
1
+ /**
2
+ * Get the extension of the file name
3
+ */
4
+ export default function extension(string: string): string;
5
5
  //# sourceMappingURL=extension.d.ts.map
@@ -1,13 +1,11 @@
1
- "use strict";
2
-
3
- /**
4
- * Get the extension of the file name
5
- */
6
- function extension(string) {
7
- if (!string) return "";
8
- const regex = /(?:\.([^.]+))?$/,
9
- extension = regex.exec(string);
10
- return extension ? extension[1] : "";
11
- }
12
-
13
- module.exports = extension;
1
+ "use strict";
2
+ /**
3
+ * Get the extension of the file name
4
+ */
5
+ function extension(string) {
6
+ if (!string) return "";
7
+ const regex = /(?:\.([^.]+))?$/,
8
+ extension = regex.exec(string);
9
+ return extension ? extension[1] : "";
10
+ }
11
+ module.exports = extension;