@stryke/helpers 0.10.5 → 0.10.7

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 (136) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +1 -1
  3. package/dist/arg-identity.d.cts.map +1 -1
  4. package/dist/arg-identity.d.mts.map +1 -1
  5. package/dist/arg-identity.mjs.map +1 -1
  6. package/dist/convert/src/index.cjs +4 -0
  7. package/dist/convert/src/index.mjs +6 -0
  8. package/dist/convert/src/parse-type-definition.cjs +1 -0
  9. package/dist/convert/src/parse-type-definition.mjs +3 -0
  10. package/dist/convert/src/string-to-utf8-array.cjs +5 -0
  11. package/dist/convert/src/string-to-utf8-array.mjs +6 -0
  12. package/dist/convert/src/string-to-utf8-array.mjs.map +1 -0
  13. package/dist/convert/src/utf8-array-to-string.cjs +5 -0
  14. package/dist/convert/src/utf8-array-to-string.mjs +6 -0
  15. package/dist/convert/src/utf8-array-to-string.mjs.map +1 -0
  16. package/dist/debounce.cjs +5 -4
  17. package/dist/debounce.d.cts +4 -6
  18. package/dist/debounce.d.cts.map +1 -1
  19. package/dist/debounce.d.mts +4 -6
  20. package/dist/debounce.d.mts.map +1 -1
  21. package/dist/debounce.mjs +5 -4
  22. package/dist/debounce.mjs.map +1 -1
  23. package/dist/deep-clone.cjs +2 -1
  24. package/dist/deep-clone.d.cts.map +1 -1
  25. package/dist/deep-clone.d.mts.map +1 -1
  26. package/dist/deep-clone.mjs +2 -1
  27. package/dist/deep-clone.mjs.map +1 -1
  28. package/dist/delay.cjs +2 -1
  29. package/dist/delay.d.cts +1 -3
  30. package/dist/delay.d.cts.map +1 -1
  31. package/dist/delay.d.mts +1 -3
  32. package/dist/delay.d.mts.map +1 -1
  33. package/dist/delay.mjs +2 -1
  34. package/dist/delay.mjs.map +1 -1
  35. package/dist/filter-empty.d.cts.map +1 -1
  36. package/dist/filter-empty.d.mts.map +1 -1
  37. package/dist/filter-empty.mjs.map +1 -1
  38. package/dist/flatten-object.cjs +2 -1
  39. package/dist/flatten-object.d.cts.map +1 -1
  40. package/dist/flatten-object.d.mts.map +1 -1
  41. package/dist/flatten-object.mjs +2 -1
  42. package/dist/flatten-object.mjs.map +1 -1
  43. package/dist/get-field.cjs +14 -7
  44. package/dist/get-field.d.cts +123 -125
  45. package/dist/get-field.d.cts.map +1 -1
  46. package/dist/get-field.d.mts +123 -125
  47. package/dist/get-field.d.mts.map +1 -1
  48. package/dist/get-field.mjs +14 -7
  49. package/dist/get-field.mjs.map +1 -1
  50. package/dist/get-ordered-by.d.cts.map +1 -1
  51. package/dist/get-ordered-by.d.mts.map +1 -1
  52. package/dist/get-ordered-by.mjs.map +1 -1
  53. package/dist/identity.d.cts.map +1 -1
  54. package/dist/identity.d.mts.map +1 -1
  55. package/dist/identity.mjs.map +1 -1
  56. package/dist/is-equal.d.cts.map +1 -1
  57. package/dist/is-equal.d.mts.map +1 -1
  58. package/dist/is-equal.mjs.map +1 -1
  59. package/dist/match-sorter.cjs +2 -2
  60. package/dist/match-sorter.mjs +2 -2
  61. package/dist/match-sorter.mjs.map +1 -1
  62. package/dist/noop.d.cts.map +1 -1
  63. package/dist/noop.d.mts.map +1 -1
  64. package/dist/noop.mjs.map +1 -1
  65. package/dist/omit.mjs.map +1 -1
  66. package/dist/pick.mjs.map +1 -1
  67. package/dist/remove-accents.cjs +1 -3
  68. package/dist/remove-accents.d.cts.map +1 -1
  69. package/dist/remove-accents.d.mts.map +1 -1
  70. package/dist/remove-accents.mjs +1 -3
  71. package/dist/remove-accents.mjs.map +1 -1
  72. package/dist/remove-empty-items.d.cts.map +1 -1
  73. package/dist/remove-empty-items.d.mts.map +1 -1
  74. package/dist/remove-empty-items.mjs.map +1 -1
  75. package/dist/semaphore.cjs +10 -10
  76. package/dist/semaphore.d.cts +10 -10
  77. package/dist/semaphore.d.cts.map +1 -1
  78. package/dist/semaphore.d.mts +10 -10
  79. package/dist/semaphore.d.mts.map +1 -1
  80. package/dist/semaphore.mjs +10 -10
  81. package/dist/semaphore.mjs.map +1 -1
  82. package/dist/set-field.cjs +1 -1
  83. package/dist/set-field.d.cts.map +1 -1
  84. package/dist/set-field.d.mts.map +1 -1
  85. package/dist/set-field.mjs +1 -1
  86. package/dist/set-field.mjs.map +1 -1
  87. package/dist/throttle.d.cts.map +1 -1
  88. package/dist/throttle.d.mts.map +1 -1
  89. package/dist/throttle.mjs.map +1 -1
  90. package/dist/timeout.d.cts.map +1 -1
  91. package/dist/timeout.d.mts.map +1 -1
  92. package/dist/timeout.mjs.map +1 -1
  93. package/dist/to-deep-key.d.cts.map +1 -1
  94. package/dist/to-deep-key.d.mts.map +1 -1
  95. package/dist/to-deep-key.mjs.map +1 -1
  96. package/dist/type-checks/src/index.cjs +21 -0
  97. package/dist/type-checks/src/index.mjs +23 -0
  98. package/dist/type-checks/src/is-buffer.cjs +13 -0
  99. package/dist/type-checks/src/is-buffer.mjs +14 -0
  100. package/dist/type-checks/src/is-buffer.mjs.map +1 -0
  101. package/dist/type-checks/src/is-collection.cjs +1 -0
  102. package/dist/type-checks/src/is-collection.mjs +3 -0
  103. package/dist/type-checks/src/is-deep-key.cjs +6 -0
  104. package/dist/type-checks/src/is-deep-key.mjs +6 -0
  105. package/dist/type-checks/src/is-deep-key.mjs.map +1 -1
  106. package/dist/type-checks/src/is-function.cjs +3 -1
  107. package/dist/type-checks/src/is-function.mjs +1 -1
  108. package/dist/type-checks/src/is-object-index.cjs +6 -0
  109. package/dist/type-checks/src/is-object-index.mjs +6 -0
  110. package/dist/type-checks/src/is-object-index.mjs.map +1 -1
  111. package/dist/type-checks/src/is-plain-object.cjs +3 -2
  112. package/dist/type-checks/src/is-plain-object.mjs +3 -3
  113. package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
  114. package/dist/type-checks/src/is-set-string.cjs +1 -1
  115. package/dist/type-checks/src/is-set-string.mjs +1 -1
  116. package/dist/type-checks/src/property-exists.cjs +1 -0
  117. package/dist/type-checks/src/property-exists.mjs +1 -1
  118. package/dist/type-checks/src/type-detect.cjs +15 -0
  119. package/dist/type-checks/src/type-detect.mjs +17 -0
  120. package/dist/type-checks/src/type-detect.mjs.map +1 -0
  121. package/dist/types/src/object.d.cts +1 -1
  122. package/dist/types/src/object.d.mts +1 -1
  123. package/dist/unflatten-object.cjs +1 -1
  124. package/dist/unflatten-object.d.cts +1 -1
  125. package/dist/unflatten-object.d.cts.map +1 -1
  126. package/dist/unflatten-object.d.mts +1 -1
  127. package/dist/unflatten-object.d.mts.map +1 -1
  128. package/dist/unflatten-object.mjs +1 -1
  129. package/dist/unflatten-object.mjs.map +1 -1
  130. package/dist/union.d.cts.map +1 -1
  131. package/dist/union.d.mts.map +1 -1
  132. package/dist/union.mjs.map +1 -1
  133. package/dist/with-timeout.d.cts.map +1 -1
  134. package/dist/with-timeout.d.mts.map +1 -1
  135. package/dist/with-timeout.mjs.map +1 -1
  136. package/package.json +2 -2
@@ -9,244 +9,242 @@ type GetField<T, P> = P extends `${infer Left}.${infer Right}` ? Left extends ke
9
9
  /**
10
10
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
11
11
  *
12
- * @template T - The type of the object.
13
- * @template K - The type of the key in the object.
14
- * @template D - The type of the default value.
12
+ * @typeParam T - The type of the object.
13
+ * @typeParam K - The type of the key in the object.
15
14
  *
16
- * @param {T} object - The object to query.
17
- * @param {K | [K]} path - The path of the property to get.
18
- * @returns {T[K]} - Returns the resolved value.
15
+ * @param object - The object to query.
16
+ * @param path - The path of the property to get.
17
+ * @returns The resolved value.
19
18
  */
20
19
  declare function getField<T extends object, K extends keyof T>(object: T, path: K | readonly [K]): T[K];
21
20
  /**
22
21
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
23
22
  *
24
- * @template T - The type of the object.
25
- * @template K - The type of the key in the object.
23
+ * @typeParam T - The type of the object.
24
+ * @typeParam K - The type of the key in the object.
26
25
  *
27
- * @param {T | null | undefined} object - The object to query.
28
- * @param {K | [K]} path - The path of the property to get.
29
- * @returns {T[K] | undefined} - Returns the resolved value.
26
+ * @param object - The object to query.
27
+ * @param path - The path of the property to get.
28
+ * @returns The resolved value or undefined.
30
29
  */
31
30
  declare function getField<T extends object, K extends keyof T>(object: T | null | undefined, path: K | readonly [K]): T[K] | undefined;
32
31
  /**
33
32
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
34
33
  *
35
- * @template T - The type of the object.
36
- * @template K - The type of the key in the object.
37
- * @template D - The type of the default value.
34
+ * @typeParam T - The type of the object.
35
+ * @typeParam K - The type of the key in the object.
36
+ * @typeParam D - The type of the default value.
38
37
  *
39
- * @param {T | null | undefined} object - The object to query.
40
- * @param {K | [K]} path - The path of the property to get.
41
- * @param {D} defaultValue - The value returned if the resolved value is undefined.
42
- * @returns {Exclude<T[K], undefined> | D} - Returns the resolved value.
38
+ * @param object - The object to query.
39
+ * @param path - The path of the property to get.
40
+ * @param defaultValue - The value returned if the resolved value is undefined.
41
+ * @returns The resolved value or default value.
43
42
  */
44
43
  declare function getField<T extends object, K extends keyof T, D>(object: T | null | undefined, path: K | readonly [K], defaultValue: D): Exclude<T[K], undefined> | D;
45
44
  /**
46
45
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
47
46
  *
48
- * @template T - The type of the object.
49
- * @template K1 - The type of the first key in the object.
50
- * @template K2 - The type of the second key in the object.
47
+ * @typeParam T - The type of the object.
48
+ * @typeParam K1 - The type of the first key in the object.
49
+ * @typeParam K2 - The type of the second key in the object.
51
50
  *
52
- * @param {T} object - The object to query.
53
- * @param {[K1, K2]} path - The path of the property to get.
54
- * @returns {T[K1][K2]} - Returns the resolved value.
51
+ * @param object - The object to query.
52
+ * @param path - The path of the property to get.
53
+ * @returns The resolved value.
55
54
  */
56
55
  declare function getField<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T, path: readonly [K1, K2]): T[K1][K2];
57
56
  /**
58
57
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
59
58
  *
60
- * @template T - The type of the object.
61
- * @template K1 - The type of the first key in the object.
62
- * @template K2 - The type of the second key in the object.
59
+ * @typeParam T - The type of the object.
60
+ * @typeParam K1 - The type of the first key in the object.
61
+ * @typeParam K2 - The type of the second key in the object.
63
62
  *
64
- * @param {T | null | undefined} object - The object to query.
65
- * @param {[K1, K2]} path - The path of the property to get.
66
- * @returns {T[K1][K2] | undefined} - Returns the resolved value.
63
+ * @param object - The object to query.
64
+ * @param path - The path of the property to get.
65
+ * @returns The resolved value or undefined.
67
66
  */
68
67
  declare function getField<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T | null | undefined, path: readonly [K1, K2]): T[K1][K2] | undefined;
69
68
  /**
70
69
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
71
70
  *
72
- * @template T - The type of the object.
73
- * @template K1 - The type of the first key in the object.
74
- * @template K2 - The type of the second key in the object.
75
- * @template D - The type of the default value.
71
+ * @typeParam T - The type of the object.
72
+ * @typeParam K1 - The type of the first key in the object.
73
+ * @typeParam K2 - The type of the second key in the object.
74
+ * @typeParam D - The type of the default value.
76
75
  *
77
- * @param {T | null | undefined} object - The object to query.
78
- * @param {[K1, K2]} path - The path of the property to get.
79
- * @param {D} defaultValue - The value returned if the resolved value is undefined.
80
- * @returns {Exclude<T[K1][K2], undefined> | D} - Returns the resolved value.
76
+ * @param object - The object to query.
77
+ * @param path - The path of the property to get.
78
+ * @param defaultValue - The value returned if the resolved value is undefined.
79
+ * @returns The resolved value or default value.
81
80
  */
82
81
  declare function getField<T extends object, K1 extends keyof T, K2 extends keyof T[K1], D>(object: T | null | undefined, path: readonly [K1, K2], defaultValue: D): Exclude<T[K1][K2], undefined> | D;
83
82
  /**
84
83
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
85
84
  *
86
- * @template T - The type of the object.
87
- * @template K1 - The type of the first key in the object.
88
- * @template K2 - The type of the second key in the object.
89
- * @template K3 - The type of the third key in the object.
85
+ * @typeParam T - The type of the object.
86
+ * @typeParam K1 - The type of the first key in the object.
87
+ * @typeParam K2 - The type of the second key in the object.
88
+ * @typeParam K3 - The type of the third key in the object.
90
89
  *
91
- * @param {T} object - The object to query.
92
- * @param {[K1, K2, K3]} path - The path of the property to get.
93
- * @returns {T[K1][K2][K3]} - Returns the resolved value.
90
+ * @param object - The object to query.
91
+ * @param path - The path of the property to get.
92
+ * @returns The resolved value.
94
93
  */
95
94
  declare function getField<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T, path: readonly [K1, K2, K3]): T[K1][K2][K3];
96
95
  /**
97
96
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
98
97
  *
99
- * @template T - The type of the object.
100
- * @template K1 - The type of the first key in the object.
101
- * @template K2 - The type of the second key in the object.
102
- * @template K3 - The type of the third key in the object.
98
+ * @typeParam T - The type of the object.
99
+ * @typeParam K1 - The type of the first key in the object.
100
+ * @typeParam K2 - The type of the second key in the object.
101
+ * @typeParam K3 - The type of the third key in the object.
103
102
  *
104
- * @param {T | null | undefined} object - The object to query.
105
- * @param {[K1, K2, K3]} path - The path of the property to get.
106
- * @returns {T[K1][K2][K3] | undefined} - Returns the resolved value.
103
+ * @param object - The object to query.
104
+ * @param path - The path of the property to get.
105
+ * @returns The resolved value or undefined.
107
106
  */
108
107
  declare function getField<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T | null | undefined, path: readonly [K1, K2, K3]): T[K1][K2][K3] | undefined;
109
108
  /**
110
109
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
111
110
  *
112
- * @template T - The type of the object.
113
- * @template K1 - The type of the first key in the object.
114
- * @template K2 - The type of the second key in the object.
115
- * @template K3 - The type of the third key in the object.
116
- * @template D - The type of the default value.
111
+ * @typeParam T - The type of the object.
112
+ * @typeParam K1 - The type of the first key in the object.
113
+ * @typeParam K2 - The type of the second key in the object.
114
+ * @typeParam K3 - The type of the third key in the object.
115
+ * @typeParam D - The type of the default value.
117
116
  *
118
- * @param {T | null | undefined} object - The object to query.
119
- * @param {[K1, K2, K3]} path - The path of the property to get.
120
- * @param {D} defaultValue - The value returned if the resolved value is undefined.
121
- * @returns {Exclude<T[K1][K2][K3], undefined> | D} - Returns the resolved value.
117
+ * @param object - The object to query.
118
+ * @param path - The path of the property to get.
119
+ * @param defaultValue - The value returned if the resolved value is undefined.
120
+ * @returns The resolved value or default value.
122
121
  */
123
122
  declare function getField<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], D>(object: T | null | undefined, path: readonly [K1, K2, K3], defaultValue: D): Exclude<T[K1][K2][K3], undefined> | D;
124
123
  /**
125
124
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
126
125
  *
127
- * @template T - The type of the object.
128
- * @template K1 - The type of the first key in the object.
129
- * @template K2 - The type of the second key in the object.
130
- * @template K3 - The type of the third key in the object.
131
- * @template K4 - The type of the fourth key in the object.
126
+ * @typeParam T - The type of the object.
127
+ * @typeParam K1 - The type of the first key in the object.
128
+ * @typeParam K2 - The type of the second key in the object.
129
+ * @typeParam K3 - The type of the third key in the object.
130
+ * @typeParam K4 - The type of the fourth key in the object.
132
131
  *
133
- * @param {T} object - The object to query.
134
- * @param {[K1, K2, K3, K4]} path - The path of the property to get.
135
- * @returns {T[K1][K2][K3][K4]} - Returns the resolved value.
132
+ * @param object - The object to query.
133
+ * @param path - The path of the property to get.
134
+ * @returns The resolved value.
136
135
  */
137
136
  declare function getField<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4];
138
137
  /**
139
138
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
140
139
  *
141
- * @template T - The type of the object.
142
- * @template K1 - The type of the first key in the object.
143
- * @template K2 - The type of the second key in the object.
144
- * @template K3 - The type of the third key in the object.
145
- * @template K4 - The type of the fourth key in the object.
140
+ * @typeParam T - The type of the object.
141
+ * @typeParam K1 - The type of the first key in the object.
142
+ * @typeParam K2 - The type of the second key in the object.
143
+ * @typeParam K3 - The type of the third key in the object.
144
+ * @typeParam K4 - The type of the fourth key in the object.
146
145
  *
147
- * @param {T | null | undefined} object - The object to query.
148
- * @param {[K1, K2, K3, K4]} path - The path of the property to get.
149
- * @returns {T[K1][K2][K3][K4] | undefined} - Returns the resolved value.
146
+ * @param object - The object to query.
147
+ * @param path - The path of the property to get.
148
+ * @returns The resolved value or undefined.
150
149
  */
151
150
  declare function getField<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T | null | undefined, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined;
152
151
  /**
153
152
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
154
153
  *
155
- * @template T - The type of the object.
156
- * @template K1 - The type of the first key in the object.
157
- * @template K2 - The type of the second key in the object.
158
- * @template K3 - The type of the third key in the object.
159
- * @template K4 - The type of the fourth key in the object.
160
- * @template D - The type of the default value.
154
+ * @typeParam T - The type of the object.
155
+ * @typeParam K1 - The type of the first key in the object.
156
+ * @typeParam K2 - The type of the second key in the object.
157
+ * @typeParam K3 - The type of the third key in the object.
158
+ * @typeParam K4 - The type of the fourth key in the object.
159
+ * @typeParam D - The type of the default value.
161
160
  *
162
- * @param {T | null | undefined} object - The object to query.
163
- * @param {[K1, K2, K3, K4]} path - The path of the property to get.
164
- * @param {D} defaultValue - The value returned if the resolved value is undefined.
165
- * @returns {Exclude<T[K1][K2][K3][K4], undefined> | D} - Returns the resolved value.
161
+ * @param object - The object to query.
162
+ * @param path - The path of the property to get.
163
+ * @param defaultValue - The value returned if the resolved value is undefined.
164
+ * @returns The resolved value or default value.
166
165
  */
167
166
  declare function getField<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], D>(object: T | null | undefined, path: readonly [K1, K2, K3, K4], defaultValue: D): Exclude<T[K1][K2][K3][K4], undefined> | D;
168
167
  /**
169
168
  * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
170
169
  *
171
- * @template T - The type of the value.
170
+ * @typeParam T - The type of the value.
172
171
  *
173
- * @param {Record<number, T>} object - The object to query.
174
- * @param {number} path - The path of the property to get.
175
- * @returns {T} - Returns the resolved value.
172
+ * @param object - The object to query.
173
+ * @param path - The path of the property to get.
174
+ * @returns The resolved value.
176
175
  */
177
176
  declare function getField<T>(object: Record<number, T>, path: number): T;
178
177
  /**
179
178
  * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
180
179
  *
181
- * @template T - The type of the value.
180
+ * @typeParam T - The type of the value.
182
181
  *
183
- * @param {Record<number, T> | null | undefined} object - The object to query.
184
- * @param {number} path - The path of the property to get.
185
- * @returns {T | undefined} - Returns the resolved value.
182
+ * @param object - The object to query.
183
+ * @param path - The path of the property to get.
184
+ * @returns The resolved value or undefined.
186
185
  */
187
186
  declare function getField<T>(object: Record<number, T> | null | undefined, path: number): T | undefined;
188
187
  /**
189
188
  * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
190
189
  *
191
- * @template T - The type of the value.
192
- * @template D - The type of the default value.
190
+ * @typeParam T - The type of the value.
191
+ * @typeParam D - The type of the default value.
193
192
  *
194
- * @param {Record<number, T> | null | undefined} object - The object to query.
195
- * @param {number} path - The path of the property to get.
196
- * @param {D} defaultValue - The value returned if the resolved value is undefined.
197
- * @returns {T | D} - Returns the resolved value.
193
+ * @param object - The object to query.
194
+ * @param path - The path of the property to get.
195
+ * @param defaultValue - The value returned if the resolved value is undefined.
196
+ * @returns The resolved value or default value.
198
197
  */
199
198
  declare function getField<T, D>(object: Record<number, T> | null | undefined, path: number, defaultValue: D): T | D;
200
199
  /**
201
200
  * Retrieves the value at a given path from a null or undefined object, returning the default value.
202
201
  *
203
- * @template D - The type of the default value.
202
+ * @typeParam D - The type of the default value.
204
203
  *
205
- * @param {null | undefined} object - The object to query.
206
- * @param {PropertyKey} path - The path of the property to get.
207
- * @param {D} defaultValue - The value returned if the resolved value is undefined.
208
- * @returns {D} - Returns the default value.
204
+ * @param object - The object to query.
205
+ * @param path - The path of the property to get.
206
+ * @param defaultValue - The value returned if the resolved value is undefined.
207
+ * @returns The default value.
209
208
  */
210
209
  declare function getField<D>(object: null | undefined, path: PropertyKey, defaultValue: D): D;
211
210
  /**
212
211
  * Retrieves the value at a given path from a null or undefined object, returning undefined.
213
212
  *
214
- * @param {null | undefined} object - The object to query.
215
- * @param {PropertyKey} path - The path of the property to get.
216
- * @returns {undefined} - Returns undefined.
213
+ * @param object - The object to query.
214
+ * @param path - The path of the property to get.
217
215
  */
218
216
  declare function getField(object: null | undefined, path: PropertyKey): undefined;
219
217
  /**
220
218
  * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.
221
219
  *
222
- * @template T - The type of the object.
223
- * @template P - The type of the path.
220
+ * @typeParam T - The type of the object.
221
+ * @typeParam P - The type of the path.
224
222
  *
225
- * @param {T} data - The object to query.
226
- * @param {P} path - The path of the property to get.
227
- * @returns {string extends P ? any : GetField<T, P>} - Returns the resolved value.
223
+ * @param data - The object to query.
224
+ * @param path - The path of the property to get.
225
+ * @returns The resolved value, or any if path is a general string.
228
226
  */
229
227
  declare function getField<T, P extends string>(data: T, path: P): string extends P ? any : GetField<T, P>;
230
228
  /**
231
229
  * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.
232
230
  *
233
- * @template T - The type of the object.
234
- * @template P - The type of the path.
235
- * @template D - The type of the default value.
231
+ * @typeParam T - The type of the object.
232
+ * @typeParam P - The type of the path.
233
+ * @typeParam D - The type of the default value.
236
234
  *
237
- * @param {T} data - The object to query.
238
- * @param {P} path - The path of the property to get.
239
- * @param {D} defaultValue - The value returned if the resolved value is undefined.
240
- * @returns {Exclude<GetField<T, P>, null | undefined> | D} - Returns the resolved value.
235
+ * @param data - The object to query.
236
+ * @param path - The path of the property to get.
237
+ * @param defaultValue - The value returned if the resolved value is undefined.
238
+ * @returns The resolved value or default value.
241
239
  */
242
240
  declare function getField<T, P extends string, D = GetField<T, P>>(data: T, path: P, defaultValue: D): Exclude<GetField<T, P>, null | undefined> | D;
243
241
  /**
244
242
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
245
243
  *
246
- * @param {unknown} object - The object to query.
247
- * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to get.
248
- * @param {unknown} [defaultValue] - The value returned if the resolved value is undefined.
249
- * @returns {any} - Returns the resolved value.
244
+ * @param object - The object to query.
245
+ * @param path - The path of the property to get.
246
+ * @param defaultValue - The value returned if the resolved value is undefined.
247
+ * @returns The resolved value.
250
248
  */
251
249
  declare function getField(object: unknown, path: PropertyKey | readonly PropertyKey[], defaultValue?: unknown): any;
252
250
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"get-field.d.mts","names":[],"sources":["../src/get-field.ts"],"sourcesContent":[],"mappings":";;;;KAyBK,eAAwC,CAAA,CAAA,EAAA,CAAA,CAAA,GAAhB,CAAgB,SAAA,MAAA,CAAA,GACzC,CADyC,CACvC,CADuC,CAAA,GAEzC,CAFyC,SAAA,GAAA,MAAA,EAAA,GAAA,QAAA,SAAA,MAGhB,CAHgB,GAAA,MAAA,SAItB,CAJsB,CAAA,QAAA,CAAA,GAAA,MAAA,SAAA,MAKd,CALc,GAMjC,CANiC,CAAA,MAAA,CAAA,GAAA,SAAA,GAAA,SAAA,GAAA,SAAA,GAAA,SAAA;KAYxC,0BAXD,CAAA,CAAA,EAAA,GAAA,CAAA,GAYA,QAZA,CAYS,OAZT,CAYiB,CAZjB,EAAA,S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-string-key.mjs";
3
2
  import { isDeepKey } from "./type-checks/src/is-deep-key.mjs";
3
+ import "./type-checks/src/index.mjs";
4
+ import { toStringKey } from "./convert/src/to-string-key.mjs";
5
+ import "./convert/src/index.mjs";
4
6
  import { toPath } from "./to-path.mjs";
5
7
 
6
8
  //#region src/get-field.ts
7
9
  /**
8
10
  * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
9
11
  *
10
- * @param {unknown} object - The object to query.
11
- * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to get.
12
- * @param {unknown} [defaultValue] - The value returned if the resolved value is undefined.
13
- * @returns {any} - Returns the resolved value.
12
+ * @param object - The object to query.
13
+ * @param path - The path of the property to get.
14
+ * @param defaultValue - The value returned if the resolved value is undefined.
15
+ * @returns The resolved value.
14
16
  */
15
17
  function getField(object, path, defaultValue) {
16
18
  if (object === null) return defaultValue;
@@ -30,6 +32,11 @@ function getField(object, path, defaultValue) {
30
32
  if (result === void 0) return defaultValue;
31
33
  return result;
32
34
  }
35
+ case "bigint":
36
+ case "boolean":
37
+ case "undefined":
38
+ case "object":
39
+ case "function":
33
40
  default: {
34
41
  if (Array.isArray(path)) return getWithPath(object, path, defaultValue);
35
42
  path = Object.is(path?.valueOf(), -0) ? "-0" : String(path);
@@ -42,9 +49,9 @@ function getField(object, path, defaultValue) {
42
49
  function getWithPath(object, path, defaultValue) {
43
50
  if (path.length === 0) return defaultValue;
44
51
  let current = object;
45
- for (const element_ of path) {
52
+ for (const element of path) {
46
53
  if (current === null) return defaultValue;
47
- current = current[element_];
54
+ current = current[element];
48
55
  }
49
56
  if (current === void 0) return defaultValue;
50
57
  return current;
@@ -1 +1 @@
1
- {"version":3,"file":"get-field.mjs","names":[],"sources":["../src/get-field.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 License, and is\n free for commercial and private use. For more information, please visit\n our licensing page.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://stormsoftware.com/projects/stryke/docs\n Contact: https://stormsoftware.com/contact\n License: https://stormsoftware.com/projects/stryke/license\n\n ------------------------------------------------------------------- */\n\nimport { toStringKey } from \"@stryke/convert/to-string-key\";\nimport { isDeepKey } from \"@stryke/type-checks/is-deep-key\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { toPath } from \"./to-path\";\n\n/**\n * See the definition of `@types/lodash`.\n */\ntype GetIndexedField<T, K> = K extends keyof T\n ? T[K]\n : K extends `${number}`\n ? \"length\" extends keyof T\n ? number extends T[\"length\"]\n ? number extends keyof T\n ? T[number]\n : undefined\n : undefined\n : undefined\n : undefined;\n\ntype FieldWithPossiblyUndefined<T, Key> =\n | GetField<Exclude<T, undefined>, Key>\n | Extract<T, undefined>;\n\ntype IndexedFieldWithPossiblyUndefined<T, Key> =\n | GetIndexedField<Exclude<T, undefined>, Key>\n | Extract<T, undefined>;\n\nexport type GetField<T, P> = P extends `${infer Left}.${infer Right}`\n ? Left extends keyof Exclude<T, undefined>\n ?\n | FieldWithPossiblyUndefined<Exclude<T, undefined>[Left], Right>\n | Extract<T, undefined>\n : Left extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? FieldWithPossiblyUndefined<\n IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>,\n Right\n >\n : undefined\n : undefined\n : P extends keyof T\n ? T[P]\n : P extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>\n : undefined\n : IndexedFieldWithPossiblyUndefined<T, P>;\n\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K - The type of the key in the object.\n * @template D - The type of the default value.\n *\n * @param {T} object - The object to query.\n * @param {K | [K]} path - The path of the property to get.\n * @returns {T[K]} - Returns the resolved value.\n */\nexport function getField<T extends object, K extends keyof T>(\n object: T,\n path: K | readonly [K]\n): T[K];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K - The type of the key in the object.\n *\n * @param {T | null | undefined} object - The object to query.\n * @param {K | [K]} path - The path of the property to get.\n * @returns {T[K] | undefined} - Returns the resolved value.\n */\nexport function getField<T extends object, K extends keyof T>(\n object: T | null | undefined,\n path: K | readonly [K]\n): T[K] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K - The type of the key in the object.\n * @template D - The type of the default value.\n *\n * @param {T | null | undefined} object - The object to query.\n * @param {K | [K]} path - The path of the property to get.\n * @param {D} defaultValue - The value returned if the resolved value is undefined.\n * @returns {Exclude<T[K], undefined> | D} - Returns the resolved value.\n */\nexport function getField<T extends object, K extends keyof T, D>(\n object: T | null | undefined,\n path: K | readonly [K],\n defaultValue: D\n): Exclude<T[K], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K1 - The type of the first key in the object.\n * @template K2 - The type of the second key in the object.\n *\n * @param {T} object - The object to query.\n * @param {[K1, K2]} path - The path of the property to get.\n * @returns {T[K1][K2]} - Returns the resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1]\n>(object: T, path: readonly [K1, K2]): T[K1][K2];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K1 - The type of the first key in the object.\n * @template K2 - The type of the second key in the object.\n *\n * @param {T | null | undefined} object - The object to query.\n * @param {[K1, K2]} path - The path of the property to get.\n * @returns {T[K1][K2] | undefined} - Returns the resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1]\n>(object: T | null | undefined, path: readonly [K1, K2]): T[K1][K2] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K1 - The type of the first key in the object.\n * @template K2 - The type of the second key in the object.\n * @template D - The type of the default value.\n *\n * @param {T | null | undefined} object - The object to query.\n * @param {[K1, K2]} path - The path of the property to get.\n * @param {D} defaultValue - The value returned if the resolved value is undefined.\n * @returns {Exclude<T[K1][K2], undefined> | D} - Returns the resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2],\n defaultValue: D\n): Exclude<T[K1][K2], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K1 - The type of the first key in the object.\n * @template K2 - The type of the second key in the object.\n * @template K3 - The type of the third key in the object.\n *\n * @param {T} object - The object to query.\n * @param {[K1, K2, K3]} path - The path of the property to get.\n * @returns {T[K1][K2][K3]} - Returns the resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2]\n>(object: T, path: readonly [K1, K2, K3]): T[K1][K2][K3];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K1 - The type of the first key in the object.\n * @template K2 - The type of the second key in the object.\n * @template K3 - The type of the third key in the object.\n *\n * @param {T | null | undefined} object - The object to query.\n * @param {[K1, K2, K3]} path - The path of the property to get.\n * @returns {T[K1][K2][K3] | undefined} - Returns the resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2]\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3]\n): T[K1][K2][K3] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K1 - The type of the first key in the object.\n * @template K2 - The type of the second key in the object.\n * @template K3 - The type of the third key in the object.\n * @template D - The type of the default value.\n *\n * @param {T | null | undefined} object - The object to query.\n * @param {[K1, K2, K3]} path - The path of the property to get.\n * @param {D} defaultValue - The value returned if the resolved value is undefined.\n * @returns {Exclude<T[K1][K2][K3], undefined> | D} - Returns the resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3],\n defaultValue: D\n): Exclude<T[K1][K2][K3], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K1 - The type of the first key in the object.\n * @template K2 - The type of the second key in the object.\n * @template K3 - The type of the third key in the object.\n * @template K4 - The type of the fourth key in the object.\n *\n * @param {T} object - The object to query.\n * @param {[K1, K2, K3, K4]} path - The path of the property to get.\n * @returns {T[K1][K2][K3][K4]} - Returns the resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3]\n>(object: T, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K1 - The type of the first key in the object.\n * @template K2 - The type of the second key in the object.\n * @template K3 - The type of the third key in the object.\n * @template K4 - The type of the fourth key in the object.\n *\n * @param {T | null | undefined} object - The object to query.\n * @param {[K1, K2, K3, K4]} path - The path of the property to get.\n * @returns {T[K1][K2][K3][K4] | undefined} - Returns the resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3]\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3, K4]\n): T[K1][K2][K3][K4] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template K1 - The type of the first key in the object.\n * @template K2 - The type of the second key in the object.\n * @template K3 - The type of the third key in the object.\n * @template K4 - The type of the fourth key in the object.\n * @template D - The type of the default value.\n *\n * @param {T | null | undefined} object - The object to query.\n * @param {[K1, K2, K3, K4]} path - The path of the property to get.\n * @param {D} defaultValue - The value returned if the resolved value is undefined.\n * @returns {Exclude<T[K1][K2][K3][K4], undefined> | D} - Returns the resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3, K4],\n defaultValue: D\n): Exclude<T[K1][K2][K3][K4], undefined> | D;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the value.\n *\n * @param {Record<number, T>} object - The object to query.\n * @param {number} path - The path of the property to get.\n * @returns {T} - Returns the resolved value.\n */\nexport function getField<T>(object: Record<number, T>, path: number): T;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the value.\n *\n * @param {Record<number, T> | null | undefined} object - The object to query.\n * @param {number} path - The path of the property to get.\n * @returns {T | undefined} - Returns the resolved value.\n */\nexport function getField<T>(\n object: Record<number, T> | null | undefined,\n path: number\n): T | undefined;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the value.\n * @template D - The type of the default value.\n *\n * @param {Record<number, T> | null | undefined} object - The object to query.\n * @param {number} path - The path of the property to get.\n * @param {D} defaultValue - The value returned if the resolved value is undefined.\n * @returns {T | D} - Returns the resolved value.\n */\nexport function getField<T, D>(\n object: Record<number, T> | null | undefined,\n path: number,\n defaultValue: D\n): T | D;\n/**\n * Retrieves the value at a given path from a null or undefined object, returning the default value.\n *\n * @template D - The type of the default value.\n *\n * @param {null | undefined} object - The object to query.\n * @param {PropertyKey} path - The path of the property to get.\n * @param {D} defaultValue - The value returned if the resolved value is undefined.\n * @returns {D} - Returns the default value.\n */\nexport function getField<D>(\n object: null | undefined,\n path: PropertyKey,\n defaultValue: D\n): D;\n/**\n * Retrieves the value at a given path from a null or undefined object, returning undefined.\n *\n * @param {null | undefined} object - The object to query.\n * @param {PropertyKey} path - The path of the property to get.\n * @returns {undefined} - Returns undefined.\n */\nexport function getField(\n object: null | undefined,\n path: PropertyKey\n): undefined;\n/**\n * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template P - The type of the path.\n *\n * @param {T} data - The object to query.\n * @param {P} path - The path of the property to get.\n * @returns {string extends P ? any : GetField<T, P>} - Returns the resolved value.\n */\nexport function getField<T, P extends string>(\n data: T,\n path: P\n): string extends P ? any : GetField<T, P>;\n/**\n * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @template T - The type of the object.\n * @template P - The type of the path.\n * @template D - The type of the default value.\n *\n * @param {T} data - The object to query.\n * @param {P} path - The path of the property to get.\n * @param {D} defaultValue - The value returned if the resolved value is undefined.\n * @returns {Exclude<GetField<T, P>, null | undefined> | D} - Returns the resolved value.\n */\nexport function getField<T, P extends string, D = GetField<T, P>>(\n data: T,\n path: P,\n defaultValue: D\n): Exclude<GetField<T, P>, null | undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @param {unknown} object - The object to query.\n * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to get.\n * @param {unknown} [defaultValue] - The value returned if the resolved value is undefined.\n * @returns {any} - Returns the resolved value.\n */\nexport function getField(\n object: unknown,\n path: PropertyKey | readonly PropertyKey[],\n defaultValue?: unknown\n): any;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @param {unknown} object - The object to query.\n * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to get.\n * @param {unknown} [defaultValue] - The value returned if the resolved value is undefined.\n * @returns {any} - Returns the resolved value.\n */\nexport function getField(\n object: any,\n path: PropertyKey | readonly PropertyKey[],\n defaultValue?: any\n): any {\n if (object === null) {\n return defaultValue;\n }\n\n switch (typeof path) {\n case \"string\": {\n const result = object[path];\n\n if (result === undefined) {\n if (isDeepKey(path)) {\n return getField(object, toPath(path), defaultValue);\n }\n return defaultValue;\n }\n\n return result;\n }\n case \"number\":\n case \"symbol\": {\n if (isNumber(path)) {\n path = toStringKey(path);\n }\n\n const result = Array.isArray(path)\n ? undefined\n : object[path as PropertyKey];\n if (result === undefined) {\n return defaultValue;\n }\n\n return result;\n }\n default: {\n if (Array.isArray(path)) {\n return getWithPath(object, path, defaultValue);\n }\n\n path = Object.is(path?.valueOf(), -0) ? \"-0\" : String(path);\n\n const result = object[path];\n\n if (result === undefined) {\n return defaultValue;\n }\n\n return result;\n }\n }\n}\n\nfunction getWithPath(\n object: any,\n path: readonly PropertyKey[],\n defaultValue?: any\n): any {\n if (path.length === 0) {\n return defaultValue;\n }\n\n let current = object;\n\n for (const element_ of path) {\n if (current === null) {\n return defaultValue;\n }\n\n current = current[element_];\n }\n\n if (current === undefined) {\n return defaultValue;\n }\n\n return current;\n}\n"],"mappings":";;;;;;;;;;;;;;AAkaA,SAAgB,SACd,QACA,MACA,cACK;AACL,KAAI,WAAW,KACb,QAAO;AAGT,SAAQ,OAAO,MAAf;EACE,KAAK,UAAU;GACb,MAAM,SAAS,OAAO;AAEtB,OAAI,WAAW,QAAW;AACxB,QAAI,UAAU,KAAK,CACjB,QAAO,SAAS,QAAQ,OAAO,KAAK,EAAE,aAAa;AAErD,WAAO;;AAGT,UAAO;;EAET,KAAK;EACL,KAAK,UAAU;AACb,OAAI,SAAS,KAAK,CAChB,QAAO,YAAY,KAAK;GAG1B,MAAM,SAAS,MAAM,QAAQ,KAAK,GAC9B,SACA,OAAO;AACX,OAAI,WAAW,OACb,QAAO;AAGT,UAAO;;EAET,SAAS;AACP,OAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,YAAY,QAAQ,MAAM,aAAa;AAGhD,UAAO,OAAO,GAAG,MAAM,SAAS,EAAE,GAAG,GAAG,OAAO,OAAO,KAAK;GAE3D,MAAM,SAAS,OAAO;AAEtB,OAAI,WAAW,OACb,QAAO;AAGT,UAAO;;;;AAKb,SAAS,YACP,QACA,MACA,cACK;AACL,KAAI,KAAK,WAAW,EAClB,QAAO;CAGT,IAAI,UAAU;AAEd,MAAK,MAAM,YAAY,MAAM;AAC3B,MAAI,YAAY,KACd,QAAO;AAGT,YAAU,QAAQ;;AAGpB,KAAI,YAAY,OACd,QAAO;AAGT,QAAO"}
1
+ {"version":3,"file":"get-field.mjs","names":[],"sources":["../src/get-field.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toStringKey } from \"@stryke/convert\";\nimport { isDeepKey, isNumber } from \"@stryke/type-checks\";\nimport { toPath } from \"./to-path\";\n\n/**\n * See the definition of `@types/lodash`.\n */\ntype GetIndexedField<T, K> = K extends keyof T\n ? T[K]\n : K extends `${number}`\n ? \"length\" extends keyof T\n ? number extends T[\"length\"]\n ? number extends keyof T\n ? T[number]\n : undefined\n : undefined\n : undefined\n : undefined;\n\ntype FieldWithPossiblyUndefined<T, Key> =\n | GetField<Exclude<T, undefined>, Key>\n | Extract<T, undefined>;\n\ntype IndexedFieldWithPossiblyUndefined<T, Key> =\n | GetIndexedField<Exclude<T, undefined>, Key>\n | Extract<T, undefined>;\n\nexport type GetField<T, P> = P extends `${infer Left}.${infer Right}`\n ? Left extends keyof Exclude<T, undefined>\n ?\n | FieldWithPossiblyUndefined<Exclude<T, undefined>[Left], Right>\n | Extract<T, undefined>\n : Left extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? FieldWithPossiblyUndefined<\n IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>,\n Right\n >\n : undefined\n : undefined\n : P extends keyof T\n ? T[P]\n : P extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>\n : undefined\n : IndexedFieldWithPossiblyUndefined<T, P>;\n\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K - The type of the key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<T extends object, K extends keyof T>(\n object: T,\n path: K | readonly [K]\n): T[K];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K - The type of the key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<T extends object, K extends keyof T>(\n object: T | null | undefined,\n path: K | readonly [K]\n): T[K] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K - The type of the key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<T extends object, K extends keyof T, D>(\n object: T | null | undefined,\n path: K | readonly [K],\n defaultValue: D\n): Exclude<T[K], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1]\n>(object: T, path: readonly [K1, K2]): T[K1][K2];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1]\n>(object: T | null | undefined, path: readonly [K1, K2]): T[K1][K2] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2],\n defaultValue: D\n): Exclude<T[K1][K2], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2]\n>(object: T, path: readonly [K1, K2, K3]): T[K1][K2][K3];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2]\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3]\n): T[K1][K2][K3] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3],\n defaultValue: D\n): Exclude<T[K1][K2][K3], undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam K4 - The type of the fourth key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3]\n>(object: T, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4];\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam K4 - The type of the fourth key in the object.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3]\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3, K4]\n): T[K1][K2][K3][K4] | undefined;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam K1 - The type of the first key in the object.\n * @typeParam K2 - The type of the second key in the object.\n * @typeParam K3 - The type of the third key in the object.\n * @typeParam K4 - The type of the fourth key in the object.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<\n T extends object,\n K1 extends keyof T,\n K2 extends keyof T[K1],\n K3 extends keyof T[K1][K2],\n K4 extends keyof T[K1][K2][K3],\n D\n>(\n object: T | null | undefined,\n path: readonly [K1, K2, K3, K4],\n defaultValue: D\n): Exclude<T[K1][K2][K3][K4], undefined> | D;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value.\n */\nexport function getField<T>(object: Record<number, T>, path: number): T;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value or undefined.\n */\nexport function getField<T>(\n object: Record<number, T> | null | undefined,\n path: number\n): T | undefined;\n/**\n * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the value.\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<T, D>(\n object: Record<number, T> | null | undefined,\n path: number,\n defaultValue: D\n): T | D;\n/**\n * Retrieves the value at a given path from a null or undefined object, returning the default value.\n *\n * @typeParam D - The type of the default value.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The default value.\n */\nexport function getField<D>(\n object: null | undefined,\n path: PropertyKey,\n defaultValue: D\n): D;\n\n/**\n * Retrieves the value at a given path from a null or undefined object, returning undefined.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n */\nexport function getField(\n object: null | undefined,\n path: PropertyKey\n): undefined;\n\n/**\n * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam P - The type of the path.\n *\n * @param data - The object to query.\n * @param path - The path of the property to get.\n * @returns The resolved value, or any if path is a general string.\n */\nexport function getField<T, P extends string>(\n data: T,\n path: P\n): string extends P ? any : GetField<T, P>;\n/**\n * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @typeParam T - The type of the object.\n * @typeParam P - The type of the path.\n * @typeParam D - The type of the default value.\n *\n * @param data - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value or default value.\n */\nexport function getField<T, P extends string, D = GetField<T, P>>(\n data: T,\n path: P,\n defaultValue: D\n): Exclude<GetField<T, P>, null | undefined> | D;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value.\n */\nexport function getField(\n object: unknown,\n path: PropertyKey | readonly PropertyKey[],\n defaultValue?: unknown\n): any;\n/**\n * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.\n *\n * @param object - The object to query.\n * @param path - The path of the property to get.\n * @param defaultValue - The value returned if the resolved value is undefined.\n * @returns The resolved value.\n */\nexport function getField(\n object: any,\n path: PropertyKey | readonly PropertyKey[],\n defaultValue?: any\n): any {\n if (object === null) {\n return defaultValue;\n }\n\n switch (typeof path) {\n case \"string\": {\n const result = object[path];\n\n if (result === undefined) {\n if (isDeepKey(path)) {\n return getField(object, toPath(path), defaultValue);\n }\n return defaultValue;\n }\n\n return result;\n }\n case \"number\":\n case \"symbol\": {\n if (isNumber(path)) {\n path = toStringKey(path);\n }\n\n const result = Array.isArray(path)\n ? undefined\n : object[path as PropertyKey];\n if (result === undefined) {\n return defaultValue;\n }\n\n return result;\n }\n case \"bigint\":\n case \"boolean\":\n case \"undefined\":\n case \"object\":\n case \"function\":\n default: {\n if (Array.isArray(path)) {\n return getWithPath(object, path, defaultValue);\n }\n\n path = Object.is(path?.valueOf(), -0) ? \"-0\" : String(path);\n\n const result = object[path];\n\n if (result === undefined) {\n return defaultValue;\n }\n\n return result;\n }\n }\n}\n\nfunction getWithPath(\n object: any,\n path: readonly PropertyKey[],\n defaultValue?: any\n): any {\n if (path.length === 0) {\n return defaultValue;\n }\n\n let current = object;\n\n for (const element of path) {\n if (current === null) {\n return defaultValue;\n }\n\n current = current[element];\n }\n\n if (current === undefined) {\n return defaultValue;\n }\n\n return current;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkaA,SAAgB,SACd,QACA,MACA,cACK;AACL,KAAI,WAAW,KACb,QAAO;AAGT,SAAQ,OAAO,MAAf;EACE,KAAK,UAAU;GACb,MAAM,SAAS,OAAO;AAEtB,OAAI,WAAW,QAAW;AACxB,QAAI,UAAU,KAAK,CACjB,QAAO,SAAS,QAAQ,OAAO,KAAK,EAAE,aAAa;AAErD,WAAO;;AAGT,UAAO;;EAET,KAAK;EACL,KAAK,UAAU;AACb,OAAI,SAAS,KAAK,CAChB,QAAO,YAAY,KAAK;GAG1B,MAAM,SAAS,MAAM,QAAQ,KAAK,GAC9B,SACA,OAAO;AACX,OAAI,WAAW,OACb,QAAO;AAGT,UAAO;;EAET,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,SAAS;AACP,OAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,YAAY,QAAQ,MAAM,aAAa;AAGhD,UAAO,OAAO,GAAG,MAAM,SAAS,EAAE,GAAG,GAAG,OAAO,OAAO,KAAK;GAE3D,MAAM,SAAS,OAAO;AAEtB,OAAI,WAAW,OACb,QAAO;AAGT,UAAO;;;;AAKb,SAAS,YACP,QACA,MACA,cACK;AACL,KAAI,KAAK,WAAW,EAClB,QAAO;CAGT,IAAI,UAAU;AAEd,MAAK,MAAM,WAAW,MAAM;AAC1B,MAAI,YAAY,KACd,QAAO;AAGT,YAAU,QAAQ;;AAGpB,KAAI,YAAY,OACd,QAAO;AAGT,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-ordered-by.d.cts","names":[],"sources":["../src/get-ordered-by.ts"],"sourcesContent":[],"mappings":";KAiBK,KAAA;;AAmCL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,4BACF,kBACC,cACL,UACP"}
1
+ {"version":3,"file":"get-ordered-by.d.cts","names":[],"sources":["../src/get-ordered-by.ts"],"sourcesContent":[],"mappings":";KAkBK,KAAA;;AAmCL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,4BACF,kBACC,cACL,UACP"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-ordered-by.d.mts","names":[],"sources":["../src/get-ordered-by.ts"],"sourcesContent":[],"mappings":";KAiBK,KAAA;;AAmCL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,4BACF,kBACC,cACL,UACP"}
1
+ {"version":3,"file":"get-ordered-by.d.mts","names":[],"sources":["../src/get-ordered-by.ts"],"sourcesContent":[],"mappings":";KAkBK,KAAA;;AAmCL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,4BACF,kBACC,cACL,UACP"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-ordered-by.mjs","names":[],"sources":["../src/get-ordered-by.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 License, and is\n free for commercial and private use. For more information, please visit\n our licensing page.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://stormsoftware.com/projects/stryke/docs\n Contact: https://stormsoftware.com/contact\n License: https://stormsoftware.com/projects/stryke/license\n\n ------------------------------------------------------------------- */\n\ntype Order = \"asc\" | \"desc\";\n\n/**\n * Sorts an array of objects based on multiple properties and their corresponding order directions.\n *\n * @remarks\n * This function takes an array of objects, an array of keys to sort by, and an array of order directions.\n * It returns the sorted array, ordering by each key according to its corresponding direction\n * ('asc' for ascending or 'desc' for descending). If values for a key are equal,\n * it moves to the next key to determine the order.\n *\n * @example\n * ```typescript\n * // Sort an array of objects by 'user' in ascending order and 'age' in descending order.\n * const users = [\n * { user: 'fred', age: 48 },\n * { user: 'barney', age: 34 },\n * { user: 'fred', age: 40 },\n * { user: 'barney', age: 36 },\n * ];\n * const result = orderBy(users, ['user', 'age'], ['asc', 'desc']);\n * // result will be:\n * // [\n * // { user: 'barney', age: 36 },\n * // { user: 'barney', age: 34 },\n * // { user: 'fred', age: 48 },\n * // { user: 'fred', age: 40 },\n * // ]\n * ```\n *\n * @param collection - The array of objects to be sorted.\n * @param keys - An array of keys (properties) by which to sort.\n * @param orders - An array of order directions ('asc' for ascending or 'desc' for descending).\n * @returns The sorted array.\n */\nexport function getOrderedBy<T>(\n collection: T[],\n keys: (keyof T)[],\n orders: Order[]\n): T[] {\n const compareValues = (a: T[keyof T], b: T[keyof T], order: Order) => {\n if (a < b) {\n return order === \"asc\" ? -1 : 1;\n }\n if (a > b) {\n return order === \"asc\" ? 1 : -1;\n }\n return 0;\n };\n\n const effectiveOrders = keys.map(\n (_, index) => orders[index] ?? orders.at(-1)\n );\n\n return [...collection].sort((a, b) => {\n for (const [i, key] of keys.entries()) {\n const order = effectiveOrders[i];\n const result = compareValues(a[key], b[key], order!);\n if (result !== 0) {\n return result;\n }\n }\n return 0;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,aACd,YACA,MACA,QACK;CACL,MAAM,iBAAiB,GAAe,GAAe,UAAiB;AACpE,MAAI,IAAI,EACN,QAAO,UAAU,QAAQ,KAAK;AAEhC,MAAI,IAAI,EACN,QAAO,UAAU,QAAQ,IAAI;AAE/B,SAAO;;CAGT,MAAM,kBAAkB,KAAK,KAC1B,GAAG,UAAU,OAAO,UAAU,OAAO,GAAG,GAAG,CAC7C;AAED,QAAO,CAAC,GAAG,WAAW,CAAC,MAAM,GAAG,MAAM;AACpC,OAAK,MAAM,CAAC,GAAG,QAAQ,KAAK,SAAS,EAAE;GACrC,MAAM,QAAQ,gBAAgB;GAC9B,MAAM,SAAS,cAAc,EAAE,MAAM,EAAE,MAAM,MAAO;AACpD,OAAI,WAAW,EACb,QAAO;;AAGX,SAAO;GACP"}
1
+ {"version":3,"file":"get-ordered-by.mjs","names":[],"sources":["../src/get-ordered-by.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\ntype Order = \"asc\" | \"desc\";\n\n/**\n * Sorts an array of objects based on multiple properties and their corresponding order directions.\n *\n * @remarks\n * This function takes an array of objects, an array of keys to sort by, and an array of order directions.\n * It returns the sorted array, ordering by each key according to its corresponding direction\n * ('asc' for ascending or 'desc' for descending). If values for a key are equal,\n * it moves to the next key to determine the order.\n *\n * @example\n * ```typescript\n * // Sort an array of objects by 'user' in ascending order and 'age' in descending order.\n * const users = [\n * { user: 'fred', age: 48 },\n * { user: 'barney', age: 34 },\n * { user: 'fred', age: 40 },\n * { user: 'barney', age: 36 },\n * ];\n * const result = orderBy(users, ['user', 'age'], ['asc', 'desc']);\n * // result will be:\n * // [\n * // { user: 'barney', age: 36 },\n * // { user: 'barney', age: 34 },\n * // { user: 'fred', age: 48 },\n * // { user: 'fred', age: 40 },\n * // ]\n * ```\n *\n * @param collection - The array of objects to be sorted.\n * @param keys - An array of keys (properties) by which to sort.\n * @param orders - An array of order directions ('asc' for ascending or 'desc' for descending).\n * @returns The sorted array.\n */\nexport function getOrderedBy<T>(\n collection: T[],\n keys: (keyof T)[],\n orders: Order[]\n): T[] {\n const compareValues = (a: T[keyof T], b: T[keyof T], order: Order) => {\n if (a < b) {\n return order === \"asc\" ? -1 : 1;\n }\n if (a > b) {\n return order === \"asc\" ? 1 : -1;\n }\n return 0;\n };\n\n const effectiveOrders = keys.map(\n (_, index) => orders[index] ?? orders.at(-1)\n );\n\n return [...collection].sort((a, b) => {\n for (const [i, key] of keys.entries()) {\n const order = effectiveOrders[i];\n const result = compareValues(a[key], b[key], order!);\n if (result !== 0) {\n return result;\n }\n }\n return 0;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,SAAgB,aACd,YACA,MACA,QACK;CACL,MAAM,iBAAiB,GAAe,GAAe,UAAiB;AACpE,MAAI,IAAI,EACN,QAAO,UAAU,QAAQ,KAAK;AAEhC,MAAI,IAAI,EACN,QAAO,UAAU,QAAQ,IAAI;AAE/B,SAAO;;CAGT,MAAM,kBAAkB,KAAK,KAC1B,GAAG,UAAU,OAAO,UAAU,OAAO,GAAG,GAAG,CAC7C;AAED,QAAO,CAAC,GAAG,WAAW,CAAC,MAAM,GAAG,MAAM;AACpC,OAAK,MAAM,CAAC,GAAG,QAAQ,KAAK,SAAS,EAAE;GACrC,MAAM,QAAQ,gBAAgB;GAC9B,MAAM,SAAS,cAAc,EAAE,MAAM,EAAE,MAAM,MAAO;AACpD,OAAI,WAAW,EACb,QAAO;;AAGX,SAAO;GACP"}
@@ -1 +1 @@
1
- {"version":3,"file":"identity.d.cts","names":[],"sources":["../src/identity.ts"],"sourcesContent":[],"mappings":";;AA8BA;;;;;;;;;;;;iBAAgB,eAAe,IAAI"}
1
+ {"version":3,"file":"identity.d.cts","names":[],"sources":["../src/identity.ts"],"sourcesContent":[],"mappings":";;AA+BA;;;;;;;;;;;;iBAAgB,eAAe,IAAI"}
@@ -1 +1 @@
1
- {"version":3,"file":"identity.d.mts","names":[],"sources":["../src/identity.ts"],"sourcesContent":[],"mappings":";;AA8BA;;;;;;;;;;;;iBAAgB,eAAe,IAAI"}
1
+ {"version":3,"file":"identity.d.mts","names":[],"sources":["../src/identity.ts"],"sourcesContent":[],"mappings":";;AA+BA;;;;;;;;;;;;iBAAgB,eAAe,IAAI"}
@@ -1 +1 @@
1
- {"version":3,"file":"identity.mjs","names":[],"sources":["../src/identity.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 License, and is\n free for commercial and private use. For more information, please visit\n our licensing page.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://stormsoftware.com/projects/stryke/docs\n Contact: https://stormsoftware.com/contact\n License: https://stormsoftware.com/projects/stryke/license\n\n ------------------------------------------------------------------- */\n\n/**\n * Returns the input value unchanged.\n *\n * @example\n * ```ts\n * identity(5); // Returns 5\n * identity('hello'); // Returns 'hello'\n * identity({ key: 'value' }); // Returns { key: 'value' }\n * ```\n *\n * @param x - The value to be returned.\n * @returns The input value.\n */\nexport function identity<T>(x: T): T {\n return x;\n}\n"],"mappings":";;;;;;;;;;;;;;AA8BA,SAAgB,SAAY,GAAS;AACnC,QAAO"}
1
+ {"version":3,"file":"identity.mjs","names":[],"sources":["../src/identity.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Returns the input value unchanged.\n *\n * @example\n * ```ts\n * identity(5); // Returns 5\n * identity('hello'); // Returns 'hello'\n * identity({ key: 'value' }); // Returns { key: 'value' }\n * ```\n *\n * @param x - The value to be returned.\n * @returns The input value.\n */\nexport function identity<T>(x: T): T {\n return x;\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAgB,SAAY,GAAS;AACnC,QAAO"}