Code Monkey home page Code Monkey logo

miao-lang's Introduction

喵语言(Miao-lang)

这是一个可以将人类语言翻译为喵语言的程序。

在线演示:https://miao-lang.com

特性

  • 可以将任意文本转为由若干“喵”组成的喵语言,且这个过程是可逆的
  • 支持网页、微信等常见应用,将喵语言复制到这些应用并发送不会损失信息

安装

npm install miao-lang

使用方法

import Miao from 'miao-lang'

let human_msg = 'Hello 喵星人!'
let miao_msg = Miao.encode(human_msg)

console.log(miao_msg) // 喵​‍‍‌‌‌​‌‍‍‌‌​‍‍‌‍‍​‍‍‍‌​‍‌‍​‌‍‍‌‌​‌‍‌​‌‌‍‌​‍‍喵​‍‍‍‍‍​‍‌‌​‍​‍‍​‍‌‍‍​‌‍‌‌​‌‌‌‍​‍‍​‍‌‌‌‍​‍‍‌‌​‌喵‌‌​‌‌‍​‌‌‍​‌‌‍‌‌​‌‌‍‍‍喵。

let msg2 = Miao.decode(miao_msg)

console.log(msg2) // Hello 喵星人!
console.log(msg2 === human_msg) // true

API

  • Miao.encode(t: string, options?: Human2miaoOptions): string 将普通文本转为喵语言
  • Miao.decode(t: string): string 将喵语言转为普通文本
  • Miao.isMiao(t: string): string 判断输入的文本是否为喵语言

Types

  • Human2miaoOptions
    • calls: string 动物叫声, 如: , ,
    • halfwidthSymbol: boolean 是否使用半角符号,如,.?!

多种族化

示例:

import Miao from 'miao-lang'

let human_msg = 'Hello 鸽子精!'
let gu_msg = Miao.encode(human_msg, { calls: '咕' })

console.log(gu_msg) // 咕咕咕咕。

国际化

示例:

import Miao from 'miao-lang'

let human_msg = 'Hello Guys.'
let msg = Miao.encode(human_msg, { calls: 'Meow ', halfwidthSymbol: true})

console.log(msg) // Meow ​‍‍‌‌‌​‌‍‍‌‌​‍‍‌‍‍​‍‍‍‌​‍‌‍​‌‍‍‌‌​‌‍‌​‌‌‍‌​‍‌Meow ‍‍‍​‌‍​‍‍‌‍‍​‍‍​‍‍‌​‌‌‍‌‌​‍‌​‌‌‌‌‍‌Meow .

工作原理

喵语言本质上是一种文本编码、解码算法,其原理为使用零宽字符将原文编码,并隐藏于若干“喵”之中。目前版本中所用到的零宽字符有 \u200b\u200c\u200d

其中编码流程如下:

  1. 生成 Base64 字符与零宽字符的对照表;
  2. 将原文转为 Base64 编码;
  3. 使用对照表将 Base64 编码后的内容转为由零宽字符组成的不可见的新编码;
  4. 根据一定规则,在新编码的最前、最后以及中间位置,插入若干“喵”以及标点符号;
  5. 完成。

解码过程则是以上流程的逆运算。

最后

本项目纯属娱乐,祝大家玩得开心! 愿喵之力与你同在!

miao-lang's People

Contributors

oldj avatar moonrailgun avatar

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.