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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dao3fun/cooh-storage

v2.2.1

Published

a small storage by cooh

Downloads

20

Readme

START

storageType<T, TT>

interface storageType<T, TT> T: 存储的数据类型 TT: 转成JSON后的数据类型 注意:T中可能有不可以转成JSON的数据。此时需要手动转成JSON.

属性 / 方法:

  • datas: T 存储的数据
  • fromJSON(storageType: TT): void 从JSON转成storageType<T, TT>
  • copy(storageType: storageType<T, TT>): void 让自己变成一个对象的副本。
  • toJSON(): TT 与fromJSON相反。

interface keyObject 用于自定义存入数据的键。

属性 / 方法:

  • getKey(): string; 把数据转成string。数据无要求。

示例:

export class MyKey implements keyObject {
  constructor(public userId: string) {}
  getKey() {
    return this.userId;
  }
} // Key为构造的userId.

class default_keyObject implements keyObject 用于GamePlayer的保存。 效果与上方示例相同。

属性 / 方法:

  • userId: string;
  • constructor(userId: string);
  • getKey(): string;

class cooh_storage<T, DATA, TT extends storageType<DATA, T>>

  • T: 存成的JSON格式
  • DATA: 需要存的数据
  • TT: 自己实现的storageType。 用于T与DATA互转

属性/方法:

构造函数: 传入参数:

  • type: 需要在组数据空间还是普通数据空间存数据
  • name: 数据库的名字
  • default_data: 没有数据的人默认数据

create(player: GamePlayer | keyObject): ValueObject

  • player: GamePlayer对象或自定义键。兼容GamePlayer对象是为了让存玩家数据的操作变得更加简单。

class ValueObject<
JSON,
DATA,
ST extends storageType<DATA, JSON>,
KEY extends keyObject>

属性/方法:

  • datas: ST; 存储数据
  • default: ST; 存储默认数据
  • player: KEY; 存储键
  • storage: GameDataStorage; 存储Storage
  • 构造函数 一般不会用到。通过cooh_storage构造。
  • async load() 加载数据
  • async save() 保存数据

export type GamePlayerStorage<
  T,
  DATA,
  TT extends storageType<DATA, T>,
> = ValueObject<T, DATA, TT, default_keyObject>;

存储玩家数据的数据库类型。 旨在让存储玩家数据更加简单。

END