@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
|
@@ -1,67 +1,116 @@
|
|
|
1
1
|
import { type Maybe } from './maybe.type';
|
|
2
2
|
/**
|
|
3
|
-
* City name
|
|
3
|
+
* City name string (e.g. "San Antonio").
|
|
4
4
|
*/
|
|
5
5
|
export type CityString = string;
|
|
6
6
|
/**
|
|
7
|
-
* Full state name
|
|
7
|
+
* Full state name string (e.g. "Texas").
|
|
8
8
|
*/
|
|
9
9
|
export type StateString = string;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Two-letter US state code (e.g. "TX").
|
|
12
12
|
*/
|
|
13
13
|
export type StateCodeString = string;
|
|
14
14
|
/**
|
|
15
|
-
* Full country name
|
|
15
|
+
* Full country name string (e.g. "United States").
|
|
16
16
|
*/
|
|
17
17
|
export type CountryString = string;
|
|
18
18
|
/**
|
|
19
|
-
* Country code
|
|
19
|
+
* Country code string (e.g. "US").
|
|
20
20
|
*/
|
|
21
21
|
export type CountryCodeString = string;
|
|
22
|
+
/**
|
|
23
|
+
* A single line in a street address.
|
|
24
|
+
*/
|
|
22
25
|
export type AddressLineString = string;
|
|
26
|
+
/**
|
|
27
|
+
* Postal/zip code string.
|
|
28
|
+
*/
|
|
23
29
|
export type ZipCodeString = string;
|
|
24
30
|
/**
|
|
25
|
-
* Basic US
|
|
31
|
+
* Basic US address with two address lines, city, state, and zip code.
|
|
26
32
|
*/
|
|
27
33
|
export interface UnitedStatesAddress {
|
|
34
|
+
/** Primary street address line. */
|
|
28
35
|
line1: AddressLineString;
|
|
36
|
+
/** Secondary address line (apartment, suite, etc.). */
|
|
29
37
|
line2?: AddressLineString;
|
|
38
|
+
/** City name. */
|
|
30
39
|
city: CityString;
|
|
40
|
+
/** State name or two-letter state code. */
|
|
31
41
|
state: StateString | StateCodeString;
|
|
42
|
+
/** Postal/zip code. */
|
|
32
43
|
zip: ZipCodeString;
|
|
33
44
|
}
|
|
34
45
|
/**
|
|
35
|
-
* UnitedStatesAddress with
|
|
46
|
+
* Extends {@link UnitedStatesAddress} with optional contact information for display purposes,
|
|
47
|
+
* such as a recipient name and phone number.
|
|
36
48
|
*/
|
|
37
49
|
export interface UnitedStatesAddressWithContact extends UnitedStatesAddress {
|
|
50
|
+
/** Contact name associated with this address. */
|
|
38
51
|
name?: string;
|
|
52
|
+
/** Phone number associated with this address. */
|
|
39
53
|
phone?: string;
|
|
40
54
|
}
|
|
41
55
|
/**
|
|
42
|
-
*
|
|
56
|
+
* Formats a {@link UnitedStatesAddress} or {@link UnitedStatesAddressWithContact} into a human-readable multi-line string.
|
|
43
57
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
58
|
+
* Empty or undefined fields are omitted. If the input includes contact fields (name, phone), they appear at the top.
|
|
59
|
+
* Returns `undefined` if no meaningful parts are present.
|
|
60
|
+
*
|
|
61
|
+
* @param input - the address to format
|
|
62
|
+
* @param addLinebreaks - whether to join parts with newlines (default `true`) or concatenate them directly
|
|
46
63
|
*/
|
|
47
64
|
export declare function unitedStatesAddressString(input: Maybe<Partial<UnitedStatesAddress | UnitedStatesAddressWithContact>>, addLinebreaks?: boolean): Maybe<string>;
|
|
48
65
|
/**
|
|
49
|
-
*
|
|
66
|
+
* Checks whether the input address has all required fields populated (line1, city, state, zip).
|
|
67
|
+
*
|
|
68
|
+
* Useful for validating an address before submission or display.
|
|
69
|
+
*
|
|
70
|
+
* @param input - the address to validate
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const address: UnitedStatesAddress = {
|
|
75
|
+
* line1: 'hello world',
|
|
76
|
+
* city: 'San Antonio',
|
|
77
|
+
* state: 'TX',
|
|
78
|
+
* zip: '78216'
|
|
79
|
+
* };
|
|
50
80
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
81
|
+
* isCompleteUnitedStatesAddress(address);
|
|
82
|
+
* // true
|
|
83
|
+
* ```
|
|
53
84
|
*/
|
|
54
85
|
export declare function isCompleteUnitedStatesAddress(input: Maybe<UnitedStatesAddress>): boolean;
|
|
55
86
|
/**
|
|
56
|
-
* Regex
|
|
87
|
+
* Regex that matches valid two-letter US state and territory codes (uppercase only).
|
|
88
|
+
*
|
|
89
|
+
* Includes all 50 states plus DC, PR, GU, AS, MP, VI, FM, MH, and PW.
|
|
57
90
|
*/
|
|
58
91
|
export declare const US_STATE_CODE_STRING_REGEX: RegExp;
|
|
92
|
+
/**
|
|
93
|
+
* Tests whether the input string is a valid two-letter US state or territory code.
|
|
94
|
+
*
|
|
95
|
+
* Only matches uppercase codes; lowercase input returns `false`.
|
|
96
|
+
*
|
|
97
|
+
* @param input - the string to test
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* isUsStateCodeString('TX');
|
|
102
|
+
* // true
|
|
103
|
+
*
|
|
104
|
+
* isUsStateCodeString('XX');
|
|
105
|
+
* // false
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
59
108
|
export declare function isUsStateCodeString(input: string): boolean;
|
|
60
109
|
/**
|
|
61
|
-
* Simple regex
|
|
110
|
+
* Simple regex for validating postal/zip codes.
|
|
62
111
|
*
|
|
63
|
-
*
|
|
112
|
+
* Matches alphanumeric codes between 2 and 12 characters, allowing hyphens and spaces in the middle.
|
|
64
113
|
*
|
|
65
|
-
* https://stackoverflow.com/a/19844362
|
|
114
|
+
* Credit: https://stackoverflow.com/a/19844362
|
|
66
115
|
*/
|
|
67
116
|
export declare const ZIP_CODE_STRING_REGEX: RegExp;
|
package/src/lib/value/bound.d.ts
CHANGED
|
@@ -3,70 +3,204 @@ import { type Rectangle } from './vector';
|
|
|
3
3
|
import { type LatLngPoint, type LatLngPointInput, type LatLngPrecision, type LatLngPointFunction } from './point';
|
|
4
4
|
import { type DecisionFunction } from './decision';
|
|
5
5
|
import { type ArrayOrValue } from '../array';
|
|
6
|
+
/**
|
|
7
|
+
* Alias for the south-west corner point of a {@link LatLngBound}.
|
|
8
|
+
*/
|
|
6
9
|
export type LatLngBoundSouthWestPoint = LatLngPoint;
|
|
10
|
+
/**
|
|
11
|
+
* Alias for the north-east corner point of a {@link LatLngBound}.
|
|
12
|
+
*/
|
|
7
13
|
export type LatLngBoundNothEastPoint = LatLngPoint;
|
|
14
|
+
/**
|
|
15
|
+
* A geographic bounding box defined by its south-west and north-east corner points.
|
|
16
|
+
*
|
|
17
|
+
* Used throughout the library for spatial queries, overlap detection, and map viewport calculations.
|
|
18
|
+
*/
|
|
8
19
|
export interface LatLngBound {
|
|
9
20
|
sw: LatLngBoundSouthWestPoint;
|
|
10
21
|
ne: LatLngBoundNothEastPoint;
|
|
11
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* A value that is either a {@link LatLngBound} or a {@link LatLngPoint}.
|
|
25
|
+
*/
|
|
12
26
|
export type LatLngBoundOrPoint = LatLngBound | LatLngPoint;
|
|
27
|
+
/**
|
|
28
|
+
* Type guard that checks whether the input is a {@link LatLngBound} by testing for the presence of `sw` and `ne` properties.
|
|
29
|
+
*/
|
|
13
30
|
export declare function isLatLngBound(input: LatLngBound | unknown): input is LatLngBound;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a deep copy of the bound so that mutations to the copy do not affect the original.
|
|
33
|
+
*
|
|
34
|
+
* @param input - bound to copy
|
|
35
|
+
* @returns a new bound with copied corner points
|
|
36
|
+
*/
|
|
14
37
|
export declare function copyLatLngBound(input: LatLngBound): LatLngBound;
|
|
38
|
+
/**
|
|
39
|
+
* Checks whether two bounds are identical by comparing both corner points.
|
|
40
|
+
*
|
|
41
|
+
* @param a - first bound
|
|
42
|
+
* @param b - second bound
|
|
43
|
+
* @returns `true` if both the `sw` and `ne` corners are the same
|
|
44
|
+
*/
|
|
15
45
|
export declare function isSameLatLngBound(a: LatLngBound, b: LatLngBound): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Computes the difference between the `ne` and `sw` corner points of a bound, giving the span in latitude and longitude.
|
|
48
|
+
*
|
|
49
|
+
* @param bounds - bound to measure
|
|
50
|
+
* @param wrap - whether to wrap the difference across the antimeridian
|
|
51
|
+
* @returns a point whose `lat`/`lng` represent the span of the bound
|
|
52
|
+
*/
|
|
16
53
|
export declare function diffLatLngBoundPoints(bounds: LatLngBound, wrap?: boolean): LatLngPoint;
|
|
17
54
|
/**
|
|
18
55
|
* Returns true if the input LatLngBound either strictly wraps the map or fully wraps the map.
|
|
19
56
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
57
|
+
* A bound "wraps" when it crosses the antimeridian (longitude +/-180), requiring special handling
|
|
58
|
+
* for containment and overlap checks.
|
|
59
|
+
*
|
|
60
|
+
* @param bound - bound to check
|
|
61
|
+
* @returns `true` if the bound wraps the map in either sense
|
|
22
62
|
*/
|
|
23
63
|
export declare function latLngBoundWrapsMap(bound: LatLngBound): boolean;
|
|
24
64
|
/**
|
|
25
|
-
* Returns true if the input LatLngBound's sw corner comes after the ne corner
|
|
65
|
+
* Returns true if the input LatLngBound's sw corner comes after the ne corner longitudinally,
|
|
66
|
+
* indicating the bound crosses the antimeridian.
|
|
26
67
|
*
|
|
27
|
-
* @param bound
|
|
28
|
-
* @returns
|
|
68
|
+
* @param bound - bound to check
|
|
69
|
+
* @returns `true` if the sw longitude is greater than the ne longitude
|
|
29
70
|
*/
|
|
30
71
|
export declare function latLngBoundStrictlyWrapsMap(bound: LatLngBound): boolean;
|
|
31
72
|
/**
|
|
32
|
-
* Returns true if the LatLngBound's
|
|
33
|
-
*
|
|
34
|
-
*
|
|
73
|
+
* Returns true if the LatLngBound's longitudinal span exceeds the total longitude range (360 degrees),
|
|
74
|
+
* meaning the bound covers the entire map horizontally.
|
|
75
|
+
*
|
|
76
|
+
* @param bound - bound to check
|
|
77
|
+
* @returns `true` if the absolute longitude difference exceeds the total longitude range
|
|
35
78
|
*/
|
|
36
79
|
export declare function latLngBoundFullyWrapsMap(bound: LatLngBound): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the north-east corner point of the bound.
|
|
82
|
+
*
|
|
83
|
+
* @param bound - bound to read
|
|
84
|
+
* @returns the `ne` corner point
|
|
85
|
+
*/
|
|
37
86
|
export declare function latLngBoundNorthEastPoint(bound: LatLngBound): LatLngPoint;
|
|
87
|
+
/**
|
|
88
|
+
* Derives the north-west corner point from the bound's `ne` latitude and `sw` longitude.
|
|
89
|
+
*
|
|
90
|
+
* @param bound - bound to read
|
|
91
|
+
* @returns the computed north-west corner point
|
|
92
|
+
*/
|
|
38
93
|
export declare function latLngBoundNorthWestPoint(bound: LatLngBound): LatLngPoint;
|
|
94
|
+
/**
|
|
95
|
+
* Derives the south-east corner point from the bound's `sw` latitude and `ne` longitude.
|
|
96
|
+
*
|
|
97
|
+
* @param bound - bound to read
|
|
98
|
+
* @returns the computed south-east corner point
|
|
99
|
+
*/
|
|
39
100
|
export declare function latLngBoundSouthEastPoint(bound: LatLngBound): LatLngPoint;
|
|
101
|
+
/**
|
|
102
|
+
* Returns the south-west corner point of the bound.
|
|
103
|
+
*
|
|
104
|
+
* @param bound - bound to read
|
|
105
|
+
* @returns the `sw` corner point
|
|
106
|
+
*/
|
|
40
107
|
export declare function latLngBoundSouthWestPoint(bound: LatLngBound): LatLngPoint;
|
|
108
|
+
/**
|
|
109
|
+
* Computes the geographic center of the bound by averaging the corner coordinates.
|
|
110
|
+
*
|
|
111
|
+
* @param bound - bound to compute the center of
|
|
112
|
+
* @returns the center point
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const bound = latLngBound({ lat: 0, lng: 0 }, { lat: 40, lng: 40 });
|
|
117
|
+
* const center = latLngBoundCenterPoint(bound);
|
|
118
|
+
* // center.lat === 20, center.lng === 20
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
41
121
|
export declare function latLngBoundCenterPoint(bound: LatLngBound): LatLngPoint;
|
|
122
|
+
/**
|
|
123
|
+
* Returns the northern latitude boundary (the `ne` latitude).
|
|
124
|
+
*
|
|
125
|
+
* @param bound - bound to read
|
|
126
|
+
* @returns the latitude of the north edge
|
|
127
|
+
*/
|
|
42
128
|
export declare function latLngBoundNorthBound(bound: LatLngBound): number;
|
|
129
|
+
/**
|
|
130
|
+
* Returns the southern latitude boundary (the `sw` latitude).
|
|
131
|
+
*
|
|
132
|
+
* @param bound - bound to read
|
|
133
|
+
* @returns the latitude of the south edge
|
|
134
|
+
*/
|
|
43
135
|
export declare function latLngBoundSouthBound(bound: LatLngBound): number;
|
|
136
|
+
/**
|
|
137
|
+
* Returns the eastern longitude boundary (the `ne` longitude).
|
|
138
|
+
*
|
|
139
|
+
* @param bound - bound to read
|
|
140
|
+
* @returns the longitude of the east edge
|
|
141
|
+
*/
|
|
44
142
|
export declare function latLngBoundEastBound(bound: LatLngBound): number;
|
|
143
|
+
/**
|
|
144
|
+
* Returns the western longitude boundary (the `sw` longitude).
|
|
145
|
+
*
|
|
146
|
+
* @param bound - bound to read
|
|
147
|
+
* @returns the longitude of the west edge
|
|
148
|
+
*/
|
|
45
149
|
export declare function latLngBoundWestBound(bound: LatLngBound): number;
|
|
46
150
|
/**
|
|
47
151
|
* Tuple of the sw corner and the north east point.
|
|
48
152
|
*/
|
|
49
153
|
export type LatLngBoundTuple = [LatLngBoundSouthWestPoint | LatLngPointInput, LatLngBoundNothEastPoint | LatLngPointInput];
|
|
154
|
+
/**
|
|
155
|
+
* Tuple of four points that define the corners of a bounding box, from which the min/max extents are derived.
|
|
156
|
+
*/
|
|
50
157
|
export type LatLngBoundTuplePoints = [LatLngPointInput, LatLngPointInput, LatLngPointInput, LatLngPointInput];
|
|
158
|
+
/**
|
|
159
|
+
* Accepted input types for creating a {@link LatLngBound}: a bound object, a 2-element tuple (sw/ne), or a 4-element tuple of corner points.
|
|
160
|
+
*/
|
|
51
161
|
export type LatLngBoundInput = LatLngBound | LatLngBoundTuple | LatLngBoundTuplePoints;
|
|
162
|
+
/**
|
|
163
|
+
* Convenience function that creates a {@link LatLngBoundTuple} using the default configuration.
|
|
164
|
+
*
|
|
165
|
+
* @param input - a sw point or any bound input
|
|
166
|
+
* @param inputNe - optional ne point when providing two separate points
|
|
167
|
+
* @returns a tuple of `[sw, ne]` points
|
|
168
|
+
*/
|
|
52
169
|
export declare function latLngBoundTuple(input: LatLngBoundSouthWestPoint | LatLngBoundInput, inputNe?: LatLngBoundNothEastPoint): LatLngBoundTuple;
|
|
53
170
|
/**
|
|
54
|
-
* Converts the input to a
|
|
171
|
+
* Converts the input to a {@link LatLngBoundTuple}. Accepts the same flexible input types as {@link LatLngBoundFunction}.
|
|
55
172
|
*/
|
|
56
173
|
export type LatLngBoundTupleFunction = ((input: LatLngBoundSouthWestPoint | LatLngBoundInput, inputNe?: LatLngBoundNothEastPoint) => LatLngBoundTuple) & ((sw: LatLngBoundSouthWestPoint, ne: LatLngBoundNothEastPoint) => LatLngBoundTuple) & ((bound: LatLngBoundInput) => LatLngBoundTuple);
|
|
57
174
|
export type LatLngBoundTupleFunctionConfig = LatLngBoundFunctionConfig;
|
|
58
175
|
/**
|
|
59
|
-
* Creates a LatLngBoundTupleFunction
|
|
176
|
+
* Creates a {@link LatLngBoundTupleFunction} that converts various bound inputs into a `[sw, ne]` tuple,
|
|
177
|
+
* applying optional precision to the resulting points.
|
|
60
178
|
*
|
|
61
|
-
* @param precision
|
|
62
|
-
* @returns
|
|
179
|
+
* @param config - optional configuration for point precision
|
|
180
|
+
* @returns a function that produces bound tuples from flexible inputs
|
|
63
181
|
*/
|
|
64
182
|
export declare function latLngBoundTupleFunction(config?: LatLngBoundTupleFunctionConfig): LatLngBoundTupleFunction;
|
|
183
|
+
/**
|
|
184
|
+
* Convenience function that creates a {@link LatLngBound} using the default configuration.
|
|
185
|
+
*
|
|
186
|
+
* @param input - a sw point or any bound input
|
|
187
|
+
* @param inputNe - optional ne point when providing two separate points
|
|
188
|
+
* @returns a bound object
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* const bound = latLngBound({ lat: 0, lng: 0 }, { lat: 40, lng: 40 });
|
|
193
|
+
* // bound.sw.lat === 0, bound.ne.lat === 40
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
65
196
|
export declare function latLngBound(input: LatLngBoundSouthWestPoint | LatLngBoundInput, inputNe?: LatLngBoundNothEastPoint): LatLngBound;
|
|
66
197
|
/**
|
|
67
|
-
* Converts
|
|
198
|
+
* Converts various input types to a {@link LatLngBound}. Accepts two separate points, a bound object, a 2-element tuple, or a 4-element tuple.
|
|
68
199
|
*/
|
|
69
200
|
export type LatLngBoundFunction = ((input: LatLngBoundSouthWestPoint | LatLngBoundInput, inputNe?: LatLngBoundNothEastPoint) => LatLngBound) & ((sw: LatLngBoundSouthWestPoint, ne: LatLngBoundNothEastPoint) => LatLngBound) & ((bound: LatLngBoundInput) => LatLngBound);
|
|
201
|
+
/**
|
|
202
|
+
* Configuration for creating a {@link LatLngBoundFunction}.
|
|
203
|
+
*/
|
|
70
204
|
export interface LatLngBoundFunctionConfig {
|
|
71
205
|
/**
|
|
72
206
|
* Point function to use for calculations.
|
|
@@ -77,34 +211,136 @@ export interface LatLngBoundFunctionConfig {
|
|
|
77
211
|
*/
|
|
78
212
|
precision?: LatLngPrecision;
|
|
79
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Creates a {@link LatLngBoundFunction} that normalizes various bound input formats into a {@link LatLngBound}.
|
|
216
|
+
*
|
|
217
|
+
* Supports creating bounds from: two separate points, a `[sw, ne]` tuple, a four-point tuple (computes min/max extents),
|
|
218
|
+
* or a pre-existing bound object.
|
|
219
|
+
*
|
|
220
|
+
* @param config - optional configuration for point precision and custom point functions
|
|
221
|
+
* @returns a function that produces bounds from flexible inputs
|
|
222
|
+
* @throws {Error} when the input cannot be parsed into a valid bound
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const fn = latLngBoundFunction({ precision: 3 });
|
|
227
|
+
* const result = fn([{ lat: 20, lng: 20 }, { lat: 30, lng: 30 }]);
|
|
228
|
+
* // result.sw.lat === 20, result.ne.lat === 30
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
80
231
|
export declare function latLngBoundFunction(config?: LatLngBoundFunctionConfig): LatLngBoundFunction;
|
|
232
|
+
/**
|
|
233
|
+
* Input type for {@link extendLatLngBound}: a single bound/point or an array of them.
|
|
234
|
+
*/
|
|
81
235
|
export type ExtendLatLngBoundInput = ArrayOrValue<LatLngBoundOrPoint>;
|
|
236
|
+
/**
|
|
237
|
+
* Creates a {@link LatLngBound} from the input, which may be a single point, a single bound, or an array of points/bounds.
|
|
238
|
+
*
|
|
239
|
+
* When given an array, the first element seeds the initial bound and subsequent elements extend it.
|
|
240
|
+
*
|
|
241
|
+
* @param input - one or more points/bounds to derive the bounding box from
|
|
242
|
+
* @returns the computed bound, or `undefined` if the input is empty
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* const bound = latLngBoundFromInput([
|
|
247
|
+
* { lat: 0, lng: 0 },
|
|
248
|
+
* { lat: 40, lng: 40 }
|
|
249
|
+
* ]);
|
|
250
|
+
* // bound covers from (0,0) to (40,40)
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
82
253
|
export declare function latLngBoundFromInput(input: ExtendLatLngBoundInput): Maybe<LatLngBound>;
|
|
254
|
+
/**
|
|
255
|
+
* Extends an existing bound to include all the given points and/or bounds.
|
|
256
|
+
*
|
|
257
|
+
* The returned bound's `sw` corner uses the minimum lat/lng encountered, and its `ne` corner uses the maximum.
|
|
258
|
+
*
|
|
259
|
+
* @param bound - the starting bound to extend
|
|
260
|
+
* @param extendWith - one or more points/bounds to include
|
|
261
|
+
* @returns a new bound that encompasses the original and all extensions
|
|
262
|
+
*/
|
|
83
263
|
export declare function extendLatLngBound(bound: LatLngBound, extendWith: ExtendLatLngBoundInput): LatLngBound;
|
|
264
|
+
/**
|
|
265
|
+
* A decision function that checks whether a point or bound satisfies a spatial condition against a reference bound.
|
|
266
|
+
*/
|
|
84
267
|
export type LatLngBoundCheckFunction = DecisionFunction<LatLngBoundOrPoint>;
|
|
85
268
|
/**
|
|
86
269
|
* Function that returns true if the input is entirely within the context's bound.
|
|
270
|
+
*
|
|
271
|
+
* Exposes the reference bound via the `_bound` property.
|
|
87
272
|
*/
|
|
88
273
|
export type IsWithinLatLngBoundFunction = LatLngBoundCheckFunction & {
|
|
89
274
|
readonly _bound: LatLngBound;
|
|
90
275
|
};
|
|
276
|
+
/**
|
|
277
|
+
* Creates an {@link IsWithinLatLngBoundFunction} that checks if a given point or bound
|
|
278
|
+
* falls entirely within the specified bound. Points are checked directly; bounds require
|
|
279
|
+
* both corners to be within.
|
|
280
|
+
*
|
|
281
|
+
* @param bound - the reference bound to check containment against
|
|
282
|
+
* @returns a function that returns `true` if the input is within the reference bound
|
|
283
|
+
*/
|
|
91
284
|
export declare function isWithinLatLngBoundFunction(bound: LatLngBound): IsWithinLatLngBoundFunction;
|
|
285
|
+
/**
|
|
286
|
+
* Checks whether one bound is entirely contained within another by verifying both its corners are within the outer bound.
|
|
287
|
+
*
|
|
288
|
+
* @param bound - the inner bound to test
|
|
289
|
+
* @param within - the outer bound to test against
|
|
290
|
+
* @returns `true` if both corners of `bound` are within `within`
|
|
291
|
+
*/
|
|
92
292
|
export declare function isLatLngBoundWithinLatLngBound(bound: LatLngBound, within: LatLngBound): boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Checks whether a point lies within a bound. Handles bounds that wrap the antimeridian by checking
|
|
295
|
+
* if the longitude falls on either side of the wrap.
|
|
296
|
+
*
|
|
297
|
+
* @param point - the point to test
|
|
298
|
+
* @param within - the bound to test against
|
|
299
|
+
* @returns `true` if the point is within the bound
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* const bound = latLngBound({ lat: 0, lng: 0 }, { lat: 40, lng: 40 });
|
|
304
|
+
* isLatLngPointWithinLatLngBound(latLngPoint(10, 10), bound);
|
|
305
|
+
* // true
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
93
308
|
export declare function isLatLngPointWithinLatLngBound(point: LatLngPoint, within: LatLngBound): boolean;
|
|
94
309
|
/**
|
|
95
310
|
* Function that returns true if the input overlaps the context's bound.
|
|
311
|
+
*
|
|
312
|
+
* Exposes the reference bound via the `_bound` property.
|
|
96
313
|
*/
|
|
97
314
|
export type OverlapsLatLngBoundFunction = LatLngBoundCheckFunction & {
|
|
98
315
|
readonly _bound: LatLngBound;
|
|
99
316
|
};
|
|
317
|
+
/**
|
|
318
|
+
* Checks whether two bounds overlap each other.
|
|
319
|
+
*
|
|
320
|
+
* @param a - the first bound
|
|
321
|
+
* @param b - the second bound
|
|
322
|
+
* @returns `true` if the bounds overlap
|
|
323
|
+
*/
|
|
100
324
|
export declare function latLngBoundOverlapsLatLngBound(a: LatLngBound, b: LatLngBound): boolean;
|
|
325
|
+
/**
|
|
326
|
+
* Creates an {@link OverlapsLatLngBoundFunction} that checks whether a given point or bound
|
|
327
|
+
* overlaps the reference bound. Internally converts bounds to rectangles for overlap detection,
|
|
328
|
+
* handling antimeridian wrapping.
|
|
329
|
+
*
|
|
330
|
+
* @param bound - the reference bound to check overlap against
|
|
331
|
+
* @returns a function that returns `true` if the input overlaps the reference bound
|
|
332
|
+
*/
|
|
101
333
|
export declare function overlapsLatLngBoundFunction(bound: LatLngBound): OverlapsLatLngBoundFunction;
|
|
334
|
+
/**
|
|
335
|
+
* The total span of longitude in degrees (360).
|
|
336
|
+
*/
|
|
102
337
|
export declare const TOTAL_SPAN_OF_LONGITUDE = 360;
|
|
103
338
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
339
|
+
* Normalizes a {@link LatLngBound} into a {@link Rectangle} in an arbitrary coordinate space
|
|
340
|
+
* where the left edge (-180 longitude) begins at x=360. This allows safe rectangle-based
|
|
341
|
+
* overlap comparisons without worrying about antimeridian wrapping.
|
|
107
342
|
*
|
|
108
|
-
* @param bound
|
|
343
|
+
* @param bound - the geographic bound to convert
|
|
344
|
+
* @returns a rectangle suitable for overlap calculations
|
|
109
345
|
*/
|
|
110
346
|
export declare function boundToRectangle(bound: LatLngBound): Rectangle;
|
package/src/lib/value/build.d.ts
CHANGED
|
@@ -1,18 +1,43 @@
|
|
|
1
1
|
import { type Configurable } from '../type';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Represents a mutable partial version of a normally read-only model, used during construction/configuration.
|
|
4
|
+
*
|
|
5
|
+
* Combines `Partial` and `Configurable` (writable) so that properties can be set incrementally before the object is treated as complete.
|
|
4
6
|
*/
|
|
5
7
|
export type Building<T> = Partial<Configurable<T>>;
|
|
8
|
+
/**
|
|
9
|
+
* Function that mutates a {@link Building} instance to populate its properties.
|
|
10
|
+
*/
|
|
6
11
|
export type BuildFunction<T> = (base: Building<T>) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for the {@link build} function, providing the base object and the build function to apply.
|
|
14
|
+
*/
|
|
7
15
|
export interface BuildConfig<T extends object> {
|
|
16
|
+
/**
|
|
17
|
+
* Optional pre-existing partial object to build upon. If omitted, an empty object is used.
|
|
18
|
+
*/
|
|
8
19
|
base?: Building<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Function that mutates the base to populate it with the desired values.
|
|
22
|
+
*/
|
|
9
23
|
build: BuildFunction<T>;
|
|
10
24
|
}
|
|
11
25
|
/**
|
|
12
|
-
* Convenience function
|
|
26
|
+
* Convenience function for imperatively constructing an object of a specific type by mutating a base object via a build function.
|
|
27
|
+
*
|
|
28
|
+
* This is useful when building objects whose type is normally read-only, allowing incremental property assignment during construction.
|
|
29
|
+
*
|
|
30
|
+
* @param config - the build configuration containing the base object and build function
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* interface User { name: string; age: number; }
|
|
13
35
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
36
|
+
* const user = build<User>({
|
|
37
|
+
* base: {},
|
|
38
|
+
* build: (x) => { x.name = 'Alice'; x.age = 30; }
|
|
39
|
+
* });
|
|
40
|
+
* // user === { name: 'Alice', age: 30 }
|
|
41
|
+
* ```
|
|
17
42
|
*/
|
|
18
43
|
export declare function build<T extends object>({ base, build }: BuildConfig<T>): T;
|
|
@@ -5,19 +5,41 @@ import { type Maybe } from './maybe.type';
|
|
|
5
5
|
*/
|
|
6
6
|
export type EqualityComparatorFunction<T> = (a: T, b: T) => boolean;
|
|
7
7
|
/**
|
|
8
|
-
* Wraps
|
|
8
|
+
* Wraps an {@link EqualityComparatorFunction} to safely handle `Maybe` values.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* The wrapped function delegates to the comparator only when both values are non-nullish.
|
|
11
|
+
* When both are nullish, it uses strict equality (`===`), so `null === null` is `true`
|
|
12
|
+
* but `null === undefined` is `false`.
|
|
13
|
+
*
|
|
14
|
+
* @param compare - the comparator to wrap
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const safeCompare = safeEqualityComparatorFunction((a: number, b: number) => a === b);
|
|
19
|
+
* safeCompare(1, 1); // true
|
|
20
|
+
* safeCompare(null, null); // true
|
|
21
|
+
* safeCompare(null, undefined); // false
|
|
22
|
+
* ```
|
|
12
23
|
*/
|
|
13
24
|
export declare function safeEqualityComparatorFunction<T>(compare: EqualityComparatorFunction<T>): EqualityComparatorFunction<Maybe<T>>;
|
|
14
25
|
/**
|
|
15
|
-
*
|
|
26
|
+
* Convenience function that safely compares two `Maybe` values using the provided comparator.
|
|
27
|
+
*
|
|
28
|
+
* Delegates to {@link safeEqualityComparatorFunction} internally, so nullish values are handled
|
|
29
|
+
* without invoking the comparator.
|
|
30
|
+
*
|
|
31
|
+
* @param a - first value to compare
|
|
32
|
+
* @param b - second value to compare
|
|
33
|
+
* @param compare - the equality comparator for non-nullish values
|
|
16
34
|
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* safeCompareEquality(0, 1, (a, b) => a === b);
|
|
38
|
+
* // false
|
|
39
|
+
*
|
|
40
|
+
* safeCompareEquality(null, null, (a, b) => a === b);
|
|
41
|
+
* // true (comparator is not invoked)
|
|
42
|
+
* ```
|
|
21
43
|
*/
|
|
22
44
|
export declare function safeCompareEquality<T>(a: Maybe<T>, b: Maybe<T>, compare: EqualityComparatorFunction<T>): boolean;
|
|
23
45
|
/**
|
|
@@ -29,29 +51,22 @@ export declare function safeCompareEquality<T>(a: Maybe<T>, b: Maybe<T>, compare
|
|
|
29
51
|
*/
|
|
30
52
|
export type CompareEqualityWithValueFromItemsFunction<I, V> = ((a: Maybe<I>, b: Maybe<I>) => boolean) & {
|
|
31
53
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* @param a
|
|
35
|
-
* @returns
|
|
54
|
+
* The function used to extract comparable values from each input item.
|
|
36
55
|
*/
|
|
37
56
|
readonly _readValues: ReadValueFunction<I, V>;
|
|
38
57
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @param a
|
|
42
|
-
* @param b
|
|
43
|
-
* @returns
|
|
58
|
+
* The equality comparator applied to the extracted values.
|
|
44
59
|
*/
|
|
45
60
|
readonly _equalityComparator: EqualityComparatorFunction<V>;
|
|
46
61
|
};
|
|
47
62
|
/**
|
|
48
|
-
* Creates a
|
|
63
|
+
* Creates a {@link CompareEqualityWithValueFromItemsFunction} that extracts values from items before comparing them.
|
|
49
64
|
*
|
|
50
|
-
*
|
|
65
|
+
* This is a convenience wrapper around {@link compareEqualityWithValueFromItemsFunctionFactory} that
|
|
66
|
+
* accepts both the value reader and comparator in a single call.
|
|
51
67
|
*
|
|
52
|
-
* @param readValues
|
|
53
|
-
* @param equalityComparator
|
|
54
|
-
* @returns
|
|
68
|
+
* @param readValues - extracts the comparable value from each item
|
|
69
|
+
* @param equalityComparator - compares the extracted values for equality
|
|
55
70
|
*/
|
|
56
71
|
export declare function compareEqualityWithValueFromItemsFunction<I, V>(readValues: ReadValueFunction<I, V>, equalityComparator: EqualityComparatorFunction<V>): CompareEqualityWithValueFromItemsFunction<I, V>;
|
|
57
72
|
/**
|
|
@@ -59,9 +74,22 @@ export declare function compareEqualityWithValueFromItemsFunction<I, V>(readValu
|
|
|
59
74
|
*/
|
|
60
75
|
export type CompareEqualityWithValueFromItemsFunctionFactory<I, V> = ((equalityComparator: EqualityComparatorFunction<V>) => CompareEqualityWithValueFromItemsFunction<I, V>) & Pick<CompareEqualityWithValueFromItemsFunction<I, V>, '_readValues'>;
|
|
61
76
|
/**
|
|
62
|
-
* Creates a
|
|
77
|
+
* Creates a {@link CompareEqualityWithValueFromItemsFunctionFactory} that is pre-configured with a value reader.
|
|
78
|
+
*
|
|
79
|
+
* The returned factory accepts different equality comparators, allowing reuse of the same value extraction logic
|
|
80
|
+
* with varying comparison strategies.
|
|
81
|
+
*
|
|
82
|
+
* @param readValues - extracts the comparable value from each item
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const factory = compareEqualityWithValueFromItemsFunctionFactory<number, number[]>((x) => [x]);
|
|
87
|
+
* const fn = factory(iterablesAreSetEquivalent);
|
|
63
88
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
89
|
+
* fn(0, 0); // true
|
|
90
|
+
* fn(null, null); // true
|
|
91
|
+
* fn(undefined, undefined); // true
|
|
92
|
+
* fn(0, 1); // false
|
|
93
|
+
* ```
|
|
66
94
|
*/
|
|
67
95
|
export declare function compareEqualityWithValueFromItemsFunctionFactory<I, V>(readValues: ReadValueFunction<I, V>): CompareEqualityWithValueFromItemsFunctionFactory<I, V>;
|