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

international-types

v0.8.1

Published

Type-safe internationalization (i18n) utility types

Downloads

82,801

Readme


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) {
  return 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, BaseLocale, Scopes, ScopedValue, CreateParams, ParamsObject } from 'international-types'

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

function scopedT<Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined>(scope?: Scope) {
  return function t<Key extends LocaleKeys<Locale, Scope>, Value extends ScopedValue<Locale, Scope, Key>>(
    key: Key,
    ...params: CreateParams<ParamsObject<Value>, Locale, Scope, Key, Value>
  ) {
    // ...
  }
}

const t = scopedT<Locale, undefined>();

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

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

License

MIT