Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

international-types

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

international-types

Type-safe internationalization (i18n) utility types

  • 0.3.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
decreased by-5.91%
Maintainers
1
Weekly downloads
 
Created
Source


Type-safe internationalization (i18n) utility types


  • Features
  • Usage
  • License

Features

  • Autocompletion: For locale keys, scopes and params!
  • Extensible: Designed to be used with any library

Note: Using Next.js? Check out next-international!

Usage

pnpm install international-types

Type-safe keys

import type { LocaleKeys } from 'international-types'

type Locale = {
  hello: 'Hello'
  'hello.world': 'Hello World!'
}

function t<Key extends LocaleKeys<Locale, undefined>>(key: Key) {
  // ...
}

t('')
// hello | hello.world

Type-safe scopes with keys

import type { LocaleKeys, Scopes } from 'international-types'

type Locale = {
  hello: 'Hello'
  'scope.nested.demo': 'Nested scope'
  'scope.nested.another.demo': 'Another nested scope'
}

function scopedT<Scope extends Scopes<Locale>>(scope: Scope) {
  function t<Key extends LocaleKeys<Locale, Scope>>(key: Key) {
    // ...
  }
}

const t = scopedT('')
// scope | scope.nested

t('')
// For scope: nested.demo | nested.another.demo
// For scope.nested: demo | another.demo

Type-safe params

import type { LocaleKeys, LocaleValue } from 'international-types'

type Locale = {
  param: 'This is a {value}'
  'hello.people': 'Hello {name}! You are {age} years old.'
}

function t<
  Key extends LocaleKeys<Locale, undefined>,
  Value extends LocaleValue = ScopedValue<Locale, undefined, Key>,
>(key: Key, param: ParamsObject<Value>) {
  // ...
}

t('param', {
  value: ''
  // value is required
})

t('hello.people', {
  name: '',
  age: ''
  // name and age are required
})

License

MIT

Keywords

FAQs

Package last updated on 01 Sep 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc