Socket
Socket
Sign inDemoInstall

@volvo-cars/market-sites

Package Overview
Dependencies
0
Maintainers
9
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @volvo-cars/market-sites

![@volvo-cars/market-sites](https://badgen.net/npm/v/@volvo-cars/market-sites) ![@volvo-cars/market-sites](https://badgen.net/bundlephobia/minzip/@volvo-cars/market-sites)


Version published
Weekly downloads
65
increased by8.33%
Maintainers
9
Install size
117 kB
Created
Weekly downloads
 

Readme

Source

@volvo-cars/market-sites

@volvo-cars/market-sites @volvo-cars/market-sites

A package providing regional and market localization data for market sites on volvocars.com, stored in a size efficient format.

It is meant to complement the Intl API and should only contain data that changes very rarely such as country names, measurement systems, etc. Some of this data is on it's way to be built in to browsers with Intl.Locale and unit preferences.

It will not provide configuration values or application specific data.

Usage

getMarketSite(siteSlug: string): MarketSite

siteSlug

  • A site slug, a URL friendly identifier of the market site (the first part of the pathname on www.volvocars.com).
  • The full pathname, e.g. location.pathname

If a site could not be found, a MarketSite with English defaults are given.

Examples

import { getMarketSite } from '@volvo-cars/market-sites';

const us = getMarketSite('us');
// {
//   "href": "/us",
//   "htmlLanguage": "en-US",
//   "languageCode": "en",
//   "languageDirection": "ltr",
//   "languageName": "English",
//   "locale": "en-US",
//   "localizedLanguageName": "English",
//   "marketName": "United States",
//   "multilingual": false,
//   "regionCode": "US",
//   "roadLengthUnit": "mile",
//   "siteSlug": "us",
// }

const intl = getMarketSite('/intl/cars/xc90');
// {
//   "href": "/intl",
//   "htmlLanguage": "en",
//   "languageCode": "en",
//   "languageDirection": "ltr",
//   "languageName": "English",
//   "locale": "en-001",
//   "localizedLanguageName": "English",
//   "marketName": "International",
//   "multilingual": false,
//   "regionCode": "001",
//   "roadLengthUnit": "kilometer",
//   "siteSlug": "intl",
// }

const arabicBaharain = getMarketSite('ar-bh');
// {
//   "href": "/ar-bh",
//   "htmlLanguage": "ar-BH",
//   "languageCode": "ar",
//   "languageDirection": "rtl",
//   "languageName": "Arabic",
//   "locale": "ar-BH",
//   "localizedLanguageName": "العربية",
//   "marketName": "Bahrain",
//   "multilingual": true,
//   "regionCode": "BH",
//   "roadLengthUnit": "kilometer",
//   "siteSlug": "ar-bh",
// }

const englishBahrain = getMarketSite('en-bh');
// {
//   "href": "/en-bh",
//   "htmlLanguage": "en-BH",
//   "languageCode": "en",
//   "languageDirection": "ltr",
//   "languageName": "English",
//   "locale": "en-BH",
//   "localizedLanguageName": "English",
//   "marketName": "Bahrain",
//   "multilingual": true,
//   "regionCode": "BH",
//   "roadLengthUnit": "kilometer",
//   "siteSlug": "en-bh",
// }

const missingSite = getMarketSite('foo');
// {
//   "href": "/",
//   "htmlLanguage": "en",
//   "languageCode": "en",
//   "languageDirection": "ltr",
//   "languageName": "English",
//   "locale": "en",
//   "localizedLanguageName": "English",
//   "marketName": undefined,
//   "multilingual": undefined,
//   "regionCode": undefined,
//   "roadLengthUnit": "kilometer",
//   "siteSlug": undefined,
// }

getMarketSiteByRegionAndLanguage(regionCode: string, languageCode: string): MarketSite

Given the region and language, returns a Market Site.

regionCode

languageCode

Examples

import { getMarketSiteByRegionAndLanguage } from '@volvo-cars/market-sites';

getMarketSiteByRegionAndLanguage('CH', 'it');
//  {
//   "href": "/it-ch",
//   "htmlLanguage": "it-CH",
//   "languageCode": "it",
//   "languageDirection": "ltr",
//   "languageName": "Italian",
//   "locale": "it-CH",
//   "localizedLanguageName": "italiano",
//   "marketName": "Switzerland",
//   "multilingual": true,
//   "regionCode": "CH",
//   "roadLengthUnit": "kilometer",
//   "siteSlug": "it-ch",
// }

getMarketSitesByRegion(regionCode: string): MarketSite[]

Returns an array of all available sites for a given market/region.

regionCode

Examples

const swissSites = getMarketSitesByRegion('CH');
// [
//   {
//     "href": "/fr-ch",
//     "htmlLanguage": "fr-CH",
//     "languageCode": "fr",
//     "languageDirection": "ltr",
//     "languageName": "French",
//     "locale": "fr-CH",
//     "localizedLanguageName": "français",
//     "marketName": "Switzerland",
//     "multilingual": true,
//     "regionCode": "CH",
//     "roadLengthUnit": "kilometer",
//     "siteSlug": "fr-ch",
//   },
//   {
//     "href": "/de-ch",
//     "htmlLanguage": "de-CH",
//     "languageCode": "de",
//     "languageDirection": "ltr",
//     "languageName": "German",
//     "locale": "de-CH",
//     "localizedLanguageName": "Deutsch",
//     "marketName": "Switzerland",
//     "multilingual": true,
//     "regionCode": "CH",
//     "roadLengthUnit": "kilometer",
//     "siteSlug": "de-ch",
//   },
//   {
//     "href": "/it-ch",
//     "htmlLanguage": "it-CH",
//     "languageCode": "it",
//     "languageDirection": "ltr",
//     "languageName": "Italian",
//     "locale": "it-CH",
//     "localizedLanguageName": "italiano",
//     "marketName": "Switzerland",
//     "multilingual": true,
//     "regionCode": "CH",
//     "roadLengthUnit": "kilometer",
//     "siteSlug": "it-ch",
//   },
// ]

getAllMarketSites(): MarketSite[]

Returns an array of all available market sites.

validateSiteSlug(siteSlug?: string): void

Throws an error if siteSlug is not a valid market site slug.

isValidSiteSlug(siteSlug?: string): boolean

Returns true/false if siteSlug is a valid site slug.

MarketSite

class MarketSite {
  /**
   * URL to the home page of the market site.
   */
  href: string;

  /**
   * A locale that's only includes the region suffix if required to distinguish
   * between different market sites. Suitable for `<html lang="">`.
   */
  htmlLanguage: string;

  /**
   * Name of the market site language in English.
   */
  languageName: string;

  /**
   * Name of the market site language in the native language.
   */
  localizedLanguageName: string;

  /**
   * Writing direction of the market site language.
   */
  languageDirection: 'ltr' | 'rtl';

  /**
   * The ISO 639-1 or ISO-639-2 language code part of the locale without script or region.
   *
   * Useful for some APIs that don't accept locales with regions.
   */
  languageCode: string;

  /**
   * A Unicode BCP 47 locale identifier consisting of
   *
   *  - An ISO 639-1 language code (e.g. 'en')
   *  - (optionally) a script code (e.g. 'Latn')
   *  - A region (or country) code (e.g. 'US')
   *
   * This is what you should use with browser APIs such as `Intl`.
   */
  locale: string;

  /**
   * Unique URL friendly identifier of the market site.
   * The first part of the pathname on www.volvocars.com.
   */
  siteSlug: string | undefined;

  /**
   * Region or country name in English.
   *
   * Usually a country, with exceptions such as Hong Kong (China) and Special Sales markets.
   */
  marketName: string | undefined;

  /**
   * Region or country code, e.g. US, SE.
   */
  regionCode: string | undefined;

  /**
   * Whether or not the market/region has more sites in different languages.
   */
  multilingual: boolean | undefined;

  /**
   * Road length unit for region.
   */
  roadLengthUnit: 'mile' | 'kilometer';
}

FAQs

Last updated on 09 May 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc