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

niba-data

v0.1.5

Published

A simple, easy-to-use web storage solution

Downloads

14

Readme

niba-data

A super simple web storage tool that can be used in browsers as well as in Node environments.

一个超级简单的 Web 存储工具,可用于浏览器,也可用于 Node 环境。

-----------|---------|----------|---------|---------|-------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------|---------|----------|---------|---------|-------------------
All files  |   96.21 |    76.52 |   97.36 |   96.21 |
 base.js   |   98.49 |    79.22 |     100 |   98.49 | 200,298
 helper.js |   96.15 |       84 |     100 |   96.15 | 50
 index.js  |       0 |        0 |       0 |       0 |
 logger.js |      50 |      100 |       0 |      50 | 4
 pager.js  |    87.5 |    46.15 |     100 |    87.5 | 25,45,67
-----------|---------|----------|---------|---------|-------------------

install 安装

npm i niba-data

define model 定义模型

class Organ extends NBModel {
  propsMap = {
    name: String,
    spell: String,
    kind: String,
    parent_id: String,
    state: Number,
    remark: String,
    avatar_id: String,
    create_time: Date,
  };

  fulltext = ["name", "spell", "remark"];

  constructor() {
    super({ name: "organs" });
  }
}

save 保存

const organ = new Organ();
const { _id } = await organ.save({
  name: `测试机构`,
  spell: `csjg`,
  avatar_id: null,
  kind: "0",
  parent_id: "178b7af3-4c85-4dc0-8a25-8c80db425ae8",
  state: 1,
  remark: null,
  create_time: new Date(),
});

upsert 保存或更新

const organ = new Organ();
const saved = await organ.upsert({
  name: `测试机构`,
  spell: `csjg`,
  avatar_id: null,
  kind: "0",
  parent_id: "178b7af3-4c85-4dc0-8a25-8c80db425ae8",
  state: 1,
  remark: null,
  create_time: new Date(),
});

await organ.upsert({
  ...saved,
  ...{
    name: "测试机构X",
  },
});

read 读取

const indb = await organ.get(saved._id);

delete 删除

const result = await organ.delete(_id);

query 查询

const selector = {
  kind: "30",
  spell: "csjg_86",
};

const organ = new Organ();
const result = await organ.query({ selector, sort: ["name"] });

分页

const organ = new Organ();
const result = await organ.pagedQuery({
  selector: {
    spell: "csjg_86",
  },
  sort: ["name"],
  page: 1,
  rows: 10,
});

全文检索

const organ = new Organ();
const result = await organ.search({
  kws: "_86",
  sort: [{ name: "asc" }],
});

分页全文检索

const organ = new Organ();
const result = await organ.pagedSearch({
  kws: "_86",
  rows: 2,
});