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

json2memory

v1.0.0

Published

a plugin for pomelo to load json file

Downloads

2

Readme

json2memory

a plugin for pomelo to load json file

作用分析

  • 游戏研发当中,程序要提供配置接口给数值策划,让数值策划根据自己的计算填出理想的数值.
  • 在数值填好excel数据后,一般会用倒表工具导出到json文件,再由程序启动的时候读取json文件到内存.称之为静态数据.
  • 开发项目都会需要静态数据,那导入json文件到内存的工作便可以造一个轮子.
  • 该插件基于pomelo,将json文件夹下的所有json文件中的数据读取到内存,以供程序使用.

使用方法

  • 进入pomelo项目的game-server下,运行npm命令下载插件
npm install json2memory --save
  • 在config下增加json2memory目录,在json2memory目录下增加config.json
{
  "development": "/app/data/json",    // 指向存放json文件的文件夹
  "production": "/app/data/json"      // 指向存放json文件的文件夹
}
  • 获取静态数据的方法有两种
  1. 获取某个文件的所有数据
require('json2memory').getData('jsonName'); // 'jsonName'为某个json文件的文件名
  1. 根据id获取某个文件下id对应的数据(对象数据直接获取id对应数据,数组数据则将id作为下标获取数据)
require('json2memory').getDataById('jsonName', 'id'); // id为json数据下的某个key

注意

该插件并未设置数据只读,使用数据的时候切莫随意更改数据内容,否则静态数据的内容就有可能变成更改后的样子.