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.6.2 to 0.7.0

16

dist/index.d.ts

@@ -5,6 +5,7 @@ export type LocaleValue = string | number | boolean | null | undefined | Date;

export type ExplicitLocales = Record<string, BaseLocale>;
export type LocaleKeys<Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined, Key extends string = Extract<keyof Locale, string>> = Scope extends undefined ? Key : Key extends `${Scope}.${infer Test}` ? Test : never;
export type LocaleKeys<Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined, Key extends string = Extract<keyof Locale, string>> = Scope extends undefined ? RemovePlural<Key> : Key extends `${Scope}.${infer Test}` ? RemovePlural<Test> : never;
type Delimiter = `=${number}` | 'other';
type ExtractParams<Value extends LocaleValue> = Value extends '' ? [] : Value extends `${string}{${infer Param}}${infer Tail}` ? [Param, ...ExtractParams<Tail>] : [];
export type Params<Value extends LocaleValue> = Value extends '' ? [] : Value extends `{${infer Param}, plural, ${Delimiter} {${infer Content}} ${Delimiter} {${infer Content2}} ${Delimiter} {${infer Content3}}}` ? [Param, ...ExtractParams<Content>, ...ExtractParams<Content2>, ...ExtractParams<Content3>] : Value extends `{${infer Param}, plural, ${Delimiter} {${infer Content}} ${Delimiter} {${infer Content2}}}` ? [Param, ...ExtractParams<Content>, ...ExtractParams<Content2>] : Value extends `${string}{${infer Param}}${infer Tail}` ? [Param, ...Params<Tail>] : [];
export type GetParams<Value extends LocaleValue> = Value extends '' ? [] : Value extends `${string}{${infer Param}}${infer Tail}` ? [Param, ...Params<Tail>] : [];
export type ParamsObject<Value extends LocaleValue> = Record<Params<Value>[number], LocaleValue>;

@@ -16,3 +17,3 @@ type ExtractScopes<Value extends string, Prev extends string | undefined = undefined> = Value extends `${infer Head}.${infer Tail}` ? [

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 ? Locale[Key] : Locale[`${Scope}.${Key}`];
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}`];
type UnionToIntersection<U> = (U extends never ? never : (arg: U) => never) extends (arg: infer I) => void ? I : never;

@@ -31,2 +32,13 @@ type UnionToTuple<T> = UnionToIntersection<T extends never ? never : (t: T) => T> extends (_: never) => infer W ? [...UnionToTuple<Exclude<T, W>>, W] : [];

};
type PluralSuffix = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
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];
export {};

2

package.json
{
"name": "international-types",
"version": "0.6.2",
"version": "0.7.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