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

@vocab/types

Package Overview
Dependencies
Maintainers
4
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vocab/types - npm Package Compare versions

Comparing version 0.0.9 to 1.0.0

16

CHANGELOG.md
# @vocab/types
## 1.0.0
### Major Changes
- [`3031054`](https://github.com/seek-oss/vocab/commit/303105440851db6126f0606e1607745b27dd981c) [#51](https://github.com/seek-oss/vocab/pull/51) Thanks [@jahredhope](https://github.com/jahredhope)! - Release v1.0.0
Release Vocab as v1.0.0 to signify a stable API and support future [semver versioning](https://semver.org/) releases.
Vocab has seen a lot of iteration and changes since it was first published on 20 November 2020. We are now confident with the API and believe Vocab is ready for common use.
### Patch Changes
- [`0074382`](https://github.com/seek-oss/vocab/commit/007438273ef70f5d5ded45777933651ad8df36f6) [#52](https://github.com/seek-oss/vocab/pull/52) Thanks [@jahredhope](https://github.com/jahredhope)! - Remove React dependency on core types.
Direct use of tags in Translations now have stricter type definitions.
## 0.0.9

@@ -4,0 +20,0 @@

31

dist/declarations/src/index.d.ts

@@ -1,18 +0,16 @@

import { ReactNode } from 'react';
export { FormatXMLElementFn } from 'intl-messageformat';
export declare type LanguageName = string;
export declare type TranslationKey = string;
export declare type TranslationMessage = string;
interface TranslationRequirements {
params?: Record<string, any>;
returnType: string | ReactNode;
}
export declare type TranslationRequirementsByKey = Record<string, TranslationRequirements>;
export declare type ParsedFormatFn = (parts: any) => any;
export declare type ParsedFormatFnByKey = Record<string, ParsedFormatFn>;
export declare type ICUFormatResult<T = unknown> = string | T | (string | T);
/**
* ParsedICUMessage A strictly typed formatter from intl-messageformat
*/
interface ParsedICUMessage<Requirements extends TranslationRequirements> {
format: Requirements['params'] extends Record<string, any> ? (params: Requirements['params']) => Requirements['returnType'] : () => Requirements['returnType'];
interface ParsedICUMessage<FormatFn extends ParsedFormatFn> {
format: FormatFn;
}
export declare type ParsedICUMessages<RequirementsByKey extends TranslationRequirementsByKey> = {
[key in keyof RequirementsByKey]: ParsedICUMessage<RequirementsByKey[key]>;
export declare type ParsedICUMessages<FormatFnByKey extends ParsedFormatFnByKey> = {
[key in keyof FormatFnByKey]: ParsedICUMessage<FormatFnByKey[key]>;
};

@@ -22,19 +20,19 @@ /**

*/
export declare type TranslationModule<RequirementsByKey extends TranslationRequirementsByKey> = {
getValue: (locale: string) => ParsedICUMessages<RequirementsByKey> | undefined;
export declare type TranslationModule<FormatFnByKey extends ParsedFormatFnByKey> = {
getValue: (locale: string) => ParsedICUMessages<FormatFnByKey> | undefined;
load: () => Promise<void>;
};
export declare type TranslationModuleByLanguage<Language extends LanguageName, RequirementsByKey extends TranslationRequirementsByKey> = Record<Language, TranslationModule<RequirementsByKey>>;
export declare type TranslationModuleByLanguage<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey> = Record<Language, TranslationModule<FormatFnByKey>>;
/**
* TranslationFile contains a record of TranslationModules per language, exposing a set of methods to load and return the module by language
*/
export declare type TranslationFile<Language extends LanguageName, RequirementsByKey extends TranslationRequirementsByKey> = {
export declare type TranslationFile<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey> = {
/**
* Retrieve messages. If not loaded, will attempt to load messages and resolve once complete.
*/
getMessages: (language: Language, locale?: string) => Promise<ParsedICUMessages<RequirementsByKey>>;
getMessages: (language: Language, locale?: string) => Promise<ParsedICUMessages<FormatFnByKey>>;
/**
* Retrieve already loaded messages. Will return null if no messages have not been loaded.
*/
getLoadedMessages: (language: Language, locale?: string) => ParsedICUMessages<RequirementsByKey> | null;
getLoadedMessages: (language: Language, locale?: string) => ParsedICUMessages<FormatFnByKey> | null;
/**

@@ -85,2 +83,1 @@ * Load messages for the given language. Resolving once complete.

};
export {};
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var intlMessageformat = require('intl-messageformat');
Object.defineProperty(exports, 'FormatXMLElementFn', {
enumerable: true,
get: function () {
return intlMessageformat.FormatXMLElementFn;
}
});
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var intlMessageformat = require('intl-messageformat');
Object.defineProperty(exports, 'FormatXMLElementFn', {
enumerable: true,
get: function () {
return intlMessageformat.FormatXMLElementFn;
}
});

@@ -1,1 +0,1 @@

export { FormatXMLElementFn } from 'intl-messageformat';
{
"name": "@vocab/types",
"version": "0.0.9",
"version": "1.0.0",
"main": "dist/vocab-types.cjs.js",

@@ -5,0 +5,0 @@ "module": "dist/vocab-types.esm.js",

@@ -5,30 +5,27 @@ # Vocab

## Getting started
Vocab helps you ship multiple languages without compromising the reliability of your site or slowing down delivery.
### Step 1: Install Dependencies
- Shareable translations
Vocab is a monorepo with different packages you can install depending on your usage, the below list will get you started using the cli, React and webpack integrations.
Translations are co-located with the components that use them. Vocab uses the module graph allowing shared components to be installed with package managers like npm, just like any other module.
```bash
$ npm i --save @vocab/cli @vocab/react @vocab/webpack
```
- Loading translations dynamically
### Step 2: Setup Webpack plugin
Vocab only loads the current user's language. If the language changes Vocab can load the new language behind the scenes without reloading the page.
Before starting to write code you'll need to setup webpack to understand how to use `translation.json` files.
- Strongly typed with TypeScript
This is done using the **VocabWebpackPlugin**.
When using translations TypeScript will ensure code only accesses valid translations and translations are passed all required dynamic values.
**webpack.config.js**
## Getting started
```js
const VocabWebpackPlugin = require('@vocab/webpack').default;
### Step 1: Install Dependencies
module.exports = {
...,
plugins: [new VocabWebpackPlugin({})]
}
Vocab is a monorepo with different packages you can install depending on your usage, the below list will get you started using the cli, React and webpack integrations.
```bash
$ npm i --save @vocab/cli @vocab/react @vocab/webpack
```
### Step 3: Configure Vocab
### Step 2: Configure Vocab

@@ -117,4 +114,21 @@ You can configure Vocab directly when calling the API or via a `vocab.config.js` file.

### Step 6: Optimize for fast page loading
### Step 6: [Optional] Setup Webpack plugin
Right now every language is loaded into your web application all the time, which could lead to a large bundle size. Ideally you will want to switch out the Node/default runtime for web runtime that will load only the active language.
This is done using the **VocabWebpackPlugin**. Applying this plugin to your client webpack configuration will replace all vocab files with a dynamic asynchronous chunks designed for the web.
**webpack.config.js**
```js
const { VocabWebpackPlugin } = require('@vocab/webpack');
module.exports = {
...,
plugins: [new VocabWebpackPlugin()]
}
```
### Step 7: [Optional] Optimize for fast page loading
Using the above method without optimizing what chunks webpack uses you may find the page needing to do an extra round trip to load languages on a page.

@@ -121,0 +135,0 @@

@@ -1,2 +0,2 @@

import { ReactNode } from 'react';
export { FormatXMLElementFn } from 'intl-messageformat';

@@ -8,24 +8,16 @@ export type LanguageName = string;

interface TranslationRequirements {
params?: Record<string, any>;
returnType: string | ReactNode;
}
export type TranslationRequirementsByKey = Record<
string,
TranslationRequirements
>;
export type ParsedFormatFn = (parts: any) => any;
export type ParsedFormatFnByKey = Record<string, ParsedFormatFn>;
export type ICUFormatResult<T = unknown> = string | T | (string | T);
/**
* ParsedICUMessage A strictly typed formatter from intl-messageformat
*/
interface ParsedICUMessage<Requirements extends TranslationRequirements> {
format: Requirements['params'] extends Record<string, any>
? (params: Requirements['params']) => Requirements['returnType']
: () => Requirements['returnType'];
interface ParsedICUMessage<FormatFn extends ParsedFormatFn> {
format: FormatFn;
}
export type ParsedICUMessages<
RequirementsByKey extends TranslationRequirementsByKey
> = {
[key in keyof RequirementsByKey]: ParsedICUMessage<RequirementsByKey[key]>;
export type ParsedICUMessages<FormatFnByKey extends ParsedFormatFnByKey> = {
[key in keyof FormatFnByKey]: ParsedICUMessage<FormatFnByKey[key]>;
};

@@ -36,8 +28,4 @@

*/
export type TranslationModule<
RequirementsByKey extends TranslationRequirementsByKey
> = {
getValue: (
locale: string,
) => ParsedICUMessages<RequirementsByKey> | undefined;
export type TranslationModule<FormatFnByKey extends ParsedFormatFnByKey> = {
getValue: (locale: string) => ParsedICUMessages<FormatFnByKey> | undefined;
load: () => Promise<void>;

@@ -48,4 +36,4 @@ };

Language extends LanguageName,
RequirementsByKey extends TranslationRequirementsByKey
> = Record<Language, TranslationModule<RequirementsByKey>>;
FormatFnByKey extends ParsedFormatFnByKey
> = Record<Language, TranslationModule<FormatFnByKey>>;

@@ -57,3 +45,3 @@ /**

Language extends LanguageName,
RequirementsByKey extends TranslationRequirementsByKey
FormatFnByKey extends ParsedFormatFnByKey
> = {

@@ -66,3 +54,3 @@ /**

locale?: string,
) => Promise<ParsedICUMessages<RequirementsByKey>>;
) => Promise<ParsedICUMessages<FormatFnByKey>>;
/**

@@ -74,3 +62,3 @@ * Retrieve already loaded messages. Will return null if no messages have not been loaded.

locale?: string,
) => ParsedICUMessages<RequirementsByKey> | null;
) => ParsedICUMessages<FormatFnByKey> | null;
/**

@@ -77,0 +65,0 @@ * Load messages for the given language. Resolving once complete.

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