@escapenavigator/utils 2.0.13 → 2.0.15
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.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const addressesLikelyMismatch: (googleAddress?: string | null, ourAddress?: string | null) => boolean;
|
|
2
|
+
export declare const namesLikelyMismatch: (googleName?: string | null, profileTitle?: string | null) => boolean;
|
|
3
|
+
export declare const isGooglePlaceSuspicious: (input: {
|
|
4
|
+
status?: string | null;
|
|
5
|
+
profileId?: number | null;
|
|
6
|
+
locationId?: number | null;
|
|
7
|
+
googleName?: string | null;
|
|
8
|
+
googleAddress?: string | null;
|
|
9
|
+
profileTitle?: string | null;
|
|
10
|
+
locationAddress?: string | null;
|
|
11
|
+
}) => boolean;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isGooglePlaceSuspicious = exports.namesLikelyMismatch = exports.addressesLikelyMismatch = void 0;
|
|
4
|
+
const addressTokens = (value) => {
|
|
5
|
+
if (!value)
|
|
6
|
+
return [];
|
|
7
|
+
return value
|
|
8
|
+
.toLowerCase()
|
|
9
|
+
.replace(/[^a-z0-9]/g, ' ')
|
|
10
|
+
.split(/\s+/)
|
|
11
|
+
.filter((token) => token.length > 2);
|
|
12
|
+
};
|
|
13
|
+
const addressesLikelyMismatch = (googleAddress, ourAddress) => {
|
|
14
|
+
if (!googleAddress || !ourAddress)
|
|
15
|
+
return false;
|
|
16
|
+
const googleTokenSet = new Set(addressTokens(googleAddress));
|
|
17
|
+
const shared = addressTokens(ourAddress).filter((token) => googleTokenSet.has(token)).length;
|
|
18
|
+
return shared < 2;
|
|
19
|
+
};
|
|
20
|
+
exports.addressesLikelyMismatch = addressesLikelyMismatch;
|
|
21
|
+
const normalizeTitle = (title) => {
|
|
22
|
+
if (!title)
|
|
23
|
+
return '';
|
|
24
|
+
return title
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
.replace(/[^\p{L}\p{N}\s]/gu, ' ')
|
|
27
|
+
.replace(/\b(the|a|an|le|la|les|der|die|das|el|los|il)\b/g, ' ')
|
|
28
|
+
.replace(/\b(escape room|escape rooms|real life)\b/g, ' ')
|
|
29
|
+
.replace(/\s+/g, ' ')
|
|
30
|
+
.trim();
|
|
31
|
+
};
|
|
32
|
+
const titleSimilarity = (a, b) => {
|
|
33
|
+
const left = new Set(normalizeTitle(a).split(' ').filter(Boolean));
|
|
34
|
+
const right = new Set(normalizeTitle(b).split(' ').filter(Boolean));
|
|
35
|
+
if (!left.size || !right.size)
|
|
36
|
+
return 0;
|
|
37
|
+
let common = 0;
|
|
38
|
+
for (const token of left) {
|
|
39
|
+
if (right.has(token))
|
|
40
|
+
common++;
|
|
41
|
+
}
|
|
42
|
+
return common / Math.min(left.size, right.size);
|
|
43
|
+
};
|
|
44
|
+
const namesLikelyMismatch = (googleName, profileTitle) => {
|
|
45
|
+
if (!googleName || !profileTitle)
|
|
46
|
+
return false;
|
|
47
|
+
const gp = normalizeTitle(googleName);
|
|
48
|
+
const profile = normalizeTitle(profileTitle);
|
|
49
|
+
if (!gp || !profile)
|
|
50
|
+
return false;
|
|
51
|
+
if (gp.includes(profile) || profile.includes(gp))
|
|
52
|
+
return false;
|
|
53
|
+
return titleSimilarity(googleName, profileTitle) < 0.5;
|
|
54
|
+
};
|
|
55
|
+
exports.namesLikelyMismatch = namesLikelyMismatch;
|
|
56
|
+
const isGooglePlaceSuspicious = (input) => {
|
|
57
|
+
if (input.status === 'conflict' || input.status === 'new_location')
|
|
58
|
+
return true;
|
|
59
|
+
if (input.profileId && !input.locationId)
|
|
60
|
+
return true;
|
|
61
|
+
if (input.profileId && input.locationId) {
|
|
62
|
+
if ((0, exports.addressesLikelyMismatch)(input.googleAddress, input.locationAddress))
|
|
63
|
+
return true;
|
|
64
|
+
if ((0, exports.namesLikelyMismatch)(input.googleName, input.profileTitle))
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
};
|
|
69
|
+
exports.isGooglePlaceSuspicious = isGooglePlaceSuspicious;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './format-flex-duration-label';
|
|
|
11
11
|
export * from './functional-popover-panel-style';
|
|
12
12
|
export * from './get-documents-links';
|
|
13
13
|
export * from './get-full-name';
|
|
14
|
+
export * from './google-places-link-warnings';
|
|
14
15
|
export * from './get-handled-error-message';
|
|
15
16
|
export * from './get-order-cancelation-state';
|
|
16
17
|
export * from './get-service-error';
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __exportStar(require("./format-flex-duration-label"), exports);
|
|
|
27
27
|
__exportStar(require("./functional-popover-panel-style"), exports);
|
|
28
28
|
__exportStar(require("./get-documents-links"), exports);
|
|
29
29
|
__exportStar(require("./get-full-name"), exports);
|
|
30
|
+
__exportStar(require("./google-places-link-warnings"), exports);
|
|
30
31
|
__exportStar(require("./get-handled-error-message"), exports);
|
|
31
32
|
__exportStar(require("./get-order-cancelation-state"), exports);
|
|
32
33
|
__exportStar(require("./get-service-error"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@escapenavigator/utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"test": "jest"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@escapenavigator/types": "^2.0.
|
|
17
|
+
"@escapenavigator/types": "^2.0.14",
|
|
18
18
|
"axios": "^0.21.4",
|
|
19
19
|
"class-transformer": "^0.5.1",
|
|
20
20
|
"class-validator": "^0.13.2",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"ts-jest": "^29.1.1",
|
|
30
30
|
"typescript": "^5.6"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "d88028b791bdfcd2cc529f66db490a4bf7761fdd"
|
|
33
33
|
}
|