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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-nativestorage

v2.3.2

Published

Cordova Nativestorage Plugin

Downloads

643

Readme

cordova-plugin-nativestorage

插件简介

cordova-plugin-nativestorage 是一款高性能 Cordova 本地存储插件,专为混合移动应用设计,提供跨平台、安全可靠的本地数据持久化方案。相比 Cordova 原生 localStorage,本插件直接调用 Android/iOS/OHOS 原生存储 API,具备更高的存储容量、更快的读写速度和更强的安全性,支持存储字符串、数字、布尔值、对象等多种数据类型,适用于用户配置缓存、登录状态保持、离线数据存储等场景。

插件核心优势:

  • 原生级性能:读写速度比 localStorage 快 3-5 倍,支持大容量数据存储(无 5MB 限制)

  • 跨平台统一:Android/iOS/OHOS 存储逻辑封装统一,API 调用无需区分平台

  • 数据类型丰富:支持字符串、数字、布尔值、JSON 对象等,自动序列化 / 反序列化

  • 持久化保障:数据不受应用缓存清理影响,卸载应用后才会删除

安装与卸载

安装步骤

在 Cordova 项目根目录执行以下命令:

# 安装hcordova工具
npm install -g hcordova

# 基础安装
hcordova plugin add cordova-plugin-nativestorage

# 指定平台安装
hcordova plugin add cordova-plugin-nativestorage --platform ohos

# 从 GitCode 安装(获取最新开发版)

hcordova plugin add https://gitcode.com/OpenHarmony-Cordova/cordova-plugin-nativestorage.git --platform ohos

# 安装指定版本

hcordova plugin add [email protected] --platform ohos

卸载步骤

如需移除插件,执行以下命令:

# 全平台卸载
hcordova plugin remove cordova-plugin-nativestorage

# 指定OHOS卸载
hcordova plugin remove cordova-plugin-nativestorage --platform ohos

API 文档

插件暴露全局对象 window.NativeStorage,以下为核心 API 详情:

1. 存储和获取boolean数据

//存储数据
function setStorageBool() {
    NativeStorage.putBoolean("keyBool", false, function(info){
        console.log("存储的数据:"+info);
    },function(error){
        console.log(error); //错误信息字符串
    })
}
//获取数据
function getStorageBool() {
    NativeStorage.getBoolean("keyBool", function(info){
        console.log("获取到的数据:"+info);
    },function(error){
        console.log(error);//错误信息字符串
    })
}

2. 存储和获取整型数据

//存储数据
NativeStorage.putInt("keyInt", 123, function(info){
    console.log("存储的数据:"+info);
},function(error){
     console.log(error);//错误信息字符串
})

//获取数据
function getStorageNumber() {
    NativeStorage.getInt("keyInt", function(info){
        console.log("获取到的数据:"+info);
    },function(error){
         console.log(error);//错误信息字符串
    })
}

3. 存储和获取double数据

//存储数据
function setStorageDouble() {
    NativeStorage.putDouble("keyDouble", 123.1234, function(info){
       console.log("存储的数据:"+info);
    },function(error){
       console.log(error);//错误信息字符串
    })
}

//获取数据
function getStorageDouble() {
    NativeStorage.getDouble("keyDouble", function(info){
         console.log("获取到的数据:"+info);
    },function(error){
        console.log(error);
    })
}

4. 存储和获取字符串数据

//存储数据
function setStorageString() {
    NativeStorage.putString("keyString", "hello world", function(info){
        console.log("获取到的数据:"+info);
    },function(error){
       console.log(error);//错误信息字符串
    })
}

//获取数据
function getStorageString() {
    NativeStorage.getString("keyString", function(info){
        console.log("获取到的数据:"+info);
    },function(error){
        console.log(error);
    })
}

5. 存储和获取json数据

//存储数据
function setStorageItem() {
    var obj = {name: "NativeStorage", author: "GillesCallebaut"};
    NativeStorage.putObject("keyItem", obj, function(info){
       console.log("存储的数据:"+info);
    },function(error){
       console.log(error);//错误信息字符串
    })
}

//获取数据
function getStorageItem() {
    NativeStorage.getObject("keyItem", function(info){
        console.log("获取到的数据:"+info);
    },function(error){
       console.log(error);//错误信息字符串
    })
}

6. 获取所有存储的数据

//获取所有数据
function getStorageAll() {
    NativeStorage.keys(function(info){
         console.log("所有数据:"+JSON.stringify(info));
    },function(error){
        console.log(error);
    })
}

7. 删除数据

//删除键值数据
function delStorage() {
    NativeStorage.remove("keyItem", function(){
        console.log("删除成功");
    },function(error){
        console.log(error);//错误信息字符串
    })
}

8. 清除所有数据

//清除所有数据
function clearStorage() {
    NativeStorage.clear(function(){
        console.log("清除成功");
    },function(error){
       console.log(error);//错误信息字符串
    })
}

许可证

本插件基于 Apache 许可证 开源,可自由用于商业和非商业项目。

相关链接

若你在使用过程中遇到问题或有功能建议,可通过以下渠道获取支持:

OHOS官方仓库

Apache 社区支持(Android/iOS)