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

icu2ts

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icu2ts

Generate type definitions for ICU messages. This is meant as a building block for typesafe i18n libraries.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

icu2ts

Generate type definitions for ICU messages. This is meant as a building block for typesafe i18n libraries.

Example

import { generateType } from "icu2ts";

const message =
    "Hello {name}! You have {count, plural, one {1 message} other {# messages}}.";

const typeDefinition = generateType(message);

// typeDefinition = { name: string, count: number };

The types may not be as compact as they could be, but they are correct.

Caveats

When a select, plural, or selectordinal with an "other" branch is encountered it is not possible to use a type-union, since the fallback type would match all branches, not just the fallback. Instead, the type is a union of all branch-types. This is rarely a problem, but you should be aware of it.

Eg:

const msg = "{count, plural, one {1 {arg1}} other {# {arg2}}}";
//becomes
{ count: number } & ({ arg1: string } | { arg2: string }); //No type-narrowing

Until TypeScript supports a union of the form "a" | string, this is the best we can do.

FAQs

Package last updated on 25 Sep 2023

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