@dereekb/util 8.8.1 → 8.10.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/package.json +1 -1
  3. package/src/lib/array/array.string.d.ts +8 -20
  4. package/src/lib/array/array.string.js +14 -13
  5. package/src/lib/array/array.string.js.map +1 -1
  6. package/src/lib/error/error.d.ts +4 -0
  7. package/src/lib/error/error.js +18 -1
  8. package/src/lib/error/error.js.map +1 -1
  9. package/src/lib/index.d.ts +3 -1
  10. package/src/lib/index.js +3 -1
  11. package/src/lib/index.js.map +1 -1
  12. package/src/lib/nodejs/index.d.ts +1 -0
  13. package/src/lib/nodejs/index.js +5 -0
  14. package/src/lib/nodejs/index.js.map +1 -0
  15. package/src/lib/nodejs/stream.d.ts +22 -0
  16. package/src/lib/nodejs/stream.js +34 -0
  17. package/src/lib/nodejs/stream.js.map +1 -0
  18. package/src/lib/number/number.d.ts +4 -0
  19. package/src/lib/number/number.js.map +1 -1
  20. package/src/lib/number/round.d.ts +36 -1
  21. package/src/lib/number/round.js +51 -1
  22. package/src/lib/number/round.js.map +1 -1
  23. package/src/lib/path/index.d.ts +1 -0
  24. package/src/lib/path/index.js +5 -0
  25. package/src/lib/path/index.js.map +1 -0
  26. package/src/lib/path/path.d.ts +157 -0
  27. package/src/lib/path/path.js +226 -0
  28. package/src/lib/path/path.js.map +1 -0
  29. package/src/lib/promise/callback.d.ts +4 -0
  30. package/src/lib/promise/callback.js +21 -0
  31. package/src/lib/promise/callback.js.map +1 -0
  32. package/src/lib/promise/index.d.ts +1 -0
  33. package/src/lib/promise/index.js +1 -0
  34. package/src/lib/promise/index.js.map +1 -1
  35. package/src/lib/string/char.d.ts +34 -0
  36. package/src/lib/string/char.js +66 -0
  37. package/src/lib/string/char.js.map +1 -0
  38. package/src/lib/string/index.d.ts +4 -0
  39. package/src/lib/string/index.js +8 -0
  40. package/src/lib/string/index.js.map +1 -0
  41. package/src/lib/string/replace.d.ts +30 -0
  42. package/src/lib/string/replace.js +78 -0
  43. package/src/lib/string/replace.js.map +1 -0
  44. package/src/lib/{string.d.ts → string/string.d.ts} +2 -2
  45. package/src/lib/{string.js → string/string.js} +0 -0
  46. package/src/lib/string/string.js.map +1 -0
  47. package/src/lib/string/transform.d.ts +24 -0
  48. package/src/lib/string/transform.js +43 -0
  49. package/src/lib/string/transform.js.map +1 -0
  50. package/src/lib/value/index.d.ts +1 -0
  51. package/src/lib/value/index.js +1 -0
  52. package/src/lib/value/index.js.map +1 -1
  53. package/src/lib/value/map.d.ts +29 -1
  54. package/src/lib/value/map.js +42 -1
  55. package/src/lib/value/map.js.map +1 -1
  56. package/src/lib/value/point.d.ts +192 -0
  57. package/src/lib/value/point.js +191 -0
  58. package/src/lib/value/point.js.map +1 -0
  59. package/test/CHANGELOG.md +12 -0
  60. package/test/package.json +2 -2
  61. package/src/lib/string.js.map +0 -1
@@ -1,9 +1,14 @@
1
+ import { ArrayOrValue } from '../array/array';
1
2
  import { PromiseOrValue } from '../promise/promise';
2
- import { Maybe } from './maybe.type';
3
+ import { Maybe, MaybeNot } from './maybe.type';
3
4
  /**
4
5
  * Converts one value to another.
5
6
  */
6
7
  export declare type MapFunction<I, O> = (input: I) => O;
8
+ /**
9
+ * MapFunction with the same input as output.
10
+ */
11
+ export declare type MapSameFunction<I> = MapFunction<I, I>;
7
12
  /**
8
13
  * Converts a MapFunction into one that returns a promise.
9
14
  */
@@ -23,6 +28,7 @@ export declare type ApplyMapFunctionWithOptions<I, O, C> = (input: I, target?: M
23
28
  export declare function mapArrayFunction<I, O>(mapFunction: MapFunction<I, O>): MapArrayFunction<MapFunction<I, O>>;
24
29
  export declare const MAP_IDENTITY: (input: unknown) => unknown;
25
30
  export declare function mapIdentityFunction<T>(): MapFunction<T, T>;
31
+ export declare function isMapIdentityFunction(fn: unknown): fn is typeof MAP_IDENTITY;
26
32
  export declare type MapFunctionOutputPair<O, I = unknown> = {
27
33
  input: I;
28
34
  output: O;
@@ -47,3 +53,25 @@ export declare type MapFunctionOutput<O extends object, I = unknown> = O & {
47
53
  */
48
54
  export declare function wrapMapFunctionOutput<O extends object, I = unknown>(fn: MapFunction<I, O>): MapFunction<I, MapFunctionOutput<O, I>>;
49
55
  export declare function mapFunctionOutput<O extends object, I = unknown>(output: O, input: I): MapFunctionOutput<O, I>;
56
+ /**
57
+ * Chains together multiple MapSameFunctions in the same order. Functions that are not defined are ignored.
58
+ *
59
+ * @param fns
60
+ */
61
+ export declare function chainMapSameFunctions<I>(input: ArrayOrValue<Maybe<MapSameFunction<I>>>): MapSameFunction<I>;
62
+ /**
63
+ * Creates a single function that chains the two map functions together, if apply is true or undefined.
64
+ *
65
+ * If apply is false, or the second map function is not defined, returns the first map function.
66
+ *
67
+ * @param a
68
+ * @param b
69
+ */
70
+ export declare function chainMapFunction<I>(a: MapSameFunction<I>, b: Maybe<MapSameFunction<I>>): MapSameFunction<I>;
71
+ export declare function chainMapFunction<I>(a: MapSameFunction<I>, b: Maybe<MapSameFunction<I>>, apply?: boolean): MapSameFunction<I>;
72
+ export declare function chainMapFunction<I, O, B>(a: MapFunction<I, O>, b: MapFunction<O, B>): MapFunction<I, B>;
73
+ export declare function chainMapFunction<I, O, B>(a: MapFunction<I, O>, b: MaybeNot): MapFunction<I, O>;
74
+ export declare function chainMapFunction<I, O, B>(a: MapFunction<I, O>, b: Maybe<MapFunction<O, B>>, apply: false): MapFunction<I, O>;
75
+ export declare function chainMapFunction<I, O, B>(a: MapFunction<I, O>, b: MaybeNot, apply: true): MapFunction<I, O>;
76
+ export declare function chainMapFunction<I, O, B>(a: MapFunction<I, O>, b: MapFunction<O, B>, apply: true): MapFunction<I, B>;
77
+ export declare function chainMapFunction<I, O, B>(a: MapFunction<I, O>, b: Maybe<MapFunction<O, B>>, apply: boolean): MapFunction<I, O> | MapFunction<I, B>;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapFunctionOutput = exports.wrapMapFunctionOutput = exports.mapFunctionOutputPair = exports.mapIdentityFunction = exports.MAP_IDENTITY = exports.mapArrayFunction = void 0;
3
+ exports.chainMapFunction = exports.chainMapSameFunctions = exports.mapFunctionOutput = exports.wrapMapFunctionOutput = exports.mapFunctionOutputPair = exports.isMapIdentityFunction = exports.mapIdentityFunction = exports.MAP_IDENTITY = exports.mapArrayFunction = void 0;
4
+ const array_1 = require("../array/array");
5
+ const array_value_1 = require("../array/array.value");
4
6
  const build_1 = require("./build");
5
7
  function mapArrayFunction(mapFunction) {
6
8
  return (input) => input.map(mapFunction);
@@ -12,6 +14,10 @@ function mapIdentityFunction() {
12
14
  return exports.MAP_IDENTITY;
13
15
  }
14
16
  exports.mapIdentityFunction = mapIdentityFunction;
17
+ function isMapIdentityFunction(fn) {
18
+ return fn === exports.MAP_IDENTITY;
19
+ }
20
+ exports.isMapIdentityFunction = isMapIdentityFunction;
15
21
  /**
16
22
  * Wraps a MapFunction to instead provide the input and output values.
17
23
  *
@@ -49,4 +55,39 @@ function mapFunctionOutput(output, input) {
49
55
  });
50
56
  }
51
57
  exports.mapFunctionOutput = mapFunctionOutput;
58
+ // MARK: Chaining
59
+ /**
60
+ * Chains together multiple MapSameFunctions in the same order. Functions that are not defined are ignored.
61
+ *
62
+ * @param fns
63
+ */
64
+ function chainMapSameFunctions(input) {
65
+ const fns = (0, array_value_1.filterMaybeValues)((0, array_1.asArray)(input).filter((x) => !isMapIdentityFunction(x))); // remove all identify functions too
66
+ let fn;
67
+ switch (fns.length) {
68
+ case 0:
69
+ fn = mapIdentityFunction();
70
+ break;
71
+ case 1:
72
+ fn = fns[0];
73
+ break;
74
+ default:
75
+ fn = fns[0];
76
+ for (let i = 1; i < fns.length; i += 1) {
77
+ fn = chainMapFunction(fn, fns[i]);
78
+ }
79
+ break;
80
+ }
81
+ return fn;
82
+ }
83
+ exports.chainMapSameFunctions = chainMapSameFunctions;
84
+ function chainMapFunction(a, b, apply = true) {
85
+ if (apply && b != null) {
86
+ return (x) => b(a(x));
87
+ }
88
+ else {
89
+ return a;
90
+ }
91
+ }
92
+ exports.chainMapFunction = chainMapFunction;
52
93
  //# sourceMappingURL=map.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"map.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/value/map.ts"],"names":[],"mappings":";;;AACA,mCAAgC;AA8BhC,SAAgB,gBAAgB,CAAO,WAA8B;IACnE,OAAO,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAChD,CAAC;AAFD,4CAEC;AAEM,MAAM,YAAY,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,KAAK,CAAC;AAAzC,QAAA,YAAY,gBAA6B;AAEtD,SAAgB,mBAAmB;IACjC,OAAO,oBAAiC,CAAC;AAC3C,CAAC;AAFD,kDAEC;AAQD;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAiB,EAAqB;IACzE,OAAO,CAAC,KAAQ,EAAE,EAAE;QAClB,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QAEzB,OAAO;YACL,KAAK;YACL,MAAM;SACP,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AATD,sDASC;AAQD;;;;GAIG;AACH,SAAgB,qBAAqB,CAAgC,EAAqB;IACxF,OAAO,CAAC,KAAQ,EAAE,EAAE;QAClB,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC;AACJ,CAAC;AALD,sDAKC;AAED,SAAgB,iBAAiB,CAAgC,MAAS,EAAE,KAAQ;IAClF,OAAO,IAAA,aAAK,EAA0B;QACpC,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;YACX,CAAC,CAAC,MAAM,GAAG,KAA0C,CAAC;QACxD,CA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AA0C,CAAC;QACxD,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAPD,8CAOC;AAED,iBAAiB;AACjB;;;;GAIG;AACH,SAAgB,qBAAqB,CAAI,KAA8C;IACrF,MAAM,GAAG,GAAG,IAAA,+BAAiB,EAAC,IAAA,eAAO,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oCAAoC;IAC5H,IAAI,EAAsB,CAAC;IAE3B,QAAQ,GAAG,CAAC,MAAM,EAAE;QAClB,KAAK,CAAC;YACJ,EAAE,GAAG,mBAAmB,EAAE,CAAC;YAC3B,MAAM;QACR,KAAK,CAAC;YACJ,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;YACZ,MAAM;QACR;YACE,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;YAEZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;gBACtC,EAAE,GAAG,gBAAgB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;aACnC;YACD,MAAM;KACT;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AArBD,sDAqBC;AAkBD,SAAgB,gBAAgB,CAAU,CAAoB,EAAE,CAA2B,EAAE,KAAK,GAAG,IAAI;IACvG,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,EAAE;QACtB,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACvB;SAAM;QACL,OAAO,CAAC,CAAC;KACV;AACH,CAAC;AAND,4CAMC"}
@@ -0,0 +1,192 @@
1
+ import { Factory } from '../getter/getter';
2
+ import { NumberPrecision } from '../number/round';
3
+ /**
4
+ * Latitude value
5
+ */
6
+ export declare type Latitude = number;
7
+ /**
8
+ * Longitude value
9
+ */
10
+ export declare type Longitude = number;
11
+ export declare const MIN_LATITUDE_VALUE = -90;
12
+ export declare const MAX_LATITUDE_VALUE = 90;
13
+ export declare const MIN_LONGITUDE_VALUE = -180;
14
+ export declare const MAX_LONGITUDE_VALUE = 180;
15
+ export interface LatLngPoint {
16
+ lat: Latitude;
17
+ lng: Longitude;
18
+ }
19
+ export declare function latLngPoint(lat: Latitude, lng: Longitude): LatLngPoint;
20
+ export declare function isValidLatitude(lat: Latitude): boolean;
21
+ export declare function isValidLongitude(lat: Longitude): boolean;
22
+ export declare function defaultLatLngPoint(): LatLngPoint;
23
+ /**
24
+ * Returns true if the input point's lat/lng values are within the acceptable values range.
25
+ *
26
+ * @param input
27
+ * @returns
28
+ */
29
+ export declare function isValidLatLngPoint(input: LatLngPoint): boolean;
30
+ /**
31
+ * A lat,lng encoded value.
32
+ */
33
+ export declare type LatLngString = `${Latitude},${Longitude}`;
34
+ export declare type LatLngPrecision = NumberPrecision;
35
+ /**
36
+ * Creates a LatLngString from the input.
37
+ *
38
+ * @param lat
39
+ * @param lng
40
+ */
41
+ export declare function latLngString(lat: Latitude, lng?: Longitude): LatLngString;
42
+ export declare function latLngString(latLng: LatLngPoint): LatLngString;
43
+ export declare function latLngString(latLng: LatLngString): LatLngString;
44
+ /**
45
+ * A lat/lng regex with capture groups for lat and lng.
46
+ *
47
+ * Has a max precision of 10, which is easily precise enough for all GPS cases.
48
+ *
49
+ * https://stackoverflow.com/questions/3518504/regular-expression-for-matching-latitude-longitude-coordinates
50
+ */
51
+ export declare const LAT_LNG_PATTERN: RegExp;
52
+ /**
53
+ * Checks whether or not the input has the expected pattern.
54
+ *
55
+ * @param input
56
+ */
57
+ export declare function isLatLngString(input: string): input is LatLngString;
58
+ /**
59
+ * 111KM meter preicison, 0 decimal places
60
+ */
61
+ export declare const LAT_LONG_100KM_PRECISION = 0;
62
+ /**
63
+ * 11.1KM meter preicison, 1 decimal place
64
+ */
65
+ export declare const LAT_LONG_10KM_PRECISION = 1;
66
+ /**
67
+ * 1.11KM meter preicison, 2 decimal places
68
+ */
69
+ export declare const LAT_LONG_1KM_PRECISION = 2;
70
+ /**
71
+ * 111 meter preicison, 3 decimal places
72
+ */
73
+ export declare const LAT_LONG_100M_PRECISION = 3;
74
+ /**
75
+ * 11.1 meter preicison, 4 decimal places
76
+ */
77
+ export declare const LAT_LONG_10M_PRECISION = 4;
78
+ /**
79
+ * 001.11 meter preicison, 5 decimal places
80
+ */
81
+ export declare const LAT_LONG_1M_PRECISION = 5;
82
+ /**
83
+ * 011.10 centimeter preicison, 6 decimal places
84
+ */
85
+ export declare const LAT_LONG_10CM_PRECISION = 6;
86
+ /**
87
+ * 001.11 centimeter precision, 7 decimal places
88
+ */
89
+ export declare const LAT_LONG_1CM_PRECISION = 7;
90
+ /**
91
+ * 001.11 milimeter precision, 8 decimal places
92
+ */
93
+ export declare const LAT_LONG_1MM_PRECISION = 8;
94
+ /**
95
+ * 0.1mm precision, 9 decimal places
96
+ *
97
+ * "Hey, check out this specific sand grain!"
98
+ *
99
+ * https://xkcd.com/2170/
100
+ */
101
+ export declare const LAT_LONG_GRAINS_OF_SAND_PRECISION = 9;
102
+ /**
103
+ * Rounds the input latLng value to a given precision.
104
+ */
105
+ export declare type LatLngPointPrecisionFunction = (latLngPoint: LatLngPoint) => LatLngPoint;
106
+ export declare function latLngPointPrecisionFunction(precision: LatLngPrecision): LatLngPointPrecisionFunction;
107
+ /**
108
+ * Converts the input to a LatLngString
109
+ */
110
+ export declare type LatLngStringFunction = ((lat: Latitude | LatLngPoint | LatLngString | string, lng?: Longitude) => LatLngString) & ((latLng: string | LatLngString) => LatLngString) & ((latLng: LatLngPoint) => LatLngString) & ((lat: Latitude, lng?: Longitude) => LatLngString);
111
+ export declare type LatLngStringFunctionConfig = LatLngPointFunctionConfig;
112
+ /**
113
+ * Creates a LatLngStringFunction
114
+ *
115
+ * @param precision
116
+ * @returns
117
+ */
118
+ export declare function latLngStringFunction(config?: LatLngStringFunctionConfig): LatLngStringFunction;
119
+ /**
120
+ * Converts the input to a LatLngPoint
121
+ */
122
+ export declare type LatLngPointFunction = ((lat: Latitude | LatLngPoint | LatLngString | string, lng?: Longitude) => LatLngPoint) & ((latLng: string | LatLngString) => LatLngPoint) & ((latLng: LatLngPoint) => LatLngPoint) & ((lat: Latitude, lng?: Longitude) => LatLngPoint);
123
+ export interface LatLngPointFunctionConfig {
124
+ /**
125
+ * LatLngPrecision to use
126
+ */
127
+ precision?: LatLngPrecision;
128
+ /**
129
+ * Whether or not to validate and only return valid LatLng values.
130
+ *
131
+ * Is true by default.
132
+ */
133
+ validate?: boolean;
134
+ /**
135
+ * The default LatLngPoint to return.
136
+ */
137
+ default?: Factory<LatLngPoint>;
138
+ }
139
+ /**
140
+ * Creates a LatLngPointFunction
141
+ *
142
+ * @param precision
143
+ * @returns
144
+ */
145
+ export declare function latLngPointFunction(config?: LatLngPointFunctionConfig): LatLngPointFunction;
146
+ /**
147
+ * Creates a LatLngPoint from the input latLng string.
148
+ *
149
+ * @param latLngString
150
+ */
151
+ export declare function latLngPointFromString(latLngString: LatLngString | string): LatLngPoint;
152
+ export declare function validLatLngPoint(latLngPoint: LatLngPoint, defaultValue?: Factory<LatLngPoint>): LatLngPoint;
153
+ /**
154
+ * Returns a valid LatLngPoint by validating the input and returns the input value if it is valid, or a default value that is valid.
155
+ *
156
+ * @param latLngPoint
157
+ */
158
+ export declare type ValidLatLngPointFunction = (latLngPoint: LatLngPoint) => LatLngPoint;
159
+ export declare function validLatLngPointFunction(defaultValue?: Factory<LatLngPoint>): ValidLatLngPointFunction;
160
+ /**
161
+ * References a latLng using a LatLngPoint
162
+ */
163
+ export declare type LatLngPointRef = {
164
+ readonly latLng: LatLngPoint;
165
+ };
166
+ /**
167
+ * References a latLng using a LatLngString
168
+ */
169
+ export declare type LatLngStringRef = {
170
+ readonly latLng: LatLngString;
171
+ };
172
+ /**
173
+ * An object that references a latLng
174
+ */
175
+ export declare type LatLngRef = LatLngPointRef | LatLngStringRef;
176
+ /**
177
+ * A LatLngPointRef with arbitrary data
178
+ */
179
+ export declare type LatLngDataPoint<T> = LatLngPointRef & {
180
+ readonly data: T;
181
+ };
182
+ /**
183
+ * Converts the input value to a LatLngDataPoint
184
+ */
185
+ export declare type LatLngDataPointFunction<T extends LatLngRef> = (data: T) => LatLngDataPoint<T>;
186
+ /**
187
+ * Creates a LatLngDataPointFunction
188
+ *
189
+ * @param precision
190
+ * @returns
191
+ */
192
+ export declare function latLngDataPointFunction<T extends LatLngRef>(config?: LatLngPointFunctionConfig): LatLngDataPointFunction<T>;
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.latLngDataPointFunction = exports.validLatLngPointFunction = exports.validLatLngPoint = exports.latLngPointFromString = exports.latLngPointFunction = exports.latLngStringFunction = exports.latLngPointPrecisionFunction = exports.LAT_LONG_GRAINS_OF_SAND_PRECISION = exports.LAT_LONG_1MM_PRECISION = exports.LAT_LONG_1CM_PRECISION = exports.LAT_LONG_10CM_PRECISION = exports.LAT_LONG_1M_PRECISION = exports.LAT_LONG_10M_PRECISION = exports.LAT_LONG_100M_PRECISION = exports.LAT_LONG_1KM_PRECISION = exports.LAT_LONG_10KM_PRECISION = exports.LAT_LONG_100KM_PRECISION = exports.isLatLngString = exports.LAT_LNG_PATTERN = exports.latLngString = exports.isValidLatLngPoint = exports.defaultLatLngPoint = exports.isValidLongitude = exports.isValidLatitude = exports.latLngPoint = exports.MAX_LONGITUDE_VALUE = exports.MIN_LONGITUDE_VALUE = exports.MAX_LATITUDE_VALUE = exports.MIN_LATITUDE_VALUE = void 0;
4
+ const round_1 = require("../number/round");
5
+ exports.MIN_LATITUDE_VALUE = -90.0;
6
+ exports.MAX_LATITUDE_VALUE = 90.0;
7
+ exports.MIN_LONGITUDE_VALUE = -180.0;
8
+ exports.MAX_LONGITUDE_VALUE = 180.0;
9
+ function latLngPoint(lat, lng) {
10
+ return { lat, lng };
11
+ }
12
+ exports.latLngPoint = latLngPoint;
13
+ function isValidLatitude(lat) {
14
+ return lat >= exports.MIN_LATITUDE_VALUE && lat <= exports.MAX_LATITUDE_VALUE;
15
+ }
16
+ exports.isValidLatitude = isValidLatitude;
17
+ function isValidLongitude(lat) {
18
+ return lat >= exports.MIN_LONGITUDE_VALUE && lat <= exports.MAX_LONGITUDE_VALUE;
19
+ }
20
+ exports.isValidLongitude = isValidLongitude;
21
+ function defaultLatLngPoint() {
22
+ return { lat: 0, lng: 0 };
23
+ }
24
+ exports.defaultLatLngPoint = defaultLatLngPoint;
25
+ /**
26
+ * Returns true if the input point's lat/lng values are within the acceptable values range.
27
+ *
28
+ * @param input
29
+ * @returns
30
+ */
31
+ function isValidLatLngPoint(input) {
32
+ return isValidLatitude(input.lat) && isValidLongitude(input.lng);
33
+ }
34
+ exports.isValidLatLngPoint = isValidLatLngPoint;
35
+ function latLngString(lat, lng) {
36
+ return latLngStringFunction()(lat, lng);
37
+ }
38
+ exports.latLngString = latLngString;
39
+ /**
40
+ * A lat/lng regex with capture groups for lat and lng.
41
+ *
42
+ * Has a max precision of 10, which is easily precise enough for all GPS cases.
43
+ *
44
+ * https://stackoverflow.com/questions/3518504/regular-expression-for-matching-latitude-longitude-coordinates
45
+ */
46
+ exports.LAT_LNG_PATTERN = /(?<lat>^[-+]?(?:[1-8]?\d(?:\.\d{0,10})?|90(?:\.0{0,10})?))\s*,\s*(?<lng>[-+]?(?:180(?:\.0{0,10})?|(?:1[0-7]\d|[1-9]?\d)(?:\.\d{0,10})?))$/;
47
+ /**
48
+ * Checks whether or not the input has the expected pattern.
49
+ *
50
+ * @param input
51
+ */
52
+ function isLatLngString(input) {
53
+ return exports.LAT_LNG_PATTERN.test(input);
54
+ }
55
+ exports.isLatLngString = isLatLngString;
56
+ /**
57
+ * 111KM meter preicison, 0 decimal places
58
+ */
59
+ exports.LAT_LONG_100KM_PRECISION = 0;
60
+ /**
61
+ * 11.1KM meter preicison, 1 decimal place
62
+ */
63
+ exports.LAT_LONG_10KM_PRECISION = 1;
64
+ /**
65
+ * 1.11KM meter preicison, 2 decimal places
66
+ */
67
+ exports.LAT_LONG_1KM_PRECISION = 2;
68
+ /**
69
+ * 111 meter preicison, 3 decimal places
70
+ */
71
+ exports.LAT_LONG_100M_PRECISION = 3;
72
+ /**
73
+ * 11.1 meter preicison, 4 decimal places
74
+ */
75
+ exports.LAT_LONG_10M_PRECISION = 4;
76
+ /**
77
+ * 001.11 meter preicison, 5 decimal places
78
+ */
79
+ exports.LAT_LONG_1M_PRECISION = 5;
80
+ /**
81
+ * 011.10 centimeter preicison, 6 decimal places
82
+ */
83
+ exports.LAT_LONG_10CM_PRECISION = 6;
84
+ /**
85
+ * 001.11 centimeter precision, 7 decimal places
86
+ */
87
+ exports.LAT_LONG_1CM_PRECISION = 7;
88
+ /**
89
+ * 001.11 milimeter precision, 8 decimal places
90
+ */
91
+ exports.LAT_LONG_1MM_PRECISION = 8;
92
+ /**
93
+ * 0.1mm precision, 9 decimal places
94
+ *
95
+ * "Hey, check out this specific sand grain!"
96
+ *
97
+ * https://xkcd.com/2170/
98
+ */
99
+ exports.LAT_LONG_GRAINS_OF_SAND_PRECISION = 9;
100
+ function latLngPointPrecisionFunction(precision) {
101
+ const precisionFunction = (0, round_1.cutValueToPrecisionFunction)(precision);
102
+ return (latLng) => {
103
+ const { lat: latInput, lng: lngInput } = latLng;
104
+ const lat = precisionFunction(latInput);
105
+ const lng = precisionFunction(lngInput);
106
+ return { lat, lng };
107
+ };
108
+ }
109
+ exports.latLngPointPrecisionFunction = latLngPointPrecisionFunction;
110
+ /**
111
+ * Creates a LatLngStringFunction
112
+ *
113
+ * @param precision
114
+ * @returns
115
+ */
116
+ function latLngStringFunction(config) {
117
+ const fn = latLngPointFunction(config);
118
+ return (lat, lng) => {
119
+ const latLng = fn(lat, lng);
120
+ return `${latLng.lat},${latLng.lng}`;
121
+ };
122
+ }
123
+ exports.latLngStringFunction = latLngStringFunction;
124
+ /**
125
+ * Creates a LatLngPointFunction
126
+ *
127
+ * @param precision
128
+ * @returns
129
+ */
130
+ function latLngPointFunction(config) {
131
+ const { validate, default: defaultValue, precision = exports.LAT_LONG_1MM_PRECISION } = config !== null && config !== void 0 ? config : {};
132
+ const precisionFunction = latLngPointPrecisionFunction(precision);
133
+ const validateFunction = validLatLngPointFunction(defaultValue);
134
+ const mapFn = validate !== false ? (input) => precisionFunction(validateFunction(input)) : precisionFunction;
135
+ return (lat, lng) => {
136
+ let latLng;
137
+ const latType = typeof lat;
138
+ if (latType === 'string') {
139
+ latLng = latLngPointFromString(lat);
140
+ }
141
+ else if (latType === 'object') {
142
+ latLng = lat;
143
+ }
144
+ else if (lng != null) {
145
+ latLng = latLngPoint(lat, lng);
146
+ }
147
+ else {
148
+ throw new Error(`Invalid lat/lng input "${lat},${lng}"`);
149
+ }
150
+ return mapFn(latLng); // round to a given precision
151
+ };
152
+ }
153
+ exports.latLngPointFunction = latLngPointFunction;
154
+ /**
155
+ * Creates a LatLngPoint from the input latLng string.
156
+ *
157
+ * @param latLngString
158
+ */
159
+ function latLngPointFromString(latLngString) {
160
+ const [latString, lngString] = latLngString.split(',');
161
+ const lat = Number(latString) || 0; // default lat and lng to 0 if not valid.
162
+ const lng = Number(lngString) || 0;
163
+ return { lat, lng };
164
+ }
165
+ exports.latLngPointFromString = latLngPointFromString;
166
+ function validLatLngPoint(latLngPoint, defaultValue) {
167
+ return validLatLngPointFunction(defaultValue)(latLngPoint);
168
+ }
169
+ exports.validLatLngPoint = validLatLngPoint;
170
+ function validLatLngPointFunction(defaultValue = defaultLatLngPoint) {
171
+ return (latLngPoint) => (isValidLatLngPoint(latLngPoint) ? latLngPoint : defaultValue());
172
+ }
173
+ exports.validLatLngPointFunction = validLatLngPointFunction;
174
+ /**
175
+ * Creates a LatLngDataPointFunction
176
+ *
177
+ * @param precision
178
+ * @returns
179
+ */
180
+ function latLngDataPointFunction(config) {
181
+ const fn = latLngPointFunction(config);
182
+ return (data) => {
183
+ const latLng = fn(data.latLng);
184
+ return {
185
+ latLng,
186
+ data
187
+ };
188
+ };
189
+ }
190
+ exports.latLngDataPointFunction = latLngDataPointFunction;
191
+ //# sourceMappingURL=point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"point.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/value/point.ts"],"names":[],"mappings":";;;AACA,2CAA+E;AAalE,QAAA,kBAAkB,GAAG,CAAC,IAAI,CAAC;AAC3B,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAC1B,QAAA,mBAAmB,GAAG,CAAC,KAAK,CAAC;AAC7B,QAAA,mBAAmB,GAAG,KAAK,CAAC;AAOzC,SAAgB,WAAW,CAAC,GAAa,EAAE,GAAc;IACvD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC;AAFD,kCAEC;AAED,SAAgB,eAAe,CAAC,GAAa;IAC3C,OAAO,GAAG,IAAI,0BAAkB,IAAI,GAAG,IAAI,0BAAkB,CAAC;AAChE,CAAC;AAFD,0CAEC;AAED,SAAgB,gBAAgB,CAAC,GAAc;IAC7C,OAAO,GAAG,IAAI,2BAAmB,IAAI,GAAG,IAAI,2BAAmB,CAAC;AAClE,CAAC;AAFD,4CAEC;AAED,SAAgB,kBAAkB;IAChC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AAC5B,CAAC;AAFD,gDAEC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,KAAkB;IACnD,OAAO,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACnE,CAAC;AAFD,gDAEC;AAkBD,SAAgB,YAAY,CAAC,GAA0C,EAAE,GAAe;IACtF,OAAO,oBAAoB,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1C,CAAC;AAFD,oCAEC;AAED;;;;;;GAMG;AACU,QAAA,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AAC,CAAC;AACJ,CAAC;AAtBD,kDAsBC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,YAAmC;IACvE,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvD,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,yCAAyC;IAC7E,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACtB,CAAC;AALD,sDAKC;AAED,SAAgB,gBAAgB,CAAC,WAAwB,EAAE,YAAmC;IAC5F,OAAO,wBAAwB,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,CAAC;AAC7D,CAAC;AAFD,4CAEC;AASD,SAAgB,wBAAwB,CAAC,eAAqC,kBAAkB;IAC9F,OAAO,CAAC,WAAwB,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;AACxG,CAAC;AAFD,4DAEC;AAkCD;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAsB,MAAkC;IAC7F,MAAM,EAAE,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,CAAC,IAAO,EAAE,EAAE;QACjB,MAAM,MAAM,GAAgB,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5C,OAAO;YACL,MAAM;YACN,IAAI;SACL,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AATD,0DASC"}
package/test/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ # [8.10.0](https://github.com/dereekb/dbx-components/compare/v8.9.1-dev...v8.10.0) (2022-07-04)
6
+
7
+
8
+
9
+ ## [8.9.1](https://github.com/dereekb/dbx-components/compare/v8.9.0-dev...v8.9.1) (2022-06-30)
10
+
11
+
12
+
13
+ # [8.9.0](https://github.com/dereekb/dbx-components/compare/v8.8.1-dev...v8.9.0) (2022-06-30)
14
+
15
+
16
+
5
17
  ## [8.8.1](https://github.com/dereekb/dbx-components/compare/v8.8.0-dev...v8.8.1) (2022-06-29)
6
18
 
7
19
 
package/test/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@dereekb/util/test",
3
- "version": "8.8.1",
3
+ "version": "8.10.0",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "typings": "./src/index.d.ts",
7
7
  "dependencies": {},
8
8
  "peerDependencies": {
9
- "@dereekb/util": "8.8.1",
9
+ "@dereekb/util": "8.10.0",
10
10
  "make-error": "^1.3.0",
11
11
  "ts-essentials": "^9.1.2",
12
12
  "extra-set": "^2.2.11",
@@ -1 +0,0 @@
1
- {"version":3,"file":"string.js","sourceRoot":"","sources":["../../../../../packages/util/src/lib/string.ts"],"names":[],"mappings":";;;AAkBA,SAAgB,qBAAqB,CAAC,KAAoB;IACxD,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,iBAAiB,EAAE,CAAC;AACpC,CAAC;AAFD,sDAEC;AAID,SAAgB,yBAAyB,CAAc,KAA8B,EAAE,QAA8B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAiB;IAC3I,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAC5C,CAAC;AAHD,8DAGC;AAED,SAAgB,8BAA8B,CAAC,KAAkC;IAC/E,OAAO,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC;AAFD,wEAEC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,KAAqB,EAAE,MAAM,GAAG,GAAG;IACvE,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC;KACrD;SAAM;QACL,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAND,sDAMC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,KAAa;IACjD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAFD,sDAEC"}