atlas-obscura-api 4.0.1 → 4.1.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/index.d.mts +17 -0
- package/index.d.ts +17 -0
- package/index.js +7 -0
- package/index.js.map +1 -1
- package/index.mjs +7 -0
- package/index.mjs.map +1 -1
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -68,12 +68,28 @@ interface AOPlacesAll extends AOCoordinates {
|
|
|
68
68
|
id: number;
|
|
69
69
|
}
|
|
70
70
|
//#endregion
|
|
71
|
+
//#region src/interfaces/user.interface.d.ts
|
|
72
|
+
interface AOUser {
|
|
73
|
+
id: number;
|
|
74
|
+
places: AOUserPlace[];
|
|
75
|
+
}
|
|
76
|
+
interface AOUserPlace {
|
|
77
|
+
id: number;
|
|
78
|
+
title: string;
|
|
79
|
+
subtitle: string;
|
|
80
|
+
url: string;
|
|
81
|
+
location: string;
|
|
82
|
+
thumbnail_url: string;
|
|
83
|
+
coordinates: AOCoordinates;
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
71
86
|
//#region src/services/location.service.d.ts
|
|
72
87
|
declare class PlacesScraper {
|
|
73
88
|
placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]>;
|
|
74
89
|
search(coords: AOCoordinates, page?: number, options?: AOFetchOptions): Promise<AOLocationResult>;
|
|
75
90
|
placeByIdShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort>;
|
|
76
91
|
placeFull(url: string, options?: AOFetchOptions): Promise<AOPlaceExtend>;
|
|
92
|
+
user(user: string, options?: AOFetchOptions): Promise<AOUser>;
|
|
77
93
|
}
|
|
78
94
|
//#endregion
|
|
79
95
|
//#region src/index.d.ts
|
|
@@ -84,6 +100,7 @@ declare class AtlasObscura {
|
|
|
84
100
|
placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]>;
|
|
85
101
|
placeShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort>;
|
|
86
102
|
placeFull(id: number, options?: AOFetchOptions): Promise<AOPlace>;
|
|
103
|
+
user(user: string, options?: AOFetchOptions): Promise<AOUser>;
|
|
87
104
|
}
|
|
88
105
|
declare const atlasObscura: AtlasObscura;
|
|
89
106
|
//#endregion
|
package/index.d.ts
CHANGED
|
@@ -68,12 +68,28 @@ interface AOPlacesAll extends AOCoordinates {
|
|
|
68
68
|
id: number;
|
|
69
69
|
}
|
|
70
70
|
//#endregion
|
|
71
|
+
//#region src/interfaces/user.interface.d.ts
|
|
72
|
+
interface AOUser {
|
|
73
|
+
id: number;
|
|
74
|
+
places: AOUserPlace[];
|
|
75
|
+
}
|
|
76
|
+
interface AOUserPlace {
|
|
77
|
+
id: number;
|
|
78
|
+
title: string;
|
|
79
|
+
subtitle: string;
|
|
80
|
+
url: string;
|
|
81
|
+
location: string;
|
|
82
|
+
thumbnail_url: string;
|
|
83
|
+
coordinates: AOCoordinates;
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
71
86
|
//#region src/services/location.service.d.ts
|
|
72
87
|
declare class PlacesScraper {
|
|
73
88
|
placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]>;
|
|
74
89
|
search(coords: AOCoordinates, page?: number, options?: AOFetchOptions): Promise<AOLocationResult>;
|
|
75
90
|
placeByIdShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort>;
|
|
76
91
|
placeFull(url: string, options?: AOFetchOptions): Promise<AOPlaceExtend>;
|
|
92
|
+
user(user: string, options?: AOFetchOptions): Promise<AOUser>;
|
|
77
93
|
}
|
|
78
94
|
//#endregion
|
|
79
95
|
//#region src/index.d.ts
|
|
@@ -84,6 +100,7 @@ declare class AtlasObscura {
|
|
|
84
100
|
placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]>;
|
|
85
101
|
placeShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort>;
|
|
86
102
|
placeFull(id: number, options?: AOFetchOptions): Promise<AOPlace>;
|
|
103
|
+
user(user: string, options?: AOFetchOptions): Promise<AOUser>;
|
|
87
104
|
}
|
|
88
105
|
declare const atlasObscura: AtlasObscura;
|
|
89
106
|
//#endregion
|
package/index.js
CHANGED
|
@@ -76,6 +76,7 @@ const parseResults = (matches) => {
|
|
|
76
76
|
const URL_PLACES_ALL = "https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map";
|
|
77
77
|
const urlSearch = (coord, page) => `https://www.atlasobscura.com/search?utf8=%E2%9C%93&q=&location=&nearby=true&lat=${coord.lat}&lng=${coord.lng}${page ? "&page=" + page : ""}`;
|
|
78
78
|
const urlPlaceId = (id) => `https://www.atlasobscura.com/places/${id}.json?place_only=1`;
|
|
79
|
+
const urlUser = (name) => `https://www.atlasobscura.com/users/${name}`;
|
|
79
80
|
|
|
80
81
|
//#endregion
|
|
81
82
|
//#region src/services/location.service.ts
|
|
@@ -124,6 +125,9 @@ var PlacesScraper = class {
|
|
|
124
125
|
images
|
|
125
126
|
};
|
|
126
127
|
}
|
|
128
|
+
async user(user, options) {
|
|
129
|
+
return parseResults((0, node_html_parser.parse)(await fetchPage(urlUser(user), options?.headers)).innerHTML.match(/AtlasObscura\.user_profile = (.*?);/)).user;
|
|
130
|
+
}
|
|
127
131
|
};
|
|
128
132
|
|
|
129
133
|
//#endregion
|
|
@@ -149,6 +153,9 @@ var AtlasObscura = class {
|
|
|
149
153
|
...placeRich
|
|
150
154
|
};
|
|
151
155
|
}
|
|
156
|
+
async user(user, options) {
|
|
157
|
+
return this.locationService.user(user, options);
|
|
158
|
+
}
|
|
152
159
|
};
|
|
153
160
|
const locationScraper = new PlacesScraper();
|
|
154
161
|
const atlasObscura = new AtlasObscura(locationScraper);
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["USER_AGENTS: string[]","locations: T","place: AOPlaceShort","locationService: PlacesScraper","atlasObscura: AtlasObscura"],"sources":["../src/fetchers/index.ts","../src/utils.ts","../src/vars.ts","../src/services/location.service.ts","../src/index.ts"],"sourcesContent":["const USER_AGENTS: string[] = [\n 'Dalvik/2.1.0 (Linux; U; Android 8.1.0; C6L Build/OPM2.171019.012)',\n 'Mozilla/5.0 (Windows; Windows NT 10.0; x64) AppleWebKit/537.50 (KHTML, like Gecko) Chrome/48.0.2572.385 Safari/537.9 Edge/8.37913',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',\n 'Dalvik/2.1.0 (Linux; U; Android 11; SM-A505GT Build/RP1A.200720.012)',\n 'Mozilla/5.0 (Windows NT 10.3;; en-US) AppleWebKit/602.25 (KHTML, like Gecko) Chrome/54.0.2457.241 Safari/534.5 Edge/9.65405',\n 'Mozilla/5.0 (Windows; U; Windows NT 10.4; x64) AppleWebKit/536.41 (KHTML, like Gecko) Chrome/53.0.3535.112 Safari/600.5 Edge/14.39786',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_0; like Mac OS X) AppleWebKit/601.9 (KHTML, like Gecko) Chrome/47.0.2876.394 Mobile Safari/600.5',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_6_3; like Mac OS X) AppleWebKit/602.24 (KHTML, like Gecko) Chrome/54.0.3204.297 Mobile Safari/537.0',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_9_6; like Mac OS X) AppleWebKit/601.4 (KHTML, like Gecko) Chrome/55.0.2808.105 Mobile Safari/600.4',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2_1; like Mac OS X) AppleWebKit/600.14 (KHTML, like Gecko) Chrome/50.0.3808.259 Mobile Safari/534.1',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_4_2; like Mac OS X) AppleWebKit/534.21 (KHTML, like Gecko) Chrome/47.0.3531.351 Mobile Safari/533.0'\n];\n\nconst DEFAULT_HEADERS = {\n 'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)],\n 'Cache-Control': 'no-cache',\n};\n\nexport const fetchPage = async (url: string, headersCustom?: Headers): Promise<string> => {\n try {\n const response = await fetch(url, {\n headers: { ...DEFAULT_HEADERS, ...headersCustom },\n credentials: 'omit'\n });\n\n if (!response.ok) {\n throw new Error(`atlas-obscura-api: Bad response ${response.status} for url: ${url}`);\n }\n\n return await response.text();\n } catch (error) {\n console.error('fetchPage error:', error);\n return 'Error';\n }\n};\n","export const parseResults = <T>(matches: RegExpMatchArray): T => {\n let locations: T = null;\n\n if (matches && matches[1]?.length) {\n try {\n locations = JSON.parse(matches[1]);\n } catch (error) {\n console.error('Error parsing all places');\n }\n }\n return locations;\n};\n","export const URL_PLACES_ALL =\n 'https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map';\n\nexport const urlSearch = (coord: { lat: number; lng: number }, page?: number): string =>\n `https://www.atlasobscura.com/search?utf8=%E2%9C%93&q=&location=&nearby=true&lat=${coord.lat\n }&lng=${coord.lng}${page ? '&page=' + page : ''}`;\n\nexport const urlPlaceId = (id: number): string =>\n `https://www.atlasobscura.com/places/${id}.json?place_only=1`;\n","import { parse } from 'node-html-parser';\nimport { fetchPage } from '../fetchers/index.js';\nimport { parseResults } from '../utils.js';\nimport { URL_PLACES_ALL, urlPlaceId, urlSearch } from '../vars.js';\nimport { AOCoordinates, AOFetchOptions } from './../interfaces/global.js';\nimport { AOLocationResult } from './../interfaces/locations.interface.js';\nimport { AOPlaceExtend, AOPlaceShort } from './../interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './../interfaces/places-all.interface.js';\n\nexport class PlacesScraper {\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n const response = await fetchPage(URL_PLACES_ALL, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.all_places = (.*?);/);\n\n return parseResults<AOPlacesAll[]>(data);\n }\n\n public async search(coords: AOCoordinates, page = 1, options?: AOFetchOptions): Promise<AOLocationResult> {\n const url = urlSearch(coords, page);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.place_search = (.*?);/);\n\n return parseResults<AOLocationResult>(data);\n }\n\n public async placeByIdShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n const url = urlPlaceId(id);\n const data = await fetchPage(url, options?.headers);\n\n let place: AOPlaceShort = null;\n\n try {\n place = JSON.parse(data);\n if (place && typeof place.hide_from_maps === 'string') {\n (place as any).hide_from_maps = place.hide_from_maps === 'true';\n }\n } catch (error) {\n console.error('Error parsing placeById', id);\n }\n return place;\n }\n\n public async placeFull(url: string, options?: AOFetchOptions): Promise<AOPlaceExtend> {\n const data = await fetchPage(url, options?.headers);\n const html = parse(data);\n\n const descriptions = html.querySelectorAll('.place-body p').map((p) => p.innerHTML);\n\n const sectionDirections = Array.from(html.querySelectorAll('section')).find((sec) => {\n const h2 = sec.querySelector('h2');\n return h2 && h2.textContent.trim() === 'Know Before You Go';\n });\n const directions = sectionDirections\n ? Array.from(sectionDirections.querySelectorAll('p')).map((p) => p.textContent.trim())\n : [];\n\n const tags = html.querySelectorAll('.aon-pill-badge-component').map((x) => {\n return {\n title: x.querySelector('.aon-pill-badge-text')?.innerHTML.trim(),\n link: x.attributes.href\n };\n });\n\n const slides = html.querySelectorAll('.swiper-slide');\n const images = Array.from(slides)\n .map((slide) => {\n const img = slide.querySelector('img');\n return img ? img.getAttribute('src') : null;\n })\n .filter(Boolean);\n\n const imageCover = images[0];\n\n return { description: descriptions, directions, tags, imageCover, images };\n }\n}\n","import { AOCoordinates, AOFetchOptions } from './interfaces/global.js';\nimport { AOLocationResult } from './interfaces/locations.interface.js';\nimport { AOPlace, AOPlaceShort } from './interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './interfaces/places-all.interface.js';\nimport { PlacesScraper } from './services/location.service.js';\n\nexport class AtlasObscura {\n constructor(private locationService: PlacesScraper) { }\n\n public async search(coords: AOCoordinates, options?: AOFetchOptions): Promise<AOLocationResult> {\n return this.locationService.search(coords, 1, options);\n }\n\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n return this.locationService.placesAll(options);\n }\n\n public async placeShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n return this.locationService.placeByIdShort(id, options);\n }\n\n public async placeFull(id: number, options?: AOFetchOptions): Promise<AOPlace> {\n const place = await this.locationService.placeByIdShort(id, options);\n const placeRich = await this.locationService.placeFull(place.url, options);\n return { ...place, ...placeRich };\n }\n}\n\nconst locationScraper = new PlacesScraper();\nexport const atlasObscura: AtlasObscura = new AtlasObscura(locationScraper);\nexport type * from './interfaces/index.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAMA,cAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,kBAAkB;CACtB,cAAc,YAAY,KAAK,MAAM,KAAK,QAAQ,GAAG,YAAY,OAAO;CACxE,iBAAiB;CAClB;AAED,MAAa,YAAY,OAAO,KAAa,kBAA6C;AACxF,KAAI;EACF,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,SAAS;IAAE,GAAG;IAAiB,GAAG;IAAe;GACjD,aAAa;GACd,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,mCAAmC,SAAS,OAAO,YAAY,MAAM;AAGvF,SAAO,MAAM,SAAS,MAAM;UACrB,OAAO;AACd,UAAQ,MAAM,oBAAoB,MAAM;AACxC,SAAO;;;;;;ACjCX,MAAa,gBAAmB,YAAiC;CAC/D,IAAIC,YAAe;AAEnB,KAAI,WAAW,QAAQ,IAAI,OACzB,KAAI;AACF,cAAY,KAAK,MAAM,QAAQ,GAAG;UAC3B,OAAO;AACd,UAAQ,MAAM,2BAA2B;;AAG7C,QAAO;;;;;ACVT,MAAa,iBACX;AAEF,MAAa,aAAa,OAAqC,SAC7D,mFAAmF,MAAM,IACxF,OAAO,MAAM,MAAM,OAAO,WAAW,OAAO;AAE/C,MA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;EAEF,MAAM,SAAS,KAAK,iBAAiB,gBAAgB;EACrD,MAAM,SAAS,MAAM,KAAK,OAAO,CAC9B,KAAK,UAAU;GACd,MAAM,MAAM,MAAM,cAAc,MAAM;AACtC,UAAO,MAAM,IAAI,aAAa,MAAM,GAAG;IACvC,CACD,OAAO,QAAQ;AAIlB,SAAO;GAAE,aAAa;GAAc;GAAY;GAAM,YAFnC,OAAO;GAEwC;GAAQ;;;;;;ACvE9E,IAAa,eAAb,MAA0B;CACxB,YAAY,AAAQC,iBAAgC;EAAhC;;CAEpB,MAAa,OAAO,QAAuB,SAAqD;AAC9F,SAAO,KAAK,gBAAgB,OAAO,QAAQ,GAAG,QAAQ;;CAGxD,MAAa,UAAU,SAAkD;AACvE,SAAO,KAAK,gBAAgB,UAAU,QAAQ;;CAGhD,MAAa,WAAW,IAAY,SAAiD;AACnF,SAAO,KAAK,gBAAgB,eAAe,IAAI,QAAQ;;CAGzD,MAAa,UAAU,IAAY,SAA4C;EAC7E,MAAM,QAAQ,MAAM,KAAK,gBAAgB,eAAe,IAAI,QAAQ;EACpE,MAAM,YAAY,MAAM,KAAK,gBAAgB,UAAU,MAAM,KAAK,QAAQ;AAC1E,SAAO;GAAE,GAAG;GAAO,GAAG;GAAW;;;AAIrC,MAAM,kBAAkB,IAAI,eAAe;AAC3C,MAAaC,eAA6B,IAAI,aAAa,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["USER_AGENTS: string[]","locations: T","place: AOPlaceShort","locationService: PlacesScraper","atlasObscura: AtlasObscura"],"sources":["../src/fetchers/index.ts","../src/utils.ts","../src/vars.ts","../src/services/location.service.ts","../src/index.ts"],"sourcesContent":["const USER_AGENTS: string[] = [\n 'Dalvik/2.1.0 (Linux; U; Android 8.1.0; C6L Build/OPM2.171019.012)',\n 'Mozilla/5.0 (Windows; Windows NT 10.0; x64) AppleWebKit/537.50 (KHTML, like Gecko) Chrome/48.0.2572.385 Safari/537.9 Edge/8.37913',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',\n 'Dalvik/2.1.0 (Linux; U; Android 11; SM-A505GT Build/RP1A.200720.012)',\n 'Mozilla/5.0 (Windows NT 10.3;; en-US) AppleWebKit/602.25 (KHTML, like Gecko) Chrome/54.0.2457.241 Safari/534.5 Edge/9.65405',\n 'Mozilla/5.0 (Windows; U; Windows NT 10.4; x64) AppleWebKit/536.41 (KHTML, like Gecko) Chrome/53.0.3535.112 Safari/600.5 Edge/14.39786',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_0; like Mac OS X) AppleWebKit/601.9 (KHTML, like Gecko) Chrome/47.0.2876.394 Mobile Safari/600.5',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_6_3; like Mac OS X) AppleWebKit/602.24 (KHTML, like Gecko) Chrome/54.0.3204.297 Mobile Safari/537.0',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_9_6; like Mac OS X) AppleWebKit/601.4 (KHTML, like Gecko) Chrome/55.0.2808.105 Mobile Safari/600.4',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2_1; like Mac OS X) AppleWebKit/600.14 (KHTML, like Gecko) Chrome/50.0.3808.259 Mobile Safari/534.1',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_4_2; like Mac OS X) AppleWebKit/534.21 (KHTML, like Gecko) Chrome/47.0.3531.351 Mobile Safari/533.0'\n];\n\nconst DEFAULT_HEADERS = {\n 'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)],\n 'Cache-Control': 'no-cache',\n};\n\nexport const fetchPage = async (url: string, headersCustom?: Headers): Promise<string> => {\n try {\n const response = await fetch(url, {\n headers: { ...DEFAULT_HEADERS, ...headersCustom },\n credentials: 'omit'\n });\n\n if (!response.ok) {\n throw new Error(`atlas-obscura-api: Bad response ${response.status} for url: ${url}`);\n }\n\n return await response.text();\n } catch (error) {\n console.error('fetchPage error:', error);\n return 'Error';\n }\n};\n","export const parseResults = <T>(matches: RegExpMatchArray): T => {\n let locations: T = null;\n\n if (matches && matches[1]?.length) {\n try {\n locations = JSON.parse(matches[1]);\n } catch (error) {\n console.error('Error parsing all places');\n }\n }\n return locations;\n};\n","export const URL_PLACES_ALL =\n 'https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map';\n\nexport const urlSearch = (coord: { lat: number; lng: number }, page?: number): string =>\n `https://www.atlasobscura.com/search?utf8=%E2%9C%93&q=&location=&nearby=true&lat=${coord.lat\n }&lng=${coord.lng}${page ? '&page=' + page : ''}`;\n\nexport const urlPlaceId = (id: number): string =>\n `https://www.atlasobscura.com/places/${id}.json?place_only=1`;\n\nexport const urlUser = (name: string): string =>\n `https://www.atlasobscura.com/users/${name}`;\n","import { parse } from 'node-html-parser';\nimport { fetchPage } from '../fetchers/index.js';\nimport { AOUser } from '../interfaces/user.interface.js';\nimport { parseResults } from '../utils.js';\nimport { URL_PLACES_ALL, urlPlaceId, urlSearch, urlUser } from '../vars.js';\nimport { AOCoordinates, AOFetchOptions } from './../interfaces/global.js';\nimport { AOLocationResult } from './../interfaces/locations.interface.js';\nimport { AOPlaceExtend, AOPlaceShort } from './../interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './../interfaces/places-all.interface.js';\n\nexport class PlacesScraper {\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n const response = await fetchPage(URL_PLACES_ALL, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.all_places = (.*?);/);\n\n return parseResults<AOPlacesAll[]>(data);\n }\n\n public async search(coords: AOCoordinates, page = 1, options?: AOFetchOptions): Promise<AOLocationResult> {\n const url = urlSearch(coords, page);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.place_search = (.*?);/);\n\n return parseResults<AOLocationResult>(data);\n }\n\n public async placeByIdShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n const url = urlPlaceId(id);\n const data = await fetchPage(url, options?.headers);\n\n let place: AOPlaceShort = null;\n\n try {\n place = JSON.parse(data);\n if (place && typeof place.hide_from_maps === 'string') {\n (place as any).hide_from_maps = place.hide_from_maps === 'true';\n }\n } catch (error) {\n console.error('Error parsing placeById', id);\n }\n return place;\n }\n\n public async placeFull(url: string, options?: AOFetchOptions): Promise<AOPlaceExtend> {\n const data = await fetchPage(url, options?.headers);\n const html = parse(data);\n\n const descriptions = html.querySelectorAll('.place-body p').map((p) => p.innerHTML);\n\n const sectionDirections = Array.from(html.querySelectorAll('section')).find((sec) => {\n const h2 = sec.querySelector('h2');\n return h2 && h2.textContent.trim() === 'Know Before You Go';\n });\n const directions = sectionDirections\n ? Array.from(sectionDirections.querySelectorAll('p')).map((p) => p.textContent.trim())\n : [];\n\n const tags = html.querySelectorAll('.aon-pill-badge-component').map((x) => {\n return {\n title: x.querySelector('.aon-pill-badge-text')?.innerHTML.trim(),\n link: x.attributes.href\n };\n });\n\n const slides = html.querySelectorAll('.swiper-slide');\n const images = Array.from(slides)\n .map((slide) => {\n const img = slide.querySelector('img');\n return img ? img.getAttribute('src') : null;\n })\n .filter(Boolean);\n\n const imageCover = images[0];\n\n return { description: descriptions, directions, tags, imageCover, images };\n }\n\n public async user(user: string, options?: AOFetchOptions): Promise<AOUser> {\n const url = urlUser(user);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.user_profile = (.*?);/);\n\n const usr = parseResults<{ user: AOUser }>(data);\n\n return usr.user;\n }\n}\n","import { AOCoordinates, AOFetchOptions } from './interfaces/global.js';\nimport { AOLocationResult } from './interfaces/locations.interface.js';\nimport { AOPlace, AOPlaceShort } from './interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './interfaces/places-all.interface.js';\nimport { AOUser } from './interfaces/user.interface.js';\nimport { PlacesScraper } from './services/location.service.js';\n\nexport class AtlasObscura {\n constructor(private locationService: PlacesScraper) { }\n\n public async search(coords: AOCoordinates, options?: AOFetchOptions): Promise<AOLocationResult> {\n return this.locationService.search(coords, 1, options);\n }\n\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n return this.locationService.placesAll(options);\n }\n\n public async placeShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n return this.locationService.placeByIdShort(id, options);\n }\n\n public async placeFull(id: number, options?: AOFetchOptions): Promise<AOPlace> {\n const place = await this.locationService.placeByIdShort(id, options);\n const placeRich = await this.locationService.placeFull(place.url, options);\n return { ...place, ...placeRich };\n }\n\n public async user(user: string, options?: AOFetchOptions): Promise<AOUser> {\n return this.locationService.user(user, options);\n }\n}\n\nconst locationScraper = new PlacesScraper();\nexport const atlasObscura: AtlasObscura = new AtlasObscura(locationScraper);\nexport type * from './interfaces/index.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAMA,cAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,kBAAkB;CACtB,cAAc,YAAY,KAAK,MAAM,KAAK,QAAQ,GAAG,YAAY,OAAO;CACxE,iBAAiB;CAClB;AAED,MAAa,YAAY,OAAO,KAAa,kBAA6C;AACxF,KAAI;EACF,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,SAAS;IAAE,GAAG;IAAiB,GAAG;IAAe;GACjD,aAAa;GACd,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,mCAAmC,SAAS,OAAO,YAAY,MAAM;AAGvF,SAAO,MAAM,SAAS,MAAM;UACrB,OAAO;AACd,UAAQ,MAAM,oBAAoB,MAAM;AACxC,SAAO;;;;;;ACjCX,MAAa,gBAAmB,YAAiC;CAC/D,IAAIC,YAAe;AAEnB,KAAI,WAAW,QAAQ,IAAI,OACzB,KAAI;AACF,cAAY,KAAK,MAAM,QAAQ,GAAG;UAC3B,OAAO;A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AaC,eAA6B,IAAI,aAAa,gBAAgB"}
|
package/index.mjs
CHANGED
|
@@ -52,6 +52,7 @@ const parseResults = (matches) => {
|
|
|
52
52
|
const URL_PLACES_ALL = "https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map";
|
|
53
53
|
const urlSearch = (coord, page) => `https://www.atlasobscura.com/search?utf8=%E2%9C%93&q=&location=&nearby=true&lat=${coord.lat}&lng=${coord.lng}${page ? "&page=" + page : ""}`;
|
|
54
54
|
const urlPlaceId = (id) => `https://www.atlasobscura.com/places/${id}.json?place_only=1`;
|
|
55
|
+
const urlUser = (name) => `https://www.atlasobscura.com/users/${name}`;
|
|
55
56
|
|
|
56
57
|
//#endregion
|
|
57
58
|
//#region src/services/location.service.ts
|
|
@@ -100,6 +101,9 @@ var PlacesScraper = class {
|
|
|
100
101
|
images
|
|
101
102
|
};
|
|
102
103
|
}
|
|
104
|
+
async user(user, options) {
|
|
105
|
+
return parseResults(parse(await fetchPage(urlUser(user), options?.headers)).innerHTML.match(/AtlasObscura\.user_profile = (.*?);/)).user;
|
|
106
|
+
}
|
|
103
107
|
};
|
|
104
108
|
|
|
105
109
|
//#endregion
|
|
@@ -125,6 +129,9 @@ var AtlasObscura = class {
|
|
|
125
129
|
...placeRich
|
|
126
130
|
};
|
|
127
131
|
}
|
|
132
|
+
async user(user, options) {
|
|
133
|
+
return this.locationService.user(user, options);
|
|
134
|
+
}
|
|
128
135
|
};
|
|
129
136
|
const locationScraper = new PlacesScraper();
|
|
130
137
|
const atlasObscura = new AtlasObscura(locationScraper);
|
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["USER_AGENTS: string[]","locations: T","place: AOPlaceShort","locationService: PlacesScraper","atlasObscura: AtlasObscura"],"sources":["../src/fetchers/index.ts","../src/utils.ts","../src/vars.ts","../src/services/location.service.ts","../src/index.ts"],"sourcesContent":["const USER_AGENTS: string[] = [\n 'Dalvik/2.1.0 (Linux; U; Android 8.1.0; C6L Build/OPM2.171019.012)',\n 'Mozilla/5.0 (Windows; Windows NT 10.0; x64) AppleWebKit/537.50 (KHTML, like Gecko) Chrome/48.0.2572.385 Safari/537.9 Edge/8.37913',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',\n 'Dalvik/2.1.0 (Linux; U; Android 11; SM-A505GT Build/RP1A.200720.012)',\n 'Mozilla/5.0 (Windows NT 10.3;; en-US) AppleWebKit/602.25 (KHTML, like Gecko) Chrome/54.0.2457.241 Safari/534.5 Edge/9.65405',\n 'Mozilla/5.0 (Windows; U; Windows NT 10.4; x64) AppleWebKit/536.41 (KHTML, like Gecko) Chrome/53.0.3535.112 Safari/600.5 Edge/14.39786',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_0; like Mac OS X) AppleWebKit/601.9 (KHTML, like Gecko) Chrome/47.0.2876.394 Mobile Safari/600.5',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_6_3; like Mac OS X) AppleWebKit/602.24 (KHTML, like Gecko) Chrome/54.0.3204.297 Mobile Safari/537.0',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_9_6; like Mac OS X) AppleWebKit/601.4 (KHTML, like Gecko) Chrome/55.0.2808.105 Mobile Safari/600.4',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2_1; like Mac OS X) AppleWebKit/600.14 (KHTML, like Gecko) Chrome/50.0.3808.259 Mobile Safari/534.1',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_4_2; like Mac OS X) AppleWebKit/534.21 (KHTML, like Gecko) Chrome/47.0.3531.351 Mobile Safari/533.0'\n];\n\nconst DEFAULT_HEADERS = {\n 'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)],\n 'Cache-Control': 'no-cache',\n};\n\nexport const fetchPage = async (url: string, headersCustom?: Headers): Promise<string> => {\n try {\n const response = await fetch(url, {\n headers: { ...DEFAULT_HEADERS, ...headersCustom },\n credentials: 'omit'\n });\n\n if (!response.ok) {\n throw new Error(`atlas-obscura-api: Bad response ${response.status} for url: ${url}`);\n }\n\n return await response.text();\n } catch (error) {\n console.error('fetchPage error:', error);\n return 'Error';\n }\n};\n","export const parseResults = <T>(matches: RegExpMatchArray): T => {\n let locations: T = null;\n\n if (matches && matches[1]?.length) {\n try {\n locations = JSON.parse(matches[1]);\n } catch (error) {\n console.error('Error parsing all places');\n }\n }\n return locations;\n};\n","export const URL_PLACES_ALL =\n 'https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map';\n\nexport const urlSearch = (coord: { lat: number; lng: number }, page?: number): string =>\n `https://www.atlasobscura.com/search?utf8=%E2%9C%93&q=&location=&nearby=true&lat=${coord.lat\n }&lng=${coord.lng}${page ? '&page=' + page : ''}`;\n\nexport const urlPlaceId = (id: number): string =>\n `https://www.atlasobscura.com/places/${id}.json?place_only=1`;\n","import { parse } from 'node-html-parser';\nimport { fetchPage } from '../fetchers/index.js';\nimport { parseResults } from '../utils.js';\nimport { URL_PLACES_ALL, urlPlaceId, urlSearch } from '../vars.js';\nimport { AOCoordinates, AOFetchOptions } from './../interfaces/global.js';\nimport { AOLocationResult } from './../interfaces/locations.interface.js';\nimport { AOPlaceExtend, AOPlaceShort } from './../interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './../interfaces/places-all.interface.js';\n\nexport class PlacesScraper {\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n const response = await fetchPage(URL_PLACES_ALL, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.all_places = (.*?);/);\n\n return parseResults<AOPlacesAll[]>(data);\n }\n\n public async search(coords: AOCoordinates, page = 1, options?: AOFetchOptions): Promise<AOLocationResult> {\n const url = urlSearch(coords, page);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.place_search = (.*?);/);\n\n return parseResults<AOLocationResult>(data);\n }\n\n public async placeByIdShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n const url = urlPlaceId(id);\n const data = await fetchPage(url, options?.headers);\n\n let place: AOPlaceShort = null;\n\n try {\n place = JSON.parse(data);\n if (place && typeof place.hide_from_maps === 'string') {\n (place as any).hide_from_maps = place.hide_from_maps === 'true';\n }\n } catch (error) {\n console.error('Error parsing placeById', id);\n }\n return place;\n }\n\n public async placeFull(url: string, options?: AOFetchOptions): Promise<AOPlaceExtend> {\n const data = await fetchPage(url, options?.headers);\n const html = parse(data);\n\n const descriptions = html.querySelectorAll('.place-body p').map((p) => p.innerHTML);\n\n const sectionDirections = Array.from(html.querySelectorAll('section')).find((sec) => {\n const h2 = sec.querySelector('h2');\n return h2 && h2.textContent.trim() === 'Know Before You Go';\n });\n const directions = sectionDirections\n ? Array.from(sectionDirections.querySelectorAll('p')).map((p) => p.textContent.trim())\n : [];\n\n const tags = html.querySelectorAll('.aon-pill-badge-component').map((x) => {\n return {\n title: x.querySelector('.aon-pill-badge-text')?.innerHTML.trim(),\n link: x.attributes.href\n };\n });\n\n const slides = html.querySelectorAll('.swiper-slide');\n const images = Array.from(slides)\n .map((slide) => {\n const img = slide.querySelector('img');\n return img ? img.getAttribute('src') : null;\n })\n .filter(Boolean);\n\n const imageCover = images[0];\n\n return { description: descriptions, directions, tags, imageCover, images };\n }\n}\n","import { AOCoordinates, AOFetchOptions } from './interfaces/global.js';\nimport { AOLocationResult } from './interfaces/locations.interface.js';\nimport { AOPlace, AOPlaceShort } from './interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './interfaces/places-all.interface.js';\nimport { PlacesScraper } from './services/location.service.js';\n\nexport class AtlasObscura {\n constructor(private locationService: PlacesScraper) { }\n\n public async search(coords: AOCoordinates, options?: AOFetchOptions): Promise<AOLocationResult> {\n return this.locationService.search(coords, 1, options);\n }\n\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n return this.locationService.placesAll(options);\n }\n\n public async placeShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n return this.locationService.placeByIdShort(id, options);\n }\n\n public async placeFull(id: number, options?: AOFetchOptions): Promise<AOPlace> {\n const place = await this.locationService.placeByIdShort(id, options);\n const placeRich = await this.locationService.placeFull(place.url, options);\n return { ...place, ...placeRich };\n }\n}\n\nconst locationScraper = new PlacesScraper();\nexport const atlasObscura: AtlasObscura = new AtlasObscura(locationScraper);\nexport type * from './interfaces/index.js';\n"],"mappings":";;;AAAA,MAAMA,cAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,kBAAkB;CACtB,cAAc,YAAY,KAAK,MAAM,KAAK,QAAQ,GAAG,YAAY,OAAO;CACxE,iBAAiB;CAClB;AAED,MAAa,YAAY,OAAO,KAAa,kBAA6C;AACxF,KAAI;EACF,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,SAAS;IAAE,GAAG;IAAiB,GAAG;IAAe;GACjD,aAAa;GACd,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,mCAAmC,SAAS,OAAO,YAAY,MAAM;AAGvF,SAAO,MAAM,SAAS,MAAM;UACrB,OAAO;AACd,UAAQ,MAAM,oBAAoB,MAAM;AACxC,SAAO;;;;;;ACjCX,MAAa,gBAAmB,YAAiC;CAC/D,IAAIC,YAAe;AAEnB,KAAI,WAAW,QAAQ,IAAI,OACzB,KAAI;AACF,cAAY,KAAK,MAAM,QAAQ,GAAG;UAC3B,OAAO;AACd,UAAQ,MAAM,2BAA2B;;AAG7C,QAAO;;;;;ACVT,MAAa,iBACX;AAEF,MAAa,aAAa,OAAqC,SAC7D,mFAAmF,MAAM,IACxF,OAAO,MAAM,MAAM,OAAO,WAAW,OAAO;AAE/C,MAAa,cAAc,OACzB,uCAAuC,GAAG;;;;ACC5C,IAAa,gBAAb,MAA2B;CACzB,MAAa,UAAU,SA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AAK,OAAO,CAC9B,KAAK,UAAU;GACd,MAAM,MAAM,MAAM,cAAc,MAAM;AACtC,UAAO,MAAM,IAAI,aAAa,MAAM,GAAG;IACvC,CACD,OAAO,QAAQ;AAIlB,SAAO;GAAE,aAAa;GAAc;GAAY;GAAM,YAFnC,OAAO;GAEwC;GAAQ;;;;;;ACvE9E,IAAa,eAAb,MAA0B;CACxB,YAAY,AAAQC,iBAAgC;EAAhC;;CAEpB,MAAa,OAAO,QAAuB,SAAqD;AAC9F,SAAO,KAAK,gBAAgB,OAAO,QAAQ,GAAG,QAAQ;;CAGxD,MAAa,UAAU,SAAkD;AACvE,SAAO,KAAK,gBAAgB,UAAU,QAAQ;;CAGhD,MAAa,WAAW,IAAY,SAAiD;AACnF,SAAO,KAAK,gBAAgB,eAAe,IAAI,QAAQ;;CAGzD,MAAa,UAAU,IAAY,SAA4C;EAC7E,MAAM,QAAQ,MAAM,KAAK,gBAAgB,eAAe,IAAI,QAAQ;EACpE,MAAM,YAAY,MAAM,KAAK,gBAAgB,UAAU,MAAM,KAAK,QAAQ;AAC1E,SAAO;GAAE,GAAG;GAAO,GAAG;GAAW;;;AAIrC,MAAM,kBAAkB,IAAI,eAAe;AAC3C,MAAaC,eAA6B,IAAI,aAAa,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["USER_AGENTS: string[]","locations: T","place: AOPlaceShort","locationService: PlacesScraper","atlasObscura: AtlasObscura"],"sources":["../src/fetchers/index.ts","../src/utils.ts","../src/vars.ts","../src/services/location.service.ts","../src/index.ts"],"sourcesContent":["const USER_AGENTS: string[] = [\n 'Dalvik/2.1.0 (Linux; U; Android 8.1.0; C6L Build/OPM2.171019.012)',\n 'Mozilla/5.0 (Windows; Windows NT 10.0; x64) AppleWebKit/537.50 (KHTML, like Gecko) Chrome/48.0.2572.385 Safari/537.9 Edge/8.37913',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1',\n 'Dalvik/2.1.0 (Linux; U; Android 11; SM-A505GT Build/RP1A.200720.012)',\n 'Mozilla/5.0 (Windows NT 10.3;; en-US) AppleWebKit/602.25 (KHTML, like Gecko) Chrome/54.0.2457.241 Safari/534.5 Edge/9.65405',\n 'Mozilla/5.0 (Windows; U; Windows NT 10.4; x64) AppleWebKit/536.41 (KHTML, like Gecko) Chrome/53.0.3535.112 Safari/600.5 Edge/14.39786',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_0; like Mac OS X) AppleWebKit/601.9 (KHTML, like Gecko) Chrome/47.0.2876.394 Mobile Safari/600.5',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_6_3; like Mac OS X) AppleWebKit/602.24 (KHTML, like Gecko) Chrome/54.0.3204.297 Mobile Safari/537.0',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_9_6; like Mac OS X) AppleWebKit/601.4 (KHTML, like Gecko) Chrome/55.0.2808.105 Mobile Safari/600.4',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_2_1; like Mac OS X) AppleWebKit/600.14 (KHTML, like Gecko) Chrome/50.0.3808.259 Mobile Safari/534.1',\n 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_4_2; like Mac OS X) AppleWebKit/534.21 (KHTML, like Gecko) Chrome/47.0.3531.351 Mobile Safari/533.0'\n];\n\nconst DEFAULT_HEADERS = {\n 'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)],\n 'Cache-Control': 'no-cache',\n};\n\nexport const fetchPage = async (url: string, headersCustom?: Headers): Promise<string> => {\n try {\n const response = await fetch(url, {\n headers: { ...DEFAULT_HEADERS, ...headersCustom },\n credentials: 'omit'\n });\n\n if (!response.ok) {\n throw new Error(`atlas-obscura-api: Bad response ${response.status} for url: ${url}`);\n }\n\n return await response.text();\n } catch (error) {\n console.error('fetchPage error:', error);\n return 'Error';\n }\n};\n","export const parseResults = <T>(matches: RegExpMatchArray): T => {\n let locations: T = null;\n\n if (matches && matches[1]?.length) {\n try {\n locations = JSON.parse(matches[1]);\n } catch (error) {\n console.error('Error parsing all places');\n }\n }\n return locations;\n};\n","export const URL_PLACES_ALL =\n 'https://www.atlasobscura.com/articles/all-places-in-the-atlas-on-one-map';\n\nexport const urlSearch = (coord: { lat: number; lng: number }, page?: number): string =>\n `https://www.atlasobscura.com/search?utf8=%E2%9C%93&q=&location=&nearby=true&lat=${coord.lat\n }&lng=${coord.lng}${page ? '&page=' + page : ''}`;\n\nexport const urlPlaceId = (id: number): string =>\n `https://www.atlasobscura.com/places/${id}.json?place_only=1`;\n\nexport const urlUser = (name: string): string =>\n `https://www.atlasobscura.com/users/${name}`;\n","import { parse } from 'node-html-parser';\nimport { fetchPage } from '../fetchers/index.js';\nimport { AOUser } from '../interfaces/user.interface.js';\nimport { parseResults } from '../utils.js';\nimport { URL_PLACES_ALL, urlPlaceId, urlSearch, urlUser } from '../vars.js';\nimport { AOCoordinates, AOFetchOptions } from './../interfaces/global.js';\nimport { AOLocationResult } from './../interfaces/locations.interface.js';\nimport { AOPlaceExtend, AOPlaceShort } from './../interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './../interfaces/places-all.interface.js';\n\nexport class PlacesScraper {\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n const response = await fetchPage(URL_PLACES_ALL, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.all_places = (.*?);/);\n\n return parseResults<AOPlacesAll[]>(data);\n }\n\n public async search(coords: AOCoordinates, page = 1, options?: AOFetchOptions): Promise<AOLocationResult> {\n const url = urlSearch(coords, page);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.place_search = (.*?);/);\n\n return parseResults<AOLocationResult>(data);\n }\n\n public async placeByIdShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n const url = urlPlaceId(id);\n const data = await fetchPage(url, options?.headers);\n\n let place: AOPlaceShort = null;\n\n try {\n place = JSON.parse(data);\n if (place && typeof place.hide_from_maps === 'string') {\n (place as any).hide_from_maps = place.hide_from_maps === 'true';\n }\n } catch (error) {\n console.error('Error parsing placeById', id);\n }\n return place;\n }\n\n public async placeFull(url: string, options?: AOFetchOptions): Promise<AOPlaceExtend> {\n const data = await fetchPage(url, options?.headers);\n const html = parse(data);\n\n const descriptions = html.querySelectorAll('.place-body p').map((p) => p.innerHTML);\n\n const sectionDirections = Array.from(html.querySelectorAll('section')).find((sec) => {\n const h2 = sec.querySelector('h2');\n return h2 && h2.textContent.trim() === 'Know Before You Go';\n });\n const directions = sectionDirections\n ? Array.from(sectionDirections.querySelectorAll('p')).map((p) => p.textContent.trim())\n : [];\n\n const tags = html.querySelectorAll('.aon-pill-badge-component').map((x) => {\n return {\n title: x.querySelector('.aon-pill-badge-text')?.innerHTML.trim(),\n link: x.attributes.href\n };\n });\n\n const slides = html.querySelectorAll('.swiper-slide');\n const images = Array.from(slides)\n .map((slide) => {\n const img = slide.querySelector('img');\n return img ? img.getAttribute('src') : null;\n })\n .filter(Boolean);\n\n const imageCover = images[0];\n\n return { description: descriptions, directions, tags, imageCover, images };\n }\n\n public async user(user: string, options?: AOFetchOptions): Promise<AOUser> {\n const url = urlUser(user);\n const response = await fetchPage(url, options?.headers);\n const html = parse(response).innerHTML;\n\n const data = html.match(/AtlasObscura\\.user_profile = (.*?);/);\n\n const usr = parseResults<{ user: AOUser }>(data);\n\n return usr.user;\n }\n}\n","import { AOCoordinates, AOFetchOptions } from './interfaces/global.js';\nimport { AOLocationResult } from './interfaces/locations.interface.js';\nimport { AOPlace, AOPlaceShort } from './interfaces/placeId.interface.js';\nimport { AOPlacesAll } from './interfaces/places-all.interface.js';\nimport { AOUser } from './interfaces/user.interface.js';\nimport { PlacesScraper } from './services/location.service.js';\n\nexport class AtlasObscura {\n constructor(private locationService: PlacesScraper) { }\n\n public async search(coords: AOCoordinates, options?: AOFetchOptions): Promise<AOLocationResult> {\n return this.locationService.search(coords, 1, options);\n }\n\n public async placesAll(options?: AOFetchOptions): Promise<AOPlacesAll[]> {\n return this.locationService.placesAll(options);\n }\n\n public async placeShort(id: number, options?: AOFetchOptions): Promise<AOPlaceShort> {\n return this.locationService.placeByIdShort(id, options);\n }\n\n public async placeFull(id: number, options?: AOFetchOptions): Promise<AOPlace> {\n const place = await this.locationService.placeByIdShort(id, options);\n const placeRich = await this.locationService.placeFull(place.url, options);\n return { ...place, ...placeRich };\n }\n\n public async user(user: string, options?: AOFetchOptions): Promise<AOUser> {\n return this.locationService.user(user, options);\n }\n}\n\nconst locationScraper = new PlacesScraper();\nexport const atlasObscura: AtlasObscura = new AtlasObscura(locationScraper);\nexport type * from './interfaces/index.js';\n"],"mappings":";;;AAAA,MAAMA,cAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,kBAAkB;CACtB,cAAc,YAAY,KAAK,MAAM,KAAK,QAAQ,GAAG,YAAY,OAAO;CACxE,iBAAiB;CAClB;AAED,MAAa,YAAY,OAAO,KAAa,kBAA6C;AACxF,KAAI;EACF,MAAM,WAAW,MAAM,MAAM,KAAK;GAChC,SAAS;IAAE,GAAG;IAAiB,GAAG;IAAe;GACjD,aAAa;GACd,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,mCAAmC,SAAS,OAAO,YAAY,MAAM;AAGvF,SAAO,MAAM,SAAS,MAAM;UACrB,OAAO;AACd,UAAQ,MAAM,oBAAoB,MAAM;AACxC,SAAO;;;;;;ACjCX,MAAa,gBAAmB,YAAiC;CAC/D,IAAIC,YAAe;AAEnB,KAAI,WAAW,QAAQ,IAAI,OACzB,KAAI;AACF,cAAY,KAAK,MAAM,QAAQ,GAAG;UAC3B,OAAO;AACd,UAAQ,MAAM,2BAA2B;;AAG7C,QAAO;;;;;ACVT,MAAa,iBACX;AAEF,MAAa,aAAa,OAAqC,SAC7D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