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

cocos-pkgjson

v1.0.8

Published

a pkgJson tool, convert plist file to json data. It can be custom pkgLoader used directly

Downloads

13

Readme

cocos-pkgjson

English

a pkgJson tool, convert plist file to json data. It can be custom pkgLoader used directly

中文说明

这是一个用于生成pkgJson的工具:将.plist文件中的数据提取出来,生成cocos底层SpriteFrame的数据结构,这样在加载.pkgJson之后,使用cc._pkgJsonLoader即可直接使用数据。避免了像在加载plist文件后,还需要解析plist数据才能生成底层需要的结构。简单言之:将解析plist的数据提前,减少网络请求,加快数据获取。

有这个想法写这个工具也是由于看到了这篇文章:cc.spriteFrameCache 改造说明,但是官方并没有提供pkgJson文件的生成方式,而且个人在生成pkgJson的同时,也在官方的原基础做了一次优化,生成的pkgJson一次到位,cc._pkgJsonLoader只负责将数据存储在cc.loader.cache中即可。

作用

parse(content) || parse(content, "frame")

parse spriteFrame

parse(content, other)(other !== "frame")

parse plist content to json

How to Use

Node.js

Install using npm:

npm i cocos-pkgjson

Then require() the cocos-pkgjson module in your file:

const fs = require('fs');
const pkgJson = require('cocos-pkgjson');

// Here I use fs.readFileSync get .plist file content
let content = fs.readFileSync("test.plist", "utf8");

console.log(JSON.stringify(pkgJson.parse(content)));
/**
 * content: Data to be parse
 * type: type of parse
 *      "frame": parse spriteFrame, default
 *      "other": only parse content to Json
 */
parse(content, type);

String result:

{"_inited":true,"frames":{"0.png":{"rect":{"x":1,"y":55,"width":64,"height":49},"rotated":false,"offset":{"x":0,"y":0},"size":{"width":64,"height":49},"aliases":[]},"1.png":{"rect":{"x":1,"y":1,"width":67,"height":52},"rotated":false,"offset":{"x":0,"y":0},"size":{"width":67,"height":52},"aliases":[]}},"meta":{"image":"radio.png"}}

Json result:

配套的cc._pkgJsonLoader

cc._pkgJsonLoader = {
    load: function (realUrl, url, res, cb) {
        var self = this, locLoader = cc.loader, cache = locLoader.cache;
        locLoader.loadJson(realUrl, function (err, pkg) {
            if (err) return cb(err);
            var dir = cc.path.dirname(url);
            for (var key in pkg) {
                var filePath = cc.path.join(dir, key);
                cache[filePath] = pkg[key];
            }
            cb(null, true);
        });
    }
};

cc.loader.register(["pkgJson"], cc._pkgJsonLoader);