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

awesome-indexdb

v1.0.0

Published

Lightweight, extensible, zero dependencies JavaScript indexDB.

Downloads

4

Readme

indexDB

Lightweight, extensible, zero dependencies JavaScript indexDB.

API

支持增删改查、条数。

getCount

获取总条数

db.getCount().then(res => {console.log(res)})

remove

删除条数

const count = 10; // 删除最早的10条
db.remove(count).then(res => {console.log(res)})

getRangeData

const lower = 1694885864655;
const upper = new Date().getTime();
const where = {
    level: "INFO"
}

// 查找时间段内 level 为 INFO 的数据。

db.getRangeData("time", lower, upper, where).then(res => {console.log(res)})

addList

// 新增数据(见demo)
db.addList([]).then(res => {console.log(res)})

update

// 更新某条数据
db.update({ id: 1, level: "ERROR", info: "1111", time: 1111 }).then(res => {console.log(res)})

test

// 测试 API
db.test().then(res => {console.log(res)})

esm 使用方式

    <script type="module">
        import DB from "./dist/index.esm.js"
        const db = new DB({
            dbname: "LOG_DB",
            tablename: "log",
            dbversion: 1,

            storeParams: {
                objectStoreParams: {
                    autoIncrement: true,
                    keyPath: "id"
                },
                indexs: [
                    {
                        indexName: "id",
                        key: "id",
                        unique: true
                    },
                    {
                        indexName: "level",
                        key: "level",
                        unique: false
                    },
                    {
                        indexName: "msg",
                        key: "msg",
                        unique: false
                    },
                    {
                        indexName: "time",
                        key: "time",
                        unique: false
                    },

                ]
            }
        });




        const lower = 1694885864655;
        const upper = new Date().getTime();
        setInterval(() => {
            const levelList = ["DEBUG", "INFO", "WARING", "ERROR", "FATAL"];
            const getIndex = () => {
                return Math.floor(Math.random() * (levelList.length))
            }
            const textList = [
                `The twinkling stars scatter

                In the fresh grass and became

                Countless bright fireflies`,
                `The vast sea asks the

                Yellow bleak desert whether it is

                Thirsty all year round.`,
                `The west envies the

                East ‘cause the red sun rises there

                Without exception.`,
                `Clock jumped down from the

                Wall he said he was too tired

                To serve me again.`,
                `A group of words are

                Weeping ‘cause they lost the way

                To enter my poems.`,
            ]
            const index = Math.floor(Math.random() * (levelList.length));
            const _info = levelList[getIndex()];





            db.getCount().then((count) => {
                console.log("all count", count)
                if (count > 800000) {
                    db.remove(10000).then((res) => {
                        console.log("remove", res)
                    })
                }
            });

            // db.getRangeData("time", lower, upper,).then(res => {
            //     console.log(res.length)
            //     // const str = JSON.stringify(res)

            //     // const encoder = new TextEncoder();
            //     // const encodedData = encoder.encode(str);
            //     // const byteSize = encodedData.length;

            //     // console.log("Byte Size:", byteSize / 1024 / 1024);

            //     // downloadTxtFile(str);
            // });

            const list = new Array(1000).fill({
                level: _info,
                msg: _info + "->" + new Date().toLocaleTimeString() + textList[getIndex()] + "\/n" + textList[getIndex()],
                time: new Date().getTime(),
                extra: null
            });

            db.addList(list).then(res => {
                console.log("addList", res);
            });

            // db.update({ id: 1, level: "ERROR", info: "1111", time: 1111 }).then(res => {
            //     console.log("update", res);
            // })

            // db.test("getAllKeys").then(res => {
            //     // console.log("test", res);
            // })

        }, 1000);

        function downloadTxtFile(text) {
            const element = document.createElement("a");
            const file = new Blob([text], { type: "text/plain" });
            element.href = URL.createObjectURL(file);
            element.download = "file.txt";
            document.body.appendChild(element); // 为了兼容 Firefox
            element.click();
            document.body.removeChild(element); // 为了兼容 Firefox
        }


    </script>

umd 使用方式

    <script src="./dist/index.umd.js">
    </script>
    <script>
        const db = new DB({
            dbname: "LOG_DB",
            tablename: "log",
            dbversion: 1,
            storeParams: {
                objectStoreParams: {
                    autoIncrement: true,
                    keyPath: "id"
                },
                indexs: [
                    {
                        indexName: "id",
                        key: "id",
                        unique: true
                    },
                    {
                        indexName: "level",
                        key: "level",
                        unique: false
                    },
                    {
                        indexName: "msg",
                        key: "msg",
                        unique: false
                    },
                    {
                        indexName: "time",
                        key: "time",
                        unique: false
                    },

                ]
            }
        });

        const lower = 1694885864655;
        const upper = new Date().getTime();
        setInterval(() => {
            const levelList = ["DEBUG", "INFO", "WARING", "ERROR", "FATAL"];
            const getIndex = () => {
                return Math.floor(Math.random() * (levelList.length))
            }
            const textList = [
                `The twinkling stars scatter

                In the fresh grass and became

                Countless bright fireflies`,
                `The vast sea asks the

                Yellow bleak desert whether it is

                Thirsty all year round.`,
                `The west envies the

                East ‘cause the red sun rises there

                Without exception.`,
                `Clock jumped down from the

                Wall he said he was too tired

                To serve me again.`,
                `A group of words are

                Weeping ‘cause they lost the way

                To enter my poems.`,
            ]
            const index = Math.floor(Math.random() * (levelList.length));
            const _info = levelList[getIndex()];





            db.getCount().then((count) => {
                console.log("all count", count)
                if (count > 800000) {
                    db.remove(10000).then((res) => {
                        console.log("remove", res)
                    })
                }
            });

            // db.getRangeData("time", lower, upper,).then(res => {
            //     console.log(res.length)
            //     // const str = JSON.stringify(res)

            //     // const encoder = new TextEncoder();
            //     // const encodedData = encoder.encode(str);
            //     // const byteSize = encodedData.length;

            //     // console.log("Byte Size:", byteSize / 1024 / 1024);

            //     // downloadTxtFile(str);
            // });

            const list = new Array(1000).fill({
                level: _info,
                msg: _info + "->" + new Date().toLocaleTimeString() + textList[getIndex()] + "\/n" + textList[getIndex()],
                time: new Date().getTime(),
                extra: null
            });

            db.addList(list).then(res => {
                console.log("addList", res);
            });

            // db.update({ id: 1, level: "ERROR", info: "1111", time: 1111 }).then(res => {
            //     console.log("update", res);
            // })

            // db.test("getAllKeys").then(res => {
            //     // console.log("test", res);
            // })

        }, 1000);

        function downloadTxtFile(text) {
            const element = document.createElement("a");
            const file = new Blob([text], { type: "text/plain" });
            element.href = URL.createObjectURL(file);
            element.download = "file.txt";
            document.body.appendChild(element); // 为了兼容 Firefox
            element.click();
            document.body.removeChild(element); // 为了兼容 Firefox
        }

    </script>