Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
This is meant as a building block for typesafe i18n libraries.
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.
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.
Use the compile function to generate a function that can be used to format the message. These functions can be used to eliminate the need for a runtime i18n library.
import { compile } from "icu2ts";
const message = "Hello {name}! You have {count, plural, one {1 message} other {# messages}}.";
const compiled = compile(message, "en");
// compiled : ({name,count}) => `Hello ${name}! You have ${new Intl.PluralRules("en", {type: "cardinal"}).select(count) === "one" ? `1 message` : `${new Intl.NumberFormat("en").format(count)} messages` }.`
This code minifies very well, and does not require any runtime dependencies.
FAQs
Compile ICU MessageFormat strings into JS functions and Type Definitions
The npm package icu2ts receives a total of 0 weekly downloads. As such, icu2ts popularity was classified as not popular.
We found that icu2ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.