Giter VIP home page Giter VIP logo

utf8mb3's Introduction

utf8mb3

license npm

encode

Let mysql's utf8 encoding store four-byte characters such as emoji(让 mysql 的 utf8 编码存储表情符号这类的四字节字符).

Feature

  • Four-byte characters to three-byte characters(四字节字符转三字节字符)
  • Repeated coding remains unchanged(重复编码内容不变)
  • support wasm module(支持 wasm 使用)

JS Use

Detailed description 支持 nodejs 和 browser 环境

const {
  encode,
  decode,
  include_encode_utf8mb3,
  include_utf8mb4,
} = require("utf8mb3");

const str = "汉😊😊🛝🛝🛝汉";
// const str = "😊🛝🛝";

console.log(str, str.length);

const utf8mb3 = encode(str);

console.log("encodeUtf8mb4", utf8mb3, utf8mb3.length); // encodeUtf8mb4 汉ꂶꂶ鷶鷶鷶汉 12
console.log("decodeUtf8mb4", decode(utf8mb3)); // decodeUtf8mb4 汉😊😊🛝🛝🛝汉
console.log("include_encode_utf8mb3", include_encode_utf8mb3(utf8mb3)); // include_encode_utf8mb3 true
console.log("include_utf8mb4", include_utf8mb4(str)); // include_utf8mb4 true
console.log("include_utf8mb4", include_utf8mb4("测试")); // include_utf8mb4 false

Rust Use

Detailed description

let str = "😊";
let result = utf8mb3::encode(str);
println!("encode: {}", result); // encode: 
println!("decode: {}", utf8mb3::decode(&result)); // decode: 😊

WASI Use

...

Performance

MacOS: 13 , MacBook Pro m1 2021

Source 10000000 😊 coding time Test Script
nodejs native 684.573ms commemorate/utf8mb3-js/test.js
rust native 61.85475ms packages/utf8mb3/src/lib.rs
wasm run nodejs 96.927ms packages/utf8mb3-wasm/examples/utf8mb3-js-nodejs-play
wasm run edge browser 100.6ms packages/utf8mb3-wasm/examples/utf8mb3-js-browser-play
wasi run wasmedge AOT 35ms
wasi run warmer 60ms
wasi run wasmtime 70ms

License

MIT

utf8mb3's People

Contributors

lydanne avatar

Stargazers

Zero avatar Dujianjun avatar  avatar

Watchers

 avatar

Forkers

bjxgj

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.