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

window-open-batcher

v1.0.1

Published

window-open-batcher

Downloads

6

Readme

简介

在SPA中实现国际化,数据的来源一般有两种:

静态数据:写在js中,打包到前端文件里

动态数据: 通过后端接口返回

本工具适用于使用动态数据或者同时使用两者用的场景。该工具可以帮你整合数据,并作缓存。在需要国际化切换时,你只需要传入对应的语种。剩下的工作由工具帮你完成。

ps: 当存在缓存时,callback会可能先后执行两次,这是为了更好的用户体验:触发国际化切换直接使用缓存数据更新,此为第一次;第二次则是接口返回后,工具对比缓存发现不一样,再刷新一次。

Install

npm install TranslateManager -S

调用例子

npm run example

Quick Start

const translateManager = new TranslateManager({
    // 选填: 静态国际化数据
    staticLocaleData: {
        en: {
            title: 'hello world'
        },
        zh: {
            title: '你好,世界'
        }
    },
    // 必填:一个返回结果为promise的函数。promise里返回的是从后端获取的国际化数据
    requestFn: () => {
        return axios.get('xxx').then((res) => {
            return res; // 返回国际化数据
        }
    }
})

/**
* 主函数
* lang: 语种
* callback 回调方法
**/
translateManager.update(lang, (res) => {
    // res是可以直接使用的国际化数据,结合自己对应的业务要求编写代码
    // 业务代码...
});

constructor

| 参数名 | 是否必填 | 说明 | 默认 | | :----: | :----: | :----: | :----: | | requestFn | 是 | 获取动态国际化数据的方法 | - | | staticTranslateData | 否 | 静态国际化数据 | {} | | expireTime | 否 | 前端缓存时间 | Infinity | | storageKey | 否 | 缓存locastorage对应的名字 | LocaleGetter |