ohos_polyfill:基于 OpenHarmony 生态的 Node.js 模块适配项目

可用于 npm 仓中 Node.js built-in 基础模块的 api 适配,支持 events、path、buffer 等多个 Node.js 模块的部分接口,助力 OpenHarmony 环境下 Node.js 相关功能的实现。【此简介由AI生成】

Branch1Tags2

node-polyfill

Introduction

This project provides a polyfill that includes a subset of NodeJs modules. It is used for API adaptation of the Node.js built-in basic module in the npm repository. Currently, Currently supports [partial interfaces of the following modules(#interface).

How to Install

ohpm install @ohos/node-polyfill

For details about the OpenHarmony ohpm environment configuration, see OpenHarmony HAR.

Example

Refer to the code below to use the buffer module.

import { buffer } from "@ohos/node-polyfill";

const log = (message) => {
    console.log(message)
}

export function run_buffer (){
    const str = "This is a piece of text...";
    log("------ buffer demo start ------")
    const base64Str = buffer.Buffer.from(str).toString("base64");
    log ("str to base64 result: "+ base64Str);
    log("------ buffer demo end ------")
}

APIS

Currently, the Node APIs of the following modules are included:

Node.js Module Description Remarks
[events] Event triggering and listening. events Introduction
[path] Paths of files and directories. path Introduction
[buffer] Buffer. buffer Introduction
[stream] Stream. stream Introduction
[process] Process. process Introduction
[querystring] Query strings. querystring Introduction
[util] Utilities. util Introduction
[url] URLs. url Introduction
[timers] Timers. timers Introduction
[net] Network net Introduction
[crypto] Encryption. crypto Introduction
[string_decoder] String decoder. string_decoder Introduction

About obfuscation

  • Code obfuscation, please seeCode Obfuscation
  • If you want the node-polyfill library not to be obfuscated during code obfuscation, you need to add corresponding exclusion rules in the obfuscation rule configuration file obfuscation-rules.txt:
-keep
./oh_modules/@ohos/node-polyfill

Constraints

This project has been verified in the following version:

DevEco Studio: NEXT Beta1-5.0.3.806, SDK:API12 Release(5.0.0.66) DevEco Studio: 4.1.3.213, SDK: API 11 (4.1.2.5)

How to Contribute

If you find any problem during the use, submit an issue or a PR.

License

This project is licensed under Apache License 2.0.

Introduction

可用于 npm 仓中 Node.js built-in 基础模块的 api 适配,支持 events、path、buffer 等多个 Node.js 模块的部分接口,助力 OpenHarmony 环境下 Node.js 相关功能的实现。【此简介由AI生成】

Customize your domain