zwsp_codec 中文文档教程
zwsp_codec
zwsp_codec 是一个小模块,允许您将任意缓冲区和字符串编码和解码为表示形式 纯粹由零宽度空间组成。如果您想在不创建 URL 的情况下传输附加数据,这会很有用 更长。保证所使用的空间至少在 Discord 中可以在 URL 中使用。如果有其他消息应用程序 这些在哪里起作用,请告诉我,我会将它们添加到此描述中。
包含零宽度空格的示例链接
显然你看不到它,但是 https://example.com/ 之后的零宽度空格将被解码为 Hello, world!
。
入门
从 npm 安装软件包:
npm install zwsp_codec
然后您可以在程序中使用该模块:
// ES6
import { encodeZwsp, decodeZwsp } from 'zwsp_codec';
// Node.js
const { encodeZwsp, decodeZwsp } = require('zwsp_codec');
const buffer = Buffer.from('Hello, world!');
const encodedFromBuffer = encodeZwsp(buffer);
encodedFromBuffer // -> '\u200c\u2060\u200c\u200b\u200c\u200d\u200c\u200c\u200c\u2060\u200b\u2060\u200c\u2060\u200c\u200b'
const encodedFromString = encodeZwsp('Hello, world!');
encodedFromString === encodedFromBuffer // -> true
const decoded = decodeZwsp(encodedFromBuffer).toString('utf-8'); // -> 'Hello, world!'
encodeZwsp
可以对 Buffer
和 String
进行编码。保证输出与 UTF-8 相同。
decodeZwsp
将始终返回一个缓冲区,因此如果您想要一个字符串, 您需要使用decodeZwsp(encoded).toString('utf-8')来解码缓冲区。
许可证
zwsp_codec
zwsp_codec is a small module that allows you to encode and decode arbitrary buffers and strings to a representation purely made of zero-width spaces. This can be useful if you want to transmit additional data while not making your URL a lot longer. The spaces used are guaranteed to work in URLs at least for Discord. If there are other messaging apps where these work, let me know, and I'll add them to this description.
An example link with included zero-width spaces
Obviously you can't see it, but the zero-width spaces after https://example.com/ would be decoded to Hello, world!
.
Getting started
Install the package from npm:
npm install zwsp_codec
Then you can use the module in your programs:
// ES6
import { encodeZwsp, decodeZwsp } from 'zwsp_codec';
// Node.js
const { encodeZwsp, decodeZwsp } = require('zwsp_codec');
const buffer = Buffer.from('Hello, world!');
const encodedFromBuffer = encodeZwsp(buffer);
encodedFromBuffer // -> '\u200c\u2060\u200c\u200b\u200c\u200d\u200c\u200c\u200c\u2060\u200b\u2060\u200c\u2060\u200c\u200b'
const encodedFromString = encodeZwsp('Hello, world!');
encodedFromString === encodedFromBuffer // -> true
const decoded = decodeZwsp(encodedFromBuffer).toString('utf-8'); // -> 'Hello, world!'
encodeZwsp
can encode both Buffer
s and String
s. The output is guaranteed to be the same for UTF-8.
decodeZwsp
will always return a buffer, so if you want a string, you need to decode the buffer with decodeZwsp(encoded).toString('utf-8')
.
License
zwsp_codec is licensed under the WTFPL. For more information, see the LICENSE file.