Files
smarti18n/readme.md
T

5.1 KiB

@push.rocks/smarti18n

@push.rocks/smarti18n is a tiny, typed ESM package for working with country metadata in international applications. It currently ships a ready-to-use country-code dataset that maps ISO-style country codes to human-readable country names and international phone prefixes.

Use it when you need dependable country data for signup forms, billing profiles, phone-number UI, address flows, CRM imports, or any TypeScript project that needs country names and dialing prefixes without pulling in a large i18n framework.

Issue Reporting and Security

For reporting bugs, issues, or security vulnerabilities, please visit community.foss.global/. This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a code.foss.global/ account to submit Pull Requests directly.

Install

pnpm add @push.rocks/smarti18n

The package is published as native ESM and includes TypeScript declarations.

What It Exports

ICountryCode

export interface ICountryCode {
  code: string;
  name: string;
  phonePrefix: string;
}

Each record contains:

  • code: the two-letter country or territory code, such as DE, US, or GB
  • name: the display name for the country or territory
  • phonePrefix: the international dialing prefix without a leading +, such as 49 for Germany

Some territories do not have their own dialing prefix in the dataset. In those cases, phonePrefix is an empty string.

countryCodeArray

export const countryCodeArray: ICountryCode[];

countryCodeArray contains more than 200 country and territory records.

Usage

Import The Dataset

import { countryCodeArray } from '@push.rocks/smarti18n';

Find A Country By Code

import { countryCodeArray } from '@push.rocks/smarti18n';

const germany = countryCodeArray.find((country) => country.code === 'DE');

console.log(germany);
// { code: 'DE', name: 'Germany', phonePrefix: '49' }

Build Country Select Options

import { countryCodeArray } from '@push.rocks/smarti18n';

const countryOptions = countryCodeArray.map((country) => ({
  value: country.code,
  label: country.phonePrefix
    ? `${country.name} (+${country.phonePrefix})`
    : country.name,
}));

Create A Fast Lookup Map

import { countryCodeArray } from '@push.rocks/smarti18n';

const countriesByCode = new Map(
  countryCodeArray.map((country) => [country.code, country])
);

const unitedStates = countriesByCode.get('US');
console.log(unitedStates?.phonePrefix);
// '1'

Filter Countries With Phone Prefixes

import { countryCodeArray } from '@push.rocks/smarti18n';

const countriesWithDialingPrefixes = countryCodeArray.filter(
  (country) => country.phonePrefix.length > 0
);

API Surface

The package intentionally keeps the API small:

  • ICountryCode: TypeScript interface for a country record
  • countryCodeArray: Array of country records

There are no runtime helpers, localization engines, translation loaders, or date/number formatters in the current release. If you need those features, combine this dataset with the platform Intl APIs or your existing i18n framework.

Runtime Compatibility

@push.rocks/smarti18n is built as an ESM package and works in modern Node.js and browser-oriented TypeScript builds. The dataset is static, has no runtime dependencies, and can be imported directly in frontend or backend code.

This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the LICENSE file.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.

Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.

Company Information

Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany

For any legal inquiries or further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.