npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lcs_country

v1.0.0

Published

A library providing country data, including region codes, capital cities, time zones, and currencies.

Downloads

56

Readme

LCS Country

LCS Country is a lightweight, customizable JavaScript library for accessing and displaying detailed information about countries worldwide. With features for filtering countries, generating HTML lists, and handling country data, LCS Country is perfect for applications needing structured country-specific data like regions, currencies, time zones, and more.

Table of Contents

Installation

Install via npm:

npm install lcs_country

Or include the minified script directly in your HTML:

<script src="https://cdn.jsdelivr.net/npm/lcs_country/dist/lc.min.js"></script>

Usage

Initialization

To use LCS Country, import or reference it in your project and configure it with options tailored to your needs.

const countryData = lcsCountry({
    exception: ["united_states", "canada"],
    only: ["nigeria", "ghana", "kenya"],
    purpose: "input",
    getData: true,
    outputElement: document.getElementById("countryListContainer"),
    onSelectCallback: "onCountrySelect"
});

Options

exception

  • Type: Array<string>
  • Default: []
  • Description: List of country codes to exclude from the generated list.

only

  • Type: Array<string>
  • Default: []
  • Description: List of country codes to exclusively include in the generated list.

purpose

  • Type: string
  • Default: "extraction"
  • Description: Set the purpose to either "input" (for HTML output) or "extraction" (for data retrieval).
    • Note: If "input" is chosen, both data and HTML output can be generated if getData is set to true. For "extraction", only data is returned.

getData

  • Type: boolean
  • Default: true
  • Description: Determines if the country data is returned. This option is flexible for both "input" and "extraction" purposes:
    • For "extraction": must be set to true.
    • For "input": setting getData to true will return both data and HTML output.

outputElement

  • Type: HTMLElement|null
  • Default: null
  • Description: The HTML element to output to, required for "input" purpose.

onSelectCallback

  • Type: string|null
  • Default: null
  • Description: Name of a function to call when a user selects a country (only works for "input" purpose).

Data Retrieval

To retrieve data only, set purpose to "extraction" and ensure getData is true (default).

const countryData = lcsCountry({
    purpose: "extraction",
});
console.log(countryData);

HTML Generation

To generate an HTML list of countries, set purpose to "input" and provide an outputElement. You can also set getData to true to retrieve country data along with HTML output.

lcsCountry({
    purpose: "input",
    getData: true,
    outputElement: document.getElementById("countryListContainer"),
    onSelectCallback: "onCountrySelect"
});

Examples

  1. Exclude Specific Countries

    lcsCountry({
        exception: ["united_states", "canada"],
        purpose: "input",
        outputElement: document.getElementById("countryListContainer")
    });
  2. Generate a Selectable List with Callback

    lcsCountry({
        only: ["nigeria", "ghana", "kenya"],
        purpose: "input",
        outputElement: document.getElementById("countryListContainer"),
        onSelectCallback: "handleCountrySelection"
    });
  3. Data Extraction for Specific Countries

    const countryData = lcsCountry({
        only: ["france", "germany"],
        purpose: "extraction",
        getData: true
    });
    console.log(countryData);

Callback Handling

For onSelectCallback, provide the name of a function available in the global scope. This function will execute whenever a country in the generated list is selected.

function handleCountrySelection() {
    console.log("Country selected!");
}

Example with Callback:

lcsCountry({
    purpose: "input",
    outputElement: document.getElementById("countryListContainer"),
    onSelectCallback: "handleCountrySelection"
});

Browser Support

LCS Country is compatible with all modern browsers and does not require additional dependencies.

Contributing

Feel free to open issues and submit pull requests for any new features or fixes. Please ensure that your code adheres to the existing style and includes necessary tests.

License

This library is licensed under the MIT License. See the LICENSE file for details.