A lightweight Bootstrap Select data helper for countries, phone codes, languages, time zones, US states, and UK counties.
This package ships with a compiled runtime bundle that embeds the data directly, so a single script can be dropped into a page without relying on a separate JSON fetch step.
- Country option data with optional flag rendering
- Country phone code options
- Language option data
- Timezone options
- US state data
- UK county data
- Optional region grouping for supported datasets
- Include/exclude filtering helpers
- Bootstrap Select friendly option objects
npm install @trilbdev/boostrap-select-country-dataThe repository now follows a cleaner structure:
src/contains the source code and data filesbuild/contains the build scriptsdist/contains the generated browser bundles and CSS assets
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.18/dist/css/bootstrap-select.min.css">
<link rel="stylesheet" href="./dist/css/bs-country-data.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.18/dist/js/bootstrap-select.min.js"></script>
<script src="./dist/js/bs-country-data.min.js"></script>
<select class="selectpicker" data-live-search="true" data-bscd-type="country" data-bscd-group="true" data-bscd-flags="true">
<option value="">Select a country</option>
</select>The script will populate matching selects automatically when they contain a data-bscd-type attribute. If you include a data-bscd-selected value, matching option values are marked as selected after the list is populated.
<select class="selectpicker" data-bscd-type="country" data-bscd-selected="GB"></select><select class="selectpicker" multiple data-bscd-type="country" data-bscd-selected="US,GB,CA"></select>const bsData = require('@trilbdev/boostrap-select-country-data');
const countries = bsData.countries({
groupByRegion: true,
includeFlags: true,
});
console.log(countries[0]);The data-bscd-type attribute accepts:
countrycountry-phonelanguagetimezonesuk-countiesus-states
- Accepts:
trueorfalse - Default:
false - Supported with:
country,country-phone,language
- Accepts:
trueorfalse - Default:
false - Supported with:
country,country-phone,timezones,uk-counties
- Accepts: a single value or a comma/space-delimited list of option values
- Example:
data-bscd-selected="US,GB" - Applied after the dataset is generated so the option values match the loaded data
const bsData = require('@trilbdev/boostrap-select-country-data');
const countries = bsData.countries({
groupByRegion: true,
includeFlags: true,
});
const languages = bsData.countryLanguages({
groupByRegion: true,
includeFlags: true,
});
const timezones = bsData.timezones({
groupByContinent: true,
});
const states = bsData.usStates({ groupByRegion: true });
const counties = bsData.ukCounties({ groupByRegion: true });const europeOnly = bsData.countries({
include: {
region: ['Europe'],
},
groupByRegion: true,
});
const englishAndFrench = bsData.countryLanguages({
include: {
language: ['English', 'French'],
},
groupByRegion: true,
});
const ukCountiesWithoutLondon = bsData.ukCounties({
groupByRegion: true,
exclude: {
counties: ['Greater London'],
},
});You can also combine filters by field:
const usAndCanada = bsData.countries({
include: {
countries: ['United States', 'Canada'],
},
});
const nonEuropeanCountries = bsData.countries({
exclude: {
region: ['Europe'],
},
});countries/countryregions/regionlanguages/languagetimezones/timezonecounties/countystates/statealpha2phoneCodes/phoneCode
If you are compiling styles in your own project, you can import the package SCSS directly instead of loading the generated CSS bundle:
@use "@trilbdev/boostrap-select-country-data/src/scss/bs-country-data";If your bundler resolves node_modules paths differently, you can also do this:
@use "node_modules/@trilbdev/boostrap-select-country-data/src/scss/bs-country-data";You can override the default Sass variables when needed:
@use "@trilbdev/boostrap-select-country-data/src/scss/bs-country-data" with (
// Override path to flags directory
$flag-icons-path: "./src/dist/images/flags",
// Include only specific country flags
$flag-icons-included-countries: ("gr", "de", "gb")
);Full variable list:
$flag-icons-path: "../images/flags" !default;
$flag-icons-rect-path: "/4x3" !default;
$flag-icons-square-path: "/1x1" !default;
$flag-icons-use-square: false !default;
$flag-icons-included-countries: ("gr", "de", "gb") !default;The package builds a self-contained browser bundle and CSS output into the dist/ directory:
dist/js/bs-country-data.jsdist/js/bs-country-data.min.jsdist/css/bs-country-data.cssdist/css/bs-country-data.min.cssdist/images/flags/
The generated JS bundle embeds the country data payload so it does not require a separate JSON fetch at runtime.
This project uses flag assets from lipis/flag-icons, which provides the SVG flag set and CSS helpers used by this package.
- This package is designed to work with Bootstrap 5 and the Bootstrap Select plugin.
- Flag rendering uses the
flag-iconspackage and thefiCSS classes. - If you need the grouped data flattened for custom rendering, use
flattenGroupedOptions().