@ aryzing/ superqs
从任意值创建和解析 URL 安全查询字符串 .
安装方式
npm i @aryzing/superqs
# or
yarn add @aryzing/superqs
# or
pnpm i @aryzing/superqs
# or
bun add @aryzing/superqs
使用量
import { stringify, parse } from "@aryzing/superqs";
// Create a value of any type. This example uses an object, although any value
// can be used.
const data = {
bool: true,
undef: undefined,
nullVal: null,
date: new Date(),
hugeNum: 0xffffffffffffffffffffn,
bin: new Uint8Array([42, 24]),
};
// Create a URL-safe string representing the data above.
const stringifiedData = stringify(data);
// Use the stringified data to construct a URL.
const url = new URL(`https://example.com?data=${stringifiedData}`);
// Reconstruct the original data.
const params = new URLSearchParams(url.search);
const stringifiedDataParam = params.get("data");
const parsedData = parse(stringifiedDataParam);
// The `data` and `parsedData` values are equal.
expect(parsedData).toEqual(data); // true
使用大小写
- 将数据发送到浏览器扩展弹出.
- 创建包含应用程序状态的共享链接 .
- 将非文本数据传递给自定义元素 .
发展
开始
bun install
运行测试
bun run test
用
bun run build