@nova/types
Advanced tools
| declare const LocalizedString: unique symbol; | ||
| /** | ||
| * Represents a localized string with placeholders. | ||
| * This type will be used by the `relay-compiler` when generating types for | ||
| * a string with placeholders. | ||
| * | ||
| * You should **not** have to use this type directly, instead use the `format` function | ||
| * from the `useFormat` hook to unwrap the localized string and provide the placeholders. | ||
| * | ||
| * @param T The type of the placeholders object. | ||
| * @example | ||
| * ```ts | ||
| * // Note: This would be part of a generated type, you should not have to write this yourself. | ||
| * type MyLocalizedStrings = StringWithPlaceholders<{ | ||
| * name: string; | ||
| * age: number; | ||
| * }>; | ||
| * ``` | ||
| */ | ||
| export type StringWithPlaceholders<T extends Record<string, string | number>> = { | ||
| [LocalizedString]: T; | ||
| }; | ||
| /** | ||
| * Extract the placeholders from a localized string. | ||
| * Guarantees that the placeholder object is not empty. | ||
| */ | ||
| export type Placeholders<T> = T extends StringWithPlaceholders<infer P> ? keyof P extends never ? never : P : never; | ||
| type UseFormat = () => (localizedStringFromGraphQL: unknown, placeholders: Record<string, string | number>) => string; | ||
| /** | ||
| * The NovaLocalization type is used to provide the `useFormat` hook to the components. | ||
| * The `useFormat` hook should support replacing placeholders in a localized string. | ||
| * | ||
| * You provide this type to the `NovaLocalizationProvider` component to make | ||
| * it available to the components in your application. | ||
| * | ||
| * The components will be able to use `useFormat` from `@nova/react` to | ||
| * access the `format` function. | ||
| */ | ||
| export type NovaLocalization = { | ||
| useFormat: UseFormat; | ||
| }; | ||
| export {}; | ||
| //# sourceMappingURL=nova-localization.d.ts.map |
| {"version":3,"file":"nova-localization.d.ts","sourceRoot":"","sources":["../src/nova-localization.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe,eAA4B,CAAC;AAElD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,IAC1E;IACE,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;CACtB,CAAC;AAEJ;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,sBAAsB,CAAC,MAAM,CAAC,CAAC,GACnE,MAAM,CAAC,SAAS,KAAK,GACnB,KAAK,GACL,CAAC,GACH,KAAK,CAAC;AAEV,KAAK,SAAS,GAAG,MAAM,CACrB,0BAA0B,EAAE,OAAO,EACnC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KAC1C,MAAM,CAAC;AAEZ;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC"} |
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var nova_localization_exports = {}; | ||
| module.exports = __toCommonJS(nova_localization_exports); | ||
| const LocalizedString = Symbol("LocalizedString"); |
| // src/nova-localization.ts | ||
| var LocalizedString = Symbol("LocalizedString"); |
| const LocalizedString = Symbol("LocalizedString"); | ||
| /** | ||
| * Represents a localized string with placeholders. | ||
| * This type will be used by the `relay-compiler` when generating types for | ||
| * a string with placeholders. | ||
| * | ||
| * You should **not** have to use this type directly, instead use the `format` function | ||
| * from the `useFormat` hook to unwrap the localized string and provide the placeholders. | ||
| * | ||
| * @param T The type of the placeholders object. | ||
| * @example | ||
| * ```ts | ||
| * // Note: This would be part of a generated type, you should not have to write this yourself. | ||
| * type MyLocalizedStrings = StringWithPlaceholders<{ | ||
| * name: string; | ||
| * age: number; | ||
| * }>; | ||
| * ``` | ||
| */ | ||
| export type StringWithPlaceholders<T extends Record<string, string | number>> = | ||
| { | ||
| [LocalizedString]: T; | ||
| }; | ||
| /** | ||
| * Extract the placeholders from a localized string. | ||
| * Guarantees that the placeholder object is not empty. | ||
| */ | ||
| export type Placeholders<T> = T extends StringWithPlaceholders<infer P> | ||
| ? keyof P extends never // Make sure that the placeholder object is not empty | ||
| ? never | ||
| : P | ||
| : never; | ||
| type UseFormat = () => ( | ||
| localizedStringFromGraphQL: unknown, | ||
| placeholders: Record<string, string | number>, | ||
| ) => string; | ||
| /** | ||
| * The NovaLocalization type is used to provide the `useFormat` hook to the components. | ||
| * The `useFormat` hook should support replacing placeholders in a localized string. | ||
| * | ||
| * You provide this type to the `NovaLocalizationProvider` component to make | ||
| * it available to the components in your application. | ||
| * | ||
| * The components will be able to use `useFormat` from `@nova/react` to | ||
| * access the `format` function. | ||
| */ | ||
| export type NovaLocalization = { | ||
| useFormat: UseFormat; | ||
| }; |
+16
-1
@@ -5,3 +5,18 @@ { | ||
| { | ||
| "date": "Tue, 17 Sep 2024 19:04:35 GMT", | ||
| "date": "Tue, 11 Feb 2025 14:14:01 GMT", | ||
| "tag": "@nova/types_v1.6.0", | ||
| "version": "1.6.0", | ||
| "comments": { | ||
| "minor": [ | ||
| { | ||
| "author": "mark@thedutchies.com", | ||
| "package": "@nova/types", | ||
| "commit": "a9573acafea8547d6140e920f899f2c2f51ce7ef", | ||
| "comment": "Add localization support" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "date": "Tue, 17 Sep 2024 19:04:51 GMT", | ||
| "tag": "@nova/types_v1.5.1", | ||
@@ -8,0 +23,0 @@ "version": "1.5.1", |
+10
-2
| # Change Log - @nova/types | ||
| This log was last generated on Tue, 17 Sep 2024 19:04:35 GMT and should not be manually modified. | ||
| This log was last generated on Tue, 11 Feb 2025 14:14:01 GMT and should not be manually modified. | ||
| <!-- Start content --> | ||
| ## 1.6.0 | ||
| Tue, 11 Feb 2025 14:14:01 GMT | ||
| ### Minor changes | ||
| - Add localization support (mark@thedutchies.com) | ||
| ## 1.5.1 | ||
| Tue, 17 Sep 2024 19:04:35 GMT | ||
| Tue, 17 Sep 2024 19:04:51 GMT | ||
@@ -11,0 +19,0 @@ ### Patches |
+1
-0
@@ -5,2 +5,3 @@ export * from "./nova-commanding.interface"; | ||
| export * from "./nova-eventing.interface"; | ||
| export type { NovaLocalization, StringWithPlaceholders, Placeholders, } from "./nova-localization"; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AACxD,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AACxD,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,YAAY,EACV,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,GACb,MAAM,qBAAqB,CAAC"} |
+1
-1
| { | ||
| "name": "@nova/types", | ||
| "license": "MIT", | ||
| "version": "1.5.1", | ||
| "version": "1.6.0", | ||
| "main": "./lib/index", | ||
@@ -6,0 +6,0 @@ "scripts": { |
+5
-0
@@ -5,1 +5,6 @@ export * from "./nova-commanding.interface"; | ||
| export * from "./nova-eventing.interface"; | ||
| export type { | ||
| NovaLocalization, | ||
| StringWithPlaceholders, | ||
| Placeholders, | ||
| } from "./nova-localization"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
131874
3%38
15.15%1509
9.43%