@open-tender/utils 0.1.98 → 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 +0 -45
- package/dist/cjs/utils/maps.js +1 -31
- 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 +0 -45
- package/dist/esm/utils/maps.js +0 -29
- 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;
|
package/dist/cjs/utils/maps.js
CHANGED
|
@@ -1,37 +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
|
-
var GooglePlaceBusinessStatus;
|
|
6
|
-
(function (GooglePlaceBusinessStatus) {
|
|
7
|
-
GooglePlaceBusinessStatus["OPERATIONAL"] = "OPERATIONAL";
|
|
8
|
-
GooglePlaceBusinessStatus["CLOSED_TEMPORARILY"] = "CLOSED_TEMPORARILY";
|
|
9
|
-
GooglePlaceBusinessStatus["CLOSED_PERMANENTLY"] = "CLOSED_PERMANENTLY";
|
|
10
|
-
})(GooglePlaceBusinessStatus = exports.GooglePlaceBusinessStatus || (exports.GooglePlaceBusinessStatus = {}));
|
|
11
|
-
// seee example Google Maps Place at bottom of file
|
|
12
|
-
const makeComponents = (components) => {
|
|
13
|
-
return components.reduce((obj, i) => {
|
|
14
|
-
return Object.assign(Object.assign({}, obj), { [i.types[0]]: { long_name: i.long_name, short_name: i.short_name } });
|
|
15
|
-
}, {});
|
|
16
|
-
};
|
|
17
|
-
const makeAddress = (place) => {
|
|
18
|
-
const { address_components, formatted_address, geometry } = place;
|
|
19
|
-
const components = makeComponents(address_components);
|
|
20
|
-
const { street_number, route, locality: city, sublocality_level_1: subcity, administrative_area_level_1: state, postal_code: postalCode } = components;
|
|
21
|
-
const streetNumber = street_number ? street_number.short_name : '';
|
|
22
|
-
const street = route ? route.long_name : '';
|
|
23
|
-
const addressCity = city || subcity;
|
|
24
|
-
return {
|
|
25
|
-
street: `${streetNumber} ${street}`.trim(),
|
|
26
|
-
city: addressCity ? addressCity.long_name : '',
|
|
27
|
-
state: state ? state.short_name : '',
|
|
28
|
-
postal_code: postalCode ? postalCode.short_name : '',
|
|
29
|
-
lat: geometry.location.lat || null,
|
|
30
|
-
lng: geometry.location.lng || null,
|
|
31
|
-
formatted_address
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
exports.makeAddress = makeAddress;
|
|
35
5
|
const RADIUS_MILES = 3959; // radius of the earth in miles
|
|
36
6
|
const RADIUS_KM = 6371; // radius of the earth in kilometers
|
|
37
7
|
// https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
|
|
@@ -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;
|
package/dist/esm/utils/maps.js
CHANGED
|
@@ -1,33 +1,4 @@
|
|
|
1
1
|
import { MAX_DISTANCE } from './constants';
|
|
2
|
-
export var GooglePlaceBusinessStatus;
|
|
3
|
-
(function (GooglePlaceBusinessStatus) {
|
|
4
|
-
GooglePlaceBusinessStatus["OPERATIONAL"] = "OPERATIONAL";
|
|
5
|
-
GooglePlaceBusinessStatus["CLOSED_TEMPORARILY"] = "CLOSED_TEMPORARILY";
|
|
6
|
-
GooglePlaceBusinessStatus["CLOSED_PERMANENTLY"] = "CLOSED_PERMANENTLY";
|
|
7
|
-
})(GooglePlaceBusinessStatus || (GooglePlaceBusinessStatus = {}));
|
|
8
|
-
// seee example Google Maps Place at bottom of file
|
|
9
|
-
const makeComponents = (components) => {
|
|
10
|
-
return components.reduce((obj, i) => {
|
|
11
|
-
return Object.assign(Object.assign({}, obj), { [i.types[0]]: { long_name: i.long_name, short_name: i.short_name } });
|
|
12
|
-
}, {});
|
|
13
|
-
};
|
|
14
|
-
export const makeAddress = (place) => {
|
|
15
|
-
const { address_components, formatted_address, geometry } = place;
|
|
16
|
-
const components = makeComponents(address_components);
|
|
17
|
-
const { street_number, route, locality: city, sublocality_level_1: subcity, administrative_area_level_1: state, postal_code: postalCode } = components;
|
|
18
|
-
const streetNumber = street_number ? street_number.short_name : '';
|
|
19
|
-
const street = route ? route.long_name : '';
|
|
20
|
-
const addressCity = city || subcity;
|
|
21
|
-
return {
|
|
22
|
-
street: `${streetNumber} ${street}`.trim(),
|
|
23
|
-
city: addressCity ? addressCity.long_name : '',
|
|
24
|
-
state: state ? state.short_name : '',
|
|
25
|
-
postal_code: postalCode ? postalCode.short_name : '',
|
|
26
|
-
lat: geometry.location.lat || null,
|
|
27
|
-
lng: geometry.location.lng || null,
|
|
28
|
-
formatted_address
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
2
|
const RADIUS_MILES = 3959; // radius of the earth in miles
|
|
32
3
|
const RADIUS_KM = 6371; // radius of the earth in kilometers
|
|
33
4
|
// https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
|
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",
|