@dereekb/util 13.0.7 → 13.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fetch/package.json +2 -2
- package/index.cjs.js +4107 -1516
- package/index.esm.js +4107 -1516
- package/package.json +1 -2
- package/src/lib/array/array.d.ts +92 -47
- package/src/lib/array/array.find.d.ts +14 -18
- package/src/lib/array/array.index.d.ts +43 -14
- package/src/lib/array/array.indexed.d.ts +66 -17
- package/src/lib/array/array.limit.d.ts +11 -0
- package/src/lib/array/array.make.d.ts +9 -3
- package/src/lib/array/array.map.d.ts +20 -8
- package/src/lib/array/array.number.d.ts +63 -5
- package/src/lib/array/array.random.d.ts +12 -9
- package/src/lib/array/array.set.d.ts +24 -1
- package/src/lib/array/array.string.d.ts +104 -0
- package/src/lib/array/array.unique.d.ts +60 -8
- package/src/lib/array/array.value.d.ts +20 -11
- package/src/lib/assertion/assertion.d.ts +30 -2
- package/src/lib/assertion/assertion.generic.d.ts +8 -0
- package/src/lib/assertion/assertion.number.d.ts +16 -0
- package/src/lib/auth/auth.role.claims.d.ts +14 -8
- package/src/lib/boolean.d.ts +54 -1
- package/src/lib/contact/domain.d.ts +22 -4
- package/src/lib/contact/random.d.ts +24 -0
- package/src/lib/date/date.d.ts +8 -13
- package/src/lib/date/hour.d.ts +51 -32
- package/src/lib/date/minute.d.ts +4 -4
- package/src/lib/date/time.d.ts +12 -3
- package/src/lib/date/week.d.ts +77 -10
- package/src/lib/error/error.d.ts +54 -3
- package/src/lib/error/error.server.d.ts +25 -2
- package/src/lib/filter/filter.d.ts +12 -7
- package/src/lib/function/function.boolean.d.ts +4 -4
- package/src/lib/function/function.d.ts +2 -5
- package/src/lib/function/function.forward.d.ts +19 -3
- package/src/lib/getter/getter.cache.d.ts +9 -5
- package/src/lib/getter/getter.d.ts +39 -22
- package/src/lib/getter/getter.map.d.ts +10 -4
- package/src/lib/getter/getter.util.d.ts +3 -3
- package/src/lib/grouping.d.ts +98 -31
- package/src/lib/hash.d.ts +15 -8
- package/src/lib/iterable/iterable.d.ts +62 -50
- package/src/lib/iterable/iterable.map.d.ts +4 -4
- package/src/lib/iterate.d.ts +17 -1
- package/src/lib/key.d.ts +32 -10
- package/src/lib/lifecycle.d.ts +10 -1
- package/src/lib/map/map.d.ts +17 -16
- package/src/lib/map/map.intersection.d.ts +5 -4
- package/src/lib/map/map.key.d.ts +16 -15
- package/src/lib/misc/host.d.ts +6 -3
- package/src/lib/model/id.batch.d.ts +7 -3
- package/src/lib/model/id.factory.d.ts +16 -1
- package/src/lib/model/model.conversion.d.ts +49 -6
- package/src/lib/model/model.conversion.field.d.ts +13 -3
- package/src/lib/model/model.copy.d.ts +11 -0
- package/src/lib/model/model.d.ts +174 -1
- package/src/lib/model/model.modify.d.ts +24 -5
- package/src/lib/nodejs/stream.d.ts +8 -6
- package/src/lib/number/bitwise.dencoder.d.ts +43 -3
- package/src/lib/number/bound.d.ts +34 -5
- package/src/lib/number/dollar.d.ts +13 -6
- package/src/lib/number/factory.d.ts +11 -3
- package/src/lib/number/number.d.ts +55 -32
- package/src/lib/number/random.d.ts +13 -3
- package/src/lib/number/round.d.ts +47 -26
- package/src/lib/number/sort.d.ts +7 -1
- package/src/lib/number/transform.d.ts +16 -0
- package/src/lib/object/object.array.d.ts +16 -2
- package/src/lib/object/object.array.delta.d.ts +6 -2
- package/src/lib/object/object.d.ts +33 -5
- package/src/lib/object/object.empty.d.ts +4 -2
- package/src/lib/object/object.equal.d.ts +21 -4
- package/src/lib/object/object.filter.tuple.d.ts +105 -3
- package/src/lib/object/object.key.d.ts +13 -6
- package/src/lib/object/object.map.d.ts +30 -19
- package/src/lib/page/page.d.ts +21 -0
- package/src/lib/page/page.filter.d.ts +16 -9
- package/src/lib/path/path.d.ts +101 -14
- package/src/lib/path/path.tree.d.ts +16 -0
- package/src/lib/promise/callback.d.ts +18 -0
- package/src/lib/promise/is.d.ts +10 -3
- package/src/lib/promise/map.d.ts +5 -3
- package/src/lib/promise/poll.d.ts +14 -4
- package/src/lib/promise/promise.d.ts +84 -18
- package/src/lib/promise/promise.factory.d.ts +18 -2
- package/src/lib/promise/promise.limit.d.ts +22 -2
- package/src/lib/promise/promise.loop.d.ts +69 -1
- package/src/lib/promise/promise.ref.d.ts +14 -2
- package/src/lib/promise/promise.task.d.ts +8 -4
- package/src/lib/promise/promise.type.d.ts +4 -4
- package/src/lib/promise/use.d.ts +6 -4
- package/src/lib/promise/wait.d.ts +5 -2
- package/src/lib/relation/relation.d.ts +98 -0
- package/src/lib/service/handler.config.d.ts +47 -9
- package/src/lib/service/handler.d.ts +43 -1
- package/src/lib/service/typed.service.d.ts +21 -2
- package/src/lib/set/set.allowed.d.ts +6 -4
- package/src/lib/set/set.d.ts +174 -46
- package/src/lib/set/set.decision.d.ts +4 -2
- package/src/lib/set/set.delta.d.ts +16 -3
- package/src/lib/set/set.hashset.d.ts +43 -0
- package/src/lib/set/set.selection.d.ts +7 -3
- package/src/lib/sort.d.ts +36 -16
- package/src/lib/string/char.d.ts +48 -34
- package/src/lib/string/dencoder.d.ts +84 -13
- package/src/lib/string/factory.d.ts +13 -4
- package/src/lib/string/html.d.ts +7 -6
- package/src/lib/string/mimetype.d.ts +65 -1
- package/src/lib/string/prefix.d.ts +21 -7
- package/src/lib/string/record.d.ts +7 -4
- package/src/lib/string/replace.d.ts +77 -33
- package/src/lib/string/search.d.ts +19 -9
- package/src/lib/string/sort.d.ts +10 -1
- package/src/lib/string/string.d.ts +74 -21
- package/src/lib/string/transform.d.ts +7 -0
- package/src/lib/string/tree.d.ts +91 -29
- package/src/lib/string/url.d.ts +148 -63
- package/src/lib/tree/tree.explore.d.ts +84 -17
- package/src/lib/tree/tree.flatten.d.ts +44 -7
- package/src/lib/type.d.ts +15 -12
- package/src/lib/value/address.d.ts +66 -17
- package/src/lib/value/bound.d.ts +253 -17
- package/src/lib/value/build.d.ts +30 -5
- package/src/lib/value/comparator.d.ts +53 -25
- package/src/lib/value/cron.d.ts +14 -6
- package/src/lib/value/decision.d.ts +57 -13
- package/src/lib/value/equal.d.ts +44 -13
- package/src/lib/value/indexed.d.ts +253 -82
- package/src/lib/value/label.d.ts +16 -5
- package/src/lib/value/map.d.ts +77 -20
- package/src/lib/value/maybe.d.ts +47 -49
- package/src/lib/value/modifier.d.ts +82 -27
- package/src/lib/value/point.d.ts +248 -54
- package/src/lib/value/url.d.ts +10 -3
- package/src/lib/value/use.d.ts +99 -8
- package/src/lib/value/vector.d.ts +71 -9
- package/test/index.cjs.js +86 -23
- package/test/index.esm.js +86 -23
- package/test/package.json +2 -2
- package/test/src/lib/shared/shared.d.ts +31 -5
- package/test/src/lib/shared/shared.fail.d.ts +72 -9
- package/test/src/lib/shared/shared.function.d.ts +40 -2
- package/test/src/lib/shared/shared.wrap.d.ts +20 -1
package/src/lib/value/point.d.ts
CHANGED
|
@@ -2,19 +2,40 @@ import { type Factory } from '../getter/getter';
|
|
|
2
2
|
import { type NumberPrecision, type RoundToPrecisionFunctionType } from '../number/round';
|
|
3
3
|
import { type Maybe } from './maybe.type';
|
|
4
4
|
/**
|
|
5
|
-
* Latitude value
|
|
5
|
+
* Latitude value in degrees, ranging from -90 to 90.
|
|
6
6
|
*/
|
|
7
7
|
export type Latitude = number;
|
|
8
8
|
/**
|
|
9
|
-
* Longitude value
|
|
9
|
+
* Longitude value in degrees, ranging from -180 to 180.
|
|
10
10
|
*/
|
|
11
11
|
export type Longitude = number;
|
|
12
|
+
/**
|
|
13
|
+
* Minimum valid latitude value (-90 degrees).
|
|
14
|
+
*/
|
|
12
15
|
export declare const MIN_LATITUDE_VALUE = -90;
|
|
16
|
+
/**
|
|
17
|
+
* Maximum valid latitude value (90 degrees).
|
|
18
|
+
*/
|
|
13
19
|
export declare const MAX_LATITUDE_VALUE = 90;
|
|
20
|
+
/**
|
|
21
|
+
* Total range of latitude values (180 degrees).
|
|
22
|
+
*/
|
|
14
23
|
export declare const TOTAL_LATITUDE_RANGE: number;
|
|
24
|
+
/**
|
|
25
|
+
* Minimum valid longitude value (-180 degrees).
|
|
26
|
+
*/
|
|
15
27
|
export declare const MIN_LONGITUDE_VALUE = -180;
|
|
28
|
+
/**
|
|
29
|
+
* Maximum valid longitude value (180 degrees).
|
|
30
|
+
*/
|
|
16
31
|
export declare const MAX_LONGITUDE_VALUE = 180;
|
|
32
|
+
/**
|
|
33
|
+
* Total range of longitude values (360 degrees).
|
|
34
|
+
*/
|
|
17
35
|
export declare const TOTAL_LONGITUDE_RANGE: number;
|
|
36
|
+
/**
|
|
37
|
+
* A geographic point represented by latitude and longitude.
|
|
38
|
+
*/
|
|
18
39
|
export interface LatLngPoint {
|
|
19
40
|
lat: Latitude;
|
|
20
41
|
lng: Longitude;
|
|
@@ -28,26 +49,119 @@ export interface LonLatPoint {
|
|
|
28
49
|
lat: Latitude;
|
|
29
50
|
lon: Longitude;
|
|
30
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Type guard that checks whether the input is a {@link LatLngPoint} by testing for `lat` and `lng` properties.
|
|
54
|
+
*/
|
|
31
55
|
export declare function isLatLngPoint(input: LatLngPoint | unknown): input is LatLngPoint;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a shallow copy of the point so that mutations to the copy do not affect the original.
|
|
58
|
+
*
|
|
59
|
+
* @param input - point to copy
|
|
60
|
+
* @returns a new point with the same coordinates
|
|
61
|
+
*/
|
|
32
62
|
export declare function copyLatLngPoint(input: LatLngPoint): LatLngPoint;
|
|
63
|
+
/**
|
|
64
|
+
* Checks whether two points have identical coordinates. Handles `null`/`undefined` by returning `true` only if both are nullish.
|
|
65
|
+
*
|
|
66
|
+
* @param a - first point
|
|
67
|
+
* @param b - second point
|
|
68
|
+
* @returns `true` if both points have the same `lat` and `lng`, or both are nullish
|
|
69
|
+
*/
|
|
33
70
|
export declare function isSameLatLngPoint(a: Maybe<LatLngPoint>, b: Maybe<LatLngPoint>): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Computes the difference between two points (`a - b`), optionally wrapping the result to valid lat/lng ranges.
|
|
73
|
+
*
|
|
74
|
+
* @param a - the point to subtract from
|
|
75
|
+
* @param b - the point to subtract
|
|
76
|
+
* @param wrap - whether to wrap the result to valid lat/lng ranges; defaults to `true`
|
|
77
|
+
* @returns a point representing the difference
|
|
78
|
+
*/
|
|
34
79
|
export declare function diffLatLngPoints(a: LatLngPoint, b: LatLngPoint, wrap?: boolean): LatLngPoint;
|
|
80
|
+
/**
|
|
81
|
+
* Computes the sum of two points (`a + b`), optionally wrapping the result to valid lat/lng ranges.
|
|
82
|
+
*
|
|
83
|
+
* @param a - the first point
|
|
84
|
+
* @param b - the second point
|
|
85
|
+
* @param wrap - whether to wrap the result to valid lat/lng ranges; defaults to `true`
|
|
86
|
+
* @returns a point representing the sum
|
|
87
|
+
*/
|
|
35
88
|
export declare function addLatLngPoints(a: LatLngPoint, b: LatLngPoint, wrap?: boolean): LatLngPoint;
|
|
89
|
+
/**
|
|
90
|
+
* Wraps a point so its latitude is capped to [-90, 90] and its longitude wraps around [-180, 180].
|
|
91
|
+
*
|
|
92
|
+
* @param a - point to wrap
|
|
93
|
+
* @returns a new point with valid coordinates
|
|
94
|
+
*/
|
|
36
95
|
export declare function wrapLatLngPoint(a: LatLngPoint): LatLngPoint;
|
|
96
|
+
/**
|
|
97
|
+
* Caps a latitude value to the valid range [-90, 90]. Values outside are clamped to the nearest boundary.
|
|
98
|
+
*/
|
|
37
99
|
export declare const capLatValue: import("..").BoundNumberFunction<number>;
|
|
100
|
+
/**
|
|
101
|
+
* Wraps a longitude value into the valid range [-180, 180]. Values that exceed the range wrap around to the opposite side.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* wrapLngValue(-190);
|
|
106
|
+
* // 170
|
|
107
|
+
*
|
|
108
|
+
* wrapLngValue(190);
|
|
109
|
+
* // -170
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
38
112
|
export declare const wrapLngValue: import("..").WrapNumberFunction<number>;
|
|
113
|
+
/**
|
|
114
|
+
* Checks whether a latitude value is within the valid range [-90, 90].
|
|
115
|
+
*
|
|
116
|
+
* @param lat - latitude value to validate
|
|
117
|
+
* @returns `true` if the value is a valid latitude
|
|
118
|
+
*/
|
|
39
119
|
export declare function isValidLatitude(lat: Latitude): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Checks whether a longitude value is within the valid range [-180, 180].
|
|
122
|
+
*
|
|
123
|
+
* @param lat - longitude value to validate
|
|
124
|
+
* @returns `true` if the value is a valid longitude
|
|
125
|
+
*/
|
|
40
126
|
export declare function isValidLongitude(lat: Longitude): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Returns the default {@link LatLngPoint} at the origin (0, 0).
|
|
129
|
+
*
|
|
130
|
+
* @returns a point at latitude 0, longitude 0
|
|
131
|
+
*/
|
|
41
132
|
export declare function defaultLatLngPoint(): LatLngPoint;
|
|
133
|
+
/**
|
|
134
|
+
* Checks whether a point or string represents the default (0, 0) location.
|
|
135
|
+
* Treats empty strings as the default.
|
|
136
|
+
*
|
|
137
|
+
* @param point - a point or lat/lng string to check
|
|
138
|
+
* @returns `true` if the input represents the default location
|
|
139
|
+
*/
|
|
42
140
|
export declare function isDefaultLatLngPoint(point: LatLngPoint | LatLngString | ''): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Checks whether a point has coordinates of exactly (0, 0).
|
|
143
|
+
*
|
|
144
|
+
* @param point - point to check
|
|
145
|
+
* @returns `true` if both `lat` and `lng` are 0
|
|
146
|
+
*/
|
|
43
147
|
export declare function isDefaultLatLngPointValue(point: LatLngPoint): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Returns the south-west-most possible point (-90, -180).
|
|
150
|
+
*
|
|
151
|
+
* @returns the minimum corner of the valid coordinate space
|
|
152
|
+
*/
|
|
44
153
|
export declare function swMostLatLngPoint(): LatLngPoint;
|
|
154
|
+
/**
|
|
155
|
+
* Returns the north-east-most possible point (90, 180).
|
|
156
|
+
*
|
|
157
|
+
* @returns the maximum corner of the valid coordinate space
|
|
158
|
+
*/
|
|
45
159
|
export declare function neMostLatLngPoint(): LatLngPoint;
|
|
46
160
|
/**
|
|
47
161
|
* Returns true if the input point's lat/lng values are within the acceptable values range.
|
|
48
162
|
*
|
|
49
|
-
* @param input
|
|
50
|
-
* @returns
|
|
163
|
+
* @param input - point to validate
|
|
164
|
+
* @returns `true` if both lat and lng are within valid ranges
|
|
51
165
|
*/
|
|
52
166
|
export declare function isValidLatLngPoint(input: LatLngPoint): boolean;
|
|
53
167
|
/**
|
|
@@ -59,53 +173,75 @@ export type LatLngTuple = [Latitude, Longitude];
|
|
|
59
173
|
*/
|
|
60
174
|
export type LonLatTuple = [Longitude, Latitude];
|
|
61
175
|
/**
|
|
62
|
-
* Converts the input to a LatLngTuple.
|
|
176
|
+
* Converts the input to a {@link LatLngTuple} using the default configuration.
|
|
63
177
|
*
|
|
64
|
-
* @param lat
|
|
65
|
-
* @param lng
|
|
66
|
-
* @returns
|
|
178
|
+
* @param lat - a latitude value or any lat/lng point input
|
|
179
|
+
* @param lng - optional longitude when `lat` is a numeric latitude
|
|
180
|
+
* @returns a `[lat, lng]` tuple
|
|
67
181
|
*/
|
|
68
182
|
export declare function latLngTuple(lat: LatLngPointInput, lng?: Longitude): LatLngTuple;
|
|
69
183
|
/**
|
|
70
|
-
* Converts the input to a LonLatTuple.
|
|
184
|
+
* Converts the input to a {@link LonLatTuple} (longitude-first ordering), useful for interop with libraries like Mapbox.
|
|
185
|
+
*
|
|
186
|
+
* @param lat - a latitude value or any lat/lng point input
|
|
187
|
+
* @param lng - optional longitude when `lat` is a numeric latitude
|
|
188
|
+
* @returns a `[lng, lat]` tuple
|
|
71
189
|
*
|
|
72
|
-
* @
|
|
73
|
-
*
|
|
74
|
-
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* const result: LonLatTuple = lonLatTuple([-120, 80]);
|
|
193
|
+
* // result === [-120, 80]
|
|
194
|
+
* ```
|
|
75
195
|
*/
|
|
76
196
|
export declare function lonLatTuple(lat: LatLngPointInput, lng?: Longitude): LonLatTuple;
|
|
77
197
|
/**
|
|
78
|
-
* Converts
|
|
198
|
+
* Converts various lat/lng input formats into a {@link LatLngTuple}.
|
|
79
199
|
*/
|
|
80
200
|
export type LatLngTupleFunction = ((lat: LatLngPointInput, lng?: Longitude) => LatLngTuple) & ((latLng: string | LatLngTuple) => LatLngTuple) & ((latLng: LatLngPoint | LonLatPoint) => LatLngTuple) & ((lat: Latitude, lng?: Longitude) => LatLngTuple);
|
|
81
201
|
export type LatLngTupleFunctionConfig = LatLngPointFunctionConfig;
|
|
82
202
|
/**
|
|
83
|
-
* Creates a LatLngTupleFunction
|
|
203
|
+
* Creates a {@link LatLngTupleFunction} that converts various input formats into `[lat, lng]` tuples,
|
|
204
|
+
* applying optional precision configuration.
|
|
84
205
|
*
|
|
85
|
-
* @param precision
|
|
86
|
-
* @returns
|
|
206
|
+
* @param config - optional configuration for precision and wrapping behavior
|
|
207
|
+
* @returns a function that produces lat/lng tuples from flexible inputs
|
|
87
208
|
*/
|
|
88
209
|
export declare function latLngTupleFunction(config?: LatLngTupleFunctionConfig): LatLngTupleFunction;
|
|
89
210
|
/**
|
|
90
|
-
* A lat,lng encoded value.
|
|
211
|
+
* A lat,lng encoded value as a comma-separated string.
|
|
91
212
|
*/
|
|
92
213
|
export type LatLngString = `${Latitude},${Longitude}`;
|
|
93
214
|
/**
|
|
94
215
|
* Default LatLng value as a string.
|
|
95
216
|
*/
|
|
96
217
|
export declare const DEFAULT_LAT_LNG_STRING_VALUE = "0,0";
|
|
218
|
+
/**
|
|
219
|
+
* Returns the default {@link LatLngString} value (`'0,0'`).
|
|
220
|
+
*
|
|
221
|
+
* @returns the default lat/lng string
|
|
222
|
+
*/
|
|
97
223
|
export declare function defaultLatLngString(): typeof DEFAULT_LAT_LNG_STRING_VALUE;
|
|
224
|
+
/**
|
|
225
|
+
* Union type of all accepted input formats for creating a {@link LatLngPoint}: a numeric latitude, a point object, a lat/lng string, or a tuple.
|
|
226
|
+
*/
|
|
98
227
|
export type LatLngPointInput = Latitude | LatLngPoint | LonLatPoint | LatLngString | LatLngTuple | string;
|
|
228
|
+
/**
|
|
229
|
+
* Precision for lat/lng rounding, expressed as the number of decimal places.
|
|
230
|
+
*/
|
|
99
231
|
export type LatLngPrecision = NumberPrecision;
|
|
100
232
|
/**
|
|
101
|
-
* Creates a LatLngString from the input.
|
|
233
|
+
* Creates a {@link LatLngString} from the input using the default configuration.
|
|
102
234
|
*
|
|
103
|
-
* @param lat
|
|
104
|
-
* @param lng
|
|
235
|
+
* @param lat - latitude value or a point input
|
|
236
|
+
* @param lng - optional longitude when `lat` is a numeric latitude
|
|
237
|
+
* @returns a comma-separated lat/lng string
|
|
105
238
|
*/
|
|
106
239
|
export declare function latLngString(lat: Latitude, lng?: Longitude): LatLngString;
|
|
107
240
|
export declare function latLngString(latLng: LatLngPoint): LatLngString;
|
|
108
241
|
export declare function latLngString(latLng: LatLngString): LatLngString;
|
|
242
|
+
/**
|
|
243
|
+
* Maximum number of decimal places supported by the lat/lng regex pattern.
|
|
244
|
+
*/
|
|
109
245
|
export declare const LAT_LNG_PATTERN_MAX_PRECISION = 15;
|
|
110
246
|
/**
|
|
111
247
|
* A lat/lng regex with capture groups for lat and lng.
|
|
@@ -116,37 +252,38 @@ export declare const LAT_LNG_PATTERN_MAX_PRECISION = 15;
|
|
|
116
252
|
*/
|
|
117
253
|
export declare const LAT_LNG_PATTERN: RegExp;
|
|
118
254
|
/**
|
|
119
|
-
* Checks whether
|
|
255
|
+
* Checks whether the input string matches the expected lat/lng pattern (e.g., `"30.5,-96.3"`).
|
|
120
256
|
*
|
|
121
|
-
* @param input
|
|
257
|
+
* @param input - string to test
|
|
258
|
+
* @returns `true` if the string is a valid lat/lng format
|
|
122
259
|
*/
|
|
123
260
|
export declare function isLatLngString(input: string): input is LatLngString;
|
|
124
261
|
/**
|
|
125
|
-
* 111KM meter
|
|
262
|
+
* 111KM meter precision, 0 decimal places
|
|
126
263
|
*/
|
|
127
264
|
export declare const LAT_LONG_100KM_PRECISION = 0;
|
|
128
265
|
/**
|
|
129
|
-
* 11.1KM meter
|
|
266
|
+
* 11.1KM meter precision, 1 decimal place
|
|
130
267
|
*/
|
|
131
268
|
export declare const LAT_LONG_10KM_PRECISION = 1;
|
|
132
269
|
/**
|
|
133
|
-
* 1.11KM meter
|
|
270
|
+
* 1.11KM meter precision, 2 decimal places
|
|
134
271
|
*/
|
|
135
272
|
export declare const LAT_LONG_1KM_PRECISION = 2;
|
|
136
273
|
/**
|
|
137
|
-
* 111 meter
|
|
274
|
+
* 111 meter precision, 3 decimal places
|
|
138
275
|
*/
|
|
139
276
|
export declare const LAT_LONG_100M_PRECISION = 3;
|
|
140
277
|
/**
|
|
141
|
-
* 11.1 meter
|
|
278
|
+
* 11.1 meter precision, 4 decimal places
|
|
142
279
|
*/
|
|
143
280
|
export declare const LAT_LONG_10M_PRECISION = 4;
|
|
144
281
|
/**
|
|
145
|
-
* 001.11 meter
|
|
282
|
+
* 001.11 meter precision, 5 decimal places
|
|
146
283
|
*/
|
|
147
284
|
export declare const LAT_LONG_1M_PRECISION = 5;
|
|
148
285
|
/**
|
|
149
|
-
* 011.10 centimeter
|
|
286
|
+
* 011.10 centimeter precision, 6 decimal places
|
|
150
287
|
*/
|
|
151
288
|
export declare const LAT_LONG_10CM_PRECISION = 6;
|
|
152
289
|
/**
|
|
@@ -170,27 +307,34 @@ export declare const LAT_LONG_GRAINS_OF_SAND_PRECISION = 9;
|
|
|
170
307
|
*/
|
|
171
308
|
export type LatLngPointPrecisionFunction = (latLngPoint: LatLngPoint) => LatLngPoint;
|
|
172
309
|
/**
|
|
173
|
-
* Creates a LatLngPointPrecisionFunction
|
|
174
|
-
*
|
|
175
|
-
*
|
|
310
|
+
* Creates a {@link LatLngPointPrecisionFunction} that rounds both lat and lng values
|
|
311
|
+
* to the specified number of decimal places.
|
|
312
|
+
*
|
|
313
|
+
* @param precision - number of decimal places to retain
|
|
314
|
+
* @param precisionRounding - optional rounding strategy (e.g., floor, ceil, round)
|
|
315
|
+
* @returns a function that rounds points to the given precision
|
|
176
316
|
*/
|
|
177
317
|
export declare function latLngPointPrecisionFunction(precision: LatLngPrecision, precisionRounding?: RoundToPrecisionFunctionType): LatLngPointPrecisionFunction;
|
|
178
318
|
/**
|
|
179
|
-
* Converts
|
|
319
|
+
* Converts various lat/lng input formats into a {@link LatLngString}.
|
|
180
320
|
*/
|
|
181
321
|
export type LatLngStringFunction = ((lat: LatLngPointInput, lng?: Longitude) => LatLngString) & ((latLng: string | LatLngString) => LatLngString) & ((latLng: LatLngPoint | LonLatPoint) => LatLngString) & ((lat: Latitude, lng?: Longitude) => LatLngString);
|
|
182
322
|
export type LatLngStringFunctionConfig = LatLngPointFunctionConfig;
|
|
183
323
|
/**
|
|
184
|
-
* Creates a LatLngStringFunction
|
|
324
|
+
* Creates a {@link LatLngStringFunction} that converts various input formats into comma-separated lat/lng strings,
|
|
325
|
+
* applying optional precision configuration.
|
|
185
326
|
*
|
|
186
|
-
* @param precision
|
|
187
|
-
* @returns
|
|
327
|
+
* @param config - optional configuration for precision and wrapping behavior
|
|
328
|
+
* @returns a function that produces lat/lng strings from flexible inputs
|
|
188
329
|
*/
|
|
189
330
|
export declare function latLngStringFunction(config?: LatLngStringFunctionConfig): LatLngStringFunction;
|
|
190
331
|
/**
|
|
191
|
-
* Converts
|
|
332
|
+
* Converts various lat/lng input formats into a {@link LatLngPoint}.
|
|
192
333
|
*/
|
|
193
334
|
export type LatLngPointFunction = ((lat: LatLngPointInput, lng?: Longitude) => LatLngPoint) & ((latLng: string | LatLngString) => LatLngPoint) & ((latLng: LatLngPoint | LonLatPoint) => LatLngPoint) & ((lat: Latitude, lng: Longitude) => LatLngPoint);
|
|
335
|
+
/**
|
|
336
|
+
* Configuration for creating a {@link LatLngPointFunction}.
|
|
337
|
+
*/
|
|
194
338
|
export interface LatLngPointFunctionConfig {
|
|
195
339
|
/**
|
|
196
340
|
* LatLngPrecision to use
|
|
@@ -222,33 +366,60 @@ export interface LatLngPointFunctionConfig {
|
|
|
222
366
|
readLonLatTuples?: boolean;
|
|
223
367
|
}
|
|
224
368
|
/**
|
|
225
|
-
* Creates a LatLngPoint.
|
|
369
|
+
* Creates a {@link LatLngPoint} using the default configuration. Convenience wrapper around {@link latLngPointFunction}.
|
|
370
|
+
*
|
|
371
|
+
* @param lat - a latitude value or any lat/lng point input
|
|
372
|
+
* @param lng - optional longitude when `lat` is a numeric latitude
|
|
373
|
+
* @returns the parsed and normalized point
|
|
226
374
|
*
|
|
227
|
-
* @
|
|
228
|
-
*
|
|
229
|
-
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```ts
|
|
377
|
+
* const point = latLngPoint(30.59929, -96.38315);
|
|
378
|
+
* // point.lat === 30.59929, point.lng === -96.38315
|
|
379
|
+
* ```
|
|
230
380
|
*/
|
|
231
381
|
export declare function latLngPoint(lat: LatLngPointInput, lng?: Longitude): LatLngPoint;
|
|
232
382
|
/**
|
|
233
|
-
* Creates a LatLngPointFunction
|
|
383
|
+
* Creates a {@link LatLngPointFunction} that normalizes various input formats (numbers, strings, tuples, objects)
|
|
384
|
+
* into a {@link LatLngPoint}, with configurable precision, wrapping, and validation.
|
|
385
|
+
*
|
|
386
|
+
* @param config - optional configuration for precision, wrapping, validation, and tuple ordering
|
|
387
|
+
* @returns a function that produces points from flexible inputs
|
|
388
|
+
* @throws {Error} when the input cannot be parsed into a valid point
|
|
234
389
|
*
|
|
235
|
-
* @
|
|
236
|
-
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* const fn = latLngPointFunction({ precision: 3 });
|
|
393
|
+
* const result = fn(30.59929, -96.38315);
|
|
394
|
+
* // result.lat === 30.599, result.lng === -96.383
|
|
395
|
+
* ```
|
|
237
396
|
*/
|
|
238
397
|
export declare function latLngPointFunction(config?: LatLngPointFunctionConfig): LatLngPointFunction;
|
|
239
398
|
/**
|
|
240
|
-
*
|
|
399
|
+
* Parses a comma-separated lat/lng string into a {@link LatLngPoint}. Invalid numeric values default to 0.
|
|
241
400
|
*
|
|
242
|
-
* @param latLngString
|
|
401
|
+
* @param latLngString - string in the format `"lat,lng"`
|
|
402
|
+
* @returns the parsed point
|
|
243
403
|
*/
|
|
244
404
|
export declare function latLngPointFromString(latLngString: LatLngString | string): LatLngPoint;
|
|
405
|
+
/**
|
|
406
|
+
* Validates a point and returns it if valid, or a default point otherwise.
|
|
407
|
+
*
|
|
408
|
+
* @param latLngPoint - point to validate
|
|
409
|
+
* @param defaultValue - optional factory for the fallback point; defaults to `defaultLatLngPoint`
|
|
410
|
+
* @returns the original point if valid, or the default
|
|
411
|
+
*/
|
|
245
412
|
export declare function validLatLngPoint(latLngPoint: LatLngPoint, defaultValue?: Factory<LatLngPoint>): LatLngPoint;
|
|
246
413
|
/**
|
|
247
414
|
* Returns a valid LatLngPoint by validating the input and returns the input value if it is valid, or a default value that is valid.
|
|
248
|
-
*
|
|
249
|
-
* @param latLngPoint
|
|
250
415
|
*/
|
|
251
416
|
export type ValidLatLngPointFunction = (latLngPoint: LatLngPoint) => LatLngPoint;
|
|
417
|
+
/**
|
|
418
|
+
* Creates a {@link ValidLatLngPointFunction} that returns the input point when valid, or a default point otherwise.
|
|
419
|
+
*
|
|
420
|
+
* @param defaultValue - factory for the fallback point; defaults to `defaultLatLngPoint`
|
|
421
|
+
* @returns a validation function
|
|
422
|
+
*/
|
|
252
423
|
export declare function validLatLngPointFunction(defaultValue?: Factory<LatLngPoint>): ValidLatLngPointFunction;
|
|
253
424
|
/**
|
|
254
425
|
* References a latLng using a LatLngPoint
|
|
@@ -289,22 +460,44 @@ export type LatLngDataPoint<T> = LatLngPointRef & {
|
|
|
289
460
|
*/
|
|
290
461
|
export type LatLngDataPointFunction<T extends LatLngRef> = (data: T) => LatLngDataPoint<T>;
|
|
291
462
|
/**
|
|
292
|
-
* Creates a LatLngDataPointFunction
|
|
463
|
+
* Creates a {@link LatLngDataPointFunction} that wraps a {@link LatLngRef} object with its resolved point coordinates.
|
|
293
464
|
*
|
|
294
|
-
* @param precision
|
|
295
|
-
* @returns
|
|
465
|
+
* @param config - optional configuration for precision and wrapping behavior
|
|
466
|
+
* @returns a function that produces data points from lat/lng references
|
|
296
467
|
*/
|
|
297
468
|
export declare function latLngDataPointFunction<T extends LatLngRef>(config?: LatLngPointFunctionConfig): LatLngDataPointFunction<T>;
|
|
469
|
+
/**
|
|
470
|
+
* Configuration for {@link randomLatLngFactory}.
|
|
471
|
+
*/
|
|
298
472
|
export interface RandomLatLngFactoryConfig {
|
|
473
|
+
/**
|
|
474
|
+
* South-west corner of the bounding box for random generation. Partial values default to the minimum valid coordinates.
|
|
475
|
+
*/
|
|
299
476
|
sw?: Partial<LatLngPoint>;
|
|
477
|
+
/**
|
|
478
|
+
* North-east corner of the bounding box for random generation. Partial values default to the maximum valid coordinates.
|
|
479
|
+
*/
|
|
300
480
|
ne?: Partial<LatLngPoint>;
|
|
301
481
|
/**
|
|
302
482
|
* Precision of the LatLng to keep.
|
|
303
483
|
*/
|
|
304
484
|
precision?: LatLngPrecision;
|
|
305
485
|
}
|
|
486
|
+
/**
|
|
487
|
+
* A factory that produces random {@link LatLngPoint} values.
|
|
488
|
+
*/
|
|
306
489
|
export type RandomLatLngFactory = () => LatLngPoint;
|
|
490
|
+
/**
|
|
491
|
+
* Creates a {@link RandomLatLngFactory} that generates random points within the specified bounding box.
|
|
492
|
+
* The bounding box corners are capped/wrapped to valid coordinate ranges.
|
|
493
|
+
*
|
|
494
|
+
* @param config - optional bounding box and precision configuration
|
|
495
|
+
* @returns a factory that produces random points within the bounds
|
|
496
|
+
*/
|
|
307
497
|
export declare function randomLatLngFactory(config?: RandomLatLngFactoryConfig): RandomLatLngFactory;
|
|
498
|
+
/**
|
|
499
|
+
* Configuration for {@link randomLatLngFromCenterFactory}.
|
|
500
|
+
*/
|
|
308
501
|
export interface RandomLatLngFromCenterFactoryConfig extends Pick<RandomLatLngFactoryConfig, 'precision'> {
|
|
309
502
|
/**
|
|
310
503
|
* Center from which a rectangle is generated to pick random
|
|
@@ -320,9 +513,10 @@ export interface RandomLatLngFromCenterFactoryConfig extends Pick<RandomLatLngFa
|
|
|
320
513
|
lngDistance: number;
|
|
321
514
|
}
|
|
322
515
|
/**
|
|
323
|
-
* Creates a RandomLatLngFactory that
|
|
516
|
+
* Creates a {@link RandomLatLngFactory} that generates random points within a rectangle
|
|
517
|
+
* centered on the given point, extending by `latDistance` and `lngDistance` in each direction.
|
|
324
518
|
*
|
|
325
|
-
* @param config
|
|
326
|
-
* @returns
|
|
519
|
+
* @param config - center point, distances, and optional precision
|
|
520
|
+
* @returns a factory that produces random points near the center
|
|
327
521
|
*/
|
|
328
522
|
export declare function randomLatLngFromCenterFactory(config: RandomLatLngFromCenterFactoryConfig): RandomLatLngFactory;
|
package/src/lib/value/url.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Strips query parameters (`?...`) and hash fragments (`#...`) from a URL string, returning only the base URL.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Operates via simple string splitting rather than URL parsing, so it works with partial or non-standard URLs.
|
|
5
|
+
*
|
|
6
|
+
* @param url - the full URL string to clean
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const base = urlWithoutParameters('https://test.com:1234?test=true');
|
|
11
|
+
* // base === 'https://test.com:1234'
|
|
12
|
+
* ```
|
|
6
13
|
*/
|
|
7
14
|
export declare function urlWithoutParameters(url: string): string;
|
package/src/lib/value/use.d.ts
CHANGED
|
@@ -3,40 +3,131 @@ import { type PromiseOrValue } from '../promise/promise.type';
|
|
|
3
3
|
import { type MapFunction } from './map';
|
|
4
4
|
import { type Maybe } from './maybe.type';
|
|
5
5
|
/**
|
|
6
|
-
* A
|
|
6
|
+
* A MapFunction whose primary intent is to consume (use) the input value, optionally producing an output.
|
|
7
|
+
* Defaults to void when no output is needed, making it suitable for side-effect-style consumers.
|
|
7
8
|
*/
|
|
8
9
|
export type UseValue<I, O = void> = MapFunction<I, O>;
|
|
10
|
+
/**
|
|
11
|
+
* Applies the `use` function to the input if it is defined, otherwise returns the `defaultValue`.
|
|
12
|
+
* Provides a safe pattern for consuming nullable values with a fallback.
|
|
13
|
+
*
|
|
14
|
+
* @param input - the possibly null/undefined value to consume
|
|
15
|
+
* @param use - function to apply when input is defined
|
|
16
|
+
* @param defaultValue - fallback value or getter used when input is null/undefined
|
|
17
|
+
* @returns the result of `use`, or the default value if input was null/undefined
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const result = useValue(5, (x) => x * 2);
|
|
22
|
+
* // result === 10
|
|
23
|
+
*
|
|
24
|
+
* const fallback = useValue(undefined, (x: number) => x * 2, 0);
|
|
25
|
+
* // fallback === 0
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
9
28
|
export declare function useValue<I, O = void>(input: Maybe<I>, use: UseValue<I, O>, defaultValue?: Maybe<GetterOrValue<O>>): Maybe<O>;
|
|
29
|
+
/**
|
|
30
|
+
* A MappedUseFunction where no mapping step is applied; the input type is used directly.
|
|
31
|
+
*/
|
|
10
32
|
export type UseFunction<I> = MappedUseFunction<I, I>;
|
|
33
|
+
/**
|
|
34
|
+
* A function that first maps an input of type `A` to type `I`, then applies a {@link UseValue} consumer
|
|
35
|
+
* to the mapped result. Falls back to a default value when the input is null/undefined.
|
|
36
|
+
*/
|
|
11
37
|
export type MappedUseFunction<A, I> = <O = void>(input: Maybe<A>, use: UseValue<I, O>, defaultValue?: Maybe<GetterOrValue<O>>) => Maybe<O>;
|
|
12
38
|
/**
|
|
13
|
-
* Creates a MappedUseFunction.
|
|
39
|
+
* Creates a {@link MappedUseFunction} that transforms the input through the given `map` before applying the consumer.
|
|
40
|
+
* If the mapped result is null/undefined, the default value is returned instead.
|
|
41
|
+
*
|
|
42
|
+
* @param map - transforms the outer input into the type expected by the consumer
|
|
43
|
+
* @returns a MappedUseFunction that maps then consumes
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const mapFn = (n: number) => String(n);
|
|
48
|
+
* const mappedUseFn = mappedUseFunction(mapFn);
|
|
49
|
+
*
|
|
50
|
+
* const result = mappedUseFn(1, () => 'hello');
|
|
51
|
+
* // result === 'hello'
|
|
52
|
+
*
|
|
53
|
+
* const fallback = mappedUseFn(undefined, () => 'wrong', 'default');
|
|
54
|
+
* // fallback === 'default'
|
|
55
|
+
* ```
|
|
14
56
|
*/
|
|
15
57
|
export declare function mappedUseFunction<A, I>(map: MapFunction<A, Maybe<I>>): MappedUseFunction<A, I>;
|
|
16
58
|
/**
|
|
17
|
-
* Wraps
|
|
59
|
+
* Wraps an existing {@link MappedUseFunction} with an additional mapping step, allowing further transformation
|
|
60
|
+
* of the intermediate value before it reaches the consumer.
|
|
61
|
+
*
|
|
62
|
+
* @param mappedUseFn - the existing mapped use function to wrap
|
|
63
|
+
* @param map - additional transformation applied to the intermediate value
|
|
64
|
+
* @returns a new MappedUseFunction with the extra mapping layer
|
|
18
65
|
*/
|
|
19
66
|
export declare function wrapUseFunction<A, B, I>(mappedUseFn: MappedUseFunction<A, B>, map: MapFunction<B, Maybe<I>>): MappedUseFunction<A, I>;
|
|
20
67
|
/**
|
|
21
|
-
*
|
|
68
|
+
* A pre-configured consumer function that accepts an input and returns a value, encapsulating both the
|
|
69
|
+
* consumer logic and default value in a single callable.
|
|
22
70
|
*/
|
|
23
71
|
export type UseContextFunction<I> = <O>(input: Maybe<I>) => Maybe<O>;
|
|
24
72
|
/**
|
|
25
|
-
* Creates a UseContextFunction
|
|
73
|
+
* Creates a {@link UseContextFunction} by binding a consumer and optional default value, so callers
|
|
74
|
+
* only need to supply the input.
|
|
75
|
+
*
|
|
76
|
+
* @param use - the consumer function to bind
|
|
77
|
+
* @param defaultValue - fallback when input is null/undefined
|
|
78
|
+
* @returns a single-argument function that applies the bound consumer
|
|
26
79
|
*/
|
|
27
80
|
export declare function useContextFunction<I, O>(use: UseValue<I, O>, defaultValue?: GetterOrValue<O>): UseContextFunction<I>;
|
|
28
81
|
/**
|
|
29
|
-
*
|
|
82
|
+
* Async variant of {@link UseValue} that may return a Promise, allowing asynchronous consumption of values.
|
|
30
83
|
*/
|
|
31
84
|
export type UseAsync<I, O = void> = MapFunction<I, PromiseOrValue<O>>;
|
|
85
|
+
/**
|
|
86
|
+
* Async variant of {@link useValue}. Awaits the consumer result and supports async default value getters.
|
|
87
|
+
*
|
|
88
|
+
* @param input - the possibly null/undefined value to consume
|
|
89
|
+
* @param use - async-capable consumer function
|
|
90
|
+
* @param defaultValue - fallback value or getter when input is null/undefined
|
|
91
|
+
* @returns a Promise resolving to the consumer result or the default value
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const result = await useAsync(1, (x) => Promise.resolve(x * 2));
|
|
96
|
+
* // result === 2
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
32
99
|
export declare function useAsync<I, O = void>(input: Maybe<I>, use: UseValue<I, O>, defaultValue?: Maybe<GetterOrValue<O>>): Promise<Maybe<O>>;
|
|
100
|
+
/**
|
|
101
|
+
* A {@link MappedUseAsyncFunction} where no mapping step is applied; the input type is used directly.
|
|
102
|
+
*/
|
|
33
103
|
export type UseAsyncFunction<I> = MappedUseAsyncFunction<I, I>;
|
|
104
|
+
/**
|
|
105
|
+
* Async variant of {@link MappedUseFunction} that maps, then asynchronously consumes the result.
|
|
106
|
+
*/
|
|
34
107
|
export type MappedUseAsyncFunction<A, I> = <O = void>(input: Maybe<A>, use: UseAsync<I, O>, defaultValue?: Maybe<AsyncGetterOrValue<O>>) => Promise<Maybe<O>>;
|
|
35
108
|
/**
|
|
36
|
-
* Creates a
|
|
109
|
+
* Creates a {@link MappedUseAsyncFunction} that transforms the input through the given `map` (which may return a Promise)
|
|
110
|
+
* before applying the async consumer.
|
|
111
|
+
*
|
|
112
|
+
* @param map - transforms the outer input, optionally asynchronously, into the type expected by the consumer
|
|
113
|
+
* @returns a MappedUseAsyncFunction that maps then asynchronously consumes
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const mapFn = (n: number) => String(n);
|
|
118
|
+
* const mappedUseAsyncFn = mappedUseAsyncFunction(mapFn);
|
|
119
|
+
*
|
|
120
|
+
* const result = await mappedUseAsyncFn(1, () => Promise.resolve('hello'));
|
|
121
|
+
* // result === 'hello'
|
|
122
|
+
* ```
|
|
37
123
|
*/
|
|
38
124
|
export declare function mappedUseAsyncFunction<A, I>(map: MapFunction<A, Maybe<PromiseOrValue<Maybe<I>>>>): MappedUseAsyncFunction<A, I>;
|
|
39
125
|
/**
|
|
40
|
-
* Wraps
|
|
126
|
+
* Wraps an existing {@link MappedUseAsyncFunction} with an additional async-capable mapping step,
|
|
127
|
+
* allowing further transformation of the intermediate value before it reaches the consumer.
|
|
128
|
+
*
|
|
129
|
+
* @param mappedUsePromiseFn - the existing async mapped use function to wrap
|
|
130
|
+
* @param map - additional transformation (sync or async) applied to the intermediate value
|
|
131
|
+
* @returns a new MappedUseAsyncFunction with the extra mapping layer
|
|
41
132
|
*/
|
|
42
133
|
export declare function wrapUseAsyncFunction<A, B, I>(mappedUsePromiseFn: MappedUseAsyncFunction<A, B>, map: MapFunction<B, Maybe<PromiseOrValue<Maybe<I>>>>): MappedUseAsyncFunction<A, I>;
|