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

localdb

v0.2.12

Published

Better localStorage

Downloads

59

Readme

LocalDB

NPM version NPM download Travis Build

Example

import localdb from 'localdb'
const Notes = new localdb('notes', 'Array', true)

// insert some collections and return the collections
let notes = Notes
  .add({title: 'Today is a big day', category: 'diary'})
  .add({title: 'I met my ex today', category: 'diary'})
  .add({title: 'Levandowski is amazing!', category: 'football'})
  .get()

// remove all post categoried in football
Notes.remove('category', 'football')

// find posts and update
const query = {title: 'diary'}
const opts = {limit: 2, sort: 1, sortBy: 'title', skip: 0}
Notes.find(query, opts).forEach(note => {
  note.author = 'egoist'
  Notes.save(note)
})

// override the whole database and generate meta
Notes.override([{title: 'New post'}], true)

// populate another class, eg: your Post have a Author field
const Post = new localdb('Post', 'Array')
const User = new localdb('User', 'Array')

// you should have the Author's objectId to create an instance of that class
const author = User.extend('some_object_id')

Post.add({
  title: 'mt post title',
  author: author
})

// then you can populate that field before .find or .findOne
Post.populate('author').findOne()

// create an Object database and set some property
const Site = new localdb('site', 'Object')
Site.set('sitename', 'Google')

// get sitename
const sitename = Site.get('sitename')

// destroy some database
Site.destroy()

API

new localdb(name:String, type = 'Array', timestamp = false)

new localdb(opts:Object)

创建一个新的数据库,可选类型为 Array,Object,并赋值给变量 db

db.add(obj:Object)

当类型为 Array 时可用,在数据库中增加一条集合

db.get(where)

wherenull 时,返回数据库中的内容,返回类型为 nullObjectArray

where 的类型为 string 或者 number 时返回对应的 Object[key] 或者 Array[index]

db.findOne(query:Object)

查询并返回符合条件的一个集合

db.find(query:Object, opts:Object)

查询并返回数个集合

var opts = { limit: 0, sortBy: 'index', sort: 1, skip: 0 }

db.save(obj:Oject)

当类型为 Array 时可用,obj 为 .findOne.find 返回的结果,类型为 Object,你可以作出更改之后用 .save 更新到数据库

db.set(key:String, value)

当类型为 Object 时可用,更新此数据库的一个键值对,没有则新建

db.inc/dec(key, number)

当类型为 Object 时可用,让一个 key 的值自增/自减 number 个单位, key 值不存在时默认为 0

db.remove(key:String, value)

当类型为 Array 按键值对删除对应的集合 当类型为 Object 时直接删除该 key

db.extend(objectId)

创建一个该数据库的 Pointer 用于 populate

db.populate(field)

.find.findOne 时获取该 field 指向的 collection

db.override(colleciton, reinit = false)

collection 整个覆盖旧的数据库

reinittrue 将自动按照 opts 配置为每个 Object 生成 _id createdAt updatedAt

db.destroy()

销毁数据库


相关文章: 一个简单的 localStorage 扩展实现

License

This project is released under SOX license that means you can do whatever you want to do, but you have to open source your copy on github if you let the public uses it. All copies should be released under the same license. The owner of each copy is only reponsible for his own copy, not for the parents, not for the children.

permitted use:
fork on github
change
do evil with your copy

prohibted use:
do evil with copies not of your own
open source your copy without declaring your parent copy