npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vayjs/vay

v2.0.2

Published

[![Npm package version](https://badgen.net/npm/v/vay.js)](https://www.npmjs.com/package/vay.js)[![Npm package total downloads](https://badgen.net/npm/dt/vay.js)](https://npmjs.com/package/vay.js)[![Npm package license](https://badgen.net/npm/license/vay.j

Downloads

6

Readme

Vay.js

Npm package versionNpm package total downloadsNpm package licenseGithub tag

A lightweight (3kb minified), strongly typed, modern & dependency free internationalization (i18n) provider that features a simple API that supports interpolation, pluralization and context.

Installing

To use Vay with node and/or a bundler such as webpack or rollup, install it via yarn or npm:

yarn add @vayjs/vay
# or use npm
npm install @vayjs/vay

You can also use it directly in the browser and include it via CDN or locally.

<head>
    ...
    <!-- as a local file -->
    <script src="./your/path/to/vay.browser.min.js"></script>
    <!-- or via CDN -->
    <script src="http://unpkg.com/@vayjs/vay"></script>
    ...
</head>

Getting started

Setting up the initial Vay instance is quick and requires only a dictionary and a configuration object. Vay provides functions to create both, to utility editor autocompletion and type safety. For a more in depth guide on how to use Vay, take a look at the full documentation.

Start by importing or destructuring the required methods. You are free to use module or import syntax, Vay provides export for both standards. When included via CDN or locally, destructuring the globally accessible Vay property is the easiest way to access the API.

// node require syntax
const { Vay, defineConfig, defineDictionary } = require('vay.js');

// modern es6 style syntax
import { Vay, defineConfig, defineDictionary } from 'vay.js';

// if added to the global namespace
const { Vay, defineConfig, defineDictionary } = Vay;

Creating a Vay provider

To use Vay, create a new provider providing a config as well as any amount of dictionaries.

Note: The examples below assumes you're using es6.

import { defineConfig, defineDictionary, createProvider } from 'vay.js';

// create the Vay instance
const i18n = createProvider(
    defineConfig(), // create a default config
    defineDictionary('en', { token: 'Phrase' }), // create a dictionary
);

Note: The dictionary keys should follow the ISO 639-1 convention of two letter language codes.

Translating dynamic content using the translate() method

Vay also provides a function to translate strings dynamically. This can prove useful when Vay is used with a JavaScript framework, or when translating text that is dynamically created. When using TypeScript, the method is strongly typed and will only accepts tokens that exists in the dictionary as well as provide useful autocompletion suggestions deeding on the used IDE.

import { defineConfig, defineDictionary, createProvider } from '@vayjs/vay';

const i18n = createProvider(defineConfig(), defineDictionary('en', { title: 'Hello World' }));

i18n.translate('title'); // Return 'Hello World'

You can read more about the capabilities of the translate method on the official docs.

Translating static content using the createStaticProvider function

Use the render() method of a staticProvider to translate a subset of a provided HTML Element and it's descendants. The method should be called after the DOM has finished rendering and is best used for static websites.

<div vay="title"></div>

<script>
    const { defineConfig, defineDictionary, createProvider, createStaticProvider } = Vay;

    // setup the instance
    const i18n = createStaticProvider(
        createProvider(
            defineConfig(), // create a default config
            defineDictionary('en', { title: 'Hello World' }), // create a dictionary
        ),
    );

    // render the translations to the page
    window.addEventListener('DOMContentLoaded', () => {
        i18n.render(document.documentElement);
    });
</script>

The <div> with the token 'title' will have it's text-content replaced with the respective phrase in the dictionary, 'Hello World'. When ever the used changes the language, you can re-render the translations.

Contributing

If you would like to contribute, take a look at the contribution guide.

License

Vay is licensed under the MIT License