@open-tender/utils 0.1.97 → 0.1.99
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/dist/.DS_Store +0 -0
- package/dist/cjs/utils/googleMaps.d.ts +14 -0
- package/dist/cjs/utils/googleMaps.js +30 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/maps.d.ts +1 -46
- package/dist/cjs/utils/maps.js +1 -34
- package/dist/esm/utils/googleMaps.d.ts +14 -0
- package/dist/esm/utils/googleMaps.js +26 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/maps.d.ts +1 -46
- package/dist/esm/utils/maps.js +0 -32
- package/package.json +2 -1
package/dist/.DS_Store
CHANGED
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="google.maps" />
|
|
2
|
+
export interface AddressName {
|
|
3
|
+
long_name: string;
|
|
4
|
+
short_name: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const makeAddress: (place: google.maps.places.PlaceResult) => {
|
|
7
|
+
street: string;
|
|
8
|
+
city: string;
|
|
9
|
+
state: string;
|
|
10
|
+
postal_code: string;
|
|
11
|
+
lat: number;
|
|
12
|
+
lng: number;
|
|
13
|
+
formatted_address: string | undefined;
|
|
14
|
+
} | null;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeAddress = void 0;
|
|
4
|
+
const makeComponents = (components) => {
|
|
5
|
+
const result = components === null || components === void 0 ? void 0 : components.reduce((obj, i) => {
|
|
6
|
+
return Object.assign(Object.assign({}, obj), { [i.types[0]]: { long_name: i.long_name, short_name: i.short_name } });
|
|
7
|
+
}, {});
|
|
8
|
+
return result;
|
|
9
|
+
};
|
|
10
|
+
const makeAddress = (place) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const { address_components, formatted_address, geometry } = place;
|
|
13
|
+
const components = makeComponents(address_components);
|
|
14
|
+
if (!components)
|
|
15
|
+
return null;
|
|
16
|
+
const { street_number, route, locality: city, sublocality_level_1: subcity, administrative_area_level_1: state, postal_code: postalCode } = components;
|
|
17
|
+
const streetNumber = street_number ? street_number.short_name : '';
|
|
18
|
+
const street = route ? route.long_name : '';
|
|
19
|
+
const addressCity = city || subcity;
|
|
20
|
+
return {
|
|
21
|
+
street: `${streetNumber} ${street}`.trim(),
|
|
22
|
+
city: addressCity ? addressCity.long_name : '',
|
|
23
|
+
state: state ? state.short_name : '',
|
|
24
|
+
postal_code: postalCode ? postalCode.short_name : '',
|
|
25
|
+
lat: ((_a = geometry === null || geometry === void 0 ? void 0 : geometry.location) === null || _a === void 0 ? void 0 : _a.lat()) || 0,
|
|
26
|
+
lng: ((_b = geometry === null || geometry === void 0 ? void 0 : geometry.location) === null || _b === void 0 ? void 0 : _b.lng()) || 0,
|
|
27
|
+
formatted_address
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.makeAddress = makeAddress;
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -8,6 +8,7 @@ tslib_1.__exportStar(require("./constants"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./customer"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./datetimes"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./errors"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./googleMaps"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./helpers"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./keypad"), exports);
|
|
13
14
|
tslib_1.__exportStar(require("./maps"), exports);
|
package/dist/cjs/utils/maps.d.ts
CHANGED
|
@@ -1,49 +1,4 @@
|
|
|
1
1
|
import { Address, LatLng, RevenueCenter, RevenueCenters, ServiceType } from '@open-tender/types';
|
|
2
|
-
export interface GooglePlaceAddressComponent {
|
|
3
|
-
types: Array<string | 'postal_code' | 'street_number' | 'route' | 'locality' | 'sublocality_level_1' | 'administrative_area_level_1'>;
|
|
4
|
-
long_name?: string;
|
|
5
|
-
short_name?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare enum GooglePlaceBusinessStatus {
|
|
8
|
-
OPERATIONAL = "OPERATIONAL",
|
|
9
|
-
CLOSED_TEMPORARILY = "CLOSED_TEMPORARILY",
|
|
10
|
-
CLOSED_PERMANENTLY = "CLOSED_PERMANENTLY"
|
|
11
|
-
}
|
|
12
|
-
export interface GooglePlaceAdressGeometry {
|
|
13
|
-
location: LatLng;
|
|
14
|
-
viewport: Record<string, LatLng>;
|
|
15
|
-
}
|
|
16
|
-
export interface GooglePlace {
|
|
17
|
-
address_components: Array<GooglePlaceAddressComponent>;
|
|
18
|
-
business_status?: GooglePlaceBusinessStatus;
|
|
19
|
-
formatted_address: string;
|
|
20
|
-
formatted_phone_number: string;
|
|
21
|
-
geometry: GooglePlaceAdressGeometry;
|
|
22
|
-
permanently_closed?: boolean;
|
|
23
|
-
html_attributions?: Array<string>;
|
|
24
|
-
name: string;
|
|
25
|
-
}
|
|
26
|
-
export interface AddressName {
|
|
27
|
-
long_name: string;
|
|
28
|
-
short_name: string;
|
|
29
|
-
}
|
|
30
|
-
export interface GooglePlaceComponent {
|
|
31
|
-
street_number: AddressName;
|
|
32
|
-
route: AddressName;
|
|
33
|
-
locality: AddressName;
|
|
34
|
-
sublocality_level_1: AddressName;
|
|
35
|
-
administrative_area_level_1: AddressName;
|
|
36
|
-
postal_code: AddressName;
|
|
37
|
-
}
|
|
38
|
-
export declare const makeAddress: (place: GooglePlace) => {
|
|
39
|
-
street: string;
|
|
40
|
-
city: string;
|
|
41
|
-
state: string;
|
|
42
|
-
postal_code: string;
|
|
43
|
-
lat: number | null;
|
|
44
|
-
lng: number | null;
|
|
45
|
-
formatted_address: string;
|
|
46
|
-
};
|
|
47
2
|
export declare const getDistance: (pointA: LatLng, pointB: LatLng, inMiles?: boolean) => number;
|
|
48
3
|
export declare const inZone: (latLng: LatLng, polygon: number[][]) => boolean;
|
|
49
4
|
export declare const addDistance: (revenueCenters: RevenueCenters, latLng: LatLng) => RevenueCenters;
|
|
@@ -257,4 +212,4 @@ export declare const LOCATIONS_MESSAGES: {
|
|
|
257
212
|
};
|
|
258
213
|
};
|
|
259
214
|
};
|
|
260
|
-
export declare const renameLocation: (str:
|
|
215
|
+
export declare const renameLocation: (str: string, names: string[]) => string;
|
package/dist/cjs/utils/maps.js
CHANGED
|
@@ -1,38 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renameLocation = exports.LOCATIONS_MESSAGES = exports.makeDisplayedRevenueCenters = exports.makeDeliveryMesssaging = exports.makeWalkinMessaging = exports.makePickupMesssaging = exports.makeDeliveryRevenueCenters = exports.makeWalkinRevenueCenters = exports.makePickupRevenueCenters = exports.checkServiceType = exports.calcMinDistance = exports.sortRevenueCenters = exports.addDistance = exports.inZone = exports.getDistance =
|
|
3
|
+
exports.renameLocation = exports.LOCATIONS_MESSAGES = exports.makeDisplayedRevenueCenters = exports.makeDeliveryMesssaging = exports.makeWalkinMessaging = exports.makePickupMesssaging = exports.makeDeliveryRevenueCenters = exports.makeWalkinRevenueCenters = exports.makePickupRevenueCenters = exports.checkServiceType = exports.calcMinDistance = exports.sortRevenueCenters = exports.addDistance = exports.inZone = exports.getDistance = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
|
-
const helpers_1 = require("./helpers");
|
|
6
|
-
var GooglePlaceBusinessStatus;
|
|
7
|
-
(function (GooglePlaceBusinessStatus) {
|
|
8
|
-
GooglePlaceBusinessStatus["OPERATIONAL"] = "OPERATIONAL";
|
|
9
|
-
GooglePlaceBusinessStatus["CLOSED_TEMPORARILY"] = "CLOSED_TEMPORARILY";
|
|
10
|
-
GooglePlaceBusinessStatus["CLOSED_PERMANENTLY"] = "CLOSED_PERMANENTLY";
|
|
11
|
-
})(GooglePlaceBusinessStatus = exports.GooglePlaceBusinessStatus || (exports.GooglePlaceBusinessStatus = {}));
|
|
12
|
-
// seee example Google Maps Place at bottom of file
|
|
13
|
-
const makeComponents = (components) => {
|
|
14
|
-
return components.reduce((obj, i) => {
|
|
15
|
-
return Object.assign(Object.assign({}, obj), { [i.types[0]]: { long_name: i.long_name, short_name: i.short_name } });
|
|
16
|
-
}, {});
|
|
17
|
-
};
|
|
18
|
-
const makeAddress = (place) => {
|
|
19
|
-
const { address_components, formatted_address, geometry } = place;
|
|
20
|
-
const components = makeComponents(address_components);
|
|
21
|
-
const { street_number, route, locality: city, sublocality_level_1: subcity, administrative_area_level_1: state, postal_code: postalCode } = components;
|
|
22
|
-
const streetNumber = street_number ? street_number.short_name : '';
|
|
23
|
-
const street = route ? route.long_name : '';
|
|
24
|
-
const addressCity = city || subcity;
|
|
25
|
-
return {
|
|
26
|
-
street: `${streetNumber} ${street}`.trim(),
|
|
27
|
-
city: addressCity ? addressCity.long_name : '',
|
|
28
|
-
state: state ? state.short_name : '',
|
|
29
|
-
postal_code: postalCode ? postalCode.short_name : '',
|
|
30
|
-
lat: geometry.location.lat || null,
|
|
31
|
-
lng: geometry.location.lng || null,
|
|
32
|
-
formatted_address
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
exports.makeAddress = makeAddress;
|
|
36
5
|
const RADIUS_MILES = 3959; // radius of the earth in miles
|
|
37
6
|
const RADIUS_KM = 6371; // radius of the earth in kilometers
|
|
38
7
|
// https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
|
|
@@ -273,8 +242,6 @@ exports.LOCATIONS_MESSAGES = {
|
|
|
273
242
|
}
|
|
274
243
|
};
|
|
275
244
|
const renameLocation = (str, names) => {
|
|
276
|
-
if (!(0, helpers_1.isString)(str))
|
|
277
|
-
return str;
|
|
278
245
|
const [singular, plural] = names;
|
|
279
246
|
return str
|
|
280
247
|
.replace('1 locations', '1 location')
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="google.maps" />
|
|
2
|
+
export interface AddressName {
|
|
3
|
+
long_name: string;
|
|
4
|
+
short_name: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const makeAddress: (place: google.maps.places.PlaceResult) => {
|
|
7
|
+
street: string;
|
|
8
|
+
city: string;
|
|
9
|
+
state: string;
|
|
10
|
+
postal_code: string;
|
|
11
|
+
lat: number;
|
|
12
|
+
lng: number;
|
|
13
|
+
formatted_address: string | undefined;
|
|
14
|
+
} | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const makeComponents = (components) => {
|
|
2
|
+
const result = components === null || components === void 0 ? void 0 : components.reduce((obj, i) => {
|
|
3
|
+
return Object.assign(Object.assign({}, obj), { [i.types[0]]: { long_name: i.long_name, short_name: i.short_name } });
|
|
4
|
+
}, {});
|
|
5
|
+
return result;
|
|
6
|
+
};
|
|
7
|
+
export const makeAddress = (place) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const { address_components, formatted_address, geometry } = place;
|
|
10
|
+
const components = makeComponents(address_components);
|
|
11
|
+
if (!components)
|
|
12
|
+
return null;
|
|
13
|
+
const { street_number, route, locality: city, sublocality_level_1: subcity, administrative_area_level_1: state, postal_code: postalCode } = components;
|
|
14
|
+
const streetNumber = street_number ? street_number.short_name : '';
|
|
15
|
+
const street = route ? route.long_name : '';
|
|
16
|
+
const addressCity = city || subcity;
|
|
17
|
+
return {
|
|
18
|
+
street: `${streetNumber} ${street}`.trim(),
|
|
19
|
+
city: addressCity ? addressCity.long_name : '',
|
|
20
|
+
state: state ? state.short_name : '',
|
|
21
|
+
postal_code: postalCode ? postalCode.short_name : '',
|
|
22
|
+
lat: ((_a = geometry === null || geometry === void 0 ? void 0 : geometry.location) === null || _a === void 0 ? void 0 : _a.lat()) || 0,
|
|
23
|
+
lng: ((_b = geometry === null || geometry === void 0 ? void 0 : geometry.location) === null || _b === void 0 ? void 0 : _b.lng()) || 0,
|
|
24
|
+
formatted_address
|
|
25
|
+
};
|
|
26
|
+
};
|
package/dist/esm/utils/index.js
CHANGED
package/dist/esm/utils/maps.d.ts
CHANGED
|
@@ -1,49 +1,4 @@
|
|
|
1
1
|
import { Address, LatLng, RevenueCenter, RevenueCenters, ServiceType } from '@open-tender/types';
|
|
2
|
-
export interface GooglePlaceAddressComponent {
|
|
3
|
-
types: Array<string | 'postal_code' | 'street_number' | 'route' | 'locality' | 'sublocality_level_1' | 'administrative_area_level_1'>;
|
|
4
|
-
long_name?: string;
|
|
5
|
-
short_name?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare enum GooglePlaceBusinessStatus {
|
|
8
|
-
OPERATIONAL = "OPERATIONAL",
|
|
9
|
-
CLOSED_TEMPORARILY = "CLOSED_TEMPORARILY",
|
|
10
|
-
CLOSED_PERMANENTLY = "CLOSED_PERMANENTLY"
|
|
11
|
-
}
|
|
12
|
-
export interface GooglePlaceAdressGeometry {
|
|
13
|
-
location: LatLng;
|
|
14
|
-
viewport: Record<string, LatLng>;
|
|
15
|
-
}
|
|
16
|
-
export interface GooglePlace {
|
|
17
|
-
address_components: Array<GooglePlaceAddressComponent>;
|
|
18
|
-
business_status?: GooglePlaceBusinessStatus;
|
|
19
|
-
formatted_address: string;
|
|
20
|
-
formatted_phone_number: string;
|
|
21
|
-
geometry: GooglePlaceAdressGeometry;
|
|
22
|
-
permanently_closed?: boolean;
|
|
23
|
-
html_attributions?: Array<string>;
|
|
24
|
-
name: string;
|
|
25
|
-
}
|
|
26
|
-
export interface AddressName {
|
|
27
|
-
long_name: string;
|
|
28
|
-
short_name: string;
|
|
29
|
-
}
|
|
30
|
-
export interface GooglePlaceComponent {
|
|
31
|
-
street_number: AddressName;
|
|
32
|
-
route: AddressName;
|
|
33
|
-
locality: AddressName;
|
|
34
|
-
sublocality_level_1: AddressName;
|
|
35
|
-
administrative_area_level_1: AddressName;
|
|
36
|
-
postal_code: AddressName;
|
|
37
|
-
}
|
|
38
|
-
export declare const makeAddress: (place: GooglePlace) => {
|
|
39
|
-
street: string;
|
|
40
|
-
city: string;
|
|
41
|
-
state: string;
|
|
42
|
-
postal_code: string;
|
|
43
|
-
lat: number | null;
|
|
44
|
-
lng: number | null;
|
|
45
|
-
formatted_address: string;
|
|
46
|
-
};
|
|
47
2
|
export declare const getDistance: (pointA: LatLng, pointB: LatLng, inMiles?: boolean) => number;
|
|
48
3
|
export declare const inZone: (latLng: LatLng, polygon: number[][]) => boolean;
|
|
49
4
|
export declare const addDistance: (revenueCenters: RevenueCenters, latLng: LatLng) => RevenueCenters;
|
|
@@ -257,4 +212,4 @@ export declare const LOCATIONS_MESSAGES: {
|
|
|
257
212
|
};
|
|
258
213
|
};
|
|
259
214
|
};
|
|
260
|
-
export declare const renameLocation: (str:
|
|
215
|
+
export declare const renameLocation: (str: string, names: string[]) => string;
|
package/dist/esm/utils/maps.js
CHANGED
|
@@ -1,34 +1,4 @@
|
|
|
1
1
|
import { MAX_DISTANCE } from './constants';
|
|
2
|
-
import { isString } from './helpers';
|
|
3
|
-
export var GooglePlaceBusinessStatus;
|
|
4
|
-
(function (GooglePlaceBusinessStatus) {
|
|
5
|
-
GooglePlaceBusinessStatus["OPERATIONAL"] = "OPERATIONAL";
|
|
6
|
-
GooglePlaceBusinessStatus["CLOSED_TEMPORARILY"] = "CLOSED_TEMPORARILY";
|
|
7
|
-
GooglePlaceBusinessStatus["CLOSED_PERMANENTLY"] = "CLOSED_PERMANENTLY";
|
|
8
|
-
})(GooglePlaceBusinessStatus || (GooglePlaceBusinessStatus = {}));
|
|
9
|
-
// seee example Google Maps Place at bottom of file
|
|
10
|
-
const makeComponents = (components) => {
|
|
11
|
-
return components.reduce((obj, i) => {
|
|
12
|
-
return Object.assign(Object.assign({}, obj), { [i.types[0]]: { long_name: i.long_name, short_name: i.short_name } });
|
|
13
|
-
}, {});
|
|
14
|
-
};
|
|
15
|
-
export const makeAddress = (place) => {
|
|
16
|
-
const { address_components, formatted_address, geometry } = place;
|
|
17
|
-
const components = makeComponents(address_components);
|
|
18
|
-
const { street_number, route, locality: city, sublocality_level_1: subcity, administrative_area_level_1: state, postal_code: postalCode } = components;
|
|
19
|
-
const streetNumber = street_number ? street_number.short_name : '';
|
|
20
|
-
const street = route ? route.long_name : '';
|
|
21
|
-
const addressCity = city || subcity;
|
|
22
|
-
return {
|
|
23
|
-
street: `${streetNumber} ${street}`.trim(),
|
|
24
|
-
city: addressCity ? addressCity.long_name : '',
|
|
25
|
-
state: state ? state.short_name : '',
|
|
26
|
-
postal_code: postalCode ? postalCode.short_name : '',
|
|
27
|
-
lat: geometry.location.lat || null,
|
|
28
|
-
lng: geometry.location.lng || null,
|
|
29
|
-
formatted_address
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
2
|
const RADIUS_MILES = 3959; // radius of the earth in miles
|
|
33
3
|
const RADIUS_KM = 6371; // radius of the earth in kilometers
|
|
34
4
|
// https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
|
|
@@ -256,8 +226,6 @@ export const LOCATIONS_MESSAGES = {
|
|
|
256
226
|
}
|
|
257
227
|
};
|
|
258
228
|
export const renameLocation = (str, names) => {
|
|
259
|
-
if (!isString(str))
|
|
260
|
-
return str;
|
|
261
229
|
const [singular, plural] = names;
|
|
262
230
|
return str
|
|
263
231
|
.replace('1 locations', '1 location')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.99",
|
|
4
4
|
"description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@babel/core": "^7.19.1",
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
39
|
"@reduxjs/toolkit": "^1.8.5",
|
|
40
|
+
"@types/google.maps": "^3.53.5",
|
|
40
41
|
"@types/react": "^18.0.18",
|
|
41
42
|
"@types/react-dom": "^18.0.6",
|
|
42
43
|
"@types/uuid": "^8.3.4",
|