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 - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

48

dist/index.d.ts

@@ -16,3 +16,3 @@ export type LocaleValue = string | number | boolean | null | undefined | Date;

export type Scopes<Locale extends BaseLocale> = ExtractScopes<Extract<keyof Locale, string>>[number];
export type ScopedValue<Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined, Key extends LocaleKeys<Locale, Scope>> = Scope extends undefined ? IsPlural<Key, Locale> extends true ? Locale[`${Key}#${PluralSuffix}`] : Locale[Key] : IsPlural<Key, Locale> extends true ? Locale[`${Scope}.${Key}#${PluralSuffix}`] : Locale[`${Scope}.${Key}`];
export type ScopedValue<Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined, Key extends LocaleKeys<Locale, Scope>> = Scope extends undefined ? IsPlural<Key, Scope, Locale> extends true ? Locale[`${Key}#${PluralSuffix}`] : Locale[Key] : IsPlural<Key, Scope, Locale> extends true ? Locale[`${Scope}.${Key}#${PluralSuffix}`] : Locale[`${Scope}.${Key}`];
type UnionToIntersection<U> = (U extends never ? never : (arg: U) => never) extends (arg: infer I) => void ? I : never;

@@ -33,11 +33,39 @@ type UnionToTuple<T> = UnionToIntersection<T extends never ? never : (t: T) => T> extends (_: never) => infer W ? [...UnionToTuple<Exclude<T, W>>, W] : [];

type RemovePlural<Key extends string> = Key extends `${infer Head}#${PluralSuffix}` ? Head : Key;
type GetPlural<Key extends string, Locale extends BaseLocale> = `${Key}#${PluralSuffix}` & keyof Locale extends infer PluralKey ? PluralKey extends `${string}#${infer Plural extends PluralSuffix}` ? Plural : never : never;
type IsPlural<Key extends string, Locale extends BaseLocale> = `${Key}#${PluralSuffix}` & keyof Locale extends never ? false : true;
type GetCountUnion<Key extends string, Locale extends BaseLocale, Plural extends PluralSuffix = GetPlural<Key, Locale>> = Plural extends 'zero' ? 0 : Plural extends 'one' ? 1 : Plural extends 'two' ? 2 : number;
type AddCount<T, Key extends string, Locale extends BaseLocale> = T extends [] ? [{
count: GetCountUnion<Key, Locale>;
}] : T extends [infer R] ? [{
count: GetCountUnion<Key, Locale>;
} & R] : never;
export type CreateParams<T, Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined, Key extends LocaleKeys<Locale, Scope>, Value extends LocaleValue = ScopedValue<Locale, Scope, Key>> = IsPlural<Key, Locale> extends true ? AddCount<GetParams<Value>['length'] extends 0 ? [] : [T], Key, Locale> : GetParams<Value>['length'] extends 0 ? [] : [T];
type GetPlural<Key extends string, Scope extends Scopes<Locale> | undefined, Locale extends BaseLocale> = Scope extends undefined ? `${Key}#${PluralSuffix}` & keyof Locale extends infer PluralKey ? PluralKey extends `${string}#${infer Plural extends PluralSuffix}` ? Plural : never : never : `${Scope}.${Key}#${PluralSuffix}` & keyof Locale extends infer PluralKey ? PluralKey extends `${string}#${infer Plural extends PluralSuffix}` ? Plural : never : never;
type IsPlural<Key extends string, Scope extends Scopes<Locale> | undefined, Locale extends BaseLocale> = Scope extends undefined ? `${Key}#${PluralSuffix}` & keyof Locale extends never ? false : true : `${Scope}.${Key}#${PluralSuffix}` & keyof Locale extends never ? false : true;
type GetCountUnion<Key extends string, Scope extends Scopes<Locale> | undefined, Locale extends BaseLocale, Plural extends PluralSuffix = GetPlural<Key, Scope, Locale>> = Plural extends 'zero' ? 0 : Plural extends 'one' ? // eslint-disable-next-line @typescript-eslint/ban-types
1 | 21 | 31 | 41 | 51 | 61 | 71 | 81 | 91 | 101 | (number & {}) : Plural extends 'two' ? // eslint-disable-next-line @typescript-eslint/ban-types
2 | 22 | 32 | 42 | 52 | 62 | 72 | 82 | 92 | 102 | (number & {}) : number;
type AddCount<T, Key extends string, Scope extends Scopes<Locale> | undefined, Locale extends BaseLocale> = T extends [] ? [
{
/**
* The `count` depends on the plural tags defined in your locale,
* and the current locale rules.
*
* - `zero` allows 0
* - `one` autocompletes 1, 21, 31, 41... but allows any number
* - `two` autocompletes 2, 22, 32, 42... but allows any number
* - `few`, `many` and `other` allow any number
*
* @see https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html
*/
count: GetCountUnion<Key, Scope, Locale>;
}
] : T extends [infer R] ? [
{
/**
* The `count` depends on the plural tags defined in your locale,
* and the current locale rules.
*
* - `zero` allows 0
* - `one` autocompletes 1, 21, 31, 41... but allows any number
* - `two` autocompletes 2, 22, 32, 42... but allows any number
* - `few`, `many` and `other` allow any number
*
* @see https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html
*/
count: GetCountUnion<Key, Scope, Locale>;
} & R
] : never;
export type CreateParams<T, Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined, Key extends LocaleKeys<Locale, Scope>, Value extends LocaleValue = ScopedValue<Locale, Scope, Key>> = IsPlural<Key, Scope, Locale> extends true ? AddCount<GetParams<Value>['length'] extends 0 ? [] : [T], Key, Scope, Locale> : GetParams<Value>['length'] extends 0 ? [] : [T];
export {};
{
"name": "international-types",
"version": "0.7.0",
"version": "0.8.0",
"description": "Type-safe internationalization (i18n) utility types",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

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