Spaces:
Sleeping
Sleeping
Download src/utils/locationLabelHelper.js from Huzaifa1435/Carpool_final: direct link, hf CLI and curl.
- Browser
- Download file 948 Bytes
-
https://huggingface.co/spaces/Huzaifa1435/Carpool_final/resolve/main/src/utils/locationLabelHelper.js
- Command line
-
hf download hf://spaces/Huzaifa1435/Carpool_final/src/utils/locationLabelHelper.js
-
curl -L -o locationLabelHelper.js https://huggingface.co/spaces/Huzaifa1435/Carpool_final/resolve/main/src/utils/locationLabelHelper.js
948 Bytes
| function clean(value) { | |
| const text = (value ?? '').toString().trim(); | |
| return text === '[object Object]' ? '' : text; | |
| } | |
| function labelFromLocation(value) { | |
| if (value == null) return ''; | |
| if (typeof value === 'string' || typeof value === 'number') { | |
| return clean(value); | |
| } | |
| if (typeof value !== 'object') return clean(value); | |
| const directKeys = [ | |
| 'formattedAddress', | |
| 'formatted_address', | |
| 'description', | |
| 'name', | |
| 'address', | |
| 'label', | |
| 'placeName', | |
| 'text', | |
| ]; | |
| for (const key of directKeys) { | |
| const label = clean(value[key]); | |
| if (label) return label; | |
| } | |
| const parts = [ | |
| value.street, | |
| value.subLocality, | |
| value.sublocality, | |
| value.locality, | |
| value.city, | |
| value.administrativeArea, | |
| value.state, | |
| value.country, | |
| ] | |
| .map(clean) | |
| .filter(Boolean); | |
| return parts.length ? [...new Set(parts)].join(', ') : ''; | |
| } | |
| module.exports = { clean, labelFromLocation }; | |